fix(server): pre-register prometheus metrics at startup#1150
Open
TaylorMutch wants to merge 1 commit intomainfrom
Open
fix(server): pre-register prometheus metrics at startup#1150TaylorMutch wants to merge 1 commit intomainfrom
TaylorMutch wants to merge 1 commit intomainfrom
Conversation
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
4b32496 to
4c3842a
Compare
Collaborator
Author
|
/ok to test 4c3842a |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Records
openshell_server_start_time_secondsimmediately afterinstall_recorder()so/metricsreturns 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: Addedgauge!("openshell_server_start_time_seconds")with current Unix timestamp anddescribe_counter!/describe_histogram!for the four request metrics, immediately afterinstall_recorder().crates/openshell-server/tests/metrics_preregistration.rs(new): Integration test assertinghandle.render()is non-empty and containsopenshell_server_start_time_secondsbefore any request is made.Deviations from Plan
The approved plan proposed using only
describe_*macros. Investigation revealed thatmetrics-exporter-prometheus0.18 only emits a metric inrender()once a value has been recorded — descriptions alone produce no output. The fix was updated to also record aopenshell_server_start_time_secondsgauge at startup (a standard Prometheus pattern used by most exporters). Thedescribe_*calls are retained for HELP/TYPE metadata on request metrics.Testing
mise run pre-commitpassesTests added:
crates/openshell-server/tests/metrics_preregistration.rs::metrics_are_non_empty_before_any_request— verifieshandle.render()is non-empty and contains the startup gauge before any request flows throughMultiplexedServiceChecklist
Documentation updated: