Support negative statsd counters

closes #1898
This commit is contained in:
Cameron Sparr
2016-12-20 13:21:51 +00:00
parent 8df325a68c
commit 9866146545
3 changed files with 10 additions and 5 deletions

View File

@@ -426,8 +426,8 @@ func (s *Statsd) parseStatsdLine(line string) error {
// Parse the value
if strings.HasPrefix(pipesplit[0], "-") || strings.HasPrefix(pipesplit[0], "+") {
if m.mtype != "g" {
log.Printf("E! Error: +- values are only supported for gauges: %s\n", line)
if m.mtype != "g" && m.mtype != "c" {
log.Printf("E! Error: +- values are only supported for gauges & counters: %s\n", line)
return errors.New("Error Parsing statsd line")
}
m.additive = true

View File

@@ -197,6 +197,8 @@ func TestParse_Counters(t *testing.T) {
"sample.rate:1|c|@0.1",
"sample.rate:1|c",
"scientific.notation:4.696E+5|c",
"negative.test:100|c",
"negative.test:-5|c",
}
for _, line := range valid_lines {
@@ -230,6 +232,10 @@ func TestParse_Counters(t *testing.T) {
"sample_rate",
11,
},
{
"negative_test",
95,
},
}
for _, test := range validations {
@@ -299,11 +305,9 @@ func TestParse_InvalidLines(t *testing.T) {
"i.dont.have.a.pipe:45g",
"i.dont.have.a.colon45|c",
"invalid.metric.type:45|e",
"invalid.plus.minus.non.gauge:+10|c",
"invalid.plus.minus.non.gauge:+10|s",
"invalid.plus.minus.non.gauge:+10|ms",
"invalid.plus.minus.non.gauge:+10|h",
"invalid.plus.minus.non.gauge:-10|c",
"invalid.value:foobar|c",
"invalid.value:d11|c",
"invalid.value:1d1|c",