diff --git a/pkg/controller/controller.go b/pkg/controller/controller.go index 28415540..6fbc2b91 100644 --- a/pkg/controller/controller.go +++ b/pkg/controller/controller.go @@ -42,8 +42,8 @@ type Controller struct { canaries *sync.Map jobs map[string]CanaryJob deployer CanaryDeployer - observer metrics.CanaryObserver - recorder metrics.CanaryRecorder + observer metrics.Observer + recorder metrics.Recorder notifier *notifier.Slack meshProvider string } @@ -81,7 +81,7 @@ func NewController( }, } - recorder := metrics.NewCanaryRecorder(controllerAgentName, true) + recorder := metrics.NewRecorder(controllerAgentName, true) recorder.SetInfo(version, meshProvider) ctrl := &Controller{ diff --git a/pkg/controller/controller_test.go b/pkg/controller/controller_test.go index ade7a935..a636f7f8 100644 --- a/pkg/controller/controller_test.go +++ b/pkg/controller/controller_test.go @@ -35,7 +35,7 @@ type Mocks struct { meshClient clientset.Interface flaggerClient clientset.Interface deployer CanaryDeployer - observer metrics.CanaryObserver + observer metrics.Observer ctrl *Controller logger *zap.SugaredLogger router router.Interface @@ -92,7 +92,7 @@ func SetupMocks(abtest bool) Mocks { flaggerWindow: time.Second, deployer: deployer, observer: metrics.NewObserver("fake"), - recorder: metrics.NewCanaryRecorder(controllerAgentName, false), + recorder: metrics.NewRecorder(controllerAgentName, false), } ctrl.flaggerSynced = alwaysReady diff --git a/pkg/metrics/observer.go b/pkg/metrics/observer.go index 12dc24e3..7eaacd4d 100644 --- a/pkg/metrics/observer.go +++ b/pkg/metrics/observer.go @@ -12,8 +12,8 @@ import ( "time" ) -// CanaryObserver is used to query the Istio Prometheus db -type CanaryObserver struct { +// Observer is used to query Prometheus +type Observer struct { metricsServer string } @@ -29,17 +29,17 @@ type vectorQueryResponse struct { } } -func NewObserver(metricsServer string) CanaryObserver { - return CanaryObserver{ +func NewObserver(metricsServer string) Observer { + return Observer{ metricsServer: metricsServer, } } -func (c *CanaryObserver) GetMetricsServer() string { +func (c *Observer) GetMetricsServer() string { return c.metricsServer } -func (c *CanaryObserver) queryMetric(query string) (*vectorQueryResponse, error) { +func (c *Observer) queryMetric(query string) (*vectorQueryResponse, error) { promURL, err := url.Parse(c.metricsServer) if err != nil { return nil, err @@ -85,7 +85,7 @@ func (c *CanaryObserver) queryMetric(query string) (*vectorQueryResponse, error) } // GetScalar runs the promql query and returns the first value found -func (c *CanaryObserver) GetScalar(query string) (float64, error) { +func (c *Observer) GetScalar(query string) (float64, error) { if c.metricsServer == "fake" { return 100, nil } @@ -116,7 +116,7 @@ func (c *CanaryObserver) GetScalar(query string) (float64, error) { return *value, nil } -func (c *CanaryObserver) GetEnvoySuccessRate(name string, namespace string, metric string, interval string) (float64, error) { +func (c *Observer) GetEnvoySuccessRate(name string, namespace string, metric string, interval string) (float64, error) { if c.metricsServer == "fake" { return 100, nil } @@ -154,7 +154,7 @@ func (c *CanaryObserver) GetEnvoySuccessRate(name string, namespace string, metr } // GetDeploymentCounter returns the requests success rate using istio_requests_total metric -func (c *CanaryObserver) GetDeploymentCounter(name string, namespace string, metric string, interval string) (float64, error) { +func (c *Observer) GetDeploymentCounter(name string, namespace string, metric string, interval string) (float64, error) { if c.metricsServer == "fake" { return 100, nil } @@ -192,7 +192,7 @@ func (c *CanaryObserver) GetDeploymentCounter(name string, namespace string, met } // GetDeploymentHistogram returns the 99P requests delay using istio_request_duration_seconds_bucket metrics -func (c *CanaryObserver) GetDeploymentHistogram(name string, namespace string, metric string, interval string) (time.Duration, error) { +func (c *Observer) GetDeploymentHistogram(name string, namespace string, metric string, interval string) (time.Duration, error) { if c.metricsServer == "fake" { return 1, nil } diff --git a/pkg/metrics/observer_test.go b/pkg/metrics/observer_test.go index 5d4073fe..ac961a31 100644 --- a/pkg/metrics/observer_test.go +++ b/pkg/metrics/observer_test.go @@ -14,7 +14,7 @@ func TestCanaryObserver_GetDeploymentCounter(t *testing.T) { })) defer ts.Close() - observer := CanaryObserver{ + observer := Observer{ metricsServer: ts.URL, } @@ -36,7 +36,7 @@ func TestCanaryObserver_GetDeploymentHistogram(t *testing.T) { })) defer ts.Close() - observer := CanaryObserver{ + observer := Observer{ metricsServer: ts.URL, } diff --git a/pkg/metrics/recorder.go b/pkg/metrics/recorder.go index 699db590..6b8d50ed 100644 --- a/pkg/metrics/recorder.go +++ b/pkg/metrics/recorder.go @@ -8,8 +8,8 @@ import ( flaggerv1 "github.com/weaveworks/flagger/pkg/apis/flagger/v1alpha3" ) -// CanaryRecorder records the canary analysis as Prometheus metrics -type CanaryRecorder struct { +// Recorder records the canary analysis as Prometheus metrics +type Recorder struct { info *prometheus.GaugeVec duration *prometheus.HistogramVec total *prometheus.GaugeVec @@ -17,8 +17,8 @@ type CanaryRecorder struct { weight *prometheus.GaugeVec } -// NewCanaryRecorder creates a new recorder and registers the Prometheus metrics -func NewCanaryRecorder(controller string, register bool) CanaryRecorder { +// NewRecorder creates a new recorder and registers the Prometheus metrics +func NewRecorder(controller string, register bool) Recorder { info := prometheus.NewGaugeVec(prometheus.GaugeOpts{ Subsystem: controller, Name: "info", @@ -59,7 +59,7 @@ func NewCanaryRecorder(controller string, register bool) CanaryRecorder { prometheus.MustRegister(weight) } - return CanaryRecorder{ + return Recorder{ info: info, duration: duration, total: total, @@ -69,22 +69,22 @@ func NewCanaryRecorder(controller string, register bool) CanaryRecorder { } // SetInfo sets the version and mesh provider labels -func (cr *CanaryRecorder) SetInfo(version string, meshProvider string) { +func (cr *Recorder) SetInfo(version string, meshProvider string) { cr.info.WithLabelValues(version, meshProvider).Set(1) } // SetDuration sets the time spent in seconds performing canary analysis -func (cr *CanaryRecorder) SetDuration(cd *flaggerv1.Canary, duration time.Duration) { +func (cr *Recorder) SetDuration(cd *flaggerv1.Canary, duration time.Duration) { cr.duration.WithLabelValues(cd.Spec.TargetRef.Name, cd.Namespace).Observe(duration.Seconds()) } // SetTotal sets the total number of canaries per namespace -func (cr *CanaryRecorder) SetTotal(namespace string, total int) { +func (cr *Recorder) SetTotal(namespace string, total int) { cr.total.WithLabelValues(namespace).Set(float64(total)) } // SetStatus sets the last known canary analysis status -func (cr *CanaryRecorder) SetStatus(cd *flaggerv1.Canary, phase flaggerv1.CanaryPhase) { +func (cr *Recorder) SetStatus(cd *flaggerv1.Canary, phase flaggerv1.CanaryPhase) { status := 1 switch phase { case flaggerv1.CanaryProgressing: @@ -98,7 +98,7 @@ func (cr *CanaryRecorder) SetStatus(cd *flaggerv1.Canary, phase flaggerv1.Canary } // SetWeight sets the weight values for primary and canary destinations -func (cr *CanaryRecorder) SetWeight(cd *flaggerv1.Canary, primary int, canary int) { +func (cr *Recorder) SetWeight(cd *flaggerv1.Canary, primary int, canary int) { cr.weight.WithLabelValues(fmt.Sprintf("%s-primary", cd.Spec.TargetRef.Name), cd.Namespace).Set(float64(primary)) cr.weight.WithLabelValues(cd.Spec.TargetRef.Name, cd.Namespace).Set(float64(canary)) }