• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

maruina / go-infrabin / 18802780471
56%

Build:
DEFAULT BRANCH: master
Ran 25 Oct 2025 12:05PM UTC
Jobs 1
Files 13
Run time 1min
Badge
Embed ▾
README BADGES
x

If you need to use a raster PNG badge, change the '.svg' to '.png' in the link

Markdown

Textile

RDoc

HTML

Rst

25 Oct 2025 12:03PM UTC coverage: 54.714% (+4.2%) from 50.51%
18802780471

push

github

web-flow
Add HTTP metrics to Prometheus endpoint (#403)

* Add HTTP metrics to Prometheus endpoint

Implements custom HTTP metrics middleware to track requests going through
the grpc-gateway, addressing issue #48. Previously, only gRPC endpoint
metrics were collected; HTTP layer requests were untracked.

## Changes

- Created `pkg/infrabin/metrics.go` with custom middleware
  - Exposes `infrabin_http_requests_total` counter
  - Exposes `infrabin_http_request_duration_seconds` histogram
  - Implements `normalizeRoute()` to prevent cardinality explosion

- Modified `pkg/infrabin/http.go` to integrate metrics middleware
  - Wraps grpc-gateway handler with `HTTPMetricsMiddleware()`
  - Captures full HTTP request lifecycle including JSON conversions

- Added comprehensive tests
  - `metrics_test.go`: 12 unit tests for route normalization
  - `http_test.go`: Integration test for end-to-end metrics collection

## Design Decisions

- Zero additional dependencies (uses existing prometheus/client_golang)
- Manual route pattern mapping chosen over auto-discovery for simplicity
- Metric namespace: `infrabin_http_*` (distinct from `grpc_server_*`)
- Route normalization prevents high cardinality (e.g., /delay/5 → /delay/{duration})

## Metrics Example

```
infrabin_http_requests_total{handler="/headers",method="GET",status="200"} 15
infrabin_http_request_duration_seconds_sum{handler="/delay/{duration}",method="GET"} 16.234
```

Closes #48

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

* Fix golangci-lint error: use t.Setenv instead of os.Setenv

Replace os.Setenv/os.Unsetenv with t.Setenv() which automatically
handles cleanup and satisfies errcheck linter.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

* Change HTTP metric handler labels to match gRPC style

Update handler labels to use simple endpoint names (e.g., 'delay', 'headers')
instead o... (continued)

58 of 61 new or added lines in 2 files covered. (95.08%)

354 of 647 relevant lines covered (54.71%)

3.42 hits per line

New Missed Lines in Diff

Lines Coverage ∆ File
1
72.29
0.68% pkg/infrabin/http.go
2
96.49
pkg/infrabin/metrics.go
Jobs
ID Job ID Ran Files Coverage
1 18802780471.1 25 Oct 2025 12:05PM UTC 13
54.71
GitHub Action Run
Source Files on build 18802780471
  • Tree
  • List 13
  • Changed 1
  • Source Changed 0
  • Coverage Changed 1
Coverage ∆ File Lines Relevant Covered Missed Hits/Line
  • Back to Repo
  • 72270e53 on github
  • Prev Build on master (#18791555220)
  • Next Build on master (#18804481427)
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc