Skip to content

fix(go.d): remove only the stale peer's/device's charts in ntpd and nvme - #24542

Closed
b84330808 wants to merge 1 commit into
netdata:masterfrom
b84330808:fix-ntpd-nvme-chart-removal
Closed

b84330808 wants to merge 1 commit into
netdata:masterfrom
b84330808:fix-ntpd-nvme-chart-removal

Conversation

@b84330808

@b84330808 b84330808 commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor
Summary

Refs #24230 (same bug as the docker case there, which #24539 fixes)

ntpd and nvme remove the charts of a peer/device that went away by an unterminated chart ID prefix:

  • ntpd removePeerCharts: peer_<addr>, so removing peer 10.0.0.1 also marks every chart of 10.0.0.10-10.0.0.19 obsolete.
  • nvme removeDeviceCharts: device_<name>, so removing nvme1 also hits nvme10-nvme19.

The peer/device that is still there stays in peerAddr/devicePaths, so its charts are never added again until go.d.plugin restarts.

Both now match the exact chart IDs built from peerChartsTmpl/deviceChartsTmpl.

Test Plan
  • ntpd: TestCollector_Collect_RemovesOnlyChartsOfStalePeer collects peers 203.0.113.1 and 203.0.113.10, then again with only .10, and compares the obsolete flag of every peer chart.
  • nvme: TestCollector_Collect_RemovesOnlyChartsOfRemovedDevice does the same with /dev/nvme1n1 and /dev/nvme10n1.

On master both fail (all 203_0_113_10 / nvme10 charts are obsolete); with the fix they pass. go test -count=1 ./plugin/go.d/collector/ntpd/... ./plugin/go.d/collector/nvme/... and go vet pass, except nvme TestCollector_Init, which needs the nvme binary (not installed here) and fails the same way on master.

Additional Information

wireguard has the same pattern (device_%s, so wg1 vs wg10). I kept this PR to ntpd and nvme.

I used Claude Code to write this change.

For users: How does this change affect me?
  • ntpd (go.d/ntpd) peer charts and NVMe (go.d/nvme) device charts.
  • When an NTP peer or an NVMe controller goes away, the charts of other peers/devices whose address or name starts with the same string (e.g. 10.0.0.10 after 10.0.0.1, nvme10 after nvme1) no longer disappear.

Summary by cubic

Fixes ntpd and nvme chart removal so only the stale peer's or device's charts are marked obsolete.

Previously chart IDs were matched by an unterminated prefix: removing peer 10.0.0.1 also marked every chart of 10.0.0.10–10.0.0.19 obsolete, and removing /dev/nvme1 did the same to nvme10–nvme19. The surviving peer/device stayed in the collector's lists, so its charts were never re-created until the plugin restarted. Both collectors now match the exact chart IDs built from their chart templates.

wireguard has the same prefix-matching pattern (device_%s) and may need the same fix.

  • Regression tests added for both collectors covering peers /dev/nvme1n1 and /dev/nvme10n1 with the non-stale device still present.

Written for commit 62abd92. Summary will update on new commits.

View guided diff

Summary by CodeRabbit

  • Bug Fixes
    • Corrected chart cleanup for NTP peers and NVMe devices. When a peer or device disappears, only its charts are marked obsolete; charts for other active peers or devices with similar names remain available.

removePeerCharts (ntpd) and removeDeviceCharts (nvme) matched chart IDs
by an unterminated prefix: "peer_<addr>" and "device_<name>". Removing
peer 10.0.0.1 also marked every chart of 10.0.0.10-10.0.0.19 as obsolete,
and removing nvme1 did the same to nvme10-nvme19. The surviving peer or
device stays in peerAddr/devicePaths, so its charts were never re-created
until the plugin restarted.

Match the exact chart IDs built from the peer/device chart templates
instead.

Refs netdata#24230

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@b84330808
b84330808 requested a review from ilyam8 as a code owner November 2, 2026 17:03
@github-actions github-actions Bot added area/collectors Everything related to data collection collectors/go.d area/go labels Nov 2, 2026
@coderabbitai

coderabbitai Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: fa1082ce-54e1-46ce-9c9a-4e5d8814fa39
Commits

Reviewing files that changed from the base of the PR and between 93cf0d0 and 62abd92.

Files selected for processing: 4
  • src/go/plugin/go.d/collector/ntpd/charts.go
  • src/go/plugin/go.d/collector/ntpd/collector_test.go
  • src/go/plugin/go.d/collector/nvme/charts.go
  • src/go/plugin/go.d/collector/nvme/collector_test.go

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

Walkthrough

The ntpd and NVMe collectors now remove stale-object charts by matching IDs generated from each object's chart templates, rather than by prefix. Regression tests cover peer IDs 1 and 10 and devices nvme1n1 and nvme10n1.

Changes: Stale-object chart removal

Layer / File(s) Summary
ntpd peer chart removal
src/go/plugin/go.d/collector/ntpd/charts.go, src/go/plugin/go.d/collector/ntpd/collector_test.go
Peer chart removal matches IDs generated from peer chart templates. A regression test confirms that removing peer 1 does not obsolete peer 10 charts.
NVMe device chart removal
src/go/plugin/go.d/collector/nvme/charts.go, src/go/plugin/go.d/collector/nvme/collector_test.go
Device chart removal matches IDs generated from device chart templates. A regression test confirms that removing nvme1n1 does not obsolete nvme10n1 charts.

Estimated code review effort: 2 (Simple) | ~12 minutes

Change: Bug fix · Severity of issue fixed: Low

Possibly related PRs

  • netdata/netdata#24402: Fixes the same open-prefix chart ownership bug in the k8s_state collector with exact chart identity matching.
  • netdata/netdata#24539: Fixes the same chart removal bug in the Docker collector by generating exact chart IDs from object templates.

Suggested labels: area/collectors, collectors/go.d, area/go

Merge Risk: Minimal · up to 62abd

The change targets stale-chart removal without an identified merge-blocking issue.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: limiting stale chart removal to the affected peers and devices in the ntpd and nvme collectors.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 2 functions across 4 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches
Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@cubic-dev-ai cubic-dev-ai 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.

No issues found across 4 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.
Architecture diagram
sequenceDiagram
    participant NTPD as ntpd Collector
    participant NVMe as nvme Collector
    participant Charts as Charts Store
    participant Client as NTP Client / NVMe CLI

    Note over NTPD,Charts: NTPD Peer Chart Management
    
    NTPD->>Client: getPeerIDs()
    Client-->>NTPD: Peer list [1, 10]
    NTPD->>NTPD: Build peer chart IDs from peerChartsTmpl
    NTPD->>Charts: Add charts for peer_203_0_113_1
    NTPD->>Charts: Add charts for peer_203_0_113_10

    Note over NTPD,Charts: Peer 203.0.113.1 goes stale
    
    NTPD->>Client: getPeerIDs()
    Client-->>NTPD: Peer list [10]
    NTPD->>NTPD: Build exact chart IDs for stale peer (peer_203_0_113_1)
    NTPD->>Charts: MarkRemove() only peer_203_0_113_* charts
    Charts-->>NTPD: Peer 203_0_113_10 charts remain active

    Note over NVMe,Charts: NVMe Device Chart Management
    
    NVMe->>Client: listDevices()
    Client-->>NVMe: Devices [nvme1, nvme10]
    NVMe->>NVMe: Build device chart IDs from deviceChartsTmpl
    NVMe->>Charts: Add charts for device_nvme1
    NVMe->>Charts: Add charts for device_nvme10

    Note over NVMe,Charts: /dev/nvme1 goes stale
    
    NVMe->>Client: listDevices()
    Client-->>NVMe: Devices [nvme10]
    NVMe->>NVMe: Build exact chart IDs for stale device (nvme1)
    NVMe->>Charts: MarkRemove() only device_nvme1_* charts
    Charts-->>NVMe: Device nvme10 charts remain active
Loading

View guided diff | Re-trigger cubic

@sonarqubecloud

sonarqubecloud Bot commented Nov 2, 2026

Copy link
Copy Markdown

@b84330808

Copy link
Copy Markdown
Contributor Author

Closing too, same reason (v2 conversion is the better fix). Thanks!

@b84330808 b84330808 closed this Nov 3, 2026
@ilyam8

ilyam8 commented Nov 3, 2026

Copy link
Copy Markdown
Member

And do not touch multiple collectors within a single PR - handle them one by one.

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

Labels

area/collectors Everything related to data collection area/go collectors/go.d

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants