Skip to content

Commit

Permalink
Add test for missing labels (#463)
Browse files Browse the repository at this point in the history
  • Loading branch information
jotak authored Aug 2, 2023
1 parent 89f2c60 commit 31e9d82
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions pkg/pipeline/encode/encode_prom_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,50 @@ func Test_MetricTTL(t *testing.T) {
require.NotContains(t, exposed, `test_bytes_total{dstIP="30.0.0.3",srcIP="10.0.0.1"}`)
}

func Test_MissingLabels(t *testing.T) {
metrics := []config.GenericMap{
{
"namespace": "A",
"IP": "10.0.0.1",
"bytes": 7,
},
{
"namespace": "A",
"IP": "10.0.0.2",
"bytes": 1,
},
{
"IP": "10.0.0.3",
"bytes": 4,
},
}
params := api.PromEncode{
ExpiryTime: api.Duration{
Duration: time.Duration(60 * time.Second),
},
Metrics: []api.PromMetricsItem{
{
Name: "my_counter",
Type: "counter",
ValueKey: "bytes",
Labels: []string{"namespace"},
},
},
}

encodeProm, err := initProm(&params)
require.NoError(t, err)
for _, metric := range metrics {
encodeProm.Encode(metric)
}
time.Sleep(100 * time.Millisecond)

exposed := test.ReadExposedMetrics(t)

require.Contains(t, exposed, `my_counter{namespace="A"} 8`)
require.Contains(t, exposed, `my_counter{namespace=""} 4`)
}

func buildFlow() config.GenericMap {
return config.GenericMap{
"srcIP": "10.0.0." + strconv.Itoa(rand.Intn(20)),
Expand Down

0 comments on commit 31e9d82

Please sign in to comment.