feat(prometheus): add Prometheus payload and HTTP server backends - #104
Merged
Conversation
Add PrometheusPayloadLogger (callback-based text exposition) and PrometheusHttpServerLogger (embedded /metrics server via Simple-Web-Server). Includes shared text serializer, built-in logit_* counters/gauges, custom on_collect hook, and full test coverage. Constraint: Prometheus text format 0.0.4 only; no protobuf, OpenMetrics, histograms, or TLS in this PR. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Move LOGIT_WITH_PROMETHEUS options to top of CMakeLists.txt before C++ standard logic that depends on them. Remove unused Config fields `async` and `export_interval_ms`. Change default resource handler to return 404 for unknown paths. Add optional `/health` endpoint. Guard on_collect exception with ++m_failed_exports. Add HTTP integration tests for /metrics, /health, unknown paths, and custom paths using SimpleWeb::Client<SimpleWeb::HTTP>. Constraint: header-only library, no external test framework Rejected: custom HTTP client code | use existing Simple-Web-Server client Confidence: high Scope-risk: narrow
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
Adds two Prometheus backend loggers for exposing internal log metrics in Prometheus text exposition format 0.0.4:
on_payloadcallback. Supports custom metrics viaon_collecthook./metricsendpoint on a configurable port.What's included
New headers
include/logit_cpp/logit/loggers/prometheus/PrometheusTextFormatConfig.hpp— shared types (PrometheusMetricType,PrometheusMetricFamily,PrometheusSample, config struct)include/logit_cpp/logit/loggers/prometheus/PrometheusTextSerializer.hpp— header-only serializer with escaping, sanitization, NaN/Inf handlinginclude/logit_cpp/logit/loggers/PrometheusPayloadLogger.hpp—ILogger-based callback backendinclude/logit_cpp/logit/loggers/PrometheusHttpServerLogger.hpp—ILogger-based HTTP server backendBuilt-in metrics (all prefixed with
metric_prefix, defaultlogit_)log_records_totaldropped_logs_totalfailed_exports_totallast_log_timestamp_mstime_since_last_log_msbuild_infoCMake options
LOGIT_WITH_PROMETHEUS_SERVERimpliesLOGIT_WITH_PROMETHEUS, requires C++17, and auto-discovers Simple-Web-Server (standalone or via kurlyk submodule).Tests
tests/prometheus_text_serializer_test.cpp— 13 tests (escaping, sanitization, HELP/TYPE, labels, timestamps, NaN/Inf, precision)tests/prometheus_payload_logger_test.cpp— 8 tests (collect, callback, exceptions, custom metrics, params)tests/prometheus_http_server_logger_test.cpp— 6 tests (lifecycle, payload, custom metrics, params, start/stop)Docs & examples
docs/PrometheusLogger.md— usage guide with scrape config exampleexamples/example_logit_prometheus_payload.cppexamples/example_logit_prometheus_server.cppTest plan
prometheus_text_serializer_testpassesprometheus_payload_logger_testpassesprometheus_http_server_logger_testpassesLOGIT_WITH_PROMETHEUS=ON) compiles and tests passLOGIT_WITH_PROMETHEUS_SERVER=ON) compiles and tests passScope limits (not in this PR)
🤖 Generated with Claude Code