Skip to content

feat(prometheus): add helper builders for custom metrics - #107

Merged
LimiNode merged 2 commits into
mainfrom
feat/prometheus-metric-builders
May 22, 2026
Merged

feat(prometheus): add helper builders for custom metrics#107
LimiNode merged 2 commits into
mainfrom
feat/prometheus-metric-builders

Conversation

@LimiNode

Copy link
Copy Markdown
Owner

Summary

  • New PrometheusMetricBuilders.hpp with convenience helpers for constructing PrometheusMetricFamily, PrometheusSample, and PrometheusLabel.
  • Free functions: make_prometheus_label, make_prometheus_sample, make_prometheus_counter/gauge/untyped, add_prometheus_counter/gauge/untyped.
  • Collapses ~8 lines of boilerplate per custom metric to 1 line.

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 — uses add_prometheus_gauge
  • tests/prometheus_http_server_logger_test.cpp — uses add_prometheus_gauge
  • examples/example_logit_prometheus_server.cpp — uses add_prometheus_gauge
  • tests/CMakeLists.txt — registers new test

Test plan

  • prometheus_metric_builders_test passes (10 cases)
  • prometheus_payload_logger_test passes
  • prometheus_http_server_logger_test passes
  • prometheus_text_serializer_test passes
  • example_logit_prometheus_server builds

🤖 Generated with Claude Code

LimiNode and others added 2 commits May 22, 2026 04:23
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>
@LimiNode
LimiNode merged commit e70ddd5 into main May 22, 2026
12 checks passed
@LimiNode
LimiNode deleted the feat/prometheus-metric-builders branch June 3, 2026 00:04
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