Skip to content

lfsd: expose Prometheus metrics - #27

Open
unknwon wants to merge 2 commits into
otel-tracingfrom
otel-metrics
Open

unknwon wants to merge 2 commits into
otel-tracingfrom
otel-metrics

Conversation

@unknwon

@unknwon unknwon commented Nov 12, 2026

Copy link
Copy Markdown
Owner

Summary

Exposes Prometheus metrics. Stacked on #26 (tracing) and reuses its OpenTelemetry setup and HTTP middleware.

  • [metrics] LISTEN_ADDRESS (default 127.0.0.1:3357, empty to disable) serves /metrics on a separate listener, so metrics are not public along with the LFS endpoints. The global meter provider exports to the default Prometheus registry, which also collects the Go runtime and process metrics.
  • lfs module: Service.MeterProvider (nil means global) mirrors TracerProvider, so servers embedding the module plug in their own provider. It records lfs.batch.objects and lfs.proxied (bytes of content that went through the server rather than directly between the client and a presigning storage), both by lfs.operation.
  • HTTP: the route handlers now set Request.Pattern, as http.ServeMux does. otelhttp reads it to name the server span and to label http_server_* metrics with http_route. Forge API calls get http_client_* metrics.
  • Database: the GORM plugin reports the connection pool stats (go_sql_connections_*).
  • lfsd_auth_cache_lookups_total by lfs_auth_cache_hit, and lfsd_janitor_objects_total by janitor_pass and janitor_result.

The README lists every metric with its labels.

Test plan

  • moon run :lint and go test -race ./... for both projects.
  • lfs: proxied transfers count upload and download bytes (a rejected forged upload does not), presigned transfers count none, and batch objects count by operation.
  • lfsd: http_server_request_duration_seconds is labeled with the route.
  • End to end on PostgreSQL 17 with a real git-lfs push and pull: scraped /metrics on :3357 (404 on the LFS port), with route-labeled request metrics, 200000 proxied bytes each way, auth cache lookups, forge client metrics, DB pool, and Go runtime metrics. The token does not appear in the scrape.

@unknwon
unknwon added this pull request to stack #28 November 12, 2026 22:31
Service gains a MeterProvider field, defaulting to the global provider,
mirroring TracerProvider. It records lfs.batch.objects by operation, and
lfs.proxied, the bytes of content transferred through the server rather
than directly with a presigning storage.

Downloads are counted from the result of io.Copy in Serve rather than by
wrapping the content reader, which would stop io.Copy from using
sendfile.
Add a [metrics] section whose LISTEN_ADDRESS (127.0.0.1:3357 by default,
empty to disable) serves /metrics apart from the LFS endpoints. The global
meter provider exports to the default Prometheus registry, which also
collects the Go runtime and process metrics.

- HTTP: route handlers set Request.Pattern, which otelhttp reads to name
  the server span and to label the request metrics with http.route.
- Forge API calls get client request metrics from otelhttp.
- Database: the GORM plugin now reports the connection pool stats.
- lfsd_auth_cache_lookups_total counts auth cache hits and misses.
- lfsd_janitor_objects_total counts swept objects by pass and result.
@unknwon
unknwon removed this pull request from stack #28 November 13, 2026 04:02
@unknwon
unknwon added this pull request to stack #29 November 13, 2026 04:02
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