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)