Skip to content

Prometheus metrics endpoint #118

Description

@dlorenc

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions