Merge pull request #1148 from cdlliuy/add_canary_analysis_result_as_metric

Add canary analysis result as Prometheus metrics
This commit is contained in:
Stefan Prodan 2022-04-06 07:57:23 +03:00 committed by GitHub
commit 793b93c665
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 1 deletions

View File

@ -117,4 +117,8 @@ flagger_canary_duration_seconds_bucket{name="podinfo",namespace="test",le="10"}
flagger_canary_duration_seconds_bucket{name="podinfo",namespace="test",le="+Inf"} 6
flagger_canary_duration_seconds_sum{name="podinfo",namespace="test"} 17.3561329
flagger_canary_duration_seconds_count{name="podinfo",namespace="test"} 6
# Last canary metric analysis result per different metrics
flagger_canary_metric_analysis{metric="podinfo-http-successful-rate",name="podinfo",namespace="test"} 1
flagger_canary_metric_analysis{metric="podinfo-custom-metric",name="podinfo",namespace="test"} 0.918223108974359
```

View File

@ -146,7 +146,7 @@ func (c *Controller) runBuiltinMetricChecks(canary *flaggerv1.Canary) bool {
}
return false
}
c.recorder.SetAnalysis(canary, metric.Name, val)
if metric.ThresholdRange != nil {
tr := *metric.ThresholdRange
if tr.Min != nil && val < *tr.Min {
@ -177,6 +177,7 @@ func (c *Controller) runBuiltinMetricChecks(canary *flaggerv1.Canary) bool {
}
return false
}
c.recorder.SetAnalysis(canary, metric.Name, val.Seconds())
if metric.ThresholdRange != nil {
tr := *metric.ThresholdRange
if tr.Min != nil && val < time.Duration(*tr.Min)*time.Millisecond {
@ -209,6 +210,7 @@ func (c *Controller) runBuiltinMetricChecks(canary *flaggerv1.Canary) bool {
}
return false
}
c.recorder.SetAnalysis(canary, metric.Name, val)
if metric.ThresholdRange != nil {
tr := *metric.ThresholdRange
if tr.Min != nil && val < *tr.Min {
@ -283,6 +285,8 @@ func (c *Controller) runMetricChecks(canary *flaggerv1.Canary) bool {
return false
}
c.recorder.SetAnalysis(canary, metric.Name, val)
if metric.ThresholdRange != nil {
tr := *metric.ThresholdRange
if tr.Min != nil && val < *tr.Min {

View File

@ -31,6 +31,7 @@ type Recorder struct {
total *prometheus.GaugeVec
status *prometheus.GaugeVec
weight *prometheus.GaugeVec
analysis *prometheus.GaugeVec
}
// NewRecorder creates a new recorder and registers the Prometheus metrics
@ -67,12 +68,19 @@ func NewRecorder(controller string, register bool) Recorder {
Help: "The virtual service destination weight current value",
}, []string{"workload", "namespace"})
analysis := prometheus.NewGaugeVec(prometheus.GaugeOpts{
Subsystem: controller,
Name: "canary_metric_analysis",
Help: "Last canary analysis result per metric",
}, []string{"name", "namespace", "metric"})
if register {
prometheus.MustRegister(info)
prometheus.MustRegister(duration)
prometheus.MustRegister(total)
prometheus.MustRegister(status)
prometheus.MustRegister(weight)
prometheus.MustRegister(analysis)
}
return Recorder{
@ -81,6 +89,7 @@ func NewRecorder(controller string, register bool) Recorder {
total: total,
status: status,
weight: weight,
analysis: analysis,
}
}
@ -99,6 +108,10 @@ func (cr *Recorder) SetTotal(namespace string, total int) {
cr.total.WithLabelValues(namespace).Set(float64(total))
}
func (cr *Recorder) SetAnalysis(cd *flaggerv1.Canary, metricTemplateName string, val float64) {
cr.analysis.WithLabelValues(cd.Spec.TargetRef.Name, cd.Namespace, metricTemplateName).Set(val)
}
// SetStatus sets the last known canary analysis status
func (cr *Recorder) SetStatus(cd *flaggerv1.Canary, phase flaggerv1.CanaryPhase) {
var status int