Skip to content

Add histogram_quantiles() API with enriched metadata support#69

Open
thinkingfish wants to merge 12 commits into
mainfrom
claude/rezolus-percentiles-api-n2jY1
Open

Add histogram_quantiles() API with enriched metadata support#69
thinkingfish wants to merge 12 commits into
mainfrom
claude/rezolus-percentiles-api-n2jY1

Conversation

@thinkingfish

Copy link
Copy Markdown
Member

Summary

Introduces a new histogram_quantiles() query function that provides enriched histogram quantile results with per-timestamp metadata (total observation counts and min/max bucket upper bounds). This complements the existing histogram_percentiles() function, which is now marked as deprecated.

Key Changes

  • New histogram_quantiles() query handler: Implements a modern quantile query API that leverages the new quantiles() method from the histogram crate (v1.1.0), returning structured QuantilesResult objects with full metadata.

  • Enhanced data structures:

    • Added optional fields to MatrixSample: total_counts, min_bucket_upperbounds, max_bucket_upperbounds
    • Added corresponding fields to HistogramHeatmapResult for heatmap visualization
    • These fields are populated only for histogram_quantiles() results and skipped during serialization when None
  • New HistogramSeries::quantiles() method: Computes quantile time series using the SampleQuantiles trait, returning a BTreeMap<u64, QuantilesResult> with per-timestamp quantile data and metadata.

  • Deprecated histogram_percentiles(): Marked as deprecated with guidance to use histogram_quantiles() instead. All existing code paths updated to initialize new optional fields to None.

  • Heatmap metadata support: Enhanced heatmap generation to track and expose total counts and min/max bucket bounds per timestamp for improved visualization and percentage-based display.

  • Repository and dependency updates: Updated homepage/repository URLs to point to iopsystems/metriken, upgraded histogram crate dependency to v1.1.0.

  • Development guidelines: Added CLAUDE.md documenting versioning conventions for feature PRs (alpha versioning) vs. release PRs.

Implementation Details

The new histogram_quantiles() function:

  • Parses quantile array syntax: histogram_quantiles([0.5, 0.9, 0.99], metric_name)
  • Validates quantiles are in range [0.0, 1.0]
  • Uses the histogram crate's new quantiles() API for richer result data
  • Enriches each MatrixSample with per-timestamp metadata for downstream consumers
  • Maintains backward compatibility by keeping histogram_percentiles() functional

All MatrixSample instantiations throughout the query engine have been updated to explicitly set the new optional fields, ensuring consistent behavior across all query types.

https://claude.ai/code/session_01BKbdyjeu3VovVZafuXqD84

claude added 12 commits April 4, 2026 05:13
Adds HistogramSeries::quantiles() and Tsdb::quantiles() methods that
return BTreeMap<Quantile, UntypedSeries> for keyed quantile lookups.
Existing percentiles() API is left in place for backwards compatibility.

Updates histogram dependency to path dep for development (1.1.0).

https://claude.ai/code/session_01YQAY65y5zF3PdR2uuaypMj
Mark HistogramSeries::percentiles() and Tsdb::percentiles() as
deprecated. Existing PromQL callers use #[allow(deprecated)] until
they migrate to the new quantiles() API.

https://claude.ai/code/session_01YQAY65y5zF3PdR2uuaypMj
Feature PRs use <version>-alpha.<revision> format only.
Release version bumps are reserved for release PRs.

https://claude.ai/code/session_01YQAY65y5zF3PdR2uuaypMj
Change the return type from BTreeMap<Quantile, UntypedSeries> to
BTreeMap<u64, QuantilesResult> so each timestamp preserves the full
QuantilesResult (quantile-to-bucket map, total_count, min, max)
instead of flattening to just bucket end values.

https://claude.ai/code/session_01YQAY65y5zF3PdR2uuaypMj
…metadata

Add a new `histogram_quantiles()` PromQL function that uses the
`QuantilesResult` API from histogram 1.1.0. Unlike the deprecated
`histogram_percentiles()`, the new function enriches each MatrixSample
with `total_counts`, `min_bucket_upperbounds`, and `max_bucket_upperbounds`
per timestamp, enabling:

- Hiding non-unique quantiles when sample count is low
- Accurate percentage display in heatmaps using true total count
- Authoritative min/max bucket values for Y-axis range decisions

Also enriches `HistogramHeatmapData` and `HistogramHeatmapResult` with
the same per-timestamp metadata, computed during the existing bucket
iteration in `heatmap()`.

Existing `histogram_percentiles()` and `histogram_quantile()` PromQL
functions are preserved as-is for backward compatibility.

https://claude.ai/code/session_01BKbdyjeu3VovVZafuXqD84
…ogram_quantiles

Mark the internal handle_histogram_percentiles() method as deprecated
to guide future callers toward histogram_quantiles() which provides
enriched metadata via the QuantilesResult API.

https://claude.ai/code/session_01BKbdyjeu3VovVZafuXqD84
Instead of embedding total_counts/min_bucket_upperbounds/max_bucket_upperbounds
as optional fields on MatrixSample, emit them as independent MatrixSample
entries labeled with a `stat` key. This keeps MatrixSample simple and allows
the metadata series to be independently queried, correlated, and analyzed.

histogram_quantiles() now returns:
- One series per quantile: {__name__: metric, quantile: "0.99"}
- total_count series:      {__name__: metric, stat: "total_count"}
- min_bucket_upperbound:   {__name__: metric, stat: "min_bucket_upperbound"}
- max_bucket_upperbound:   {__name__: metric, stat: "max_bucket_upperbound"}

https://claude.ai/code/session_01BKbdyjeu3VovVZafuXqD84
Remove stat series (total_count, min/max_bucket_upperbound) from
histogram_quantiles() response and add an optional `filtered` flag that
suppresses quantile data points when the sample count is too low for
that quantile to be meaningfully distinct from the next-lower one.

https://claude.ai/code/session_01BKbdyjeu3VovVZafuXqD84
…ount

Remove the `filtered` flag from histogram_quantiles() since it breaks
PromQL compatibility. Add a new histogram_total_count(metric) query that
returns per-timestamp sample counts as a time series, enabling the
frontend to perform threshold-based quantile suppression client-side.

https://claude.ai/code/session_01BKbdyjeu3VovVZafuXqD84
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.

2 participants