Skip to content

Commit

Permalink
pkg/metrics/providers: put comments on cloudWatchProvider methods
Browse files Browse the repository at this point in the history
  • Loading branch information
mathetake committed Mar 2, 2020
1 parent fedc2d0 commit f01a1f5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 8 additions & 0 deletions pkg/metrics/providers/cloudwatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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 {
Expand Down Expand Up @@ -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{}),
Expand Down
2 changes: 1 addition & 1 deletion pkg/metrics/providers/datadog.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit f01a1f5

Please sign in to comment.