Skip to content

feat(metrics): Add histogram metrics support for latency distributions#453

Merged
kcenon merged 5 commits into
mainfrom
feature/409-histogram-metrics
Jan 14, 2026
Merged

feat(metrics): Add histogram metrics support for latency distributions#453
kcenon merged 5 commits into
mainfrom
feature/409-histogram-metrics

Conversation

@kcenon

@kcenon kcenon commented Jan 14, 2026

Copy link
Copy Markdown
Owner

Summary

  • Add histogram class for capturing value distributions with configurable bucket boundaries
  • Add sliding_histogram class for time-windowed percentile tracking (auto-expiring old data)
  • Integrate histogram metrics with metric_reporter for seamless usage
  • Support Prometheus and JSON export formats

Changes

New Files

  • include/kcenon/network/metrics/histogram.h - Histogram class with percentile calculations
  • include/kcenon/network/metrics/sliding_histogram.h - Time-windowed histogram
  • src/metrics/histogram.cpp - Histogram implementation
  • src/metrics/sliding_histogram.cpp - Sliding histogram implementation
  • tests/unit/test_histogram.cpp - Comprehensive unit tests (29 tests)

Modified Files

  • include/kcenon/network/metrics/network_metrics.h - Added histogram methods to metric_reporter
  • src/metrics/network_metrics.cpp - Implemented histogram integration
  • CMakeLists.txt - Added new source files
  • tests/CMakeLists.txt - Added histogram test target
  • docs/CHANGELOG.md - Documented new feature
  • docs/CHANGELOG_KO.md - Korean changelog update

Features

  • histogram class

    • Configurable bucket boundaries (default: network latency optimized)
    • Thread-safe atomic operations
    • Percentile calculations (p50, p95, p99, p999)
    • Prometheus format export
    • JSON format export
  • sliding_histogram class

    • Time-windowed data (default: 60 seconds)
    • Auto-expiring time buckets
    • Aggregated percentile calculations
  • metric_reporter integration

    • record_latency(), record_connection_time(), record_request_duration()
    • get_latency_p50(), get_latency_p95(), get_latency_p99()
    • get_all_histograms() for bulk export
    • reset_histograms() for clearing data

Test plan

  • All 29 histogram unit tests pass
  • Thread safety tests with concurrent recording and reading
  • Edge case tests (empty, single value, large values, negative values)
  • Export format tests (Prometheus, JSON)
  • metric_reporter integration tests
  • Build succeeds on macOS

Closes #409

Implement histogram metric class that supports:
- Configurable bucket boundaries for value distribution tracking
- Thread-safe atomic operations for concurrent recording
- Percentile calculations (p50, p95, p99, p999)
- Prometheus and JSON format export via snapshot
- Linear interpolation for percentile estimation

Addresses #409
Implement sliding window histogram that automatically expires old data:
- Configurable time window duration and bucket count
- Auto-expiring time buckets for recent-only percentile tracking
- Aggregated statistics across all active time buckets
- Useful for real-time performance monitoring

Addresses #409
Add histogram-based metrics methods to metric_reporter:
- record_latency/connection_time/request_duration for histogram recording
- get_latency_p50/p95/p99 for percentile retrieval
- get_all_histograms for bulk snapshot export
- reset_histograms for clearing all histogram data

New metric names added for histogram tracking:
- network.latency.histogram
- network.connection_time.histogram
- network.request_duration.histogram

Addresses #409
Add comprehensive test coverage including:
- Histogram basic operations (record, count, sum, min/max)
- Percentile calculations (p50, p95, p99)
- Custom bucket boundaries
- Prometheus and JSON export formats
- Thread safety with concurrent reads and writes
- Sliding histogram time windowing
- metric_reporter histogram integration

All 29 tests pass.

Addresses #409
Add documentation for histogram metrics implementation (#409):
- histogram and sliding_histogram classes
- metric_reporter integration
- Prometheus and JSON export formats
- Comprehensive test coverage

Updated both English and Korean CHANGELOGs.
@github-actions

Copy link
Copy Markdown
Contributor

Performance Comparison

Base Branch Results

No base results

PR Branch Results

No PR results

@kcenon kcenon merged commit 9d9fdcb into main Jan 14, 2026
44 checks passed
@kcenon kcenon deleted the feature/409-histogram-metrics branch January 14, 2026 23:25
kcenon added a commit that referenced this pull request Apr 13, 2026
#453)

* feat(metrics): add histogram class for latency distributions

Implement histogram metric class that supports:
- Configurable bucket boundaries for value distribution tracking
- Thread-safe atomic operations for concurrent recording
- Percentile calculations (p50, p95, p99, p999)
- Prometheus and JSON format export via snapshot
- Linear interpolation for percentile estimation

Addresses #409

* feat(metrics): add sliding_histogram for time-windowed tracking

Implement sliding window histogram that automatically expires old data:
- Configurable time window duration and bucket count
- Auto-expiring time buckets for recent-only percentile tracking
- Aggregated statistics across all active time buckets
- Useful for real-time performance monitoring

Addresses #409

* feat(metrics): integrate histogram metrics with metric_reporter

Add histogram-based metrics methods to metric_reporter:
- record_latency/connection_time/request_duration for histogram recording
- get_latency_p50/p95/p99 for percentile retrieval
- get_all_histograms for bulk snapshot export
- reset_histograms for clearing all histogram data

New metric names added for histogram tracking:
- network.latency.histogram
- network.connection_time.histogram
- network.request_duration.histogram

Addresses #409

* test(metrics): add unit tests for histogram and sliding_histogram

Add comprehensive test coverage including:
- Histogram basic operations (record, count, sum, min/max)
- Percentile calculations (p50, p95, p99)
- Custom bucket boundaries
- Prometheus and JSON export formats
- Thread safety with concurrent reads and writes
- Sliding histogram time windowing
- metric_reporter histogram integration

All 29 tests pass.

Addresses #409

* docs: update CHANGELOG with histogram metrics feature

Add documentation for histogram metrics implementation (#409):
- histogram and sliding_histogram classes
- metric_reporter integration
- Prometheus and JSON export formats
- Comprehensive test coverage

Updated both English and Korean CHANGELOGs.
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.

[METRICS] Add histogram metrics support for latency distributions

1 participant