Skip to content

fix(server): pre-register prometheus metrics at startup#1150

Open
TaylorMutch wants to merge 1 commit intomainfrom
fix/1119-pre-register-prometheus-metrics/tmutch
Open

fix(server): pre-register prometheus metrics at startup#1150
TaylorMutch wants to merge 1 commit intomainfrom
fix/1119-pre-register-prometheus-metrics/tmutch

Conversation

@TaylorMutch
Copy link
Copy Markdown
Collaborator

🏗️ build-from-issue-agent

Summary

Records openshell_server_start_time_seconds immediately after install_recorder() so /metrics returns a non-empty body from the first Prometheus scrape after pod restart. describe_* calls are also added for all four request metrics so their HELP/TYPE metadata renders correctly once traffic arrives.

Related Issue

Closes #1119

Changes

  • crates/openshell-server/src/lib.rs: Added gauge!("openshell_server_start_time_seconds") with current Unix timestamp and describe_counter!/describe_histogram! for the four request metrics, immediately after install_recorder().
  • crates/openshell-server/tests/metrics_preregistration.rs (new): Integration test asserting handle.render() is non-empty and contains openshell_server_start_time_seconds before any request is made.

Deviations from Plan

The approved plan proposed using only describe_* macros. Investigation revealed that metrics-exporter-prometheus 0.18 only emits a metric in render() once a value has been recorded — descriptions alone produce no output. The fix was updated to also record a openshell_server_start_time_seconds gauge at startup (a standard Prometheus pattern used by most exporters). The describe_* calls are retained for HELP/TYPE metadata on request metrics.

Testing

  • mise run pre-commit passes
  • Unit tests added/updated
  • E2E tests added/updated (N/A — no e2e/ changes)

Tests added:

  • Unit: crates/openshell-server/tests/metrics_preregistration.rs::metrics_are_non_empty_before_any_request — verifies handle.render() is non-empty and contains the startup gauge before any request flows through MultiplexedService
  • Integration: N/A
  • E2E: N/A

Checklist

  • Follows Conventional Commits
  • Architecture docs updated (if applicable)

Documentation updated:

  • None required — no published docs reference metrics startup behavior

@copy-pr-bot
Copy link
Copy Markdown

copy-pr-bot Bot commented May 4, 2026

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

Records openshell_server_start_time_seconds immediately after
install_recorder() so /metrics returns a non-empty body from the
first scrape after pod restart.

metrics-exporter-prometheus 0.18 only emits a metric once a value
has been recorded; describe_* alone is not sufficient. The startup
gauge fixes the empty-body window while describe_* calls register
HELP/TYPE metadata for request metrics so they render correctly
when traffic arrives.

Closes #1119
@TaylorMutch TaylorMutch force-pushed the fix/1119-pre-register-prometheus-metrics/tmutch branch from 4b32496 to 4c3842a Compare May 4, 2026 21:34
@TaylorMutch TaylorMutch marked this pull request as ready for review May 4, 2026 21:34
@TaylorMutch TaylorMutch requested a review from a team as a code owner May 4, 2026 21:34
@TaylorMutch
Copy link
Copy Markdown
Collaborator Author

/ok to test 4c3842a

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.

feat: pre-register prometheus metrics at startup so /metrics is never empty

1 participant