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

Fixed bug where query with no metric template returned an error #1611

Merged
merged 1 commit into from
Mar 7, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pkg/controller/scheduler_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,8 @@ func (c *Controller) runMetricChecks(canary *flaggerv1.Canary) bool {
canary.Name, canary.Namespace, metric.Name, val, metric.Threshold)
return false
}
} else if metric.Name != "request-success-rate" && metric.Name != "request-duration" {
c.recordEventErrorf(canary, "Metric query failed for no usable metrics template were configured")
} else if metric.Name != "request-success-rate" && metric.Name != "request-duration" && metric.Query == "" {
c.recordEventErrorf(canary, "Metric query failed for no usable metrics template and query were configured")
return false
}
}
Expand Down
45 changes: 44 additions & 1 deletion pkg/controller/scheduler_metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ func TestController_runMetricChecks(t *testing.T) {
t.Run("customVariables", func(t *testing.T) {
ctrl := newDeploymentFixture(nil).ctrl
analysis := &flaggerv1.CanaryAnalysis{Metrics: []flaggerv1.CanaryMetric{{
Name: "", TemplateVariables: map[string]string{
Name: "",
TemplateVariables: map[string]string{
"first": "abc",
"second": "def",
},
Expand Down Expand Up @@ -139,4 +140,46 @@ func TestController_runMetricChecks(t *testing.T) {
}
assert.Equal(t, true, ctrl.runMetricChecks(canary))
})

t.Run("no metric Template is defined, but a query is specified", func(t *testing.T) {
ctrl := newDeploymentFixture(nil).ctrl
analysis := &flaggerv1.CanaryAnalysis{Metrics: []flaggerv1.CanaryMetric{{
Name: "undefined metric",
ThresholdRange: &flaggerv1.CanaryThresholdRange{
Min: toFloatPtr(0),
Max: toFloatPtr(100),
},
Query: ">- sum(logback_events_total{level=\"error\", job=\"some-app\"}) <= bool 0",
}}}
canary := &flaggerv1.Canary{
ObjectMeta: metav1.ObjectMeta{Namespace: "default"},
Spec: flaggerv1.CanarySpec{Analysis: analysis},
}
assert.Equal(t, true, ctrl.runMetricChecks(canary))
})

t.Run("both have metric Template and query", func(t *testing.T) {
ctrl := newDeploymentFixture(nil).ctrl
analysis := &flaggerv1.CanaryAnalysis{Metrics: []flaggerv1.CanaryMetric{{
Name: "",
TemplateVariables: map[string]string{
"first": "abc",
"second": "def",
},
TemplateRef: &flaggerv1.CrossNamespaceObjectReference{
Name: "custom-vars",
Namespace: "default",
},
ThresholdRange: &flaggerv1.CanaryThresholdRange{
Min: toFloatPtr(0),
Max: toFloatPtr(100),
},
Query: ">- sum(logback_events_total{level=\"error\", job=\"some-app\"}) <= bool 0",
}}}
canary := &flaggerv1.Canary{
ObjectMeta: metav1.ObjectMeta{Namespace: "default"},
Spec: flaggerv1.CanarySpec{Analysis: analysis},
}
assert.Equal(t, true, ctrl.runMetricChecks(canary))
})
}