From fb909cf710b64928d3b760c37bb87fdf3388b8c5 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Sat, 24 Aug 2019 13:51:51 +0300 Subject: [PATCH] app/vminsert/influx: set `db` label only if Influx line doesnt have `db` tag --- README.md | 3 ++- app/vminsert/influx/request_handler.go | 8 +++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 592267950..867acda33 100644 --- a/README.md +++ b/README.md @@ -209,7 +209,8 @@ For instance, put the following lines into `Telegraf` config, so it sends data t Do not forget substituting `` with the real address where VictoriaMetrics runs. VictoriaMetrics maps Influx data using the following rules: -* [`db` query arg](https://docs.influxdata.com/influxdb/v1.7/tools/api/#write-http-endpoint) is mapped into `db` label value. +* [`db` query arg](https://docs.influxdata.com/influxdb/v1.7/tools/api/#write-http-endpoint) is mapped into `db` label value + unless `db` tag exists in the Influx line. * Field names are mapped to time series names prefixed with `{measurement}{separator}` value, where `{separator}` equals to `_` by default. It can be changed with `-influxMeasurementFieldSeparator` command-line flag. See also `-influxSkipSingleField` command-line flag. diff --git a/app/vminsert/influx/request_handler.go b/app/vminsert/influx/request_handler.go index b2f2d7188..e0bfbe85d 100644 --- a/app/vminsert/influx/request_handler.go +++ b/app/vminsert/influx/request_handler.go @@ -90,11 +90,17 @@ func (ctx *pushCtx) InsertRows(db string) error { for i := range rows { r := &rows[i] ic.Labels = ic.Labels[:0] - ic.AddLabel("db", db) + hasDBLabel := false for j := range r.Tags { tag := &r.Tags[j] + if tag.Key == "db" { + hasDBLabel = true + } ic.AddLabel(tag.Key, tag.Value) } + if len(db) > 0 && !hasDBLabel { + ic.AddLabel("db", db) + } ctx.metricNameBuf = storage.MarshalMetricNameRaw(ctx.metricNameBuf[:0], ic.Labels) ctx.metricGroupBuf = append(ctx.metricGroupBuf[:0], r.Measurement...) skipFieldKey := len(r.Fields) == 1 && *skipSingleField