Adding new test section to check on metrics

Signed-off-by: Pedro Tanaka <pedro.tanaka@shopify.com>
This commit is contained in:
Pedro Tanaka 2022-04-22 14:58:21 +02:00
parent 2d339b0853
commit d015cda365
No known key found for this signature in database
GPG key ID: D0D8389DA4EE060B

View file

@ -22,9 +22,9 @@ func TestRelay_RelayLine(t *testing.T) {
args args
}{
{
name: "single line",
name: "multiple lines",
args: args{
lines: []string{"foo5:100|c|#tag1:bar,#tag2:baz"},
lines: []string{"foo5:100|c|#tag1:bar,#tag2:baz", "foo2:200|c|#tag1:bar,#tag2:baz"},
expected: "foo5:100|c|#tag1:bar,#tag2:baz\n",
},
},
@ -66,18 +66,22 @@ func TestRelay_RelayLine(t *testing.T) {
}
metricNames := map[string]float64{
"statsd_exporter_relay_long_lines_total": 0,
"statsd_exporter_relay_long_lines_total": 0,
"statsd_exporter_relay_lines_relayed_total": float64(len(tt.args.lines)),
}
for metricName, expectedValue := range metricNames {
firstMetric := getFloat64(metrics, metricName, prometheus.Labels{"target": "localhost:1160"})
metric := getFloat64(metrics, metricName, prometheus.Labels{"target": "localhost:1160"})
if firstMetric == nil {
if metric == nil {
t.Fatalf("Could not find time series with first label set for metric: %s", metricName)
}
if *firstMetric != expectedValue {
t.Errorf("Expected metric %s to be %f, got %f", metricName, expectedValue, *firstMetric)
if *metric != expectedValue {
t.Errorf("Expected metric %s to be %f, got %f", metricName, expectedValue, *metric)
}
}
prometheus.Unregister(relayLongLinesTotal)
prometheus.Unregister(relayLinesRelayedTotal)
})
}
}