Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add version check for thanos. keep_firing_for now available #6283

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 4 additions & 12 deletions pkg/operator/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ func (prs *PrometheusRuleSelector) sanitizePrometheusRulesSpec(promRuleSpec moni
component := "Prometheus"

if prs.ruleFormat == ThanosFormat {
minVersionKeepFiringFor = semver.MustParse("0.34.0")
minVersionLimits = semver.MustParse("0.24.0")
component = "Thanos"
}
Expand All @@ -123,18 +124,9 @@ func (prs *PrometheusRuleSelector) sanitizePrometheusRulesSpec(promRuleSpec moni
}

for j := range promRuleSpec.Groups[i].Rules {
switch prs.ruleFormat {
case PrometheusFormat:
if promRuleSpec.Groups[i].Rules[j].KeepFiringFor != nil && prs.version.LT(minVersionKeepFiringFor) {
promRuleSpec.Groups[i].Rules[j].KeepFiringFor = nil
level.Warn(logger).Log("msg", fmt.Sprintf("ignoring 'keep_firing_for' not supported by %s", component), "minimum_version", minVersionKeepFiringFor)
}
case ThanosFormat:
// keep_firing_for is not yet supported in thanos https://github.com/thanos-io/thanos/issues/6165
if promRuleSpec.Groups[i].Rules[j].KeepFiringFor != nil {
promRuleSpec.Groups[i].Rules[j].KeepFiringFor = nil
level.Warn(logger).Log("msg", "ignoring `keep_firing_for` as it is not yet supported in thanos, see https://github.com/thanos-io/thanos/issues/6165")
}
if promRuleSpec.Groups[i].Rules[j].KeepFiringFor != nil && prs.version.LT(minVersionKeepFiringFor) {
promRuleSpec.Groups[i].Rules[j].KeepFiringFor = nil
level.Warn(logger).Log("msg", fmt.Sprintf("ignoring 'keep_firing_for' not supported by %s", component), "minimum_version", minVersionKeepFiringFor)
}
}
}
Expand Down
30 changes: 28 additions & 2 deletions pkg/operator/rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ func TestMakeRulesConfigMaps(t *testing.T) {
t.Run("shouldDropLimitFieldForUnsupportedPrometheusVersion", shouldDropLimitFieldForUnsupportedPrometheusVersion)
t.Run("shouldDropLimitFieldForUnsupportedThanosVersion", shouldDropLimitFieldForUnsupportedThanosVersion)
t.Run("shouldAcceptRuleWithKeepFiringForPrometheus", shouldAcceptRuleWithKeepFiringForPrometheus)
t.Run("shouldDropKeepFiringForThanos", shouldDropKeepFiringForThanos)
t.Run("shouldDropRuleFiringForThanos", shouldDropRuleFiringForThanos)
t.Run("shouldAcceptRuleFiringForThanos", shouldAcceptRuleFiringForThanos)
t.Run("shouldDropKeepFiringForFieldForUnsupportedPrometheusVersion", shouldDropKeepFiringForFieldForUnsupportedPrometheusVersion)
}

Expand Down Expand Up @@ -227,7 +228,7 @@ func shouldAcceptRuleWithKeepFiringForPrometheus(t *testing.T) {
}
}

func shouldDropKeepFiringForThanos(t *testing.T) {
func shouldDropRuleFiringForThanos(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a big deal but you could have kept the original name?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made this by example of Prometheus - Accept and Drop.
And, I guess, because of now it's possible to use and that option can be Accepted and should be Dropped in case of version of thanos is "old".

duration := monitoringv1.NonEmptyDuration("5m")
rules := &monitoringv1.PrometheusRule{
Spec: monitoringv1.PrometheusRuleSpec{Groups: []monitoringv1.RuleGroup{
Expand All @@ -252,6 +253,31 @@ func shouldDropKeepFiringForThanos(t *testing.T) {
}
}

func shouldAcceptRuleFiringForThanos(t *testing.T) {
duration := monitoringv1.NonEmptyDuration("5m")
rules := &monitoringv1.PrometheusRule{
Spec: monitoringv1.PrometheusRuleSpec{Groups: []monitoringv1.RuleGroup{
{
Name: "group",
Rules: []monitoringv1.Rule{
{
Alert: "alert",
Expr: intstr.FromString("vector(1)"),
KeepFiringFor: &duration,
},
},
},
}},
}

thanosVersion, _ := semver.ParseTolerant("v0.34.0")
pr := newRuleSelectorForConfigGeneration(ThanosFormat, thanosVersion)
content, _ := pr.generateRulesConfiguration(rules)
if !strings.Contains(content, "keep_firing_for") {
t.Fatalf("expected `keep_firing_for` to be present in PrometheusRule")
}
}

func shouldDropKeepFiringForFieldForUnsupportedPrometheusVersion(t *testing.T) {
duration := monitoringv1.NonEmptyDuration("5m")
rules := &monitoringv1.PrometheusRule{
Expand Down