From 84cfe4fcafcb3e2158842109cdd4b562c42e06cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20Gon=C3=A7alves?= Date: Mon, 5 Dec 2022 23:06:03 -0800 Subject: [PATCH] Datadog - Add device as a tag if it's present as a field in the series object (#3431) * Datadog - Add device as a tag if it's present as a field in the series object * address PR comments --- app/vmagent/datadog/request_handler.go | 6 ++++++ app/vminsert/datadog/request_handler.go | 3 +++ lib/protoparser/datadog/parser.go | 4 ++++ lib/protoparser/datadog/parser_test.go | 2 ++ 4 files changed, 15 insertions(+) diff --git a/app/vmagent/datadog/request_handler.go b/app/vmagent/datadog/request_handler.go index f094f2c26..ae337be8b 100644 --- a/app/vmagent/datadog/request_handler.go +++ b/app/vmagent/datadog/request_handler.go @@ -56,6 +56,12 @@ func insertRows(at *auth.Token, series []parser.Series, extraLabels []prompbmars Name: "host", Value: ss.Host, }) + if ss.Device != "" { + labels = append(labels, prompbmarshal.Label{ + Name: "device", + Value: ss.Device, + }) + } for _, tag := range ss.Tags { name, value := parser.SplitTag(tag) if name == "host" { diff --git a/app/vminsert/datadog/request_handler.go b/app/vminsert/datadog/request_handler.go index a7c9bf1a4..3f5568c08 100644 --- a/app/vminsert/datadog/request_handler.go +++ b/app/vminsert/datadog/request_handler.go @@ -56,6 +56,9 @@ func insertRows(at *auth.Token, series []parser.Series, extraLabels []prompbmars ctx.Labels = ctx.Labels[:0] ctx.AddLabel("", ss.Metric) ctx.AddLabel("host", ss.Host) + if ss.Device != "" { + ctx.AddLabel("device", ss.Device) + } for _, tag := range ss.Tags { name, value := parser.SplitTag(tag) if name == "host" { diff --git a/lib/protoparser/datadog/parser.go b/lib/protoparser/datadog/parser.go index 931617d5e..7e36e931c 100644 --- a/lib/protoparser/datadog/parser.go +++ b/lib/protoparser/datadog/parser.go @@ -67,6 +67,10 @@ type Series struct { Metric string `json:"metric"` Points []Point `json:"points"` Tags []string `json:"tags"` + // The device field does not appear in the datadog docs, but datadog-agent does use it. + // Datadog agent (v7 at least), removes the tag "device" and adds it as its own field. Why? That I don't know! + // https://github.com/DataDog/datadog-agent/blob/0ada7a97fed6727838a6f4d9c87123d2aafde735/pkg/metrics/series.go#L84-L105 + Device string `json:"device"` // Do not decode Type, since it isn't used by VictoriaMetrics // Type string `json:"type"` diff --git a/lib/protoparser/datadog/parser_test.go b/lib/protoparser/datadog/parser_test.go index 3c472d91c..b6b12230a 100644 --- a/lib/protoparser/datadog/parser_test.go +++ b/lib/protoparser/datadog/parser_test.go @@ -56,6 +56,7 @@ func TestRequestUnmarshalSuccess(t *testing.T) { "host": "test.example.com", "interval": 20, "metric": "system.load.1", + "device": "/dev/sda", "points": [[ 1575317847, 0.5 @@ -71,6 +72,7 @@ func TestRequestUnmarshalSuccess(t *testing.T) { Series: []Series{{ Host: "test.example.com", Metric: "system.load.1", + Device: "/dev/sda", Points: []Point{{ 1575317847, 0.5,