From 04be313961c1dc322583a061da08f274ef52a05c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gy=C3=B6rgy=20Krajcsovits?= Date: Tue, 7 Feb 2023 15:54:21 +0100 Subject: [PATCH] Do not use two variables for sample counts inside function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: György Krajcsovits --- pkg/distributor/distributor.go | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/pkg/distributor/distributor.go b/pkg/distributor/distributor.go index abb45a8a83a..fe39fbcb716 100644 --- a/pkg/distributor/distributor.go +++ b/pkg/distributor/distributor.go @@ -767,26 +767,24 @@ func (d *Distributor) prePushHaDedupeMiddleware(next push.Func) push.Func { } numSamples := 0 - numHistograms := 0 group := d.activeGroups.UpdateActiveGroupTimestamp(userID, validation.GroupLabel(d.limits, userID, req.Timeseries), time.Now()) for _, ts := range req.Timeseries { - numSamples += len(ts.Samples) - numHistograms += len(ts.Histograms) + numSamples += len(ts.Samples) + len(ts.Histograms) } removeReplica, err := d.checkSample(ctx, userID, cluster, replica) if err != nil { if errors.Is(err, replicasNotMatchError{}) { // These samples and histograms have been deduped. - if numSamples+numHistograms > 0 { - d.dedupedSamples.WithLabelValues(userID, cluster).Add(float64(numSamples + numHistograms)) + if numSamples > 0 { + d.dedupedSamples.WithLabelValues(userID, cluster).Add(float64(numSamples)) } return nil, httpgrpc.Errorf(http.StatusAccepted, err.Error()) } if errors.Is(err, tooManyClustersError{}) { - if numSamples+numHistograms > 0 { - d.discardedSamplesTooManyHaClusters.WithLabelValues(userID, group).Add(float64(numSamples + numHistograms)) + if numSamples > 0 { + d.discardedSamplesTooManyHaClusters.WithLabelValues(userID, group).Add(float64(numSamples)) } return nil, httpgrpc.Errorf(http.StatusBadRequest, err.Error()) @@ -804,8 +802,8 @@ func (d *Distributor) prePushHaDedupeMiddleware(next push.Func) push.Func { } } else { // If there wasn't an error but removeReplica is false that means we didn't find both HA labels. - if numSamples+numHistograms > 0 { - d.nonHASamples.WithLabelValues(userID).Add(float64(numSamples + numHistograms)) + if numSamples > 0 { + d.nonHASamples.WithLabelValues(userID).Add(float64(numSamples)) } }