Skip to content

Commit dd9b196

Browse files
committed
format metrics and cover histogram true for relabel
Signed-off-by: Ben Ye <[email protected]>
1 parent ac8d1f7 commit dd9b196

File tree

1 file changed

+46
-43
lines changed

1 file changed

+46
-43
lines changed

pkg/distributor/distributor_test.go

Lines changed: 46 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -290,10 +290,10 @@ func TestDistributor_Push(t *testing.T) {
290290
# HELP cortex_distributor_latest_seen_sample_timestamp_seconds Unix timestamp of latest received sample per user.
291291
# TYPE cortex_distributor_latest_seen_sample_timestamp_seconds gauge
292292
cortex_distributor_latest_seen_sample_timestamp_seconds{user="userDistributorPush"} 123456789.004
293-
# HELP cortex_distributor_received_samples_total The total number of received samples, excluding rejected and deduped samples.
294-
# TYPE cortex_distributor_received_samples_total counter
295-
cortex_distributor_received_samples_total{type="float",user="userDistributorPush"} 0
296-
cortex_distributor_received_samples_total{type="histogram",user="userDistributorPush"} 5
293+
# HELP cortex_distributor_received_samples_total The total number of received samples, excluding rejected and deduped samples.
294+
# TYPE cortex_distributor_received_samples_total counter
295+
cortex_distributor_received_samples_total{type="float",user="userDistributorPush"} 0
296+
cortex_distributor_received_samples_total{type="histogram",user="userDistributorPush"} 5
297297
`,
298298
},
299299
"A push to 2 happy ingesters should succeed, histograms": {
@@ -308,10 +308,10 @@ func TestDistributor_Push(t *testing.T) {
308308
# HELP cortex_distributor_latest_seen_sample_timestamp_seconds Unix timestamp of latest received sample per user.
309309
# TYPE cortex_distributor_latest_seen_sample_timestamp_seconds gauge
310310
cortex_distributor_latest_seen_sample_timestamp_seconds{user="userDistributorPush"} 123456789.004
311-
# HELP cortex_distributor_received_samples_total The total number of received samples, excluding rejected and deduped samples.
312-
# TYPE cortex_distributor_received_samples_total counter
313-
cortex_distributor_received_samples_total{type="float",user="userDistributorPush"} 0
314-
cortex_distributor_received_samples_total{type="histogram",user="userDistributorPush"} 5
311+
# HELP cortex_distributor_received_samples_total The total number of received samples, excluding rejected and deduped samples.
312+
# TYPE cortex_distributor_received_samples_total counter
313+
cortex_distributor_received_samples_total{type="float",user="userDistributorPush"} 0
314+
cortex_distributor_received_samples_total{type="histogram",user="userDistributorPush"} 5
315315
`,
316316
},
317317
"A push to 1 happy ingesters should fail, histograms": {
@@ -325,10 +325,10 @@ func TestDistributor_Push(t *testing.T) {
325325
# HELP cortex_distributor_latest_seen_sample_timestamp_seconds Unix timestamp of latest received sample per user.
326326
# TYPE cortex_distributor_latest_seen_sample_timestamp_seconds gauge
327327
cortex_distributor_latest_seen_sample_timestamp_seconds{user="userDistributorPush"} 123456789.009
328-
# HELP cortex_distributor_received_samples_total The total number of received samples, excluding rejected and deduped samples.
329-
# TYPE cortex_distributor_received_samples_total counter
330-
cortex_distributor_received_samples_total{type="float",user="userDistributorPush"} 0
331-
cortex_distributor_received_samples_total{type="histogram",user="userDistributorPush"} 10
328+
# HELP cortex_distributor_received_samples_total The total number of received samples, excluding rejected and deduped samples.
329+
# TYPE cortex_distributor_received_samples_total counter
330+
cortex_distributor_received_samples_total{type="float",user="userDistributorPush"} 0
331+
cortex_distributor_received_samples_total{type="histogram",user="userDistributorPush"} 10
332332
`,
333333
},
334334
"A push exceeding burst size should fail, histograms": {
@@ -343,10 +343,10 @@ func TestDistributor_Push(t *testing.T) {
343343
# HELP cortex_distributor_latest_seen_sample_timestamp_seconds Unix timestamp of latest received sample per user.
344344
# TYPE cortex_distributor_latest_seen_sample_timestamp_seconds gauge
345345
cortex_distributor_latest_seen_sample_timestamp_seconds{user="userDistributorPush"} 123456789.024
346-
# HELP cortex_distributor_received_samples_total The total number of received samples, excluding rejected and deduped samples.
347-
# TYPE cortex_distributor_received_samples_total counter
348-
cortex_distributor_received_samples_total{type="float",user="userDistributorPush"} 0
349-
cortex_distributor_received_samples_total{type="histogram",user="userDistributorPush"} 25
346+
# HELP cortex_distributor_received_samples_total The total number of received samples, excluding rejected and deduped samples.
347+
# TYPE cortex_distributor_received_samples_total counter
348+
cortex_distributor_received_samples_total{type="float",user="userDistributorPush"} 0
349+
cortex_distributor_received_samples_total{type="histogram",user="userDistributorPush"} 25
350350
`,
351351
},
352352
} {
@@ -3642,36 +3642,39 @@ func TestDistributor_Push_Relabel(t *testing.T) {
36423642

36433643
for _, tc := range cases {
36443644
tc := tc
3645-
t.Run(tc.name, func(t *testing.T) {
3646-
t.Parallel()
3647-
var err error
3648-
var limits validation.Limits
3649-
flagext.DefaultValues(&limits)
3650-
limits.MetricRelabelConfigs = tc.metricRelabelConfigs
3651-
3652-
ds, ingesters, _, _ := prepare(t, prepConfig{
3653-
numIngesters: 2,
3654-
happyIngesters: 2,
3655-
numDistributors: 1,
3656-
shardByAllLabels: true,
3657-
limits: &limits,
3658-
})
3645+
for _, enableHistogram := range []bool{false, true} {
3646+
enableHistogram := enableHistogram
3647+
t.Run(fmt.Sprintf("%s, histogram=%s", tc.name, strconv.FormatBool(enableHistogram)), func(t *testing.T) {
3648+
t.Parallel()
3649+
var err error
3650+
var limits validation.Limits
3651+
flagext.DefaultValues(&limits)
3652+
limits.MetricRelabelConfigs = tc.metricRelabelConfigs
36593653

3660-
// Push the series to the distributor
3661-
req := mockWriteRequest(tc.inputSeries, 1, 1, false)
3662-
_, err = ds[0].Push(ctx, req)
3663-
require.NoError(t, err)
3654+
ds, ingesters, _, _ := prepare(t, prepConfig{
3655+
numIngesters: 2,
3656+
happyIngesters: 2,
3657+
numDistributors: 1,
3658+
shardByAllLabels: true,
3659+
limits: &limits,
3660+
})
36643661

3665-
// Since each test pushes only 1 series, we do expect the ingester
3666-
// to have received exactly 1 series
3667-
for i := range ingesters {
3668-
timeseries := ingesters[i].series()
3669-
assert.Equal(t, 1, len(timeseries))
3670-
for _, v := range timeseries {
3671-
assert.Equal(t, tc.expectedSeries, cortexpb.FromLabelAdaptersToLabels(v.Labels))
3662+
// Push the series to the distributor
3663+
req := mockWriteRequest(tc.inputSeries, 1, 1, enableHistogram)
3664+
_, err = ds[0].Push(ctx, req)
3665+
require.NoError(t, err)
3666+
3667+
// Since each test pushes only 1 series, we do expect the ingester
3668+
// to have received exactly 1 series
3669+
for i := range ingesters {
3670+
timeseries := ingesters[i].series()
3671+
assert.Equal(t, 1, len(timeseries))
3672+
for _, v := range timeseries {
3673+
assert.Equal(t, tc.expectedSeries, cortexpb.FromLabelAdaptersToLabels(v.Labels))
3674+
}
36723675
}
3673-
}
3674-
})
3676+
})
3677+
}
36753678
}
36763679
}
36773680

0 commit comments

Comments
 (0)