@@ -341,6 +341,7 @@ func TestIngester_Push(t *testing.T) {
341
341
additionalMetrics []string
342
342
disableActiveSeries bool
343
343
maxExemplars int
344
+ oooTimeWindow time.Duration
344
345
}{
345
346
"should succeed on valid series and metadata" : {
346
347
reqs : []* cortexpb.WriteRequest {
@@ -553,7 +554,7 @@ func TestIngester_Push(t *testing.T) {
553
554
cortex_ingester_memory_series_removed_total{user="test"} 0
554
555
` ,
555
556
},
556
- "should soft fail on sample out of order" : {
557
+ "ooo disabled, should soft fail on sample out of order" : {
557
558
reqs : []* cortexpb.WriteRequest {
558
559
cortexpb .ToWriteRequest (
559
560
[]labels.Labels {metricLabels },
@@ -597,7 +598,7 @@ func TestIngester_Push(t *testing.T) {
597
598
cortex_ingester_active_series{user="test"} 1
598
599
` ,
599
600
},
600
- "should soft fail on sample out of bound" : {
601
+ "ooo disabled, should soft fail on sample out of bound" : {
601
602
reqs : []* cortexpb.WriteRequest {
602
603
cortexpb .ToWriteRequest (
603
604
[]labels.Labels {metricLabels },
@@ -641,6 +642,92 @@ func TestIngester_Push(t *testing.T) {
641
642
cortex_ingester_active_series{user="test"} 1
642
643
` ,
643
644
},
645
+ "ooo enabled, should soft fail on sample too old" : {
646
+ reqs : []* cortexpb.WriteRequest {
647
+ cortexpb .ToWriteRequest (
648
+ []labels.Labels {metricLabels },
649
+ []cortexpb.Sample {{Value : 2 , TimestampMs : 1575043969 }},
650
+ nil ,
651
+ cortexpb .API ),
652
+ cortexpb .ToWriteRequest (
653
+ []labels.Labels {metricLabels },
654
+ []cortexpb.Sample {{Value : 1 , TimestampMs : 1575043969 - (600 * 1000 )}},
655
+ nil ,
656
+ cortexpb .API ),
657
+ },
658
+ oooTimeWindow : 5 * time .Minute ,
659
+ expectedErr : httpgrpc .Errorf (http .StatusBadRequest , wrapWithUser (wrappedTSDBIngestErr (storage .ErrTooOldSample , model .Time (1575043969 - (600 * 1000 )), cortexpb .FromLabelsToLabelAdapters (metricLabels )), userID ).Error ()),
660
+ expectedIngested : []cortexpb.TimeSeries {
661
+ {Labels : metricLabelAdapters , Samples : []cortexpb.Sample {{Value : 2 , TimestampMs : 1575043969 }}},
662
+ },
663
+ expectedMetrics : `
664
+ # HELP cortex_ingester_ingested_samples_total The total number of samples ingested.
665
+ # TYPE cortex_ingester_ingested_samples_total counter
666
+ cortex_ingester_ingested_samples_total 1
667
+ # HELP cortex_ingester_ingested_samples_failures_total The total number of samples that errored on ingestion.
668
+ # TYPE cortex_ingester_ingested_samples_failures_total counter
669
+ cortex_ingester_ingested_samples_failures_total 1
670
+ # HELP cortex_ingester_memory_users The current number of users in memory.
671
+ # TYPE cortex_ingester_memory_users gauge
672
+ cortex_ingester_memory_users 1
673
+ # HELP cortex_ingester_memory_series The current number of series in memory.
674
+ # TYPE cortex_ingester_memory_series gauge
675
+ cortex_ingester_memory_series 1
676
+ # HELP cortex_ingester_memory_series_created_total The total number of series that were created per user.
677
+ # TYPE cortex_ingester_memory_series_created_total counter
678
+ cortex_ingester_memory_series_created_total{user="test"} 1
679
+ # HELP cortex_ingester_memory_series_removed_total The total number of series that were removed per user.
680
+ # TYPE cortex_ingester_memory_series_removed_total counter
681
+ cortex_ingester_memory_series_removed_total{user="test"} 0
682
+ # HELP cortex_discarded_samples_total The total number of samples that were discarded.
683
+ # TYPE cortex_discarded_samples_total counter
684
+ cortex_discarded_samples_total{reason="sample-too-old",user="test"} 1
685
+ # HELP cortex_ingester_active_series Number of currently active series per user.
686
+ # TYPE cortex_ingester_active_series gauge
687
+ cortex_ingester_active_series{user="test"} 1
688
+ ` ,
689
+ },
690
+ "ooo enabled, should succeed" : {
691
+ reqs : []* cortexpb.WriteRequest {
692
+ cortexpb .ToWriteRequest (
693
+ []labels.Labels {metricLabels },
694
+ []cortexpb.Sample {{Value : 2 , TimestampMs : 1575043969 }},
695
+ nil ,
696
+ cortexpb .API ),
697
+ cortexpb .ToWriteRequest (
698
+ []labels.Labels {metricLabels },
699
+ []cortexpb.Sample {{Value : 1 , TimestampMs : 1575043969 - (60 * 1000 )}},
700
+ nil ,
701
+ cortexpb .API ),
702
+ },
703
+ oooTimeWindow : 5 * time .Minute ,
704
+ expectedIngested : []cortexpb.TimeSeries {
705
+ {Labels : metricLabelAdapters , Samples : []cortexpb.Sample {{Value : 1 , TimestampMs : 1575043969 - (60 * 1000 )}, {Value : 2 , TimestampMs : 1575043969 }}},
706
+ },
707
+ expectedMetrics : `
708
+ # HELP cortex_ingester_ingested_samples_total The total number of samples ingested.
709
+ # TYPE cortex_ingester_ingested_samples_total counter
710
+ cortex_ingester_ingested_samples_total 2
711
+ # HELP cortex_ingester_ingested_samples_failures_total The total number of samples that errored on ingestion.
712
+ # TYPE cortex_ingester_ingested_samples_failures_total counter
713
+ cortex_ingester_ingested_samples_failures_total 0
714
+ # HELP cortex_ingester_memory_users The current number of users in memory.
715
+ # TYPE cortex_ingester_memory_users gauge
716
+ cortex_ingester_memory_users 1
717
+ # HELP cortex_ingester_memory_series The current number of series in memory.
718
+ # TYPE cortex_ingester_memory_series gauge
719
+ cortex_ingester_memory_series 1
720
+ # HELP cortex_ingester_memory_series_created_total The total number of series that were created per user.
721
+ # TYPE cortex_ingester_memory_series_created_total counter
722
+ cortex_ingester_memory_series_created_total{user="test"} 1
723
+ # HELP cortex_ingester_memory_series_removed_total The total number of series that were removed per user.
724
+ # TYPE cortex_ingester_memory_series_removed_total counter
725
+ cortex_ingester_memory_series_removed_total{user="test"} 0
726
+ # HELP cortex_ingester_active_series Number of currently active series per user.
727
+ # TYPE cortex_ingester_active_series gauge
728
+ cortex_ingester_active_series{user="test"} 1
729
+ ` ,
730
+ },
644
731
"should soft fail on two different sample values at the same timestamp" : {
645
732
reqs : []* cortexpb.WriteRequest {
646
733
cortexpb .ToWriteRequest (
@@ -777,6 +864,7 @@ func TestIngester_Push(t *testing.T) {
777
864
778
865
limits := defaultLimitsTestConfig ()
779
866
limits .MaxExemplars = testData .maxExemplars
867
+ limits .OutOfOrderTimeWindow = model .Duration (testData .oooTimeWindow )
780
868
i , err := prepareIngesterWithBlocksStorageAndLimits (t , cfg , limits , "" , registry )
781
869
require .NoError (t , err )
782
870
require .NoError (t , services .StartAndAwaitRunning (context .Background (), i ))
0 commit comments