Skip to content

Instantly share code, notes, and snippets.

@k24dizzle
Created May 1, 2023 19:21
Show Gist options
  • Save k24dizzle/54d6c45b95bdeb76bf82632280ee2bfa to your computer and use it in GitHub Desktop.
Save k24dizzle/54d6c45b95bdeb76bf82632280ee2bfa to your computer and use it in GitHub Desktop.
histogram sum is not correct example
package main
import (
"fmt"
"net/http"
"time"
"github.com/prometheus/client_golang/prometheus"
tally "github.com/uber-go/tally/v4"
promreporter "github.com/uber-go/tally/v4/prometheus"
)
func main() {
reg := prometheus.NewRegistry()
r := promreporter.NewReporter(promreporter.Options{
Registerer: reg,
})
// Note: `promreporter.DefaultSeparator` is "_".
// Prometheus doesnt like metrics with "." or "-" in them.
scope, closer := tally.NewRootScope(tally.ScopeOptions{
Tags: map[string]string{},
CachedReporter: r,
Separator: promreporter.DefaultSeparator,
}, 1*time.Second)
defer closer.Close()
boundaries := []float64{
1,
11,
111,
}
histogram := scope.Tagged(map[string]string{
"foo": "quk",
}).Histogram("test_histogram", tally.ValueBuckets(boundaries))
go func() {
for {
time.Sleep(time.Second)
histogram.RecordValue(10)
}
}()
http.Handle("/metrics", r.HTTPHandler())
fmt.Printf("Serving :8080/metrics\n")
fmt.Printf("%v\n", http.ListenAndServe(":8080", nil))
select {}
}
# HELP test_histogram test_histogram histogram
# TYPE test_histogram histogram
test_histogram_bucket{foo="quk",le="1"} 0
test_histogram_bucket{foo="quk",le="11"} 21
test_histogram_bucket{foo="quk",le="111"} 21
test_histogram_bucket{foo="quk",le="+Inf"} 21
test_histogram_sum{foo="quk"} 231
test_histogram_count{foo="quk"} 21
@k24dizzle
Copy link
Author

test_histogram_sum should always be a multiple of 10, but instead it is a multiple of 11

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment