Skip to content

feat(prometheus): add Prometheus payload and HTTP server backends - #104

Merged
LimiNode merged 2 commits into
mainfrom
feat/prometheus-exporters
May 21, 2026
Merged

feat(prometheus): add Prometheus payload and HTTP server backends#104
LimiNode merged 2 commits into
mainfrom
feat/prometheus-exporters

Conversation

@LimiNode

Copy link
Copy Markdown
Owner

Summary

Adds two Prometheus backend loggers for exposing internal log metrics in Prometheus text exposition format 0.0.4:

  • PrometheusPayloadLogger — callback-based; collects built-in metrics and delivers serialized payload via on_payload callback. Supports custom metrics via on_collect hook.
  • PrometheusHttpServerLogger — embedded HTTP server using Simple-Web-Server; serves /metrics endpoint 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 handling
  • include/logit_cpp/logit/loggers/PrometheusPayloadLogger.hppILogger-based callback backend
  • include/logit_cpp/logit/loggers/PrometheusHttpServerLogger.hppILogger-based HTTP server backend

Built-in metrics (all prefixed with metric_prefix, default logit_)

Metric Type Description
log_records_total counter Total log records processed
dropped_logs_total counter Dropped log records
failed_exports_total counter Failed callback/export attempts
last_log_timestamp_ms gauge Timestamp of last log (ms)
time_since_last_log_ms gauge Time since last log (ms)
build_info gauge Build info (value=1, labels: version, compiler)

CMake options

option(LOGIT_WITH_PROMETHEUS "Enable Prometheus text payload support" OFF)
option(LOGIT_WITH_PROMETHEUS_SERVER "Enable Prometheus HTTP server backend" OFF)

LOGIT_WITH_PROMETHEUS_SERVER implies LOGIT_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 example
  • examples/example_logit_prometheus_payload.cpp
  • examples/example_logit_prometheus_server.cpp

Test plan

  • prometheus_text_serializer_test passes
  • prometheus_payload_logger_test passes
  • prometheus_http_server_logger_test passes
  • Default build without Prometheus compiles cleanly (regression check)
  • Payload-only build (LOGIT_WITH_PROMETHEUS=ON) compiles and tests pass
  • Server build (LOGIT_WITH_PROMETHEUS_SERVER=ON) compiles and tests pass

Scope limits (not in this PR)

  • OpenMetrics format / protobuf exposition
  • Pushgateway / remote_write
  • TLS or authentication on HTTP server
  • Histograms / summaries
  • Label cardinality analysis
  • Dynamic metric deletion from registry

🤖 Generated with Claude Code

LimiNode and others added 2 commits May 22, 2026 00:22
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
@LimiNode
LimiNode merged commit f5fda3f into main May 21, 2026
12 checks passed
@LimiNode
LimiNode deleted the feat/prometheus-exporters 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