Skip to content

Commit b48666f

Browse files
committed
More test asserts fixed
Follow-up to prometheus/client_golang#1424 Signed-off-by: György Krajcsovits <[email protected]>
1 parent 102125c commit b48666f

File tree

3 files changed

+11
-39
lines changed

3 files changed

+11
-39
lines changed

pkg/distributor/distributor_test.go

+8-33
Original file line numberDiff line numberDiff line change
@@ -418,37 +418,7 @@ func TestDistributor_MetricsCleanup(t *testing.T) {
418418

419419
d.cleanupInactiveUser("userA")
420420

421-
require.NoError(t, testutil.GatherAndCompare(reg, strings.NewReader(`
422-
# HELP cortex_distributor_deduped_samples_total The total number of deduplicated samples.
423-
# TYPE cortex_distributor_deduped_samples_total counter
424-
425-
# HELP cortex_distributor_latest_seen_sample_timestamp_seconds Unix timestamp of latest received sample per user.
426-
# TYPE cortex_distributor_latest_seen_sample_timestamp_seconds gauge
427-
428-
# HELP cortex_distributor_metadata_in_total The total number of metadata the have come in to the distributor, including rejected.
429-
# TYPE cortex_distributor_metadata_in_total counter
430-
431-
# HELP cortex_distributor_non_ha_samples_received_total The total number of received samples for a user that has HA tracking turned on, but the sample didn't contain both HA labels.
432-
# TYPE cortex_distributor_non_ha_samples_received_total counter
433-
434-
# HELP cortex_distributor_received_metadata_total The total number of received metadata, excluding rejected.
435-
# TYPE cortex_distributor_received_metadata_total counter
436-
cortex_distributor_received_metadata_total{user="userB"} 10
437-
438-
# HELP cortex_distributor_received_samples_total The total number of received samples, excluding rejected and deduped samples.
439-
# TYPE cortex_distributor_received_samples_total counter
440-
cortex_distributor_received_samples_total{user="userB"} 10
441-
442-
# HELP cortex_distributor_received_exemplars_total The total number of received exemplars, excluding rejected and deduped exemplars.
443-
# TYPE cortex_distributor_received_exemplars_total counter
444-
cortex_distributor_received_exemplars_total{user="userB"} 10
445-
446-
# HELP cortex_distributor_samples_in_total The total number of samples that have come in to the distributor, including rejected or deduped samples.
447-
# TYPE cortex_distributor_samples_in_total counter
448-
449-
# HELP cortex_distributor_exemplars_in_total The total number of exemplars that have come in to the distributor, including rejected or deduped exemplars.
450-
# TYPE cortex_distributor_exemplars_in_total counter
451-
`), metrics...))
421+
require.ErrorContains(t, testutil.GatherAndCompare(reg, strings.NewReader(""), metrics...), "expected metric name(s) not found")
452422
}
453423

454424
func TestDistributor_PushRequestRateLimiter(t *testing.T) {
@@ -1678,7 +1648,11 @@ func TestDistributor_ExemplarValidation(t *testing.T) {
16781648
}
16791649

16801650
assert.Equal(t, tc.expectedExemplars, tc.req.Timeseries)
1681-
assert.NoError(t, testutil.GatherAndCompare(regs[0], strings.NewReader(tc.expectedMetrics), "cortex_discarded_exemplars_total"))
1651+
if len(tc.expectedMetrics) > 0 {
1652+
assert.NoError(t, testutil.GatherAndCompare(regs[0], strings.NewReader(tc.expectedMetrics), "cortex_discarded_exemplars_total"))
1653+
} else {
1654+
assert.ErrorContains(t, testutil.GatherAndCompare(regs[0], strings.NewReader(""), "cortex_discarded_exemplars_total"), "expected metric name(s) not found")
1655+
}
16821656
})
16831657
}
16841658
}
@@ -7226,7 +7200,8 @@ func TestDistributor_StorageConfigMetrics(t *testing.T) {
72267200
# HELP cortex_distributor_ingest_storage_enabled Whether writes are being processed via ingest storage. Equal to 1 if ingest storage is enabled, 0 if disabled.
72277201
# TYPE cortex_distributor_ingest_storage_enabled gauge
72287202
cortex_distributor_ingest_storage_enabled 1
7229-
`), "cortex_distributor_replication_factor", "cortex_distributor_ingest_storage_enabled"))
7203+
`), "cortex_distributor_ingest_storage_enabled"))
7204+
assert.ErrorContains(t, testutil.GatherAndCompare(regs[0], strings.NewReader(""), "cortex_distributor_replication_factor"), "expected metric name(s) not found")
72307205
})
72317206
}
72327207

pkg/frontend/v1/frontend_test.go

+1-4
Original file line numberDiff line numberDiff line change
@@ -222,10 +222,7 @@ func TestFrontendMetricsCleanup(t *testing.T) {
222222

223223
fr.cleanupInactiveUserMetrics("1")
224224

225-
require.NoError(t, testutil.GatherAndCompare(reg, strings.NewReader(`
226-
# HELP cortex_query_frontend_queue_length Number of queries in the queue.
227-
# TYPE cortex_query_frontend_queue_length gauge
228-
`), "cortex_query_frontend_queue_length"))
225+
require.ErrorContains(t, testutil.GatherAndCompare(reg, strings.NewReader(""), "cortex_query_frontend_queue_length"), "expected metric name(s) not found")
229226
}
230227

231228
testFrontend(t, defaultFrontendConfig(), handler, test, nil, reg)

pkg/querier/tenantfederation/merge_queryable_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ func TestMergeQueryable_Select(t *testing.T) {
554554
require.EqualError(t, seriesSet.Err(), tc.expectedQueryErr.Error())
555555
} else {
556556
require.NoError(t, seriesSet.Err())
557-
assert.NoError(t, testutil.GatherAndCompare(reg, strings.NewReader(tc.expectedMetrics), "cortex_querier_federation_sample_tenants_queried"))
557+
assert.NoError(t, testutil.GatherAndCompare(reg, strings.NewReader(tc.expectedMetrics), "cortex_querier_federation_tenants_queried"))
558558
assertEqualWarnings(t, tc.expectedWarnings, seriesSet.Warnings())
559559
}
560560

@@ -709,7 +709,7 @@ func TestMergeQueryable_LabelNames(t *testing.T) {
709709
} else {
710710
require.NoError(t, err)
711711
assert.Equal(t, scenario.labelNamesTestCase.expectedLabelNames, labelNames)
712-
assert.NoError(t, testutil.GatherAndCompare(reg, strings.NewReader(scenario.labelNamesTestCase.expectedMetrics), "cortex_querier_federation_sample_tenants_queried"))
712+
assert.NoError(t, testutil.GatherAndCompare(reg, strings.NewReader(scenario.labelNamesTestCase.expectedMetrics), "cortex_querier_federation_tenants_queried"))
713713
assertEqualWarnings(t, scenario.labelNamesTestCase.expectedWarnings, warnings)
714714
}
715715
})

0 commit comments

Comments
 (0)