Skip to content

Conversation

beorn7
Copy link
Member

@beorn7 beorn7 commented Jul 3, 2025

This deals with the count field of native histograms in the same way
as with simple float counters. It then scale the whole histogram with
the same factor as it has scaled the count. This will still allow
individual buckets to get extrapolated below zero, but maybe that is
fine.

This implements approach (2) as described in
#15976 (comment)

This is now ready for review.

For posterity: This approach was chosen as per discussion in #15976 , with @gen1321 and @krajorama being the other two contributors.

@beorn7
Copy link
Member Author

beorn7 commented Jul 3, 2025

Should we go with this approach, this might actually be close to the final code, which proves the simplicity. (Assuming I haven't missed anything substantial…)

Another thought: Even though this will have overblown values for some buckets, I am not so sure anymore if "fixing" those is the right thing. By reducing the overblown buckets, we are increasing other buckets, so one might argue we are actually glossing over differences between buckets that has been in the data, but has been "smoothed out" with the other approaches (3) and (4).

Or in other words: The outcome of this approach (2) is easier to reason with.

For "optimal" rate estimation, the hopes are that the new smoothed keyword will take care of it. It doesn't extrapolate at all (but it interpolates), so it doesn't suffer from the problem in the first place, and it should work just fine for NH. Which is another point to make for keeping things simple on the classic rate/increase front.

This deals with the count field of native histograms in the same way
as with simple float counters. It then scale the whole histogram with
the same factor as it has scaled the count. This will still allow
individual buckets to get extrapolated below zero, but maybe that is
fine.

This implements approach (2) as described in
#15976 (comment)

Signed-off-by: beorn7 <beorn@grafana.com>
@beorn7 beorn7 force-pushed the beorn7/histogram2 branch from 19407d8 to bcf7a82 Compare July 8, 2025 17:01
@beorn7 beorn7 marked this pull request as ready for review July 8, 2025 17:02
@beorn7 beorn7 requested a review from roidelapluie as a code owner July 8, 2025 17:02
@beorn7 beorn7 requested review from krajorama and removed request for roidelapluie July 8, 2025 17:31
@beorn7 beorn7 changed the title PoC for approach (2): scale a histogram the same as the count promql(histograms): scale a histogram the same as the count Jul 8, 2025
Copy link
Member

@krajorama krajorama left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, we could add some testcases to show that histogram_count behaves correctly, but that can be a next PR.

@beorn7 beorn7 merged commit 3621413 into main Jul 10, 2025
45 checks passed
@beorn7 beorn7 deleted the beorn7/histogram2 branch July 10, 2025 11:26
Konstantinov-Innokentii added a commit to grafana/mimir that referenced this pull request Jul 17, 2025
Upstream pr - prometheus/prometheus#16828

Signed-off-by: Innokentii Konstantinov <innokenty.konstantinov@grafana.com>
Konstantinov-Innokentii added a commit to grafana/mimir that referenced this pull request Jul 21, 2025
## Update mimir-prometheus dependency

*This PR was automatically created by the
[update-vendored-mimir-prometheus.yml](https://github.com/grafana/mimir/blob/main/.github/workflows/update-vendored-mimir-prometheus.yml)
workflow.*

### Details:
- **Source branch/ref**:
[`main`](https://github.com/grafana/mimir-prometheus/tree/main)
- **Previous commit**:
[`73cbc98c25ff`](grafana/mimir-prometheus@73cbc98c25ff)
- **New commit**:
[`acace3cd1e0232d0d167e1f8062accd0a318d06c`](grafana/mimir-prometheus@acace3c)
- **Changes**:
[`73cbc98c25ff...acace3cd1e0232d0d167e1f8062accd0a318d06c`](grafana/mimir-prometheus@73cbc98...acace3c)

### Note to reviewer:
There are two manual changes to make it mergeable:

- [Use NewLeveledCompactorWithOptions instead of
NewLeveledCompactorWithChunkSize](7e0061b)
– NewLeveledCompactorWithChunkSize was removed in upstream

- [ Port "Prevent extrapolation below zero for histogram count" to MQE
](https://github.com/grafana/mimir/pull/12106/files#diff-1256527183ea6d432ef0f080e75927eefb108f47554f9e20633c1b30756a3134).
This one is more subtle.
prometheus/prometheus#16828 was merged in
upstream, affecting query results and causing some MQE tests to fail.
The solution was to port the change to the MQE histogram rate
implementation.

---------

Signed-off-by: Innokentii Konstantinov <innokenty.konstantinov@grafana.com>
Co-authored-by: mimir-github-bot[bot] <mimir-github-bot[bot]@users.noreply.github.com>
Co-authored-by: Innokentii Konstantinov <innokenty.konstantinov@grafana.com>
Co-authored-by: Dimitar Dimitrov <dimitar.dimitrov@grafana.com>
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