Signed-off-by: Amit Saha <amitsaha.in@gmail.com>
This commit is contained in:
Amit Saha 2019-09-13 14:27:35 +10:00
parent d64c674394
commit 1bddef857d
2 changed files with 35 additions and 7 deletions

View file

@ -87,6 +87,36 @@ func TestHandlePacket(t *testing.T) {
labels: map[string]string{}, labels: map[string]string{},
}, },
}, },
}, {
name: "distribution with sampling",
in: "foo:0.01|d|@0.2|#tag1:bar,#tag2:baz",
out: Events{
&TimerEvent{
metricName: "foo",
value: 0.01,
labels: map[string]string{"tag1": "bar", "tag2": "baz"},
},
&TimerEvent{
metricName: "foo",
value: 0.01,
labels: map[string]string{"tag1": "bar", "tag2": "baz"},
},
&TimerEvent{
metricName: "foo",
value: 0.01,
labels: map[string]string{"tag1": "bar", "tag2": "baz"},
},
&TimerEvent{
metricName: "foo",
value: 0.01,
labels: map[string]string{"tag1": "bar", "tag2": "baz"},
},
&TimerEvent{
metricName: "foo",
value: 0.01,
labels: map[string]string{"tag1": "bar", "tag2": "baz"},
},
},
}, { }, {
name: "datadog tag extension", name: "datadog tag extension",
in: "foo:100|c|#tag1:bar,tag2:baz", in: "foo:100|c|#tag1:bar,tag2:baz",

View file

@ -389,11 +389,7 @@ samples:
for _, component := range components[2:] { for _, component := range components[2:] {
switch component[0] { switch component[0] {
case '@': case '@':
if statType == "g" {
log.Debugln("Illegal sampling factor for gauge metric type on line", line)
sampleErrors.WithLabelValues("illegal_sample_factor").Inc()
continue
}
samplingFactor, err = strconv.ParseFloat(component[1:], 64) samplingFactor, err = strconv.ParseFloat(component[1:], 64)
if err != nil { if err != nil {
log.Debugf("Invalid sampling factor %s on line %s", component[1:], line) log.Debugf("Invalid sampling factor %s on line %s", component[1:], line)
@ -403,9 +399,11 @@ samples:
samplingFactor = 1 samplingFactor = 1
} }
if statType == "c" { if statType == "g" {
continue
} else if statType == "c" {
value /= samplingFactor value /= samplingFactor
} else if statType == "ms" || statType == "h" { } else if statType == "ms" || statType == "h" || statType == "d" {
multiplyEvents = int(1 / samplingFactor) multiplyEvents = int(1 / samplingFactor)
} }
case '#': case '#':