diff --git a/app/vmagent/influx/request_handler.go b/app/vmagent/influx/request_handler.go index 489e0874e..4ac39982e 100644 --- a/app/vmagent/influx/request_handler.go +++ b/app/vmagent/influx/request_handler.go @@ -63,17 +63,18 @@ func insertRows(db string, rows []parser.Row) error { for i := range rows { r := &rows[i] commonLabels = commonLabels[:0] + hasDBKey := false for j := range r.Tags { tag := &r.Tags[j] if tag.Key == "db" { - db = "" + hasDBKey = true } commonLabels = append(commonLabels, prompbmarshal.Label{ Name: tag.Key, Value: tag.Value, }) } - if len(db) > 0 { + if len(db) > 0 && !hasDBKey { commonLabels = append(commonLabels, prompbmarshal.Label{ Name: "db", Value: db, diff --git a/app/vminsert/influx/request_handler.go b/app/vminsert/influx/request_handler.go index 196117f01..4362c6105 100644 --- a/app/vminsert/influx/request_handler.go +++ b/app/vminsert/influx/request_handler.go @@ -66,14 +66,17 @@ func insertRows(db string, rows []parser.Row) error { for i := range rows { r := &rows[i] ic.Labels = ic.Labels[:0] + hasDBKey := false for j := range r.Tags { tag := &r.Tags[j] if tag.Key == "db" { - db = "" + hasDBKey = true } ic.AddLabel(tag.Key, tag.Value) } - ic.AddLabel("db", db) + if !hasDBKey { + ic.AddLabel("db", db) + } ctx.metricGroupBuf = ctx.metricGroupBuf[:0] if !*skipMeasurement { ctx.metricGroupBuf = append(ctx.metricGroupBuf, r.Measurement...)