Skip to content

feat: Do not enforce labels vs agg metric stream #16696

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions pkg/distributor/distributor.go
Original file line number Diff line number Diff line change
Expand Up @@ -548,13 +548,15 @@ func (d *Distributor) PushWithResolver(ctx context.Context, req *logproto.PushRe
continue
}

if missing, lbsMissing := d.missingEnforcedLabels(lbs, tenantID, policy); missing {
err := fmt.Errorf(validation.MissingEnforcedLabelsErrorMsg, strings.Join(lbsMissing, ","), tenantID, stream.Labels)
d.writeFailuresManager.Log(tenantID, err)
validationErrors.Add(err)
discardedBytes := util.EntriesTotalSize(stream.Entries)
d.validator.reportDiscardedDataWithTracker(ctx, validation.MissingEnforcedLabels, validationContext, lbs, retentionHours, policy, discardedBytes, len(stream.Entries))
continue
if !d.validator.IsAggregatedMetricStream(lbs) {
if missing, lbsMissing := d.missingEnforcedLabels(lbs, tenantID, policy); missing {
err := fmt.Errorf(validation.MissingEnforcedLabelsErrorMsg, strings.Join(lbsMissing, ","), tenantID, stream.Labels)
d.writeFailuresManager.Log(tenantID, err)
validationErrors.Add(err)
discardedBytes := util.EntriesTotalSize(stream.Entries)
d.validator.reportDiscardedDataWithTracker(ctx, validation.MissingEnforcedLabels, validationContext, lbs, retentionHours, policy, discardedBytes, len(stream.Entries))
continue
}
}

if block, statusCode, reason, err := d.validator.ShouldBlockIngestion(validationContext, now, policy); block {
Expand Down
12 changes: 12 additions & 0 deletions pkg/distributor/distributor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,18 @@ func Test_PushWithEnforcedLabels(t *testing.T) {
// Metrics should remain unchanged
assert.Equal(t, float64(10000), testutil.ToFloat64(validation.DiscardedBytes))
assert.Equal(t, float64(100), testutil.ToFloat64(validation.DiscardedSamples))

// enforced labels are configured but the stream is an aggregated metric, so no errors.
limits.EnforcedLabels = []string{"app", "env"}
distributors, _ = prepare(t, 1, 3, limits, nil)

req = makeWriteRequestWithLabels(100, 100, []string{`{__aggregated_metric__="foo"}`}, false, false, false)
_, err = distributors[0].Push(ctx, req)
require.NoError(t, err)

// Metrics should remain unchanged
assert.Equal(t, float64(10000), testutil.ToFloat64(validation.DiscardedBytes))
assert.Equal(t, float64(100), testutil.ToFloat64(validation.DiscardedSamples))
}

func TestDistributorPushConcurrently(t *testing.T) {
Expand Down
8 changes: 6 additions & 2 deletions pkg/distributor/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,11 @@ func (v Validator) ValidateEntry(ctx context.Context, vCtx validationContext, la
return nil
}

// Validate labels returns an error if the labels are invalid
func (v Validator) IsAggregatedMetricStream(ls labels.Labels) bool {
return ls.Has(push.AggregatedMetricLabel)
}

// Validate labels returns an error if the labels are invalid and if the stream is an aggregated metric stream
func (v Validator) ValidateLabels(vCtx validationContext, ls labels.Labels, stream logproto.Stream, retentionHours, policy string) error {
if len(ls) == 0 {
// TODO: is this one correct?
Expand All @@ -152,7 +156,7 @@ func (v Validator) ValidateLabels(vCtx validationContext, ls labels.Labels, stre
}

// Skip validation for aggregated metric streams, as we create those for internal use
if ls.Has(push.AggregatedMetricLabel) {
if v.IsAggregatedMetricStream(ls) {
return nil
}

Expand Down