Rename observer and recorder

This commit is contained in:
stefanprodan
2019-03-30 11:49:43 +02:00
parent b2c12c1131
commit 6a080f3032
5 changed files with 27 additions and 27 deletions
+3 -3
View File
@@ -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{
+2 -2
View File
@@ -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
+10 -10
View File
@@ -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
}
+2 -2
View File
@@ -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,
}
+10 -10
View File
@@ -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))
}