From 028531e9534840a02569ccc4adc377c24df43aee Mon Sep 17 00:00:00 2001 From: Amit Saha Date: Mon, 9 Sep 2019 17:23:45 +1000 Subject: [PATCH] Fix for issue #250 Signed-off-by: Amit Saha --- bridge_test.go | 10 ++++++++++ exporter.go | 6 +++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/bridge_test.go b/bridge_test.go index e243ed1..51b9703 100644 --- a/bridge_test.go +++ b/bridge_test.go @@ -157,6 +157,16 @@ func TestHandlePacket(t *testing.T) { labels: map[string]string{"tag1": "bar", "tag2": "baz"}, }, }, + }, { + name: "histogram with sampling", + in: "foo:0.01|h|@0.1|#tag1:bar,#tag2:baz", + out: Events{ + &TimerEvent{ + metricName: "foo", + value: 0.01, + labels: map[string]string{"tag1": "bar", "tag2": "baz"}, + }, + }, }, { name: "datadog tag extension with multiple colons", in: "foo:100|c|@0.1|#tag1:foo:bar", diff --git a/exporter.go b/exporter.go index c252e82..65d8ef7 100644 --- a/exporter.go +++ b/exporter.go @@ -389,8 +389,8 @@ samples: for _, component := range components[2:] { switch component[0] { case '@': - if statType != "c" && statType != "ms" { - log.Debugln("Illegal sampling factor for non-counter metric on line", line) + if statType == "g" { + log.Debugln("Illegal sampling factor for gauge metric type on line", line) sampleErrors.WithLabelValues("illegal_sample_factor").Inc() continue } @@ -405,7 +405,7 @@ samples: if statType == "c" { value /= samplingFactor - } else if statType == "ms" { + } else if statType == "ms" || statType == "h" { multiplyEvents = int(1 / samplingFactor) } case '#':