diff --git a/pkg/metrics/providers/cloudwatch.go b/pkg/metrics/providers/cloudwatch.go index bc9692914..f84d17fdf 100644 --- a/pkg/metrics/providers/cloudwatch.go +++ b/pkg/metrics/providers/cloudwatch.go @@ -30,6 +30,8 @@ type cloudWatchClient interface { GetMetricData(input *cloudwatch.GetMetricDataInput) (*cloudwatch.GetMetricDataOutput, error) } +// newCloudWatchProvider takes a metricInterval, a provider spec and the credentials map, and +// returns a cloudWatchProvider ready to execute queries against the AWS CloudWatch metrics func newCloudWatchProvider(metricInterval string, provider flaggerv1.MetricTemplateProvider) (*cloudWatchProvider, error) { region := strings.TrimLeft(provider.Address, "monitoring.") region = strings.TrimRight(region, ".amazonaws.com") @@ -51,6 +53,8 @@ func newCloudWatchProvider(metricInterval string, provider flaggerv1.MetricTempl }, err } +// RunQuery executes the aws cloud watch metrics query against GetMetricsData endpoint +// and returns the the first result as float64 func (p *cloudWatchProvider) RunQuery(query string) (float64, error) { var cq []*cloudwatch.MetricDataQuery if err := json.Unmarshal([]byte(query), &cq); err != nil { @@ -83,6 +87,10 @@ func (p *cloudWatchProvider) RunQuery(query string) (float64, error) { return aws.Float64Value(vs[0]), nil } +// IsOnline calls GetMetricsData endpoint with the empty query +// and returns an error if the returned status code is NOT http.StatusBadRequests. +// For example, if the flagger does not have permission to perform `cloudwatch:GetMetricsData`, +// the returned status code would be http.StatusForbidden func (p *cloudWatchProvider) IsOnline() (bool, error) { _, err := p.client.GetMetricData(&cloudwatch.GetMetricDataInput{ EndTime: aws.Time(time.Time{}), diff --git a/pkg/metrics/providers/datadog.go b/pkg/metrics/providers/datadog.go index e3759a9c7..bfd51f3a7 100644 --- a/pkg/metrics/providers/datadog.go +++ b/pkg/metrics/providers/datadog.go @@ -45,7 +45,7 @@ type datadogResponse struct { } } -// newDatadogProvider takes a canary spec, a provider spec and the credentials map, and +// newDatadogProvider takes a metricInterval, a provider spec and the credentials map, and // returns a Datadog client ready to execute queries against the API func newDatadogProvider(metricInterval string, provider flaggerv1.MetricTemplateProvider,