From 86044f65610473346687fc2d928259d60d03452b Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Tue, 14 Jul 2020 14:17:22 +0300 Subject: [PATCH] app/{vminsert,vmagent}: add `-influxSkipMeasurement` command-line flag for using field name as metric name See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/626 --- app/vmagent/influx/request_handler.go | 6 +++++- app/vminsert/influx/request_handler.go | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/app/vmagent/influx/request_handler.go b/app/vmagent/influx/request_handler.go index 642bd3d87..a17ef60f8 100644 --- a/app/vmagent/influx/request_handler.go +++ b/app/vmagent/influx/request_handler.go @@ -19,6 +19,7 @@ import ( var ( measurementFieldSeparator = flag.String("influxMeasurementFieldSeparator", "_", "Separator for '{measurement}{separator}{field_name}' metric name when inserted via Influx line protocol") skipSingleField = flag.Bool("influxSkipSingleField", false, "Uses '{measurement}' instead of '{measurement}{separator}{field_name}' for metic name if Influx line contains only a single field") + skipMeasurement = flag.Bool("influxSkipMeasurement", false, "Uses '{field_name}' as a metric name while ignoring '{measurement}' and '-influxMeasurementFieldSeparator'") ) var ( @@ -79,7 +80,10 @@ func insertRows(db string, rows []parser.Row) error { Value: db, }) } - ctx.metricGroupBuf = append(ctx.metricGroupBuf[:0], r.Measurement...) + ctx.metricGroupBuf = ctx.metricGroupBuf[:0] + if !*skipMeasurement { + ctx.metricGroupBuf = append(ctx.metricGroupBuf, r.Measurement...) + } skipFieldKey := len(r.Fields) == 1 && *skipSingleField if len(ctx.metricGroupBuf) > 0 && !skipFieldKey { ctx.metricGroupBuf = append(ctx.metricGroupBuf, *measurementFieldSeparator...) diff --git a/app/vminsert/influx/request_handler.go b/app/vminsert/influx/request_handler.go index 838c0f86d..e96492394 100644 --- a/app/vminsert/influx/request_handler.go +++ b/app/vminsert/influx/request_handler.go @@ -22,6 +22,7 @@ import ( var ( measurementFieldSeparator = flag.String("influxMeasurementFieldSeparator", "_", "Separator for '{measurement}{separator}{field_name}' metric name when inserted via Influx line protocol") skipSingleField = flag.Bool("influxSkipSingleField", false, "Uses '{measurement}' instead of '{measurement}{separator}{field_name}' for metic name if Influx line contains only a single field") + skipMeasurement = flag.Bool("influxSkipMeasurement", false, "Uses '{field_name}' as a metric name while ignoring '{measurement}' and '-influxMeasurementFieldSeparator'") ) var ( @@ -88,7 +89,10 @@ func insertRows(at *auth.Token, db string, rows []parser.Row, mayOverrideAccount if len(db) > 0 && !hasDBLabel { ic.AddLabel("db", db) } - ctx.metricGroupBuf = append(ctx.metricGroupBuf[:0], r.Measurement...) + ctx.metricGroupBuf = ctx.metricGroupBuf[:0] + if !*skipMeasurement { + ctx.metricGroupBuf = append(ctx.metricGroupBuf, r.Measurement...) + } skipFieldKey := len(r.Fields) == 1 && *skipSingleField if len(ctx.metricGroupBuf) > 0 && !skipFieldKey { ctx.metricGroupBuf = append(ctx.metricGroupBuf, *measurementFieldSeparator...)