@@ -88,7 +88,8 @@ func TestController_runMetricChecks(t *testing.T) {
88
88
t .Run ("customVariables" , func (t * testing.T ) {
89
89
ctrl := newDeploymentFixture (nil ).ctrl
90
90
analysis := & flaggerv1.CanaryAnalysis {Metrics : []flaggerv1.CanaryMetric {{
91
- Name : "" , TemplateVariables : map [string ]string {
91
+ Name : "" ,
92
+ TemplateVariables : map [string ]string {
92
93
"first" : "abc" ,
93
94
"second" : "def" ,
94
95
},
@@ -139,4 +140,46 @@ func TestController_runMetricChecks(t *testing.T) {
139
140
}
140
141
assert .Equal (t , true , ctrl .runMetricChecks (canary ))
141
142
})
143
+
144
+ t .Run ("no metric Template is defined, but a query is specified" , func (t * testing.T ) {
145
+ ctrl := newDeploymentFixture (nil ).ctrl
146
+ analysis := & flaggerv1.CanaryAnalysis {Metrics : []flaggerv1.CanaryMetric {{
147
+ Name : "undefined metric" ,
148
+ ThresholdRange : & flaggerv1.CanaryThresholdRange {
149
+ Min : toFloatPtr (0 ),
150
+ Max : toFloatPtr (100 ),
151
+ },
152
+ Query : ">- sum(logback_events_total{level=\" error\" , job=\" some-app\" }) <= bool 0" ,
153
+ }}}
154
+ canary := & flaggerv1.Canary {
155
+ ObjectMeta : metav1.ObjectMeta {Namespace : "default" },
156
+ Spec : flaggerv1.CanarySpec {Analysis : analysis },
157
+ }
158
+ assert .Equal (t , true , ctrl .runMetricChecks (canary ))
159
+ })
160
+
161
+ t .Run ("both have metric Template and query" , func (t * testing.T ) {
162
+ ctrl := newDeploymentFixture (nil ).ctrl
163
+ analysis := & flaggerv1.CanaryAnalysis {Metrics : []flaggerv1.CanaryMetric {{
164
+ Name : "" ,
165
+ TemplateVariables : map [string ]string {
166
+ "first" : "abc" ,
167
+ "second" : "def" ,
168
+ },
169
+ TemplateRef : & flaggerv1.CrossNamespaceObjectReference {
170
+ Name : "custom-vars" ,
171
+ Namespace : "default" ,
172
+ },
173
+ ThresholdRange : & flaggerv1.CanaryThresholdRange {
174
+ Min : toFloatPtr (0 ),
175
+ Max : toFloatPtr (100 ),
176
+ },
177
+ Query : ">- sum(logback_events_total{level=\" error\" , job=\" some-app\" }) <= bool 0" ,
178
+ }}}
179
+ canary := & flaggerv1.Canary {
180
+ ObjectMeta : metav1.ObjectMeta {Namespace : "default" },
181
+ Spec : flaggerv1.CanarySpec {Analysis : analysis },
182
+ }
183
+ assert .Equal (t , true , ctrl .runMetricChecks (canary ))
184
+ })
142
185
}
0 commit comments