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
This commit is contained in:
Pedro Gonçalves 2022-12-05 23:06:03 -08:00 committed by Aliaksandr Valialkin
parent f98751bfc3
commit 84cfe4fcaf
No known key found for this signature in database
GPG Key ID: A72BEC6CD3D0DED1
4 changed files with 15 additions and 0 deletions

View File

@ -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" {

View File

@ -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" {

View File

@ -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"`

View File

@ -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,