From f6d4275087eed81ff1e9b6a8941152f29adb4299 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin <valyala@gmail.com> 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 489e0874ea..4ac39982e5 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 bddb677a55..dc5c037225 100644 --- a/app/vminsert/influx/request_handler.go +++ b/app/vminsert/influx/request_handler.go @@ -70,6 +70,7 @@ func insertRows(at *auth.Token, db string, rows []parser.Row, mayOverrideAccount for i := range rows { r := &rows[i] ic.Labels = ic.Labels[:0] + hasDBKey := false for j := range r.Tags { tag := &r.Tags[j] if mayOverrideAccountProjectID { @@ -82,11 +83,13 @@ func insertRows(at *auth.Token, db string, rows []parser.Row, mayOverrideAccount } } 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...)