lib/protoparser/datadogv2: take into account source_type_name field, since it contains useful value such as kubernetes, docker, system, etc.

This commit is contained in:
Aliaksandr Valialkin 2023-12-21 23:05:41 +02:00
parent b4ba8d0d76
commit 7575f5c501
No known key found for this signature in database
GPG Key ID: 52C003EE2BCDB9EB
4 changed files with 16 additions and 4 deletions

View File

@ -58,6 +58,12 @@ func insertRows(at *auth.Token, series []datadogv2.Series, extraLabels []prompbm
Value: rs.Name, Value: rs.Name,
}) })
} }
if ss.SourceTypeName != "" {
labels = append(labels, prompbmarshal.Label{
Name: "source_type_name",
Value: ss.SourceTypeName,
})
}
for _, tag := range ss.Tags { for _, tag := range ss.Tags {
name, value := datadogutils.SplitTag(tag) name, value := datadogutils.SplitTag(tag)
if name == "host" { if name == "host" {

View File

@ -59,6 +59,9 @@ func insertRows(series []datadogv2.Series, extraLabels []prompbmarshal.Label) er
} }
ctx.AddLabel(name, value) ctx.AddLabel(name, value)
} }
if ss.SourceTypeName != "" {
ctx.AddLabel("source_type_name", ss.SourceTypeName)
}
for j := range extraLabels { for j := range extraLabels {
label := &extraLabels[j] label := &extraLabels[j]
ctx.AddLabel(label.Name, label.Value) ctx.AddLabel(label.Name, label.Value)

View File

@ -76,11 +76,10 @@ type Series struct {
Metric string `json:"metric"` Metric string `json:"metric"`
// Points points for the given metric // Points points for the given metric
Points []Point `json:"points"` Points []Point `json:"points"`
Resources []Resource `json:"resources"`
// Do not decode SourceTypeName, since it isn't used by VictoriaMetrics Resources []Resource `json:"resources"`
// SourceTypeName string `json:"source_type_name"` SourceTypeName string `json:"source_type_name"`
Tags []string Tags []string
@ -106,6 +105,8 @@ func (s *Series) reset() {
} }
s.Resources = resources[:0] s.Resources = resources[:0]
s.SourceTypeName = ""
tags := s.Tags tags := s.Tags
for i := range tags { for i := range tags {
tags[i] = "" tags[i] = ""

View File

@ -50,6 +50,7 @@ func TestRequestUnmarshalJSONSuccess(t *testing.T) {
"type": "host" "type": "host"
} }
], ],
"source_type_name": "kubernetes",
"tags": ["environment:test"] "tags": ["environment:test"]
} }
] ]
@ -69,6 +70,7 @@ func TestRequestUnmarshalJSONSuccess(t *testing.T) {
Type: "host", Type: "host",
}, },
}, },
SourceTypeName: "kubernetes",
Tags: []string{ Tags: []string{
"environment:test", "environment:test",
}, },