mirror of
https://github.com/prometheus/statsd_exporter.git
synced 2025-02-16 23:55:15 +00:00
Add test cases for conflicting metrics with labels
Signed-off-by: Clayton O'Neill <claytono@github.com>
This commit is contained in:
parent
9f1c6b81a5
commit
3dcad090b3
1 changed files with 60 additions and 16 deletions
|
@ -162,12 +162,12 @@ mappings:
|
||||||
func TestConflictingMetrics(t *testing.T) {
|
func TestConflictingMetrics(t *testing.T) {
|
||||||
scenarios := []struct {
|
scenarios := []struct {
|
||||||
name string
|
name string
|
||||||
expected float64
|
expected []float64
|
||||||
in Events
|
in Events
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "counter vs gauge",
|
name: "counter vs gauge",
|
||||||
expected: 1,
|
expected: []float64{1},
|
||||||
in: Events{
|
in: Events{
|
||||||
&CounterEvent{
|
&CounterEvent{
|
||||||
metricName: "cvg_test",
|
metricName: "cvg_test",
|
||||||
|
@ -179,9 +179,51 @@ func TestConflictingMetrics(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "counter vs gauge with different labels",
|
||||||
|
expected: []float64{1, 2},
|
||||||
|
in: Events{
|
||||||
|
&CounterEvent{
|
||||||
|
metricName: "cvgl_test",
|
||||||
|
value: 1,
|
||||||
|
labels: map[string]string{"tag": "1"},
|
||||||
|
},
|
||||||
|
&CounterEvent{
|
||||||
|
metricName: "cvgl_test",
|
||||||
|
value: 2,
|
||||||
|
labels: map[string]string{"tag": "2"},
|
||||||
|
},
|
||||||
|
&GaugeEvent{
|
||||||
|
metricName: "cvgl_test",
|
||||||
|
value: 3,
|
||||||
|
labels: map[string]string{"tag": "1"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "counter vs gauge with same labels",
|
||||||
|
expected: []float64{3},
|
||||||
|
in: Events{
|
||||||
|
&CounterEvent{
|
||||||
|
metricName: "cvgsl_test",
|
||||||
|
value: 1,
|
||||||
|
labels: map[string]string{"tag": "1"},
|
||||||
|
},
|
||||||
|
&CounterEvent{
|
||||||
|
metricName: "cvgsl_test",
|
||||||
|
value: 2,
|
||||||
|
labels: map[string]string{"tag": "1"},
|
||||||
|
},
|
||||||
|
&GaugeEvent{
|
||||||
|
metricName: "cvgsl_test",
|
||||||
|
value: 3,
|
||||||
|
labels: map[string]string{"tag": "1"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "gauge vs counter",
|
name: "gauge vs counter",
|
||||||
expected: 2,
|
expected: []float64{2},
|
||||||
in: Events{
|
in: Events{
|
||||||
&GaugeEvent{
|
&GaugeEvent{
|
||||||
metricName: "gvc_test",
|
metricName: "gvc_test",
|
||||||
|
@ -195,7 +237,7 @@ func TestConflictingMetrics(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "counter vs histogram sum",
|
name: "counter vs histogram sum",
|
||||||
expected: 1,
|
expected: []float64{1},
|
||||||
in: Events{
|
in: Events{
|
||||||
&CounterEvent{
|
&CounterEvent{
|
||||||
metricName: "histogram_test1_sum",
|
metricName: "histogram_test1_sum",
|
||||||
|
@ -209,7 +251,7 @@ func TestConflictingMetrics(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "counter vs histogram count",
|
name: "counter vs histogram count",
|
||||||
expected: 1,
|
expected: []float64{1},
|
||||||
in: Events{
|
in: Events{
|
||||||
&CounterEvent{
|
&CounterEvent{
|
||||||
metricName: "histogram_test2_count",
|
metricName: "histogram_test2_count",
|
||||||
|
@ -223,7 +265,7 @@ func TestConflictingMetrics(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "counter vs histogram bucket",
|
name: "counter vs histogram bucket",
|
||||||
expected: 1,
|
expected: []float64{1},
|
||||||
in: Events{
|
in: Events{
|
||||||
&CounterEvent{
|
&CounterEvent{
|
||||||
metricName: "histogram_test3_bucket",
|
metricName: "histogram_test3_bucket",
|
||||||
|
@ -237,7 +279,7 @@ func TestConflictingMetrics(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "counter vs summary quantile",
|
name: "counter vs summary quantile",
|
||||||
expected: 1,
|
expected: []float64{1},
|
||||||
in: Events{
|
in: Events{
|
||||||
&CounterEvent{
|
&CounterEvent{
|
||||||
metricName: "cvsq_test",
|
metricName: "cvsq_test",
|
||||||
|
@ -251,7 +293,7 @@ func TestConflictingMetrics(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "counter vs summary count",
|
name: "counter vs summary count",
|
||||||
expected: 1,
|
expected: []float64{1},
|
||||||
in: Events{
|
in: Events{
|
||||||
&CounterEvent{
|
&CounterEvent{
|
||||||
metricName: "cvsc_count",
|
metricName: "cvsc_count",
|
||||||
|
@ -265,7 +307,7 @@ func TestConflictingMetrics(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "counter vs summary sum",
|
name: "counter vs summary sum",
|
||||||
expected: 1,
|
expected: []float64{1},
|
||||||
in: Events{
|
in: Events{
|
||||||
&CounterEvent{
|
&CounterEvent{
|
||||||
metricName: "cvss_sum",
|
metricName: "cvss_sum",
|
||||||
|
@ -306,15 +348,17 @@ mappings:
|
||||||
t.Fatalf("Cannot gather from DefaultGatherer: %v", err)
|
t.Fatalf("Cannot gather from DefaultGatherer: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
mn := s.in[0].MetricName()
|
for i, e := range s.expected {
|
||||||
m := getFloat64(metrics, mn, map[string]string{})
|
mn := s.in[i].MetricName()
|
||||||
|
m := getFloat64(metrics, mn, s.in[i].Labels())
|
||||||
|
|
||||||
if m == nil {
|
if m == nil {
|
||||||
t.Fatalf("Could not find time series with metric name '%v'", mn)
|
t.Fatalf("Could not find time series with metric name '%v'", mn)
|
||||||
}
|
}
|
||||||
|
|
||||||
if *m != s.expected {
|
if *m != e {
|
||||||
t.Fatalf("Expected to get %v, but got %v instead", s.expected, *m)
|
t.Fatalf("Expected to get %v, but got %v instead", e, *m)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue