Skip to content

Instantly share code, notes, and snippets.

@lmb
Created February 9, 2017 11:00
Show Gist options
  • Save lmb/3caaeb79efc6d6e0d2bdde8a4865e636 to your computer and use it in GitHub Desktop.
Save lmb/3caaeb79efc6d6e0d2bdde8a4865e636 to your computer and use it in GitHub Desktop.
Prometheus client_golang histogram race
package main
import (
"fmt"
"github.com/golang/protobuf/proto"
"github.com/prometheus/client_golang/prometheus"
dto "github.com/prometheus/client_model/go"
)
func main() {
hist := prometheus.NewHistogram(prometheus.HistogramOpts{
Name: "race",
Help: "racy racer",
Buckets: []float64{1.0, 2.0},
})
go func() {
for {
hist.Observe(1.9)
}
}()
res := make(chan *dto.Metric, 10000)
go func() {
for {
var obs dto.Metric
hist.Write(&obs)
res <- &obs
}
}()
i := 0
for obs := range res {
last := obs.Histogram.Bucket[len(obs.Histogram.Bucket)-1]
if *obs.Histogram.SampleCount < *last.CumulativeCount {
fmt.Println("found race")
fmt.Println(proto.MarshalTextString(obs.Histogram))
return
}
i++
if i == 100000 {
fmt.Print(".")
i = 0
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment