Phase 2: Prometheus metrics#5
Merged
Merged
Conversation
Replace the vacuous noopMetrics identity check with a sentinel distinctMetrics pointer so TestWithMetricsInstallsRecorder actually fails when WithMetrics does not install the recorder. Also tighten the ObserveLatency doc comment: "enqueue -> ack" → "creation -> ack" to match the implementation (latency is measured from job.CreatedAt, set in job.New, not from the enqueue call).
Add fakeMetrics recorder and newTestBrokerWith helper for option-injecting tests. Wire IncEnqueued and IncDeduplicated into broker.Enqueue so every successful enqueue and every dropped duplicate is counted per queue.
nack.lua already returns "retry" or "dead" to indicate which branch was taken. Switch Nack from .Err() to .Text() to capture that return value, then call IncRetried/IncDead on the Metrics interface accordingly. Tests (TestNackWithRetriesLeftRecordsRetried, TestNackWithBudgetSpentRecordsDead) were written first and confirmed RED before the one-line behavior change made them GREEN.
Owner
Author
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. 🤖 Generated with Claude Code - If this code review was useful, please react with 👍. Otherwise, react with 👎. |
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.
Summary
Completes Phase 2 by making the engine observable. Adds opt-in Prometheus instrumentation for every job-state transition plus live per-queue depth gauges, with a
/metricsendpoint oncmd/worker. No Lua scripts change; the atomic claim and at-least-once delivery are untouched — metrics are pure observation.internal/broker— a smallMetricsinterface (consumer-side contract) with anoopMetricsdefault and aWithMetrics(m)option.Enqueue/Claim/Ack/Nack/Reap/Promoterecord after the Redis op succeeds (enqueued, deduplicated, claimed, processed, retried, dead, reaped, promoted, end-to-end latency). Off by default → behaviour byte-identical when unused.internal/metrics(new package) — a PrometheusRecorderimplementingbroker.Metricsover a private registry (countersrelay_jobs_*_total, histogramrelay_job_latency_seconds, all labelled byqueue), and a pull-basedDepthCollectorreportingrelay_queue_depth{queue,state}viaZCARD/LLENat scrape time (skip-on-error, never stale). The package does not importinternal/broker— it satisfies the interface structurally, keeping the dependency arrow one-way.cmd/worker— a--metrics-addrflag (default""= off). When set, builds the recorder, registers the depth collector, and serves/metricsviapromhttp, shutting the server down after the worker pool drains so the final scrape sees the last batch.github.com/prometheus/client_golang(an instrumentation library, not a queue library — the build-from-scratch rule is intact). CLAUDE.md updated to Phase 2 complete.Design & plan
docs/superpowers/specs/2026-06-08-relay-phase2-metrics-design.mddocs/superpowers/plans/2026-06-08-relay-phase2-metrics.mdTest plan
go build ./...cleango vet ./...cleangofmt -l internal/ cmd/cleango test -race ./...— broker (DB 15), worker (DB 14), metrics (DB 13), job all pass against a real Redis (test DBs isolated sogo test ./...is parallel-safe)DepthCollectorverified viatestutil.CollectAndCompare;--metrics-addrsmoke-tested servingrelay_queue_depth