From 3b16d495142b30351cb5a440ed8fed34f45c6fb7 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 ac2a1056e..8647f8f22 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") ) var rowsInserted = tenantmetrics.NewCounterMap(`vm_rows_inserted_total{type="influx"}`) @@ -94,13 +95,18 @@ func (ctx *pushCtx) InsertRows(at *auth.Token, db string) error { ic.MetricNameBuf = storage.MarshalMetricNameRaw(ic.MetricNameBuf[:0], at.AccountID, at.ProjectID, ic.Labels) metricNameBufLen := len(ic.MetricNameBuf) 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) ic.AddLabel("", "placeholder") placeholderLabel := &ic.Labels[len(ic.Labels)-1] 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[:len(ic.Labels)-1] ic.AddLabel("", metricGroup)