feat(prometheus): add helper builders for custom metrics - #107
Merged
Conversation
Add PrometheusMetricBuilders.hpp with convenience helpers for constructing PrometheusMetricFamily and PrometheusSample objects: - make_prometheus_label(name, value) - make_prometheus_sample(name, value, labels, timestamp) - make_prometheus_counter/gauge/untyped(name, help, value, [labels]) - add_prometheus_counter/gauge/untyped(families&, name, help, value, [labels]) This collapses the ~8-line boilerplate for adding a custom metric in on_collect callbacks down to a single line. Updated existing tests and examples to use the new helpers. Added dedicated prometheus_metric_builders_test with 10 test cases. Scope-risk: narrow Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
…lders PrometheusMetricBuilders.hpp uses std::move but did not explicitly include <utility>. It happened to compile transitively, but the header must be self-contained. Also remove unused <logit/utils.hpp> from the builders test. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
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
PrometheusMetricBuilders.hppwith convenience helpers for constructingPrometheusMetricFamily,PrometheusSample, andPrometheusLabel.make_prometheus_label,make_prometheus_sample,make_prometheus_counter/gauge/untyped,add_prometheus_counter/gauge/untyped.Files changed
include/logit_cpp/logit/loggers/prometheus/PrometheusMetricBuilders.hpp(new)tests/prometheus_metric_builders_test.cpp(new, 10 test cases)tests/prometheus_payload_logger_test.cpp— usesadd_prometheus_gaugetests/prometheus_http_server_logger_test.cpp— usesadd_prometheus_gaugeexamples/example_logit_prometheus_server.cpp— usesadd_prometheus_gaugetests/CMakeLists.txt— registers new testTest plan
prometheus_metric_builders_testpasses (10 cases)prometheus_payload_logger_testpassesprometheus_http_server_logger_testpassesprometheus_text_serializer_testpassesexample_logit_prometheus_serverbuilds🤖 Generated with Claude Code