Skip to content

fix(go.d/wireguard): remove only the removed device's charts - #24568

Closed
b84330808 wants to merge 1 commit into
netdata:masterfrom
b84330808:fix-wireguard-remove-device-charts
Closed

b84330808 wants to merge 1 commit into
netdata:masterfrom
b84330808:fix-wireguard-remove-device-charts

Conversation

@b84330808

@b84330808 b84330808 commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor
Summary

Follow-up to #24542 (same bug class, refs #24230).

wireguard removeDeviceCharts matches chart IDs by the unterminated prefix device_<name>, so removing wg1 also marks every chart of wg10-wg19 obsolete. The surviving device stays in c.devices, so its charts are never added again until go.d.plugin restarts.

It now matches the exact chart IDs built from deviceChartsTmpl, like ntpd and nvme in #24542. Peer chart IDs contain the full 44-character public key, so removePeerCharts can't hit another peer this way and is left alone.

Test Plan

New TestCollector_Collect case "device removed at run time, device with a longer name is kept": it collects wg1 and wg10, drops wg1, runs the cleanup, and checks that only the device_wg1_* charts are obsolete. On master it fails (device_wg10_network_io and device_wg10_peers are obsolete too); with the fix it passes. go test -count=1 ./plugin/go.d/collector/wireguard/ and go vet pass.

Additional Information

I used Claude Code to write this change.

For users: How does this change affect me?
  • WireGuard (go.d/wireguard) device charts.
  • When a WireGuard interface goes away, the charts of other interfaces whose name starts with the same string (e.g. wg10 after wg1) no longer disappear.

Summary by cubic

Fixes the WireGuard collector so removing a device only removes that device's charts, not the charts of devices with longer names that share the same prefix (e.g., removing wg1 no longer marks wg10 charts as obsolete).

  • Matches exact chart IDs from deviceChartsTmpl instead of using an unterminated prefix match.
  • Adds a test case covering device removal with a longer-named device still present.

Written for commit 0471c56. Summary will update on new commits.

View guided diff

Summary by CodeRabbit

  • Bug Fixes
    • Removing a WireGuard device now marks only that device’s charts as obsolete. Charts for other devices with similar names remain available, preventing unintended chart cleanup when device names share a prefix.

removeDeviceCharts matched chart IDs by an unterminated prefix,
"device_<name>", so removing wg1 also marked every chart of wg10-wg19
as obsolete. The surviving device stays in c.devices, so its charts
were never re-created until the plugin restarted.

Match the exact chart IDs built from deviceChartsTmpl instead, as in
ntpd and nvme.

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

coderabbitai Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Walkthrough

WireGuard device chart cleanup now matches exact chart IDs generated from the device chart template. A collection test covers removing wg1 while retaining wg10.

Changes: WireGuard chart cleanup

Layer / File(s) Summary
Exact device chart matching
src/go/plugin/go.d/collector/wireguard/charts.go, src/go/plugin/go.d/collector/wireguard/collector_test.go
removeDeviceCharts matches exact IDs generated from deviceChartsTmpl. The collection test verifies that cleanup marks wg1 charts obsolete without marking wg10 charts obsolete.

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

Change: Bug fix

Possibly related PRs

  • netdata/netdata#24542: Applies exact chart-template ID matching to stale peer and device cleanup in ntpd and nvme.
  • netdata/netdata#24402: Uses boundary-aware matching to prevent charts for longer-named Kubernetes objects from matching a removed object.
  • netdata/netdata#24539: Uses exact container chart IDs to prevent prefix-based chart cleanup matches.

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

Merge Risk: Minimal · up to 0471c

The PR narrowly fixes device chart cleanup and adds coverage for shared device-name prefixes; no merge-blocking risk remains.

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: removing only charts for the removed WireGuard device.
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 1 functions across 2 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

CodeRabbit Verify

  • Run CodeRabbit Verify to test the changes in this pull request.
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: 48ac7793-0f17-452f-8610-8e353e279574
Commits

Reviewing files that changed from the base of the PR and between 06ab442 and 0471c56.

Files selected for processing: 2
  • src/go/plugin/go.d/collector/wireguard/charts.go
  • src/go/plugin/go.d/collector/wireguard/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.

@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 2 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.
Architecture diagram
sequenceDiagram
    participant C as Collector
    participant D as Device Manager
    participant Ch as Chart Store
    participant T as Chart Templates

    Note over C,T: WireGuard Chart Cleanup Flow

    C->>D: Collect() - fetch devices
    D-->>C: device list (wg1, wg10)
    
    loop Each device
        C->>C: Track active devices
    end
    
    alt Device wg1 removed at runtime
        C->>C: Detect wg1 no longer in device list
        C->>C: Call removeDeviceCharts("wg1")
        
        Note over C,T: NEW: Build exact chart ID set
        C->>T: Read deviceChartsTmpl definitions
        T-->>C: Chart templates (network_io, peers, etc.)
        
        loop Each chart template
            C->>C: Generate exact chart ID (e.g., device_wg1_network_io)
            C->>C: Add to lookup set
        end
        
        C->>Ch: Iterate all existing charts
        alt Chart ID matches exact set
            C->>Ch: MarkRemove() + MarkNotCreated()
            Note over Ch: Only charts for wg1 affected
        else Chart ID doesn't match
            Note over Ch: Keep charts (e.g., device_wg10_*)
        end
    end
    
    opt Device wg10 still active
        C->>Ch: Keep wg10 charts in registry
        Note over Ch: Charts survive cleanup
    end
Loading

View guided diff | Re-trigger cubic

@sonarqubecloud

sonarqubecloud Bot commented Nov 3, 2026

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
9.1% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

@ilyam8

ilyam8 commented Nov 3, 2026

Copy link
Copy Markdown
Member

@b84330808 I think the proper fix is to convert collectors to v2. v2 doesn't have this problem.

@b84330808

Copy link
Copy Markdown
Contributor Author

Makes sense, thanks. Should I close this one (and #24539, the same thing for docker)? If a v2 conversion of the wireguard collector would be welcome as a PR, I can try that instead.

@ilyam8

ilyam8 commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

Yes, you can close all of them. There's a skill in the repo for converting v1 to v2, so Claude should be able to figure it out. Also, ask Claude to remove the AI contribution attribution from commits.

@b84330808

Copy link
Copy Markdown
Contributor Author

Closing as discussed; I'll look at the v2 conversion instead. Thanks!

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