fix: restore the heartbeats_heartbeat_received_total counter - #243
Merged
gi8lino merged 2 commits intoJul 23, 2026
Conversation
Member
|
hi @cplieger thank you for your contribution! Regards! |
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.
heartbeats_heartbeat_received_totalis registered, documented in the README, and covered by registry tests, but nothing increments it anymore: since v0.22.0 no production series ever appears on/metrics, no matter how many bumps arrive.Regression trace
internal/heartbeat/actor.goline 150 at1f2b091(v0.20.0); the same call is still present at the v0.21.0 tag.IncHeartbeatReceivedcall fell out; the state gauge survived because it lives in the sender.IncHeartbeatReceivedare its own tests. Nothing ever touches a child of the labeledCounterVec(noWithLabelValueson any code path), so no series exists and the metric silently vanishes from the exposition. Confirmed live on v0.23.0: bumps accepted ({"status":"ok"},stage_transitionlogged) with noreceived_totalseries ever appearing.The fix
The increment lives in
service.Update, the single place that sees every bump and can tell the three outcomes apart:State.UpdateSeenhas already recorded last-seen and payload before the mailbox send is attempted, and history logs the event as received (enqueued: false), so the delivery genuinely arrived; only the runner wake-up was dropped.Plumbing:
NewServicetakes the metrics registry (same pattern asmanager.NewManager),run.gopasses the existingmetricsReg, and the increment is nil-guarded so callers without metrics keep working. The HTTP handler is untouched apart from what was already there.Tests:
internal/heartbeat/service: accepted + mailbox-full renderheartbeats_heartbeat_received_total{heartbeat="api"} 2on the registry's exposition; an unknown id creates no series; a nil-metrics service doesn't panic.internal/handler(heartbeat_test.gowas an empty placeholder): accepted bump reaches the service and returns 200, a service error maps to 404, a missing id is a 400 that never reaches the service.Verification
gofmt,go vet, andgo testpass for./internal/handler,./internal/heartbeat/service, and./internal/metrics(frontend built first for theweb/distembed).go test ./...currently fails on master in the packages importinginternal/notify; that's the pre-existing notifykit build break tracked in master does not compile; the PR test gate never runs #242, unrelated to this change. I baseline-checked the identical failures occur without this diff.One adjacent thing I noticed but didn't touch: the README's metrics list says
heartbeats_heartbeat_last_statuswhile the code registersheartbeats_heartbeat_last_state.Checklist
bugfits.