Skip to content

feat(health): add skip_initial_history flag to periodic log collector. False by default#3694

Open
cdraman wants to merge 1 commit into
NVIDIA:mainfrom
cdraman:HAAS-171
Open

feat(health): add skip_initial_history flag to periodic log collector. False by default#3694
cdraman wants to merge 1 commit into
NVIDIA:mainfrom
cdraman:HAAS-171

Conversation

@cdraman

@cdraman cdraman commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

When forge-hw-health runs in periodic log collection mode, the first poll against a LogService with no saved cursor drains the full entry history. For clusters that have accumulated thousands of historical entries including past XID faults or CPER records, this creates noise on startup and makes it hard to distinguish pre-existing events from new real-time faults.

Add skip_initial_history to collectors.logs.periodic (and the auto-mode fallback config). When true, the collector fetches all current entries on the first encounter of an unseen LogService, records the highest entry ID as the cursor, and discards the entries without emitting them. Subsequent polls collect only new entries from that point forward, matching the real-time-only behavior of SSE mode.

skip_initial_history is set to false by default and hence there is no change in behavior

Related issues

Closes #3636

Type of Change

  • Add - New feature or capability
  • Change - Changes in existing functionality
  • Fix - Bug fixes
  • Remove - Removed features or deprecated functionality
  • Internal - Internal changes (refactoring, tests, docs, etc.)

Breaking Changes

  • This PR contains breaking changes

Testing

  • Unit tests added/updated
  • Integration tests added/updated
  • Manual testing performed
  • No testing required (docs, internal refactor, etc.)

Additional Notes

Validated against a BMC with 4 GPU XID log services containing historical XID 149 entries:

  • Current (skip_initial_history=false): collector drained all historical entries on first poll, emitting existing XID events.
  • With the changes (skip_initial_history=true): collector logged skip_initial_history: anchored at current log position for all 4 services, emitting zero historical log events.

When `forge-hw-health` runs in periodic log collection mode, the first
poll against a LogService with no saved cursor drains the full entry
history. For clusters that have accumulated thousands of historical
entries — including past XID faults or CPER records — this creates
noise on startup and makes it hard to distinguish pre-existing events
from new real-time faults.

Add `skip_initial_history` to `collectors.logs.periodic` (and the
auto-mode fallback config). When `true`, the collector fetches all
current entries on the first encounter of an unseen LogService, records
the highest entry ID as the cursor, and discards the entries without
emitting them. Subsequent polls collect only new entries from that
point forward, matching the real-time-only behaviour of SSE mode.

Closes NVIDIA#3636

- [x] **Add** - New feature or capability
- [ ] **Change** - Changes in existing functionality
- [ ] **Fix** - Bug fixes
- [ ] **Remove** - Removed features or deprecated functionality
- [ ] **Internal** - Internal changes (refactoring, tests, docs, etc.)

- [ ] **This PR contains breaking changes**

- [ ] Unit tests added/updated
- [ ] Integration tests added/updated
- [x] Manual testing performed
- [ ] No testing required (docs, internal refactor, etc.)

Validated on `vr-nvl72-ts2-l11-032-c01` (10.71.23.88) against a BMC
with 4 GPU XID log services containing historical XID 149 entries:

- Current (skip_initial_history=false): collector drained all
  historical entries on first poll, emitting existing XID events.
- With the changes (skip_initial_history=true): collector logged
  `skip_initial_history: anchored at current log position` for all 4
  services, emitting zero historical log events.

Signed-off-by: Dasa Chandramouli <dchandramoul@nvidia.com>
@cdraman
cdraman requested a review from a team as a code owner July 17, 2026 20:52
@coderabbitai

coderabbitai Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Summary by CodeRabbit

  • New Features
    • Added a skip_initial_history setting for periodic and automatic log collection.
    • When enabled, existing log entries are skipped on first discovery, while newly generated entries continue to be collected.
    • Documented the setting in the example configuration; it is disabled by default.

Walkthrough

Adds skip_initial_history to periodic log configuration, propagates it through collector startup, and anchors first-seen log services at their current highest entry ID without emitting historical records when enabled.

Changes

Periodic log history handling

