metrics: extract boolGauge to simplify RecordInventory (issue #9) #11

Open
hermes-automation wants to merge 1 commits from wt/t_f1593f8c into main

Resolves #9 ([hermes] soteria: go:S3776).

RecordInventory in internal/server/metrics.go exceeded the SonarQube cognitive-complexity threshold (16 > 15) because of the pvc.Healthy if/else that only chooses between gauge values 1 and 0. This PR replaces that branch with a small documented boolGauge helper, removing one decision point without changing any emitted metric.

Behavior lock (RED → GREEN):

  • New TestBoolGaugeMapsHealthToPrometheusValues and TestTelemetryRecordInventoryHealthGaugeIdentity assert the rendered pvc_backup_health gauge stays exactly 1 for healthy and 0 for unhealthy PVCs with unchanged metric name and labels. The tests failed to build before the refactor (undefined boolGauge) and pass after.

Validation:

  • go test -race ./... — all packages pass
  • bash scripts/check.sh — gofmt, doc/structure/LOC/code-smell/UI hygiene, go vet, unit tests + coverage hygiene all pass (total coverage 96.20%)
  • Skip: the SonarQube scanner itself is only available in the CI quality-tools container, so the S3776 delta will be confirmed by the pipeline scan on this PR.

Started from exact main head 47205db5b2e8041bac6a06a78f94fd3662134fc8; only internal/server/metrics.go and internal/server/metrics_test.go changed.

🤖 Generated with Claude Code

Resolves #9 ([hermes] soteria: go:S3776). RecordInventory in `internal/server/metrics.go` exceeded the SonarQube cognitive-complexity threshold (16 > 15) because of the `pvc.Healthy` if/else that only chooses between gauge values 1 and 0. This PR replaces that branch with a small documented `boolGauge` helper, removing one decision point without changing any emitted metric. **Behavior lock (RED → GREEN):** - New `TestBoolGaugeMapsHealthToPrometheusValues` and `TestTelemetryRecordInventoryHealthGaugeIdentity` assert the rendered `pvc_backup_health` gauge stays exactly `1` for healthy and `0` for unhealthy PVCs with unchanged metric name and labels. The tests failed to build before the refactor (undefined `boolGauge`) and pass after. **Validation:** - `go test -race ./...` — all packages pass - `bash scripts/check.sh` — gofmt, doc/structure/LOC/code-smell/UI hygiene, `go vet`, unit tests + coverage hygiene all pass (total coverage 96.20%) - Skip: the SonarQube scanner itself is only available in the CI quality-tools container, so the S3776 delta will be confirmed by the pipeline scan on this PR. Started from exact main head 47205db5b2e8041bac6a06a78f94fd3662134fc8; only `internal/server/metrics.go` and `internal/server/metrics_test.go` changed. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
hermes-automation added 1 commit 2026-08-16 20:06:00 +00:00
Resolves the SonarQube go:S3776 cognitive-complexity finding on
RecordInventory by replacing the pvc.Healthy if/else with a boolGauge
helper. Adds tests locking the pvc_backup_health gauge to exactly 1 for
healthy and 0 for unhealthy with unchanged metric identity and labels.

Closes #9

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This pull request doesn't have enough required approvals yet. 0 of 1 approvals granted from users or teams on the allowlist.
You are not authorized to merge this pull request.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin wt/t_f1593f8c:wt/t_f1593f8c
git checkout wt/t_f1593f8c
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: titan/soteria#11
No description provided.