Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add histogram #1145

Merged
merged 20 commits into from
Nov 2, 2021
Merged

Conversation

stuartnelson3
Copy link
Contributor

WIP for adding histogram support for prometheus.

The change to Metric is very much "make it work". I'd prefer to either add some sort of metric type identifier within the Metric type and some way to enforce validity within the type (Buckets and Counts should both be set and the correct length, Value shouldn't be set at the same time as Buckets and Counts), or some sort of metric type interface.

Example sample:

Samples:map[histogram:{Value:0 Buckets:[0.0025 0.0075 0.0175 0.037500000000000006 0.07500000000000001 0.175 0.375 0.75 1.75 3.75 5] Counts:[0 0 0 0 3 3 3 3 3 3 3]}]

@stuartnelson3 stuartnelson3 requested a review from a team October 28, 2021 12:27
@apmmachine
Copy link
Contributor

apmmachine commented Oct 28, 2021

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview preview

Expand to view the summary

Build stats

  • Start Time: 2021-11-02T10:35:44.323+0000

  • Duration: 33 min 30 sec

  • Commit: 4b8c596

Test stats 🧪

Test Results
Failed 0
Passed 11644
Skipped 268
Total 11912

🤖 GitHub comments

To re-run your PR in the CI, just comment with:

  • /test : Re-trigger the build.

  • run benchmark tests : Run the benchmark test.

the Add() method now takes a metricType argument,
but I'm wondering if we should move to AddXXX
similar to how there's AddHistogram.
seems a bit neater as an API
Copy link
Member

@axw axw left a comment

Choose a reason for hiding this comment

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

Looks great! I'd prefer we don't add Gauge/Count/Summary just yet, as we're not doing anything with them and there's risk that they'll need to change.

model/model.go Outdated Show resolved Hide resolved
metrics.go Outdated Show resolved Hide resolved
metrics.go Outdated Show resolved Hide resolved
metrics.go Outdated Show resolved Hide resolved
metrics.go Outdated Show resolved Hide resolved
metrics.go Outdated Show resolved Hide resolved
module/apmprometheus/gatherer.go Outdated Show resolved Hide resolved
module/apmprometheus/gatherer.go Outdated Show resolved Hide resolved
@stuartnelson3
Copy link
Contributor Author

Tests are failing because of my use of math.Round, which was introduced in go1.10. Do we still want/need to support versions this old? go1.9 was released in august 2017.

Copy link
Member

@axw axw left a comment

Choose a reason for hiding this comment

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

Looks good overall, just a few small things.

Tests are failing because of my use of math.Round, which was introduced in go1.10. Do we still want/need to support versions this old? go1.9 was released in august 2017.

I don't want to, but yes we need to until we release a v2 of the agent.

There's an internal package with a round implementation for older versions of Go: https://github.com/elastic/apm-agent-go/tree/master/internal/apmmath

model/marshal.go Outdated Show resolved Hide resolved
model/marshal.go Outdated Show resolved Hide resolved
module/apmprometheus/gatherer.go Outdated Show resolved Hide resolved
module/apmprometheus/gatherer.go Outdated Show resolved Hide resolved
@stuartnelson3 stuartnelson3 marked this pull request as ready for review November 1, 2021 10:19
Copy link
Member

@axw axw left a comment

Choose a reason for hiding this comment

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

Code looks in good shape, seems to be an issue with the value for the last bucket.

module/apmprometheus/gatherer.go Outdated Show resolved Hide resolved
module/apmprometheus/gatherer_test.go Outdated Show resolved Hide resolved
module/apmprometheus/gatherer.go Outdated Show resolved Hide resolved
Copy link
Member

@axw axw left a comment

Choose a reason for hiding this comment

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

perfect!

// we need to modify the current final bucket,
// and add an additional bucket with these
// observations.
if infBucketCount := totalCount - bucketCount; infBucketCount > 0 {
Copy link
Member

Choose a reason for hiding this comment

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

Is it worth adding a valuesLen > 0 check to this? I don't see why anyone would do that, but we probably shouldn't panic if they do.

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 don't think that can happen, since you can't create a histogram with 0 buckets, but it doesn't hurt to check

https://github.com/prometheus/client_golang/blob/master/prometheus/histogram.go#L221-L223

@stuartnelson3 stuartnelson3 enabled auto-merge (squash) November 2, 2021 10:40
@stuartnelson3 stuartnelson3 merged commit ee25156 into elastic:master Nov 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants