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

Function TestRejectInconsistentPush

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

Source from the content-addressed store, hash-verified

1096}
1097
1098func TestRejectInconsistentPush(t *testing.T) {
1099 dms := NewDiskMetricStore("", 100*time.Millisecond, nil, logger)
1100
1101 ts1 := time.Now()
1102 grouping1 := map[string]string{
1103 "job": "job1",
1104 }
1105 errCh := make(chan error, 1)
1106 dms.SubmitWriteRequest(WriteRequest{
1107 Labels: grouping1,
1108 Timestamp: ts1,
1109 MetricFamilies: testutil.MetricFamiliesMap(mfgc),
1110 Done: errCh,
1111 })
1112 var err error
1113 for err = range errCh {
1114 }
1115 if err == nil {
1116 t.Error("Expected error pushing inconsistent go_goroutines metric.")
1117 }
1118 pushTimestamp := newPushTimestampGauge(grouping1, time.Time{})
1119 pushFailedTimestamp := newPushFailedTimestampGauge(grouping1, ts1)
1120 if err := checkMetricFamilies(
1121 dms,
1122 pushTimestamp, pushFailedTimestamp,
1123 ); err != nil {
1124 t.Error(err)
1125 }
1126
1127 ts2 := ts1.Add(time.Second)
1128 errCh = make(chan error, 1)
1129 dms.SubmitWriteRequest(WriteRequest{
1130 Labels: grouping1,
1131 Timestamp: ts2,
1132 MetricFamilies: testutil.MetricFamiliesMap(mf1a),
1133 Done: errCh,
1134 })
1135 for err := range errCh {
1136 t.Fatal("Unexpected error:", err)
1137 }
1138 pushTimestamp = newPushTimestampGauge(grouping1, ts2)
1139 if err := checkMetricFamilies(
1140 dms, mf1a,
1141 pushTimestamp, pushFailedTimestamp,
1142 ); err != nil {
1143 t.Error(err)
1144 }
1145
1146 ts3 := ts2.Add(time.Second)
1147 grouping3 := map[string]string{
1148 "job": "job1",
1149 "instance": "instance2",
1150 }
1151 errCh = make(chan error, 1)
1152 dms.SubmitWriteRequest(WriteRequest{
1153 Labels: grouping3,
1154 Timestamp: ts3,
1155 MetricFamilies: testutil.MetricFamiliesMap(mf1b),

Callers

nothing calls this directly

Calls 8

SubmitWriteRequestMethod · 0.95
ShutdownMethod · 0.95
MetricFamiliesMapFunction · 0.92
NewDiskMetricStoreFunction · 0.85
newPushTimestampGaugeFunction · 0.85
checkMetricFamiliesFunction · 0.85
ErrorMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…