diff --git a/artifacts/flagger/crd.yaml b/artifacts/flagger/crd.yaml index 106cb1ff..b101d7be 100644 --- a/artifacts/flagger/crd.yaml +++ b/artifacts/flagger/crd.yaml @@ -91,7 +91,7 @@ spec: properties: items: type: object - required: ['name', 'interval', 'threshold'] + required: ['name', 'threshold'] properties: name: type: string diff --git a/charts/flagger/templates/crd.yaml b/charts/flagger/templates/crd.yaml index 0fd89e01..5e3c40a3 100644 --- a/charts/flagger/templates/crd.yaml +++ b/charts/flagger/templates/crd.yaml @@ -92,7 +92,7 @@ spec: properties: items: type: object - required: ['name', 'interval', 'threshold'] + required: ['name', 'threshold'] properties: name: type: string diff --git a/pkg/apis/flagger/v1alpha3/types.go b/pkg/apis/flagger/v1alpha3/types.go index 5829e954..f6bead85 100755 --- a/pkg/apis/flagger/v1alpha3/types.go +++ b/pkg/apis/flagger/v1alpha3/types.go @@ -27,6 +27,7 @@ const ( CanaryKind = "Canary" ProgressDeadlineSeconds = 600 AnalysisInterval = 60 * time.Second + MetricInterval = "1m" ) // +genclient @@ -128,7 +129,7 @@ type CanaryAnalysis struct { // CanaryMetric holds the reference to Istio metrics used for canary analysis type CanaryMetric struct { Name string `json:"name"` - Interval string `json:"interval"` + Interval string `json:"interval,omitempty"` Threshold float64 `json:"threshold"` // +optional Query string `json:"query,omitempty"` @@ -172,3 +173,8 @@ func (c *Canary) GetAnalysisInterval() time.Duration { return interval } + +// GetMetricInterval returns the metric interval default value (1m) +func (c *Canary) GetMetricInterval() string { + return MetricInterval +} diff --git a/pkg/controller/observer.go b/pkg/controller/observer.go index 15b48d9f..051321e4 100644 --- a/pkg/controller/observer.go +++ b/pkg/controller/observer.go @@ -80,8 +80,8 @@ func (c *CanaryObserver) GetScalar(query string) (float64, error) { return 100, nil } - query = strings.Replace(query, "\n","",-1) - query = strings.Replace(query, " ","",-1) + query = strings.Replace(query, "\n", "", -1) + query = strings.Replace(query, " ", "", -1) var value *float64 result, err := c.queryMetric(query) diff --git a/pkg/controller/scheduler.go b/pkg/controller/scheduler.go index ebb92189..934b95ab 100644 --- a/pkg/controller/scheduler.go +++ b/pkg/controller/scheduler.go @@ -405,6 +405,10 @@ func (c *Controller) analyseCanary(r *flaggerv1.Canary) bool { // run metrics checks for _, metric := range r.Spec.CanaryAnalysis.Metrics { + if metric.Interval == "" { + metric.Interval = r.GetMetricInterval() + } + if metric.Name == "istio_requests_total" { val, err := c.observer.GetDeploymentCounter(r.Spec.TargetRef.Name, r.Namespace, metric.Name, metric.Interval) if err != nil {