@@ -437,7 +437,7 @@ func TestSeriesCheck(t *testing.T) {
437
437
{
438
438
description : "#2 series never present, custom range" ,
439
439
content : "- record: foo\n expr: sum(notfound)\n " ,
440
- ctx : func () context.Context {
440
+ ctx : func (_ string ) context.Context {
441
441
s := checks.PromqlSeriesSettings {
442
442
LookbackRange : "3d" ,
443
443
LookbackStep : "6m" ,
@@ -669,7 +669,7 @@ func TestSeriesCheck(t *testing.T) {
669
669
description : "#2 series never present but metric ignored" ,
670
670
content : "- record: foo\n expr: sum(notfound)\n " ,
671
671
checker : newSeriesCheck ,
672
- ctx : func () context.Context {
672
+ ctx : func (_ string ) context.Context {
673
673
s := checks.PromqlSeriesSettings {
674
674
IgnoreMetrics : []string {"foo" , "bar" , "not.+" },
675
675
}
@@ -1413,7 +1413,7 @@ func TestSeriesCheck(t *testing.T) {
1413
1413
description : "#4 metric was present but disappeared over 1h ago / ignored" ,
1414
1414
content : "- record: foo\n expr: sum(found{job=\" foo\" , instance=\" bar\" })\n " ,
1415
1415
checker : newSeriesCheck ,
1416
- ctx : func () context.Context {
1416
+ ctx : func (_ string ) context.Context {
1417
1417
s := checks.PromqlSeriesSettings {
1418
1418
IgnoreMetrics : []string {"foo" , "found" , "not.+" },
1419
1419
}
@@ -1990,7 +1990,7 @@ func TestSeriesCheck(t *testing.T) {
1990
1990
description : "#5 metric was present but not with label value" ,
1991
1991
content : "- record: foo\n expr: sum(found{notfound=\" notfound\" , instance=~\" .+\" , not!=\" negative\" , instance!~\" bad\" })\n " ,
1992
1992
checker : newSeriesCheck ,
1993
- ctx : func () context.Context {
1993
+ ctx : func (_ string ) context.Context {
1994
1994
s := checks.PromqlSeriesSettings {
1995
1995
IgnoreMetrics : []string {"foo" , "bar" , "found" },
1996
1996
}
@@ -3771,6 +3771,129 @@ func TestSeriesCheck(t *testing.T) {
3771
3771
}
3772
3772
},
3773
3773
},
3774
+ {
3775
+ description : "series not present on other servers" ,
3776
+ content : "- record: foo\n expr: notfound\n " ,
3777
+ checker : newSeriesCheck ,
3778
+ prometheus : newSimpleProm ,
3779
+ otherProms : func (uri string ) []* promapi.FailoverGroup {
3780
+ var proms []* promapi.FailoverGroup
3781
+ for i := range 5 {
3782
+ proms = append (proms , simpleProm (fmt .Sprintf ("prom%d" , i ), uri + "/other" , time .Second , false ))
3783
+ }
3784
+ return proms
3785
+ },
3786
+ problems : func (uri string ) []checks.Problem {
3787
+ return []checks.Problem {
3788
+ {
3789
+ Lines : parser.LineRange {
3790
+ First : 2 ,
3791
+ Last : 2 ,
3792
+ },
3793
+ Reporter : checks .SeriesCheckName ,
3794
+ Text : noMetricText ("prom" , uri , "notfound" , "1w" ),
3795
+ Details : checks .SeriesCheckCommonProblemDetails ,
3796
+ Severity : checks .Bug ,
3797
+ },
3798
+ }
3799
+ },
3800
+ mocks : []* prometheusMock {
3801
+ {
3802
+ conds : []requestCondition {requestPathCond {path : "/other/api/v1/query" }},
3803
+ resp : respondWithEmptyVector (),
3804
+ },
3805
+ {
3806
+ conds : []requestCondition {requireQueryPath },
3807
+ resp : respondWithEmptyVector (),
3808
+ },
3809
+ {
3810
+ conds : []requestCondition {requireRangeQueryPath },
3811
+ resp : respondWithEmptyMatrix (),
3812
+ },
3813
+ },
3814
+ },
3815
+ {
3816
+ description : "series present on other servers" ,
3817
+ content : "- record: foo\n expr: notfound\n " ,
3818
+ checker : newSeriesCheck ,
3819
+ prometheus : newSimpleProm ,
3820
+ otherProms : func (uri string ) []* promapi.FailoverGroup {
3821
+ var proms []* promapi.FailoverGroup
3822
+ for i := range 5 {
3823
+ proms = append (proms , simpleProm (fmt .Sprintf ("prom%d" , i ), uri + "/other" , time .Second , false ))
3824
+ }
3825
+ return proms
3826
+ },
3827
+ problems : func (uri string ) []checks.Problem {
3828
+ return []checks.Problem {
3829
+ {
3830
+ Lines : parser.LineRange {
3831
+ First : 2 ,
3832
+ Last : 2 ,
3833
+ },
3834
+ Reporter : checks .SeriesCheckName ,
3835
+ Text : noMetricText ("prom" , uri , "notfound" , "1w" ),
3836
+ Details : fmt .Sprintf ("`notfound` was found on other prometheus servers:\n \n - [prom0](%s/other/graph?g0.expr=notfound)\n - [prom1](%s/other/graph?g0.expr=notfound)\n - [prom2](%s/other/graph?g0.expr=notfound)\n - [prom3](%s/other/graph?g0.expr=notfound)\n - [prom4](%s/other/graph?g0.expr=notfound)\n \n You might be trying to deploy this rule to the wrong Prometheus server instance.\n " , uri , uri , uri , uri , uri ),
3837
+ Severity : checks .Bug ,
3838
+ },
3839
+ }
3840
+ },
3841
+ mocks : []* prometheusMock {
3842
+ {
3843
+ conds : []requestCondition {requestPathCond {path : "/other/api/v1/query" }},
3844
+ resp : respondWithSingleInstantVector (),
3845
+ },
3846
+ {
3847
+ conds : []requestCondition {requireQueryPath },
3848
+ resp : respondWithEmptyVector (),
3849
+ },
3850
+ {
3851
+ conds : []requestCondition {requireRangeQueryPath },
3852
+ resp : respondWithEmptyMatrix (),
3853
+ },
3854
+ },
3855
+ },
3856
+ {
3857
+ description : "series present on other servers / 15" ,
3858
+ content : "- record: foo\n expr: notfound\n " ,
3859
+ checker : newSeriesCheck ,
3860
+ prometheus : newSimpleProm ,
3861
+ otherProms : func (uri string ) []* promapi.FailoverGroup {
3862
+ var proms []* promapi.FailoverGroup
3863
+ for i := range 15 {
3864
+ proms = append (proms , simpleProm (fmt .Sprintf ("prom%d" , i ), uri + "/other" , time .Second , false ))
3865
+ }
3866
+ return proms
3867
+ },
3868
+ problems : func (uri string ) []checks.Problem {
3869
+ return []checks.Problem {
3870
+ {
3871
+ Lines : parser.LineRange {
3872
+ First : 2 ,
3873
+ Last : 2 ,
3874
+ },
3875
+ Reporter : checks .SeriesCheckName ,
3876
+ Text : noMetricText ("prom" , uri , "notfound" , "1w" ),
3877
+ Details : fmt .Sprintf ("`notfound` was found on other prometheus servers:\n \n - [prom0](%s/other/graph?g0.expr=notfound)\n - [prom1](%s/other/graph?g0.expr=notfound)\n - [prom2](%s/other/graph?g0.expr=notfound)\n - [prom3](%s/other/graph?g0.expr=notfound)\n - [prom4](%s/other/graph?g0.expr=notfound)\n - [prom5](%s/other/graph?g0.expr=notfound)\n - [prom6](%s/other/graph?g0.expr=notfound)\n - [prom7](%s/other/graph?g0.expr=notfound)\n - [prom8](%s/other/graph?g0.expr=notfound)\n - [prom9](%s/other/graph?g0.expr=notfound)\n - and 5 other server(s).\n \n You might be trying to deploy this rule to the wrong Prometheus server instance.\n " , uri , uri , uri , uri , uri , uri , uri , uri , uri , uri ),
3878
+ Severity : checks .Bug ,
3879
+ },
3880
+ }
3881
+ },
3882
+ mocks : []* prometheusMock {
3883
+ {
3884
+ conds : []requestCondition {requestPathCond {path : "/other/api/v1/query" }},
3885
+ resp : respondWithSingleInstantVector (),
3886
+ },
3887
+ {
3888
+ conds : []requestCondition {requireQueryPath },
3889
+ resp : respondWithEmptyVector (),
3890
+ },
3891
+ {
3892
+ conds : []requestCondition {requireRangeQueryPath },
3893
+ resp : respondWithEmptyMatrix (),
3894
+ },
3895
+ },
3896
+ },
3774
3897
}
3775
3898
runTests (t , testCases )
3776
3899
}
0 commit comments