Skip to content
This repository has been archived by the owner on Jul 31, 2023. It is now read-only.

Exporter/Prometheus: Simplify histogram creation. #1061

Merged
merged 3 commits into from
Mar 13, 2019

Conversation

songy23
Copy link
Contributor

@songy23 songy23 commented Mar 12, 2019

And resolve a TODO.

With #979 and #1037, bucket bounds are guaranteed to be positive and strictly increasing.

Copy link
Member

@odeke-em odeke-em left a comment

Choose a reason for hiding this comment

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

@songy23 thanks for this change! However, I'd rather keep it as it was; merging this PR will take us back to a problem that was actually reported in May 2018. This is a bug we saw in the wild in #649 and fixed with PR #661
and Prometheus mentions this expectation at https://godoc.org/github.com/prometheus/client_golang/prometheus#NewConstHistogram.

@odeke-em
Copy link
Member

If a user defines v := view.Distribution(0, 10, 9, 20, 40) what does OpenCensus-Go do? Currently nothing, which wouldn't mitigate the problem at core. We should at that call site panic but we don't. Those changes in #979 and #1037 enforce no negative bounds but really this code is about monotonic arrangement and sorting which is totally different from the assumption of this PR, thus my objection to not merge.

@songy23
Copy link
Contributor Author

songy23 commented Mar 12, 2019

AFAIS #649 is a different issue where we didn't use cumulative counts for histogram in Prometheus. This PR doesn't change that part.

For the case when bucket bounds are out of order, we should fail fast when creating the distribution aggregation. This is the case in Java: https://github.com/census-instrumentation/opencensus-java/blob/master/api/src/main/java/io/opencensus/stats/BucketBoundaries.java#L52-L58. I'll add a PR in Go that also checks this.

@songy23
Copy link
Contributor Author

songy23 commented Mar 12, 2019

If a user defines v := view.Distribution(0, 10, 9, 20, 40) what does OpenCensus-Go do?

This should return an error. This is already specified in the proto and is also a requirement for GA. /cc @mayurkale22

@rghetia
Copy link
Contributor

rghetia commented Mar 12, 2019

it sorts the buckets here

@songy23
Copy link
Contributor Author

songy23 commented Mar 12, 2019

it sorts the buckets here

I see, then we can always guarantee the bucket bounds are ordered. I think merging this PR won't cause any problem then.

@rghetia
Copy link
Contributor

rghetia commented Mar 12, 2019

it sorts the buckets here

I see, then we can always guarantee the bucket bounds are ordered. I think merging this PR won't cause any problem then.

I don't think it should create any problem.

@odeke-em
Copy link
Member

Alright, cool then. But let's add a test to ensure that it doesn't trip things out. I ask because the PR #979 that adding sorting (4 months ago) didn't add a test for that check hence the assumptions that it won't break.

@bogdandrutu
Copy link
Contributor

+1 for having a test

@songy23
Copy link
Contributor Author

songy23 commented Mar 13, 2019

Added a test in 1f91333, PTAL.

// We want the results that look like this:
// 1: [0.25] | 1 + prev(i) = 1 + 0 = 1
// 5: [1.45] | 1 + prev(i) = 1 + 1 = 2
// 10: [] | 1 + prev(i) = 1 + 2 = 3
Copy link
Member

Choose a reason for hiding this comment

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

There is a problem here, 7.69 has to be in 10 bucket. Or is that just a bad copy+paste?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I copied and pasted it from

// We want the results that look like this:
// 1: [0.25] | 1 + prev(i) = 1 + 0 = 1
// 5: [1.45] | 1 + prev(i) = 1 + 1 = 2
// 10: [] | 1 + prev(i) = 1 + 2 = 3
// 20: [12] | 1 + prev(i) = 1 + 3 = 4
// 50: [] | 0 + prev(i) = 0 + 4 = 4
// 100: [] | 0 + prev(i) = 0 + 4 = 4
// 250: [187.12, 199.9, 245.67] | 3 + prev(i) = 3 + 4 = 7
. Looks like the previous comments are wrong. Updated.

Copy link
Member

Choose a reason for hiding this comment

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

I think they got stale during the removal of 0 as the first bucket bound, but now this is cool. Thanks for fixing them!


// Intentionally used unordered elements in the ascending distribution
// to ensure unordered bucket bounds are handled.
Aggregation: view.Distribution(10, 5, 1, 50, 20, 100, 250),
Copy link
Member

Choose a reason for hiding this comment

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

Also make sure that we duplicate a bucket boundary in there as the previous code also deduplicated boundaries :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

SG, done.

@songy23 songy23 merged commit 084f0af into census-instrumentation:master Mar 13, 2019
@songy23 songy23 deleted the prometheus-histogram branch March 13, 2019 06:18
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants