Skip to content

Commit

Permalink
More test asserts fixed
Browse files Browse the repository at this point in the history
Follow-up to prometheus/client_golang#1424

Signed-off-by: György Krajcsovits <gyorgy.krajcsovits@grafana.com>
  • Loading branch information
krajorama committed Aug 30, 2024
1 parent 102125c commit b48666f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 39 deletions.
41 changes: 8 additions & 33 deletions pkg/distributor/distributor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,37 +418,7 @@ func TestDistributor_MetricsCleanup(t *testing.T) {

d.cleanupInactiveUser("userA")

require.NoError(t, testutil.GatherAndCompare(reg, strings.NewReader(`
# HELP cortex_distributor_deduped_samples_total The total number of deduplicated samples.
# TYPE cortex_distributor_deduped_samples_total counter
# HELP cortex_distributor_latest_seen_sample_timestamp_seconds Unix timestamp of latest received sample per user.
# TYPE cortex_distributor_latest_seen_sample_timestamp_seconds gauge
# HELP cortex_distributor_metadata_in_total The total number of metadata the have come in to the distributor, including rejected.
# TYPE cortex_distributor_metadata_in_total counter
# 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.
# TYPE cortex_distributor_non_ha_samples_received_total counter
# HELP cortex_distributor_received_metadata_total The total number of received metadata, excluding rejected.
# TYPE cortex_distributor_received_metadata_total counter
cortex_distributor_received_metadata_total{user="userB"} 10
# HELP cortex_distributor_received_samples_total The total number of received samples, excluding rejected and deduped samples.
# TYPE cortex_distributor_received_samples_total counter
cortex_distributor_received_samples_total{user="userB"} 10
# HELP cortex_distributor_received_exemplars_total The total number of received exemplars, excluding rejected and deduped exemplars.
# TYPE cortex_distributor_received_exemplars_total counter
cortex_distributor_received_exemplars_total{user="userB"} 10
# HELP cortex_distributor_samples_in_total The total number of samples that have come in to the distributor, including rejected or deduped samples.
# TYPE cortex_distributor_samples_in_total counter
# HELP cortex_distributor_exemplars_in_total The total number of exemplars that have come in to the distributor, including rejected or deduped exemplars.
# TYPE cortex_distributor_exemplars_in_total counter
`), metrics...))
require.ErrorContains(t, testutil.GatherAndCompare(reg, strings.NewReader(""), metrics...), "expected metric name(s) not found")
}

func TestDistributor_PushRequestRateLimiter(t *testing.T) {
Expand Down Expand Up @@ -1678,7 +1648,11 @@ func TestDistributor_ExemplarValidation(t *testing.T) {
}

assert.Equal(t, tc.expectedExemplars, tc.req.Timeseries)
assert.NoError(t, testutil.GatherAndCompare(regs[0], strings.NewReader(tc.expectedMetrics), "cortex_discarded_exemplars_total"))
if len(tc.expectedMetrics) > 0 {
assert.NoError(t, testutil.GatherAndCompare(regs[0], strings.NewReader(tc.expectedMetrics), "cortex_discarded_exemplars_total"))
} else {
assert.ErrorContains(t, testutil.GatherAndCompare(regs[0], strings.NewReader(""), "cortex_discarded_exemplars_total"), "expected metric name(s) not found")
}
})
}
}
Expand Down Expand Up @@ -7226,7 +7200,8 @@ func TestDistributor_StorageConfigMetrics(t *testing.T) {
# 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.
# TYPE cortex_distributor_ingest_storage_enabled gauge
cortex_distributor_ingest_storage_enabled 1
`), "cortex_distributor_replication_factor", "cortex_distributor_ingest_storage_enabled"))
`), "cortex_distributor_ingest_storage_enabled"))
assert.ErrorContains(t, testutil.GatherAndCompare(regs[0], strings.NewReader(""), "cortex_distributor_replication_factor"), "expected metric name(s) not found")
})
}

Expand Down
5 changes: 1 addition & 4 deletions pkg/frontend/v1/frontend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,7 @@ func TestFrontendMetricsCleanup(t *testing.T) {

fr.cleanupInactiveUserMetrics("1")

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

testFrontend(t, defaultFrontendConfig(), handler, test, nil, reg)
Expand Down
4 changes: 2 additions & 2 deletions pkg/querier/tenantfederation/merge_queryable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ func TestMergeQueryable_Select(t *testing.T) {
require.EqualError(t, seriesSet.Err(), tc.expectedQueryErr.Error())
} else {
require.NoError(t, seriesSet.Err())
assert.NoError(t, testutil.GatherAndCompare(reg, strings.NewReader(tc.expectedMetrics), "cortex_querier_federation_sample_tenants_queried"))
assert.NoError(t, testutil.GatherAndCompare(reg, strings.NewReader(tc.expectedMetrics), "cortex_querier_federation_tenants_queried"))
assertEqualWarnings(t, tc.expectedWarnings, seriesSet.Warnings())
}

Expand Down Expand Up @@ -709,7 +709,7 @@ func TestMergeQueryable_LabelNames(t *testing.T) {
} else {
require.NoError(t, err)
assert.Equal(t, scenario.labelNamesTestCase.expectedLabelNames, labelNames)
assert.NoError(t, testutil.GatherAndCompare(reg, strings.NewReader(scenario.labelNamesTestCase.expectedMetrics), "cortex_querier_federation_sample_tenants_queried"))
assert.NoError(t, testutil.GatherAndCompare(reg, strings.NewReader(scenario.labelNamesTestCase.expectedMetrics), "cortex_querier_federation_tenants_queried"))
assertEqualWarnings(t, scenario.labelNamesTestCase.expectedWarnings, warnings)
}
})
Expand Down

0 comments on commit b48666f

Please sign in to comment.