MCPcopy
hub / github.com/prometheus/pushgateway / TestHelpStringFix

Function TestHelpStringFix

storage/diskmetricstore_test.go:1473–1536  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1471}
1472
1473func TestHelpStringFix(t *testing.T) {
1474 dms := NewDiskMetricStore("", 100*time.Millisecond, prometheus.DefaultGatherer, logger)
1475
1476 ts1 := time.Now()
1477 errCh := make(chan error, 1)
1478 dms.SubmitWriteRequest(WriteRequest{
1479 Labels: map[string]string{
1480 "job": "job1",
1481 },
1482 Timestamp: ts1,
1483 MetricFamilies: map[string]*dto.MetricFamily{
1484 "go_goroutines": mfgg,
1485 "mf_help": mfh1,
1486 },
1487 })
1488 dms.SubmitWriteRequest(WriteRequest{
1489 Labels: map[string]string{
1490 "job": "job2",
1491 },
1492 Timestamp: ts1,
1493 MetricFamilies: map[string]*dto.MetricFamily{
1494 "mf_help": mfh2,
1495 },
1496 Done: errCh,
1497 })
1498 for err := range errCh {
1499 t.Fatal("Unexpected error:", err)
1500 }
1501
1502 // Either we have settled on the mfh1 help string or the mfh2 help string.
1503 gotMFs := dms.GetMetricFamilies()
1504 if len(gotMFs) != 4 {
1505 t.Fatalf("expected 4 metric families, got %d", len(gotMFs))
1506 }
1507 gotMFsAsStrings := make([]string, len(gotMFs))
1508 for i, mf := range gotMFs {
1509 sort.Sort(metricSorter(mf.GetMetric()))
1510 gotMFsAsStrings[i] = mf.String()
1511 }
1512 sort.Strings(gotMFsAsStrings)
1513 gotGG := gotMFsAsStrings[0]
1514 got12 := gotMFsAsStrings[1]
1515 expectedGG := mfggFixed.String()
1516 expected12 := mfh12.String()
1517 expected21 := mfh21.String()
1518
1519 if gotGG != expectedGG {
1520 t.Errorf(
1521 "help strings weren't properly adjusted, got '%s', expected '%s'",
1522 gotGG, expectedGG,
1523 )
1524 }
1525 if got12 != expected12 && got12 != expected21 {
1526 t.Errorf(
1527 "help strings weren't properly adjusted, got '%s' which is neither '%s' nor '%s'",
1528 got12, expected12, expected21,
1529 )
1530 }

Callers

nothing calls this directly

Calls 5

SubmitWriteRequestMethod · 0.95
GetMetricFamiliesMethod · 0.95
ShutdownMethod · 0.95
NewDiskMetricStoreFunction · 0.85
metricSorterTypeAlias · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…