Skip to content

feat: integrate Prometheus metrics for HTTP requests and worker performance#17

Merged
DanielPopoola merged 1 commit into
masterfrom
go-version
Apr 12, 2026
Merged

feat: integrate Prometheus metrics for HTTP requests and worker performance#17
DanielPopoola merged 1 commit into
masterfrom
go-version

Conversation

@DanielPopoola
Copy link
Copy Markdown
Owner

@DanielPopoola DanielPopoola commented Apr 12, 2026

What

Exposes a /metrics endpoint and instruments the HTTP layer, queue admission, and claim expiry with Prometheus counters, gauges, and histograms.

Changes

  • Add internal/metrics package declaring all application metrics via promauto
  • Add MetricsMiddleware to capture HTTP request count and duration per route pattern (uses chi route context to avoid UUID cardinality)
  • Register /metrics handler on the router using promhttp.Handler
  • Instrument AdmissionWorker — records tick duration, tick errors, and admitted-per-event count
  • Instrument ExpiryWorker — records expired claim count per event
  • Add fairqueue and fairqueue-loadtest scrape targets to prometheus.yml

Notes

  • The loadtest binary gets HTTP metrics for free since it shares the same router
  • No new dependencies beyond prometheus/client_golang

Summary by CodeRabbit

New Features

  • Added /metrics endpoint for Prometheus-based monitoring and observability
  • Implemented comprehensive metrics collection tracking HTTP request performance (latency and request count by endpoint), queue admission operations, claims processing lifecycle events, and worker execution metrics (duration and errors)
  • Provides real-time operational visibility into API performance, queue operations, claims processing, and worker efficiency across all application components

@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 12, 2026

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

The PR introduces Prometheus metrics instrumentation across the application. It adds HTTP request metrics via middleware, defines a metrics package with Prometheus counter, histogram, and gauge metrics, registers a /metrics endpoint, and instruments worker components to record timing and event data.

Changes

Cohort / File(s) Summary
Dependency Management
go.mod
Added prometheus/client_golang v1.23.2 and related Prometheus transitive dependencies; added gopkg.in/yaml.v2 v2.4.2.
HTTP Metrics Infrastructure
internal/api/middleware.go, internal/api/server.go
Added MetricsMiddleware that wraps responses to capture HTTP status codes and records request count/duration metrics. Wired middleware into router chain and registered promhttp.Handler() at /metrics endpoint.
Metrics Definitions
internal/metrics/metrics.go
Created new metrics package with 8 Prometheus metrics: HTTP request counters and histograms, queue/claim event counters, and worker tick duration/error metrics. All metrics defined as package-level exported variables.
Worker Instrumentation
internal/worker/admission.go, internal/worker/expiry.go
Added timing instrumentation to admission worker tick duration and metrics recording for admission counts and claim expiration events.

Sequence Diagram

sequenceDiagram
    actor Client
    participant Router as HTTP Router
    participant Middleware as MetricsMiddleware
    participant Handler as Request Handler
    participant Metrics as Prometheus Metrics
    
    Client->>Router: HTTP Request
    Router->>Middleware: Pass to middleware chain
    Middleware->>Middleware: Start timer, wrap ResponseWriter
    Middleware->>Handler: Call next handler
    Handler->>Handler: Process request
    Handler->>Middleware: Write response + status
    Middleware->>Metrics: Record HTTPRequestsTotal<br/>(method, path, status)
    Middleware->>Metrics: Record HTTPRequestDuration<br/>(method, path, duration)
    Middleware->>Client: Return response
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Poem

🐰 Metrics now bloom like clover in spring,
Each request and worker begins to sing,
Prometheus counts with observant care,
Timings and totals float through the air, 🌟

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 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 summarizes the main change: integrating Prometheus metrics for HTTP requests and worker performance, which aligns with all major modifications across go.mod, middleware, server routing, and worker instrumentation.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch go-version

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@DanielPopoola DanielPopoola merged commit bba5fa6 into master Apr 12, 2026
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant