Created
February 9, 2017 11:00
-
-
Save lmb/3caaeb79efc6d6e0d2bdde8a4865e636 to your computer and use it in GitHub Desktop.
Prometheus client_golang histogram race
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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