From 0f63da369869177a4c5114d131f451494618cbce Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Tue, 28 Jul 2020 21:23:01 +0300 Subject: [PATCH] app/{vmagent,vminsert}: properly preserve `db` tag from query string passed to Influx line protocol query Previously `db` tag from the query string wasn't added to metrics after encountering `db` tag in the Influx line Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/653 --- app/vmagent/influx/request_handler.go | 5 +++-- app/vminsert/influx/request_handler.go | 7 +++++-- 2 files changed, 8 insertions(+), 4 deletions(-) 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...)