fix(dhcp): de-duplicate DHCP lease label sets - #76
Open
woobins wants to merge 1 commit into
Open
Conversation
AdGuard can return duplicate DHCP lease rows (e.g. an in-place self-update
rebuilds the lease table, or several clients behind a MAC-NAT'ing wifi
repeater share one upstream MAC). DhcpLeasesServer.Collect emitted one
metric per lease with no de-duplication, so a repeated label tuple made the
registry fail the entire /metrics scrape with:
collected metric "adguard_dhcp_leases" { ... } was collected before with
the same name and label values
i.e. a single duplicate lease 500s the whole exporter and reads as down,
even though AdGuard itself is healthy.
De-duplicate on the full label set before emitting. The metric set is built
under the existing mutex (Collect previously read the leases map unlocked
while the worker's Record writes it, which is a data race) and sent to the
channel after unlocking so a slow scrape cannot stall Record. Adds a
regression test using a pedantic registry.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When AdGuard returns duplicate DHCP lease rows,
/metricsfails with HTTP 500:A single duplicate lease takes down the entire scrape (every metric, not just leases), so Prometheus reads the exporter as down even though AdGuard itself is healthy. I have seen AdGuard emit duplicate rows after an in-place self-update (lease-table rebuild) and when several clients behind a MAC-NAT'ing wifi repeater share one upstream MAC.
Fix
De-duplicate on the full label set in
DhcpLeasesServer.Collectbefore emitting. The metric set is built under the existing mutex (Collectpreviously read the leases map unlocked while the worker'sRecordwrites it, whichgo test -raceflags as a data race) and sent to the channel after unlocking so a slow scrape cannot stallRecord.Adds a regression test using a pedantic registry; it fails on the current collector and passes with the fix.