Skip to content

Commit 31e9d82

Browse files
authored
Add test for missing labels (#463)
1 parent 89f2c60 commit 31e9d82

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

pkg/pipeline/encode/encode_prom_test.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,50 @@ func Test_MetricTTL(t *testing.T) {
328328
require.NotContains(t, exposed, `test_bytes_total{dstIP="30.0.0.3",srcIP="10.0.0.1"}`)
329329
}
330330

331+
func Test_MissingLabels(t *testing.T) {
332+
metrics := []config.GenericMap{
333+
{
334+
"namespace": "A",
335+
"IP": "10.0.0.1",
336+
"bytes": 7,
337+
},
338+
{
339+
"namespace": "A",
340+
"IP": "10.0.0.2",
341+
"bytes": 1,
342+
},
343+
{
344+
"IP": "10.0.0.3",
345+
"bytes": 4,
346+
},
347+
}
348+
params := api.PromEncode{
349+
ExpiryTime: api.Duration{
350+
Duration: time.Duration(60 * time.Second),
351+
},
352+
Metrics: []api.PromMetricsItem{
353+
{
354+
Name: "my_counter",
355+
Type: "counter",
356+
ValueKey: "bytes",
357+
Labels: []string{"namespace"},
358+
},
359+
},
360+
}
361+
362+
encodeProm, err := initProm(&params)
363+
require.NoError(t, err)
364+
for _, metric := range metrics {
365+
encodeProm.Encode(metric)
366+
}
367+
time.Sleep(100 * time.Millisecond)
368+
369+
exposed := test.ReadExposedMetrics(t)
370+
371+
require.Contains(t, exposed, `my_counter{namespace="A"} 8`)
372+
require.Contains(t, exposed, `my_counter{namespace=""} 4`)
373+
}
374+
331375
func buildFlow() config.GenericMap {
332376
return config.GenericMap{
333377
"srcIP": "10.0.0." + strconv.Itoa(rand.Intn(20)),

0 commit comments

Comments
 (0)