Skip to content

Commit a9646af

Browse files
authored
chore: Ensure tenant gets logged during ingest validation errors (#4304)
1 parent 2b3ece0 commit a9646af

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

pkg/distributor/distributor.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,8 @@ func (d *Distributor) PushParsed(ctx context.Context, req *distributormodel.Push
297297
return nil, connect.NewError(connect.CodeUnauthenticated, err)
298298
}
299299

300+
logger := log.With(d.logger, "tenant", tenantID)
301+
300302
req.TenantID = tenantID
301303
for _, series := range req.Series {
302304
serviceName := phlaremodel.Labels(series.Labels).Get(phlaremodel.LabelNameServiceName)
@@ -323,7 +325,7 @@ func (d *Distributor) PushParsed(ctx context.Context, req *distributormodel.Push
323325
// They are unfortunately part of the Push API so we explicitly clear them here.
324326
req.ClearAnnotations()
325327
if err := d.checkIngestLimit(req); err != nil {
326-
level.Debug(d.logger).Log("msg", "rejecting push request due to global ingest limit", "tenant", tenantID)
328+
level.Debug(logger).Log("msg", "rejecting push request due to global ingest limit", "tenant", tenantID)
327329
validation.DiscardedProfiles.WithLabelValues(string(validation.IngestLimitReached), tenantID).Add(float64(req.TotalProfiles))
328330
validation.DiscardedBytes.WithLabelValues(string(validation.IngestLimitReached), tenantID).Add(float64(req.TotalBytesUncompressed))
329331
return nil, err
@@ -340,15 +342,15 @@ func (d *Distributor) PushParsed(ctx context.Context, req *distributormodel.Push
340342

341343
groups := d.usageGroupEvaluator.GetMatch(tenantID, usageGroups, series.Labels)
342344
if err := d.checkUsageGroupsIngestLimit(req, groups.Names()); err != nil {
343-
level.Debug(d.logger).Log("msg", "rejecting push request due to usage group ingest limit", "tenant", tenantID)
345+
level.Debug(logger).Log("msg", "rejecting push request due to usage group ingest limit", "tenant", tenantID)
344346
validation.DiscardedProfiles.WithLabelValues(string(validation.IngestLimitReached), tenantID).Add(float64(req.TotalProfiles))
345347
validation.DiscardedBytes.WithLabelValues(string(validation.IngestLimitReached), tenantID).Add(float64(req.TotalBytesUncompressed))
346348
groups.CountDiscardedBytes(string(validation.IngestLimitReached), req.TotalBytesUncompressed)
347349
return nil, err
348350
}
349351

350352
if sample := d.shouldSample(tenantID, groups.Names()); !sample {
351-
level.Debug(d.logger).Log("msg", "skipping push request due to sampling", "tenant", tenantID)
353+
level.Debug(logger).Log("msg", "skipping push request due to sampling", "tenant", tenantID)
352354
validation.DiscardedProfiles.WithLabelValues(string(validation.SkippedBySamplingRules), tenantID).Add(float64(req.TotalProfiles))
353355
validation.DiscardedBytes.WithLabelValues(string(validation.SkippedBySamplingRules), tenantID).Add(float64(req.TotalBytesUncompressed))
354356
groups.CountDiscardedBytes(string(validation.SkippedBySamplingRules), req.TotalBytesUncompressed)
@@ -371,7 +373,7 @@ func (d *Distributor) PushParsed(ctx context.Context, req *distributormodel.Push
371373
groups.CountReceivedBytes(profName, int64(decompressedSize))
372374

373375
if err = validation.ValidateProfile(d.limits, tenantID, p.Profile, decompressedSize, series.Labels, now); err != nil {
374-
_ = level.Debug(d.logger).Log("msg", "invalid profile", "err", err)
376+
_ = level.Debug(logger).Log("msg", "invalid profile", "err", err)
375377
reason := string(validation.ReasonOf(err))
376378
validation.DiscardedProfiles.WithLabelValues(reason, tenantID).Add(float64(req.TotalProfiles))
377379
validation.DiscardedBytes.WithLabelValues(reason, tenantID).Add(float64(req.TotalBytesUncompressed))
@@ -410,7 +412,7 @@ func (d *Distributor) PushParsed(ctx context.Context, req *distributormodel.Push
410412
}
411413

412414
if err := injectMappingVersions(req.Series); err != nil {
413-
_ = level.Warn(d.logger).Log("msg", "failed to inject mapping versions", "err", err)
415+
_ = level.Warn(logger).Log("msg", "failed to inject mapping versions", "err", err)
414416
}
415417

416418
// Reduce cardinality of the session_id label.

0 commit comments

Comments
 (0)