@@ -689,6 +689,7 @@ func TestDistributor_PushIngestionRateLimiter_Histograms(t *testing.T) {
689
689
metadata int
690
690
expectedError error
691
691
expectedNHDiscardedSampleMetricValue int
692
+ isPartialDrop bool
692
693
}
693
694
694
695
ctx := user .InjectOrgID (context .Background (), "user" )
@@ -705,32 +706,32 @@ func TestDistributor_PushIngestionRateLimiter_Histograms(t *testing.T) {
705
706
"local strategy: native histograms limit should be set to each distributor" : {
706
707
distributors : 2 ,
707
708
ingestionRateStrategy : validation .LocalIngestionRateStrategy ,
708
- ingestionRate : 20 ,
709
- ingestionBurstSize : 20 ,
709
+ ingestionRate : 30 ,
710
+ ingestionBurstSize : 30 ,
710
711
nativeHistogramIngestionRate : 10 ,
711
712
nativeHistogramIngestionBurstSize : 10 ,
712
713
pushes : []testPush {
713
714
{nhSamples : 4 , expectedError : nil },
714
- {nhSamples : 6 , expectedError : nil },
715
- {nhSamples : 6 , expectedError : nil , expectedNHDiscardedSampleMetricValue : 6 },
716
- {nhSamples : 4 , metadata : 1 , expectedError : nil , expectedNHDiscardedSampleMetricValue : 10 },
717
- {nhSamples : 1 , expectedError : nil , expectedNHDiscardedSampleMetricValue : 11 },
718
- {nhSamples : 1 , expectedError : nil , expectedNHDiscardedSampleMetricValue : 12 },
715
+ {metadata : 1 , expectedError : nil },
716
+ {nhSamples : 7 , expectedError : httpgrpc . Errorf ( http . StatusTooManyRequests , "native histogram ingestion rate limit (10) exceeded while adding 7 native histogram samples" ), expectedNHDiscardedSampleMetricValue : 7 },
717
+ {nhSamples : 4 , metadata : 1 , expectedError : nil , expectedNHDiscardedSampleMetricValue : 7 },
718
+ {nhSamples : 3 , expectedError : httpgrpc . Errorf ( http . StatusTooManyRequests , "native histogram ingestion rate limit (10) exceeded while adding 3 native histogram samples" ), expectedNHDiscardedSampleMetricValue : 10 },
719
+ {metadata : 1 , expectedError : nil , expectedNHDiscardedSampleMetricValue : 10 },
719
720
},
720
721
},
721
722
"global strategy: native histograms limit should be evenly shared across distributors" : {
722
723
distributors : 2 ,
723
724
ingestionRateStrategy : validation .GlobalIngestionRateStrategy ,
724
- ingestionRate : 20 ,
725
- ingestionBurstSize : 10 ,
725
+ ingestionRate : 40 ,
726
+ ingestionBurstSize : 20 ,
726
727
nativeHistogramIngestionRate : 10 ,
727
728
nativeHistogramIngestionBurstSize : 5 ,
728
729
pushes : []testPush {
729
730
{nhSamples : 2 , expectedError : nil },
730
731
{nhSamples : 1 , expectedError : nil },
731
- {nhSamples : 3 , metadata : 1 , expectedError : nil , expectedNHDiscardedSampleMetricValue : 3 },
732
- {nhSamples : 2 , expectedError : nil , expectedNHDiscardedSampleMetricValue : 3 },
733
- {nhSamples : 1 , expectedError : nil , expectedNHDiscardedSampleMetricValue : 4 },
732
+ {nhSamples : 3 , metadata : 1 , expectedError : httpgrpc . Errorf ( http . StatusTooManyRequests , "native histogram ingestion rate limit (5) exceeded while adding 3 native histogram samples" ), expectedNHDiscardedSampleMetricValue : 3 , isPartialDrop : true },
733
+ {nhSamples : 1 , expectedError : nil , expectedNHDiscardedSampleMetricValue : 3 },
734
+ {nhSamples : 2 , expectedError : httpgrpc . Errorf ( http . StatusTooManyRequests , "native histogram ingestion rate limit (5) exceeded while adding 2 native histogram samples" ), expectedNHDiscardedSampleMetricValue : 5 },
734
735
{nhSamples : 1 , expectedError : nil , expectedNHDiscardedSampleMetricValue : 5 },
735
736
},
736
737
},
@@ -744,38 +745,61 @@ func TestDistributor_PushIngestionRateLimiter_Histograms(t *testing.T) {
744
745
pushes : []testPush {
745
746
{nhSamples : 10 , expectedError : nil },
746
747
{nhSamples : 5 , expectedError : nil },
747
- {nhSamples : 6 , metadata : 1 , expectedError : nil , expectedNHDiscardedSampleMetricValue : 6 },
748
+ {nhSamples : 6 , metadata : 1 , expectedError : httpgrpc . Errorf ( http . StatusTooManyRequests , "native histogram ingestion rate limit (5) exceeded while adding 6 native histogram samples" ), expectedNHDiscardedSampleMetricValue : 6 , isPartialDrop : true },
748
749
{nhSamples : 5 , expectedError : nil , expectedNHDiscardedSampleMetricValue : 6 },
749
- {nhSamples : 1 , expectedError : nil , expectedNHDiscardedSampleMetricValue : 7 },
750
- {nhSamples : 1 , expectedError : nil , expectedNHDiscardedSampleMetricValue : 8 },
750
+ {nhSamples : 1 , expectedError : httpgrpc .Errorf (http .StatusTooManyRequests , "native histogram ingestion rate limit (5) exceeded while adding 1 native histogram samples" ), expectedNHDiscardedSampleMetricValue : 7 },
751
751
},
752
752
},
753
- "local strategy: If NH samples hit NH rate limit, other samples should succeed when under rate limit " : {
753
+ "global strategy: Batch contains only NH samples and NH rate limit is hit " : {
754
754
distributors : 2 ,
755
- ingestionRateStrategy : validation .LocalIngestionRateStrategy ,
755
+ ingestionRateStrategy : validation .GlobalIngestionRateStrategy ,
756
756
ingestionRate : 20 ,
757
757
ingestionBurstSize : 20 ,
758
- nativeHistogramIngestionRate : 5 ,
759
- nativeHistogramIngestionBurstSize : 5 ,
758
+ nativeHistogramIngestionRate : 10 ,
759
+ nativeHistogramIngestionBurstSize : 10 ,
760
760
pushes : []testPush {
761
- {samples : 5 , nhSamples : 4 , expectedError : nil },
762
- {samples : 6 , nhSamples : 2 , expectedError : nil , expectedNHDiscardedSampleMetricValue : 2 },
763
- {samples : 4 , metadata : 1 , nhSamples : 1 , expectedError : httpgrpc .Errorf (http .StatusTooManyRequests , "ingestion rate limit (20) exceeded while adding 5 samples and 1 metadata" ), expectedNHDiscardedSampleMetricValue : 2 },
764
- {metadata : 1 , expectedError : nil , expectedNHDiscardedSampleMetricValue : 2 },
761
+ {nhSamples : 2 , expectedError : nil },
762
+ {nhSamples : 3 , expectedError : nil },
763
+ {nhSamples : 6 , expectedError : httpgrpc .Errorf (http .StatusTooManyRequests , "native histogram ingestion rate limit (5) exceeded while adding 6 native histogram samples" ), expectedNHDiscardedSampleMetricValue : 6 },
765
764
},
766
765
},
767
- "global strategy: If NH samples hit NH rate limit, other samples should succeed when under rate limit" : {
766
+ "global strategy: Batch contains only NH samples and metadata and NH rate limit is hit " : {
768
767
distributors : 2 ,
769
768
ingestionRateStrategy : validation .GlobalIngestionRateStrategy ,
770
769
ingestionRate : 20 ,
771
- ingestionBurstSize : 10 ,
770
+ ingestionBurstSize : 20 ,
772
771
nativeHistogramIngestionRate : 10 ,
773
- nativeHistogramIngestionBurstSize : 5 ,
772
+ nativeHistogramIngestionBurstSize : 10 ,
773
+ pushes : []testPush {
774
+ {nhSamples : 2 , expectedError : nil },
775
+ {nhSamples : 3 , metadata : 2 , expectedError : nil },
776
+ {nhSamples : 6 , metadata : 1 , expectedError : httpgrpc .Errorf (http .StatusTooManyRequests , "native histogram ingestion rate limit (5) exceeded while adding 6 native histogram samples" ), expectedNHDiscardedSampleMetricValue : 6 , isPartialDrop : true }},
777
+ },
778
+ "global strategy: Batch contains regular and NH samples and NH rate limit is hit" : {
779
+ distributors : 2 ,
780
+ ingestionRateStrategy : validation .GlobalIngestionRateStrategy ,
781
+ ingestionRate : 30 ,
782
+ ingestionBurstSize : 30 ,
783
+ nativeHistogramIngestionRate : 10 ,
784
+ nativeHistogramIngestionBurstSize : 10 ,
774
785
pushes : []testPush {
775
- {samples : 3 , nhSamples : 2 , expectedError : nil },
776
- {samples : 3 , nhSamples : 4 , expectedError : nil , expectedNHDiscardedSampleMetricValue : 4 },
777
- {samples : 1 , metadata : 1 , nhSamples : 1 , expectedError : httpgrpc .Errorf (http .StatusTooManyRequests , "ingestion rate limit (10) exceeded while adding 2 samples and 1 metadata" ), expectedNHDiscardedSampleMetricValue : 4 },
778
- {metadata : 1 , expectedError : nil , expectedNHDiscardedSampleMetricValue : 4 },
786
+ {samples : 3 , nhSamples : 2 , metadata : 1 , expectedError : nil },
787
+ {samples : 1 , nhSamples : 9 , metadata : 1 , expectedError : httpgrpc .Errorf (http .StatusTooManyRequests , "native histogram ingestion rate limit (5) exceeded while adding 9 native histogram samples" ), expectedNHDiscardedSampleMetricValue : 9 , isPartialDrop : true },
788
+ {nhSamples : 9 , expectedError : httpgrpc .Errorf (http .StatusTooManyRequests , "native histogram ingestion rate limit (5) exceeded while adding 9 native histogram samples" ), expectedNHDiscardedSampleMetricValue : 18 },
789
+ {samples : 3 , metadata : 1 , expectedError : nil , expectedNHDiscardedSampleMetricValue : 18 },
790
+ },
791
+ },
792
+ "global strategy: Batch contains regular and NH samples and normal ingestion rate limit is hit" : {
793
+ distributors : 2 ,
794
+ ingestionRateStrategy : validation .GlobalIngestionRateStrategy ,
795
+ ingestionRate : 20 ,
796
+ ingestionBurstSize : 20 ,
797
+ nativeHistogramIngestionRate : 10 ,
798
+ nativeHistogramIngestionBurstSize : 10 ,
799
+ pushes : []testPush {
800
+ {samples : 4 , nhSamples : 4 , metadata : 4 , expectedError : nil },
801
+ {samples : 4 , nhSamples : 4 , metadata : 4 , expectedError : httpgrpc .Errorf (http .StatusTooManyRequests , "ingestion rate limit (10) exceeded while adding 8 samples and 4 metadata" )},
802
+ {samples : 3 , nhSamples : 3 , metadata : 2 , expectedError : nil },
779
803
},
780
804
},
781
805
}
@@ -812,8 +836,13 @@ func TestDistributor_PushIngestionRateLimiter_Histograms(t *testing.T) {
812
836
assert .Equal (t , emptyResponse , response )
813
837
assert .Nil (t , err )
814
838
} else {
815
- assert .Nil (t , response )
816
839
assert .Equal (t , push .expectedError , err )
840
+ // Check if an empty response is expected
841
+ if push .isPartialDrop {
842
+ assert .Equal (t , emptyResponse , response )
843
+ } else {
844
+ assert .Nil (t , response )
845
+ }
817
846
}
818
847
assert .Equal (t , float64 (push .expectedNHDiscardedSampleMetricValue ), testutil .ToFloat64 (distributors [0 ].validateMetrics .DiscardedSamples .WithLabelValues (validation .NativeHistogramRateLimited , "user" )))
819
848
}
0 commit comments