Skip to content

Commit

Permalink
Merge pull request #1582 from LiZhenCheng9527/fix-metric-bug
Browse files Browse the repository at this point in the history
return an error for missing metric templates
  • Loading branch information
stefanprodan authored Jan 30, 2024
2 parents b562ddd + 5f8aeb8 commit 16f8e15
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/controller/scheduler_daemonset_fixture_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,10 @@ func newDaemonSetTestCanaryAB() *flaggerv1.Canary {
Min: toFloatPtr(0),
Max: toFloatPtr(500000),
},
TemplateRef: &flaggerv1.CrossNamespaceObjectReference{
Name: "envoy",
Namespace: "default",
},
Interval: "1m",
Query: "fake",
},
Expand Down
4 changes: 4 additions & 0 deletions pkg/controller/scheduler_deployment_fixture_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,10 @@ func newDeploymentTestCanaryAB() *flaggerv1.Canary {
Min: toFloatPtr(0),
Max: toFloatPtr(500000),
},
TemplateRef: &flaggerv1.CrossNamespaceObjectReference{
Name: "envoy",
Namespace: "default",
},
Interval: "1m",
Query: "fake",
},
Expand Down
3 changes: 3 additions & 0 deletions pkg/controller/scheduler_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,9 @@ 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")
return false
}
}

Expand Down
32 changes: 32 additions & 0 deletions pkg/controller/scheduler_metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,36 @@ func TestController_runMetricChecks(t *testing.T) {
}
assert.Equal(t, true, ctrl.runMetricChecks(canary))
})

t.Run("undefined metric", 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),
},
}}}
canary := &flaggerv1.Canary{
ObjectMeta: metav1.ObjectMeta{Namespace: "default"},
Spec: flaggerv1.CanarySpec{Analysis: analysis},
}
assert.Equal(t, false, ctrl.runMetricChecks(canary))
})

t.Run("builtinMetric", func(t *testing.T) {
ctrl := newDeploymentFixture(nil).ctrl
analysis := &flaggerv1.CanaryAnalysis{Metrics: []flaggerv1.CanaryMetric{{
Name: "request-success-rate",
ThresholdRange: &flaggerv1.CanaryThresholdRange{
Min: toFloatPtr(0),
Max: toFloatPtr(100),
},
}}}
canary := &flaggerv1.Canary{
ObjectMeta: metav1.ObjectMeta{Namespace: "default"},
Spec: flaggerv1.CanarySpec{Analysis: analysis},
}
assert.Equal(t, true, ctrl.runMetricChecks(canary))
})
}

0 comments on commit 16f8e15

Please sign in to comment.