Overview
Add a GET /metrics endpoint in Prometheus format so the service can be scraped by Prometheus or Cloud Monitoring. Split from #104.
Metrics to expose
| Metric |
Type |
Labels |
docstore_http_requests_total |
Counter |
method, path_template, status_code |
docstore_http_request_duration_seconds |
Histogram |
method, path_template |
docstore_db_query_duration_seconds |
Histogram |
query_name |
docstore_commits_total |
Counter |
repo |
docstore_merges_total |
Counter |
repo, result (ok/conflict/policy_denied) |
docstore_active_branches |
Gauge |
repo |
docstore_documents_total |
Gauge |
repo |
Implementation
- Add
prometheus/client_golang dependency
- Register metrics in a central
metrics.go file
- Wire HTTP middleware to record request counts and durations with normalized
path_template labels (avoid high-cardinality repo/branch names in labels)
- Expose
GET /metrics on the main mux (or a separate internal port)
- Gauge metrics (
active_branches, documents_total) updated on write operations or via periodic background collection
Configuration
DOCSTORE_METRICS_ENABLED=true # default true
DOCSTORE_METRICS_PORT=9090 # separate port recommended to avoid exposing to IAP
Notes
path_template label should use patterns like /repos/{name}/-/commit not actual repo names, to keep cardinality bounded
- Metrics port should not be behind IAP — it's for internal scraping only
Overview
Add a
GET /metricsendpoint in Prometheus format so the service can be scraped by Prometheus or Cloud Monitoring. Split from #104.Metrics to expose
docstore_http_requests_totaldocstore_http_request_duration_secondsdocstore_db_query_duration_secondsdocstore_commits_totaldocstore_merges_totaldocstore_active_branchesdocstore_documents_totalImplementation
prometheus/client_golangdependencymetrics.gofilepath_templatelabels (avoid high-cardinality repo/branch names in labels)GET /metricson the main mux (or a separate internal port)active_branches,documents_total) updated on write operations or via periodic background collectionConfiguration
Notes
path_templatelabel should use patterns like/repos/{name}/-/commitnot actual repo names, to keep cardinality bounded