mirror of
https://github.com/fluxcd/flagger.git
synced 2026-03-03 02:00:18 +00:00
Merge pull request #1148 from cdlliuy/add_canary_analysis_result_as_metric
Add canary analysis result as Prometheus metrics
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user