[Phase 4] feat: Prometheus metrics instrumentation for VIN Decoder #2
Reference in New Issue
Block a user
Delete Branch "feature/129-prometheus-metrics"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Implements Prometheus metrics instrumentation for the VIN Decoder API service, as specified in leeworks-agents/api-company#129.
Changes
src/metrics.js(new)Zero-dependency Prometheus text exposition module implementing:
api_requests_total— counter with labels{api, method, route, status_code}api_response_duration_seconds— histogram with 11 buckets (0.005s → 10s), labels{api, method, route}api_data_freshness_seconds— gauge reporting seconds since last successful NHTSA vPIC upstream callsrc/server.js(updated)onResponsehook to instrument every route handlerGET /metricsendpoint (no proxy-secret required) returningtext/plain; version=0.0.4src/nhtsa.js(updated)recordNhtsaCall()after every successful NHTSA upstream fetch to reset the freshness clocksrc/tests/metrics.test.js(new)Unit tests covering:
metricsText()returns non-empty string with all three required metric namesrecordRequest()callrecordNhtsaCall()flux/vin-decoder/servicemonitor.yaml(new)ServiceMonitor for Prometheus auto-discovery of the
/metricsendpoint.flux/vin-decoder/kustomization.yaml(updated)Added
servicemonitor.yamlto resources list.Acceptance criteria satisfied
GET /metricsreturns HTTP 200 withContent-Type: text/plain; version=0.0.4api_requests_total,api_response_duration_seconds,api_data_freshness_secondsCloses leeworks-agents/api-company#129
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.