app/vminsert: code prettifying

This commit is contained in:
Aliaksandr Valialkin 2020-09-26 04:13:10 +03:00
parent 8fc9b77496
commit e83947a882
2 changed files with 8 additions and 4 deletions

View file

@ -51,8 +51,9 @@ func insertRows(at *auth.Token, timeseries []prompb.TimeSeries) error {
}
storageNodeIdx := ctx.GetStorageNodeIdx(at, ctx.Labels)
ctx.MetricNameBuf = ctx.MetricNameBuf[:0]
for i := range ts.Samples {
r := &ts.Samples[i]
samples := ts.Samples
for i := range samples {
r := &samples[i]
if len(ctx.MetricNameBuf) == 0 {
ctx.MetricNameBuf = storage.MarshalMetricNameRaw(ctx.MetricNameBuf[:0], at.AccountID, at.ProjectID, ctx.Labels)
}
@ -60,7 +61,7 @@ func insertRows(at *auth.Token, timeseries []prompb.TimeSeries) error {
return err
}
}
rowsTotal += len(ts.Samples)
rowsTotal += len(samples)
}
rowsInserted.Get(at).Add(rowsTotal)
rowsPerInsert.Update(float64(rowsTotal))

View file

@ -6,6 +6,7 @@ import (
"github.com/VictoriaMetrics/VictoriaMetrics/app/vminsert/netstorage"
"github.com/VictoriaMetrics/VictoriaMetrics/app/vminsert/relabel"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/auth"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/logger"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/prompbmarshal"
parserCommon "github.com/VictoriaMetrics/VictoriaMetrics/lib/protoparser/common"
parser "github.com/VictoriaMetrics/VictoriaMetrics/lib/protoparser/vmimport"
@ -64,7 +65,9 @@ func insertRows(at *auth.Token, rows []parser.Row, extraLabels []prompbmarshal.L
storageNodeIdx := ctx.GetStorageNodeIdx(at, ctx.Labels)
values := r.Values
timestamps := r.Timestamps
_ = timestamps[len(values)-1]
if len(timestamps) != len(values) {
logger.Panicf("BUG: len(timestamps)=%d must match len(values)=%d", len(timestamps), len(values))
}
for j, value := range values {
timestamp := timestamps[j]
if err := ctx.WriteDataPointExt(at, storageNodeIdx, ctx.MetricNameBuf, timestamp, value); err != nil {