@@ -528,24 +528,24 @@ func (d *Distributor) Push(ctx context.Context, req *logproto.PushRequest) (*log
528
528
d .truncateLines (validationContext , & stream )
529
529
530
530
var lbs labels.Labels
531
- var retentionHours string
532
- lbs , stream .Labels , stream .Hash , retentionHours , err = d .parseStreamLabels (validationContext , stream .Labels , stream )
531
+ var retentionHours , policy string
532
+ lbs , stream .Labels , stream .Hash , retentionHours , policy , err = d .parseStreamLabels (validationContext , stream .Labels , stream )
533
533
if err != nil {
534
534
d .writeFailuresManager .Log (tenantID , err )
535
535
validationErrors .Add (err )
536
- validation .DiscardedSamples .WithLabelValues (validation .InvalidLabels , tenantID , retentionHours ).Add (float64 (len (stream .Entries )))
536
+ validation .DiscardedSamples .WithLabelValues (validation .InvalidLabels , tenantID , retentionHours , policy ).Add (float64 (len (stream .Entries )))
537
537
discardedBytes := util .EntriesTotalSize (stream .Entries )
538
- validation .DiscardedBytes .WithLabelValues (validation .InvalidLabels , tenantID , retentionHours ).Add (float64 (discardedBytes ))
538
+ validation .DiscardedBytes .WithLabelValues (validation .InvalidLabels , tenantID , retentionHours , policy ).Add (float64 (discardedBytes ))
539
539
continue
540
540
}
541
541
542
542
if missing , lbsMissing := d .missingEnforcedLabels (lbs , tenantID ); missing {
543
543
err := fmt .Errorf (validation .MissingEnforcedLabelsErrorMsg , strings .Join (lbsMissing , "," ), tenantID )
544
544
d .writeFailuresManager .Log (tenantID , err )
545
545
validationErrors .Add (err )
546
- validation .DiscardedSamples .WithLabelValues (validation .MissingEnforcedLabels , tenantID , retentionHours ).Add (float64 (len (stream .Entries )))
546
+ validation .DiscardedSamples .WithLabelValues (validation .MissingEnforcedLabels , tenantID , retentionHours , policy ).Add (float64 (len (stream .Entries )))
547
547
discardedBytes := util .EntriesTotalSize (stream .Entries )
548
- validation .DiscardedBytes .WithLabelValues (validation .MissingEnforcedLabels , tenantID , retentionHours ).Add (float64 (discardedBytes ))
548
+ validation .DiscardedBytes .WithLabelValues (validation .MissingEnforcedLabels , tenantID , retentionHours , policy ).Add (float64 (discardedBytes ))
549
549
continue
550
550
}
551
551
@@ -554,7 +554,7 @@ func (d *Distributor) Push(ctx context.Context, req *logproto.PushRequest) (*log
554
554
prevTs := stream .Entries [0 ].Timestamp
555
555
556
556
for _ , entry := range stream .Entries {
557
- if err := d .validator .ValidateEntry (ctx , validationContext , lbs , entry , retentionHours ); err != nil {
557
+ if err := d .validator .ValidateEntry (ctx , validationContext , lbs , entry , retentionHours , policy ); err != nil {
558
558
d .writeFailuresManager .Log (tenantID , err )
559
559
validationErrors .Add (err )
560
560
continue
@@ -609,7 +609,7 @@ func (d *Distributor) Push(ctx context.Context, req *logproto.PushRequest) (*log
609
609
}
610
610
611
611
n ++
612
- validationContext .validationMetrics .compute (entry , retentionHours )
612
+ validationContext .validationMetrics .compute (entry , retentionHours , policy )
613
613
pushSize += len (entry .Line )
614
614
}
615
615
stream .Entries = stream .Entries [:n ]
@@ -647,10 +647,10 @@ func (d *Distributor) Push(ctx context.Context, req *logproto.PushRequest) (*log
647
647
return nil , httpgrpc .Errorf (retStatusCode , "%s" , err .Error ())
648
648
}
649
649
650
- if ! d .ingestionRateLimiter .AllowN (now , tenantID , validationContext .validationMetrics .lineSize ) {
650
+ if ! d .ingestionRateLimiter .AllowN (now , tenantID , validationContext .validationMetrics .aggregatedPushStats . lineSize ) {
651
651
d .trackDiscardedData (ctx , req , validationContext , tenantID , validationContext .validationMetrics , validation .RateLimited )
652
652
653
- err = fmt .Errorf (validation .RateLimitedErrorMsg , tenantID , int (d .ingestionRateLimiter .Limit (now , tenantID )), validationContext .validationMetrics .lineCount , validationContext .validationMetrics .lineSize )
653
+ err = fmt .Errorf (validation .RateLimitedErrorMsg , tenantID , int (d .ingestionRateLimiter .Limit (now , tenantID )), validationContext .validationMetrics .aggregatedPushStats . lineCount , validationContext .validationMetrics . aggregatedPushStats .lineSize )
654
654
d .writeFailuresManager .Log (tenantID , err )
655
655
// Return a 429 to indicate to the client they are being rate limited
656
656
return nil , httpgrpc .Errorf (http .StatusTooManyRequests , "%s" , err .Error ())
@@ -787,14 +787,16 @@ func (d *Distributor) trackDiscardedData(
787
787
validationMetrics validationMetrics ,
788
788
reason string ,
789
789
) {
790
- for retentionHours , count := range validationMetrics .lineCountPerRetentionHours {
791
- validation .DiscardedSamples .WithLabelValues (reason , tenantID , retentionHours ).Add (float64 (count ))
792
- validation .DiscardedBytes .WithLabelValues (reason , tenantID , retentionHours ).Add (float64 (validationMetrics .lineSizePerRetentionHours [retentionHours ]))
790
+ for policy , retentionToStats := range validationMetrics .policyPushStats {
791
+ for retentionHours , stats := range retentionToStats {
792
+ validation .DiscardedSamples .WithLabelValues (reason , tenantID , retentionHours , policy ).Add (float64 (stats .lineCount ))
793
+ validation .DiscardedBytes .WithLabelValues (reason , tenantID , retentionHours , policy ).Add (float64 (stats .lineSize ))
794
+ }
793
795
}
794
796
795
797
if d .usageTracker != nil {
796
798
for _ , stream := range req .Streams {
797
- lbs , _ , _ , _ , err := d .parseStreamLabels (validationContext , stream .Labels , stream )
799
+ lbs , _ , _ , _ , _ , err := d .parseStreamLabels (validationContext , stream .Labels , stream )
798
800
if err != nil {
799
801
continue
800
802
}
@@ -1173,28 +1175,32 @@ type labelData struct {
1173
1175
hash uint64
1174
1176
}
1175
1177
1176
- func (d * Distributor ) parseStreamLabels (vContext validationContext , key string , stream logproto.Stream ) (labels.Labels , string , uint64 , string , error ) {
1178
+ func (d * Distributor ) parseStreamLabels (vContext validationContext , key string , stream logproto.Stream ) (labels.Labels , string , uint64 , string , string , error ) {
1179
+ mapping := d .validator .Limits .PoliciesStreamMapping (vContext .userID )
1177
1180
if val , ok := d .labelCache .Get (key ); ok {
1178
1181
retentionHours := d .tenantsRetention .RetentionHoursFor (vContext .userID , val .ls )
1179
- return val .ls , val .ls .String (), val .hash , retentionHours , nil
1182
+ policy := mapping .PolicyFor (val .ls )
1183
+ return val .ls , val .ls .String (), val .hash , retentionHours , policy , nil
1180
1184
}
1181
1185
1182
1186
ls , err := syntax .ParseLabels (key )
1183
1187
if err != nil {
1184
- tenantRetentionHours := d .tenantsRetention .RetentionHoursFor (vContext .userID , nil )
1185
- return nil , "" , 0 , tenantRetentionHours , fmt .Errorf (validation .InvalidLabelsErrorMsg , key , err )
1188
+ retentionHours := d .tenantsRetention .RetentionHoursFor (vContext .userID , nil )
1189
+ // TODO: check for global policy.
1190
+ return nil , "" , 0 , retentionHours , mapping .PolicyFor (nil ), fmt .Errorf (validation .InvalidLabelsErrorMsg , key , err )
1186
1191
}
1187
1192
1193
+ policy := mapping .PolicyFor (ls )
1188
1194
retentionHours := d .tenantsRetention .RetentionHoursFor (vContext .userID , ls )
1189
1195
1190
- if err := d .validator .ValidateLabels (vContext , ls , stream , retentionHours ); err != nil {
1191
- return nil , "" , 0 , retentionHours , err
1196
+ if err := d .validator .ValidateLabels (vContext , ls , stream , retentionHours , policy ); err != nil {
1197
+ return nil , "" , 0 , retentionHours , policy , err
1192
1198
}
1193
1199
1194
1200
lsHash := ls .Hash ()
1195
1201
1196
1202
d .labelCache .Add (key , labelData {ls , lsHash })
1197
- return ls , ls .String (), lsHash , retentionHours , nil
1203
+ return ls , ls .String (), lsHash , retentionHours , policy , nil
1198
1204
}
1199
1205
1200
1206
// shardCountFor returns the right number of shards to be used by the given stream.
0 commit comments