MCPcopy
hub / github.com/prometheus/client_golang / TestHistogramVecConcurrency

Function TestHistogramVecConcurrency

prometheus/histogram_test.go:241–329  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

239}
240
241func TestHistogramVecConcurrency(t *testing.T) {
242 if testing.Short() {
243 t.Skip("Skipping test in short mode.")
244 }
245
246 rand.New(rand.NewSource(42))
247
248 it := func(n uint32) bool {
249 mutations := int(n%1e4 + 1e4)
250 concLevel := int(n%7 + 1)
251 vecLength := int(n%3 + 1)
252
253 var start, end sync.WaitGroup
254 start.Add(1)
255 end.Add(concLevel)
256
257 his := NewHistogramVec(
258 HistogramOpts{
259 Name: "test_histogram",
260 Help: "helpless",
261 Buckets: []float64{-2, -1, -0.5, 0, 0.5, 1, 2, math.Inf(+1)},
262 },
263 []string{"label"},
264 )
265
266 allVars := make([][]float64, vecLength)
267 sampleSums := make([]float64, vecLength)
268 for i := 0; i < concLevel; i++ {
269 vals := make([]float64, mutations)
270 picks := make([]int, mutations)
271 for j := 0; j < mutations; j++ {
272 v := rand.NormFloat64()
273 vals[j] = v
274 pick := rand.Intn(vecLength)
275 picks[j] = pick
276 allVars[pick] = append(allVars[pick], v)
277 sampleSums[pick] += v
278 }
279
280 go func(vals []float64) {
281 start.Wait()
282 for i, v := range vals {
283 his.WithLabelValues(string('A' + rune(picks[i]))).Observe(v)
284 }
285 end.Done()
286 }(vals)
287 }
288 for _, vars := range allVars {
289 sort.Float64s(vars)
290 }
291 start.Done()
292 end.Wait()
293
294 for i := 0; i < vecLength; i++ {
295 m := &dto.Metric{}
296 s := his.WithLabelValues(string('A' + rune(i)))
297 s.(Histogram).Write(m)
298

Callers

nothing calls this directly

Calls 8

WithLabelValuesMethod · 0.95
getCumulativeCountsFunction · 0.85
WaitMethod · 0.80
NewHistogramVecFunction · 0.70
AddMethod · 0.65
ObserveMethod · 0.65
WriteMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected