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

Function expectCTsForMetricVecValues

prometheus/counter_test.go:357–387  ·  view source on GitHub ↗
(t testing.TB, vec *MetricVec, typ dto.MetricType, ctsPerLabelValue map[string]time.Time)

Source from the content-addressed store, hash-verified

355}
356
357func expectCTsForMetricVecValues(t testing.TB, vec *MetricVec, typ dto.MetricType, ctsPerLabelValue map[string]time.Time) {
358 t.Helper()
359
360 for val, ct := range ctsPerLabelValue {
361 var metric dto.Metric
362 m, err := vec.GetMetricWithLabelValues(val)
363 if err != nil {
364 t.Fatal(err)
365 }
366
367 if err := m.Write(&metric); err != nil {
368 t.Fatal(err)
369 }
370
371 var gotTs time.Time
372 switch typ {
373 case dto.MetricType_COUNTER:
374 gotTs = metric.Counter.CreatedTimestamp.AsTime()
375 case dto.MetricType_HISTOGRAM:
376 gotTs = metric.Histogram.CreatedTimestamp.AsTime()
377 case dto.MetricType_SUMMARY:
378 gotTs = metric.Summary.CreatedTimestamp.AsTime()
379 default:
380 t.Fatalf("unknown metric type %v", typ)
381 }
382
383 if !gotTs.Equal(ct) {
384 t.Errorf("expected created timestamp for %s with label value %q: %s, got %s", typ, val, ct, gotTs)
385 }
386 }
387}

Calls 2

WriteMethod · 0.65

Tested by

no test coverage detected