From 86d3d907a54e4395ec568d22b5d356c659265bca Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Fri, 14 Jun 2019 10:51:57 +0300 Subject: [PATCH] app/vminsert/influx: add `-influxSkipSingleField` flag for using `{measurement}` instead of `{measurement}{separator}{field_name}` for Influx lines with a single field Fixes https://github.com/VictoriaMetrics/VictoriaMetrics/issues/66 --- app/vminsert/influx/request_handler.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/vminsert/influx/request_handler.go b/app/vminsert/influx/request_handler.go index e5d08f89a..c077ad652 100644 --- a/app/vminsert/influx/request_handler.go +++ b/app/vminsert/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") ) var rowsInserted = metrics.NewCounter(`vm_rows_inserted_total{type="influx"}`) @@ -93,11 +94,16 @@ func (ctx *pushCtx) InsertRows(db string) error { } ctx.metricNameBuf = storage.MarshalMetricNameRaw(ctx.metricNameBuf[:0], ic.Labels) ctx.metricGroupBuf = append(ctx.metricGroupBuf[:0], r.Measurement...) - ctx.metricGroupBuf = append(ctx.metricGroupBuf, *measurementFieldSeparator...) + skipFieldKey := len(r.Fields) == 1 && *skipSingleField + if !skipFieldKey { + ctx.metricGroupBuf = append(ctx.metricGroupBuf, *measurementFieldSeparator...) + } metricGroupPrefixLen := len(ctx.metricGroupBuf) for j := range r.Fields { f := &r.Fields[j] - ctx.metricGroupBuf = append(ctx.metricGroupBuf[:metricGroupPrefixLen], f.Key...) + if !skipFieldKey { + ctx.metricGroupBuf = append(ctx.metricGroupBuf[:metricGroupPrefixLen], f.Key...) + } metricGroup := bytesutil.ToUnsafeString(ctx.metricGroupBuf) ic.Labels = ic.Labels[:0] ic.AddLabel("", metricGroup)