Skip to content

Commit

Permalink
Make the metric interval optional
Browse files Browse the repository at this point in the history
- set default value to 1m
  • Loading branch information
stefanprodan committed Feb 27, 2019
1 parent c81e698 commit 5d81876
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion artifacts/flagger/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ spec:
properties:
items:
type: object
required: ['name', 'interval', 'threshold']
required: ['name', 'threshold']
properties:
name:
type: string
Expand Down
2 changes: 1 addition & 1 deletion charts/flagger/templates/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ spec:
properties:
items:
type: object
required: ['name', 'interval', 'threshold']
required: ['name', 'threshold']
properties:
name:
type: string
Expand Down
8 changes: 7 additions & 1 deletion pkg/apis/flagger/v1alpha3/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const (
CanaryKind = "Canary"
ProgressDeadlineSeconds = 600
AnalysisInterval = 60 * time.Second
MetricInterval = "1m"
)

// +genclient
Expand Down Expand Up @@ -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"`
Expand Down Expand Up @@ -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
}
4 changes: 2 additions & 2 deletions pkg/controller/observer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions pkg/controller/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 5d81876

Please sign in to comment.