Skip to content

Commit

Permalink
steal statsd fix from vitessio#11741
Browse files Browse the repository at this point in the history
Signed-off-by: Tim Vaillancourt <[email protected]>
  • Loading branch information
timvaillancourt committed May 29, 2024
1 parent 20d6184 commit 7373227
Showing 1 changed file with 29 additions and 25 deletions.
54 changes: 29 additions & 25 deletions go/stats/statsd/statsd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func TestStatsdCounter(t *testing.T) {
t.Fatal(err)
}
result := string(bytes[:n])
expected := "test.counter_name:1|c"
expected := "test.counter_name:1|c\n"
assert.Equal(t, result, expected)
}
})
Expand Down Expand Up @@ -84,7 +84,7 @@ func TestStatsdGauge(t *testing.T) {
t.Fatal(err)
}
result := string(bytes[:n])
expected := "test.gauge_name:10.000000|g"
expected := "test.gauge_name:10|g\n"
assert.Equal(t, result, expected)
}
})
Expand Down Expand Up @@ -113,7 +113,7 @@ func TestStatsdGaugeFloat64(t *testing.T) {
t.Fatal(err)
}
result := string(bytes[:n])
expected := "test.gauge_name_f64:3.140000|g"
expected := "test.gauge_name_f64:3.14|g\n"
assert.Equal(t, result, expected)
}
})
Expand Down Expand Up @@ -143,7 +143,7 @@ func TestStatsdGaugeFunc(t *testing.T) {
t.Fatal(err)
}
result := string(bytes[:n])
expected := "test.gauge_func_name:2.000000|g"
expected := "test.gauge_func_name:2|g\n"
assert.Equal(t, result, expected)
}
})
Expand Down Expand Up @@ -172,8 +172,8 @@ func TestStatsdCounterDuration(t *testing.T) {
t.Fatal(err)
}
result := string(bytes[:n])
expected := "test.counter_duration_name:1.000000|ms"
assert.Equal(t, result, expected)
expected := "test.counter_duration_name:1.000000|ms\n"
assert.Equal(t, expected, result)
}
})
if !found {
Expand Down Expand Up @@ -203,11 +203,12 @@ func TestStatsdCountersWithSingleLabel(t *testing.T) {
result := strings.Split(string(bytes[:n]), "\n")
sort.Strings(result)
expected := []string{
"",
"test.counter_with_single_label_name:0|c|#label:tag2",
"test.counter_with_single_label_name:2|c|#label:tag1",
}
for i, res := range result {
assert.Equal(t, res, expected[i])
assert.Equal(t, expected[i], res)
}
}
})
Expand Down Expand Up @@ -236,8 +237,8 @@ func TestStatsdCountersWithMultiLabels(t *testing.T) {
t.Fatal(err)
}
result := string(bytes[:n])
expected := "test.counter_with_multiple_label_name:1|c|#label1:foo,label2:bar"
assert.Equal(t, result, expected)
expected := "test.counter_with_multiple_label_name:1|c|#label1:foo,label2:bar\n"
assert.Equal(t, expected, result)
}
})
if !found {
Expand Down Expand Up @@ -271,11 +272,12 @@ func TestStatsdCountersFuncWithMultiLabels(t *testing.T) {
result := strings.Split(string(bytes[:n]), "\n")
sort.Strings(result)
expected := []string{
"",
"test.counter_func_with_multiple_labels_name:1|c|#label1:foo,label2:bar",
"test.counter_func_with_multiple_labels_name:2|c|#label1:bar,label2:baz",
}
for i, res := range result {
assert.Equal(t, res, expected[i])
assert.Equal(t, expected[i], res)
}
}
})
Expand Down Expand Up @@ -304,8 +306,8 @@ func TestStatsdGaugesWithMultiLabels(t *testing.T) {
t.Fatal(err)
}
result := string(bytes[:n])
expected := "test.gauges_with_multiple_label_name:3.000000|g|#label1:foo,label2:bar"
assert.Equal(t, result, expected)
expected := "test.gauges_with_multiple_label_name:3|g|#label1:foo,label2:bar\n"
assert.Equal(t, expected, result)
}
})
if !found {
Expand Down Expand Up @@ -339,11 +341,12 @@ func TestStatsdGaugesFuncWithMultiLabels(t *testing.T) {
result := strings.Split(string(bytes[:n]), "\n")
sort.Strings(result)
expected := []string{
"test.gauges_func_with_multiple_labels_name:1.000000|g|#label1:foo,label2:bar",
"test.gauges_func_with_multiple_labels_name:2.000000|g|#label1:bar,label2:baz",
"",
"test.gauges_func_with_multiple_labels_name:1|g|#label1:foo,label2:bar",
"test.gauges_func_with_multiple_labels_name:2|g|#label1:bar,label2:baz",
}
for i, res := range result {
assert.Equal(t, res, expected[i])
assert.Equal(t, expected[i], res)
}
}
})
Expand Down Expand Up @@ -372,8 +375,8 @@ func TestStatsdGaugesWithSingleLabel(t *testing.T) {
t.Fatal(err)
}
result := string(bytes[:n])
expected := "test.gauges_with_single_label_name:1.000000|g|#label1:bar"
assert.Equal(t, result, expected)
expected := "test.gauges_with_single_label_name:1|g|#label1:bar\n"
assert.Equal(t, expected, result)
}
})
if !found {
Expand Down Expand Up @@ -401,8 +404,8 @@ func TestStatsdMultiTimings(t *testing.T) {
t.Fatal(err)
}
result := string(bytes[:n])
expected := "test.multi_timings_name:10.000000|ms|#label1:foo,label2:bar"
assert.Equal(t, result, expected)
expected := "test.multi_timings_name:10.000000|ms|#label1:foo,label2:bar\n"
assert.Equal(t, expected, result)
}
})
if !found {
Expand Down Expand Up @@ -430,8 +433,8 @@ func TestStatsdTimings(t *testing.T) {
t.Fatal(err)
}
result := string(bytes[:n])
expected := "test.timings_name:2.000000|ms|#label1:foo"
assert.Equal(t, result, expected)
expected := "test.timings_name:2.000000|ms|#label1:foo\n"
assert.Equal(t, expected, result)
}
})
if !found {
Expand Down Expand Up @@ -462,12 +465,13 @@ func TestStatsdHistogram(t *testing.T) {
}
result := string(bytes[:n])
expected := []string{
"test.histogram_name:2.000000|h",
"test.histogram_name:3.000000|h",
"test.histogram_name:6.000000|h",
"test.histogram_name:2|h",
"test.histogram_name:3|h",
"test.histogram_name:6|h",
"",
}
for i, res := range strings.Split(result, "\n") {
assert.Equal(t, res, expected[i])
assert.Equal(t, expected[i], res)
}
}
})
Expand Down

0 comments on commit 7373227

Please sign in to comment.