Skip to content

Commit bb8d879

Browse files
authored
chore: optimize metrics for discarded data in distributor (#4248)
1 parent 77bd4b9 commit bb8d879

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

pkg/distributor/distributor.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,7 +1030,7 @@ func (d *Distributor) visitSampleSeries(req *distributormodel.PushRequest, visit
10301030
validation.DiscardedProfiles.WithLabelValues(string(validation.ReasonOf(err)), req.TenantID).Add(float64(req.TotalProfiles))
10311031
validation.DiscardedBytes.WithLabelValues(string(validation.ReasonOf(err)), req.TenantID).Add(float64(req.TotalBytesUncompressed))
10321032
usageGroups.CountDiscardedBytes(string(validation.ReasonOf(err)), req.TotalBytesUncompressed)
1033-
return err
1033+
return connect.NewError(connect.CodeInvalidArgument, err)
10341034
}
10351035
for _, s := range visitor.series {
10361036
s.Annotations = series.Annotations
@@ -1045,8 +1045,13 @@ func (d *Distributor) visitSampleSeries(req *distributormodel.PushRequest, visit
10451045
}
10461046
}
10471047

1048-
validation.DiscardedBytes.WithLabelValues(string(validation.DroppedByRelabelRules), req.TenantID).Add(float64(req.DiscardedBytesRelabeling))
1049-
validation.DiscardedProfiles.WithLabelValues(string(validation.DroppedByRelabelRules), req.TenantID).Add(float64(req.DiscardedProfilesRelabeling))
1048+
if req.DiscardedBytesRelabeling > 0 {
1049+
validation.DiscardedBytes.WithLabelValues(string(validation.DroppedByRelabelRules), req.TenantID).Add(float64(req.DiscardedBytesRelabeling))
1050+
}
1051+
if req.DiscardedProfilesRelabeling > 0 {
1052+
validation.DiscardedProfiles.WithLabelValues(string(validation.DroppedByRelabelRules), req.TenantID).Add(float64(req.DiscardedProfilesRelabeling))
1053+
}
1054+
10501055
req.Series = result
10511056
removeEmptySeries(req)
10521057
return nil
@@ -1075,10 +1080,7 @@ type sampleSeriesVisitor struct {
10751080
}
10761081

10771082
func (v *sampleSeriesVisitor) ValidateLabels(labels phlaremodel.Labels) error {
1078-
if err := validation.ValidateLabels(v.limits, v.tenantID, labels); err != nil {
1079-
return connect.NewError(connect.CodeInvalidArgument, err)
1080-
}
1081-
return nil
1083+
return validation.ValidateLabels(v.limits, v.tenantID, labels)
10821084
}
10831085

10841086
func (v *sampleSeriesVisitor) VisitProfile(labels phlaremodel.Labels) {

0 commit comments

Comments
 (0)