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

Function TestSanitizeLabels

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

Source from the content-addressed store, hash-verified

1180}
1181
1182func TestSanitizeLabels(t *testing.T) {
1183 dms := NewDiskMetricStore("", 100*time.Millisecond, nil, logger)
1184
1185 // Push mf1c with the grouping matching mf1b, mf1b should end up in storage.
1186 ts1 := time.Now()
1187 grouping1 := map[string]string{
1188 "job": "job1",
1189 "instance": "instance2",
1190 }
1191 errCh := make(chan error, 1)
1192 dms.SubmitWriteRequest(WriteRequest{
1193 Labels: grouping1,
1194 Timestamp: ts1,
1195 MetricFamilies: testutil.MetricFamiliesMap(mf1c),
1196 Done: errCh,
1197 })
1198 for err := range errCh {
1199 t.Fatal("Unexpected error:", err)
1200 }
1201 pushTimestamp := newPushTimestampGauge(grouping1, ts1)
1202 pushFailedTimestamp := newPushFailedTimestampGauge(grouping1, time.Time{})
1203 if err := checkMetricFamilies(
1204 dms, mf1b,
1205 pushTimestamp, pushFailedTimestamp,
1206 ); err != nil {
1207 t.Error(err)
1208 }
1209
1210 // Push mf1e, missing the instance label. Again, mf1b should end up in storage.
1211 ts2 := ts1.Add(1)
1212 errCh = make(chan error, 1)
1213 dms.SubmitWriteRequest(WriteRequest{
1214 Labels: grouping1,
1215 Timestamp: ts2,
1216 MetricFamilies: testutil.MetricFamiliesMap(mf1e),
1217 Done: errCh,
1218 })
1219 for err := range errCh {
1220 t.Fatal("Unexpected error:", err)
1221 }
1222 pushTimestamp = newPushTimestampGauge(grouping1, ts2)
1223 if err := checkMetricFamilies(
1224 dms, mf1b,
1225 pushTimestamp, pushFailedTimestamp,
1226 ); err != nil {
1227 t.Error(err)
1228 }
1229
1230 // Push mf1e, missing the instance label, into a grouping without the
1231 // instance label. The result in the storage should have an empty
1232 // instance label.
1233 ts3 := ts2.Add(1)
1234 grouping3 := map[string]string{
1235 "job": "job1",
1236 }
1237 errCh = make(chan error, 1)
1238 dms.SubmitWriteRequest(WriteRequest{
1239 Labels: grouping3,

Callers

nothing calls this directly

Calls 7

SubmitWriteRequestMethod · 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…