Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

kwasniew
Copy link
Contributor

@kwasniew kwasniew commented Sep 12, 2025

About the changes

Adds a new Histogram metric type to the impact-metrics system, following the same patterns as existing Counter and Gauge metrics.

Key Features

  • observe(value, labels?) method - Records observations with optional labels
  • Prometheus-compatible bucket system - Configurable buckets with automatic Infinity bucket (in prometheus users don't have to specify Infinity bucket themselves and we do the same)
  • Memory-efficient storage - Uses bucket counts instead of storing raw values to handle millions of observations (check Discussion points for the impact of this decision)
  • Full restoration support - Can restore exact histogram state after collection failures (more complex than gauge/counter due to the nature of histograms)
  • Type-safe discriminated unions - NumericMetricSample | BucketMetricSample prevents invalid states (histograms are very different from numeric counters/gauges)

Important files

Start review by reading tests to understand how histograms work in prometheus.

Discussion points

The backend will need to support batch histogram restoration from collected bucket data, which prom-client doesn't natively support, so we'll likely need to build custom logic to reconstruct prom-client histograms from our bucket counts. I still think it's better than recording millions of samples and then calling observe million times on the server side.

@coveralls
Copy link

coveralls commented Sep 12, 2025

Pull Request Test Coverage Report for Build 17675458694

Details

  • 44 of 48 (91.67%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.06%) to 89.926%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/impact-metrics/metric-types.ts 44 48 91.67%
Totals Coverage Status
Change from base Build 17613865892: -0.06%
Covered Lines: 1252
Relevant Lines: 1331

💛 - Coveralls

@kwasniew kwasniew requested review from sighphyre and Tymek September 12, 2025 13:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: New
Development

Successfully merging this pull request may close these issues.

2 participants