diff --git a/lib/storage/storage.go b/lib/storage/storage.go index 88a2c7c5c..7cf2869b5 100644 --- a/lib/storage/storage.go +++ b/lib/storage/storage.go @@ -1204,7 +1204,6 @@ func (s *Storage) add(rows []rawRow, mrs []MetricRow, precisionBits uint8) ([]ra } } if pmrs != nil { - atomic.AddUint64(&s.slowRowInserts, uint64(len(pmrs.pmrs))) // Sort pendingMetricRows by canonical metric name in order to speed up search via `is` in the loop below. pendingMetricRows := pmrs.pmrs sort.Slice(pendingMetricRows, func(i, j int) bool { @@ -1212,6 +1211,7 @@ func (s *Storage) add(rows []rawRow, mrs []MetricRow, precisionBits uint8) ([]ra }) is := idb.getIndexSearch(0, 0, noDeadline) prevMetricNameRaw = nil + var slowInsertsCount uint64 for i := range pendingMetricRows { pmr := &pendingMetricRows[i] mr := &pmr.mr @@ -1235,6 +1235,7 @@ func (s *Storage) add(rows []rawRow, mrs []MetricRow, precisionBits uint8) ([]ra prevMetricNameRaw = mr.MetricNameRaw continue } + slowInsertsCount++ if err := is.GetOrCreateTSIDByName(&r.TSID, pmr.MetricName); err != nil { // Do not stop adding rows on error - just skip invalid row. // This guarantees that invalid rows don't prevent @@ -1249,6 +1250,7 @@ func (s *Storage) add(rows []rawRow, mrs []MetricRow, precisionBits uint8) ([]ra } idb.putIndexSearch(is) putPendingMetricRows(pmrs) + atomic.AddUint64(&s.slowRowInserts, slowInsertsCount) } if firstWarn != nil { logger.Errorf("warn occurred during rows addition: %s", firstWarn)