Layer / File(s) Summary
Configuration contracts and examples
crates/health/src/config.rs, crates/health/example/config.example.toml
Adds skip_initial_history to periodic configuration with a default of false, and documents it for auto and periodic modes.
Collector option propagation
crates/health/src/collectors/logs/periodic.rs, crates/health/src/discovery/spawn.rs
Adds the option to LogsCollectorConfig and passes it from periodic configuration into the collector.
Initial history anchoring
crates/health/src/collectors/logs/periodic.rs
On first observation of an untracked LogService, stores the highest parseable entry ID and skips existing records when enabled; the prior behavior remains when disabled.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant PeriodicLogConfig
  participant spawn_periodic_logs
  participant LogsCollector
  participant LogService
  participant PersistentState

  PeriodicLogConfig->>spawn_periodic_logs: provide skip_initial_history
  spawn_periodic_logs->>LogsCollector: construct collector configuration
  LogsCollector->>LogService: fetch entries
  LogsCollector->>PersistentState: store highest entry ID
  LogsCollector-->>PersistentState: emit no historical records on first poll
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the primary change: adding a skip_initial_history flag with default false.
Description check ✅ Passed The description accurately matches the implemented change and its intended periodic log behavior.
Linked Issues check ✅ Passed The PR satisfies #3636 by adding the new flag, defaulting it to false, and skipping initial historical entries when enabled.
Out of Scope Changes check ✅ Passed The changes stay within the requested scope, covering config, collector behavior, and spawn plumbing for the new flag.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@crates/health/src/collectors/logs/periodic.rs`:
- Around line 331-364: Update the skip_initial_history initialization flow
around last_seen_ids so services are durably marked initialized even when
all_entries is empty or contains no parseable numeric IDs; distinguish this
marker from a missing last_seen_id so subsequent entries are collected rather
than discarded as initial history. Add table-driven coverage for empty,
non-parseable, and numeric initial histories, preserving the existing numeric
anchor behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: bcb88826-4d76-49fc-8281-f0300655f4db

📥 Commits

Reviewing files that changed from the base of the PR and between 0dae3ca and 96a5876.

📒 Files selected for processing (4)
  • crates/health/example/config.example.toml
  • crates/health/src/collectors/logs/periodic.rs
  • crates/health/src/config.rs
  • crates/health/src/discovery/spawn.rs

Comment on lines +331 to 364
None => {
let all_entries = match service.entries().await {
Ok(Some(v)) => v,
Ok(None) => continue,
Err(error) => {
fetch_failures += 1;
tracing::warn!(
%service_id,
?error,
"Failed to fetch log entries"
);
continue;
}
};

if self.skip_initial_history {
// Anchor at the current highest entry ID without emitting
// historical entries, so the next poll collects only new
// entries. Matches the real-time-only behaviour of SSE.
let anchor = all_entries
.iter()
.filter_map(|e| e.base.id.parse::<i32>().ok())
.max();
if let Some(id) = anchor {
state.last_seen_ids.insert(service.odata_id().clone(), id);
tracing::info!(
%service_id,
anchor_id = id,
"skip_initial_history: anchored at current log position, \
skipping historical entries"
);
}
continue;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift

Persist initialization for services without a numeric anchor.

At Line 354, state is updated only when an entry ID parses. An initially empty service therefore remains unseen; if an entry arrives before the next poll, it is anchored and discarded as “initial history.” The same applies when the initial entries have no parseable numeric IDs.

Persist a separate durable initialized-service marker, distinguish it from a missing last_seen_id, and add table-driven coverage for empty, non-parseable, and numeric initial histories.

As per coding guidelines, “Use table-driven tests for functions mapping inputs to outputs or errors.”

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@crates/health/src/collectors/logs/periodic.rs` around lines 331 - 364, Update
the skip_initial_history initialization flow around last_seen_ids so services
are durably marked initialized even when all_entries is empty or contains no
parseable numeric IDs; distinguish this marker from a missing last_seen_id so
subsequent entries are collected rather than discarded as initial history. Add
table-driven coverage for empty, non-parseable, and numeric initial histories,
preserving the existing numeric anchor behavior.

Source: Coding guidelines

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(health): add skip_initial_history flag to periodic log collector

1 participant