Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

r/cloudwatch_metric_alarm - add validation to metric_query.metric.stat + refactor to use expanded/flatteners #19571

Merged
merged 5 commits into from
Jun 2, 2021

Conversation

DrFaust92
Copy link
Collaborator

@DrFaust92 DrFaust92 commented May 28, 2021

Community Note

  • Please vote on this pull request by adding a 👍 reaction to the original pull request comment to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for pull request followers and do not help prioritize the request

OR Closes #19567

Output from acceptance testing:

$ make testacc TESTARGS='-run=TestAccAWSCloudWatchMetricAlarm_'
--- PASS: TestAccAWSCloudWatchMetricAlarm_disappears (29.46s)
--- PASS: TestAccAWSCloudWatchMetricAlarm_extendedStatistic (34.08s)
--- PASS: TestAccAWSCloudWatchMetricAlarm_datapointsToAlarm (40.03s)
--- PASS: TestAccAWSCloudWatchMetricAlarm_AlarmActions_SWFAction (49.40s)
--- PASS: TestAccAWSCloudWatchMetricAlarm_AlarmActions_SNSTopic (54.08s)
--- PASS: TestAccAWSCloudWatchMetricAlarm_basic (57.11s)
--- PASS: TestAccAWSCloudWatchMetricAlarm_evaluateLowSampleCountPercentiles (73.35s)
--- PASS: TestAccAWSCloudWatchMetricAlarm_treatMissingData (80.53s)
--- PASS: TestAccAWSCloudWatchMetricAlarm_tags (114.83s)
--- PASS: TestAccAWSCloudWatchMetricAlarm_AlarmActions_EC2Automate (443.02s)
--- PASS: TestAccAWSCloudWatchMetricAlarm_missingStatistic (12.16s)
--- PASS: TestAccAWSCloudWatchMetricAlarm_expression (144.62s)

@DrFaust92 DrFaust92 requested a review from a team as a code owner May 28, 2021 16:15
@ghost ghost added the size/XL Managed by automation to categorize the size of a PR. label May 28, 2021
@github-actions github-actions bot added service/cloudwatch Issues and PRs that pertain to the cloudwatch service. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. labels May 28, 2021
@DrFaust92 DrFaust92 marked this pull request as draft May 28, 2021 16:18
@DrFaust92 DrFaust92 marked this pull request as ready for review May 28, 2021 16:57
Copy link
Contributor

@ewbankkit ewbankkit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀.

Commercial
% make testacc TEST=./aws TESTARGS='-run=TestAccAWSCloudWatchMetricAlarm_'    
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -count 1 -parallel 20 -run=TestAccAWSCloudWatchMetricAlarm_ -timeout 180m
=== RUN   TestAccAWSCloudWatchMetricAlarm_basic
=== PAUSE TestAccAWSCloudWatchMetricAlarm_basic
=== RUN   TestAccAWSCloudWatchMetricAlarm_AlarmActions_EC2Automate
=== PAUSE TestAccAWSCloudWatchMetricAlarm_AlarmActions_EC2Automate
=== RUN   TestAccAWSCloudWatchMetricAlarm_AlarmActions_SNSTopic
=== PAUSE TestAccAWSCloudWatchMetricAlarm_AlarmActions_SNSTopic
=== RUN   TestAccAWSCloudWatchMetricAlarm_AlarmActions_SWFAction
=== PAUSE TestAccAWSCloudWatchMetricAlarm_AlarmActions_SWFAction
=== RUN   TestAccAWSCloudWatchMetricAlarm_datapointsToAlarm
=== PAUSE TestAccAWSCloudWatchMetricAlarm_datapointsToAlarm
=== RUN   TestAccAWSCloudWatchMetricAlarm_treatMissingData
=== PAUSE TestAccAWSCloudWatchMetricAlarm_treatMissingData
=== RUN   TestAccAWSCloudWatchMetricAlarm_evaluateLowSampleCountPercentiles
=== PAUSE TestAccAWSCloudWatchMetricAlarm_evaluateLowSampleCountPercentiles
=== RUN   TestAccAWSCloudWatchMetricAlarm_extendedStatistic
=== PAUSE TestAccAWSCloudWatchMetricAlarm_extendedStatistic
=== RUN   TestAccAWSCloudWatchMetricAlarm_expression
=== PAUSE TestAccAWSCloudWatchMetricAlarm_expression
=== RUN   TestAccAWSCloudWatchMetricAlarm_missingStatistic
=== PAUSE TestAccAWSCloudWatchMetricAlarm_missingStatistic
=== RUN   TestAccAWSCloudWatchMetricAlarm_tags
=== PAUSE TestAccAWSCloudWatchMetricAlarm_tags
=== RUN   TestAccAWSCloudWatchMetricAlarm_disappears
=== PAUSE TestAccAWSCloudWatchMetricAlarm_disappears
=== CONT  TestAccAWSCloudWatchMetricAlarm_basic
=== CONT  TestAccAWSCloudWatchMetricAlarm_extendedStatistic
=== CONT  TestAccAWSCloudWatchMetricAlarm_tags
=== CONT  TestAccAWSCloudWatchMetricAlarm_missingStatistic
=== CONT  TestAccAWSCloudWatchMetricAlarm_AlarmActions_SNSTopic
=== CONT  TestAccAWSCloudWatchMetricAlarm_AlarmActions_EC2Automate
=== CONT  TestAccAWSCloudWatchMetricAlarm_disappears
=== CONT  TestAccAWSCloudWatchMetricAlarm_expression
=== CONT  TestAccAWSCloudWatchMetricAlarm_AlarmActions_SWFAction
=== CONT  TestAccAWSCloudWatchMetricAlarm_datapointsToAlarm
=== CONT  TestAccAWSCloudWatchMetricAlarm_treatMissingData
=== CONT  TestAccAWSCloudWatchMetricAlarm_evaluateLowSampleCountPercentiles
--- PASS: TestAccAWSCloudWatchMetricAlarm_missingStatistic (9.20s)
--- PASS: TestAccAWSCloudWatchMetricAlarm_disappears (23.70s)
--- PASS: TestAccAWSCloudWatchMetricAlarm_extendedStatistic (28.56s)
--- PASS: TestAccAWSCloudWatchMetricAlarm_datapointsToAlarm (28.82s)
--- PASS: TestAccAWSCloudWatchMetricAlarm_basic (31.28s)
--- PASS: TestAccAWSCloudWatchMetricAlarm_AlarmActions_SWFAction (31.98s)
--- PASS: TestAccAWSCloudWatchMetricAlarm_AlarmActions_SNSTopic (33.16s)
--- PASS: TestAccAWSCloudWatchMetricAlarm_evaluateLowSampleCountPercentiles (43.91s)
--- PASS: TestAccAWSCloudWatchMetricAlarm_treatMissingData (44.20s)
--- PASS: TestAccAWSCloudWatchMetricAlarm_tags (56.51s)
--- PASS: TestAccAWSCloudWatchMetricAlarm_expression (80.18s)
--- PASS: TestAccAWSCloudWatchMetricAlarm_AlarmActions_EC2Automate (174.71s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	178.265s
GovCloud
% make testacc TEST=./aws TESTARGS='-run=TestAccAWSCloudWatchMetricAlarm_' 
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -count 1 -parallel 20 -run=TestAccAWSCloudWatchMetricAlarm_ -timeout 180m
=== RUN   TestAccAWSCloudWatchMetricAlarm_basic
=== PAUSE TestAccAWSCloudWatchMetricAlarm_basic
=== RUN   TestAccAWSCloudWatchMetricAlarm_AlarmActions_EC2Automate
=== PAUSE TestAccAWSCloudWatchMetricAlarm_AlarmActions_EC2Automate
=== RUN   TestAccAWSCloudWatchMetricAlarm_AlarmActions_SNSTopic
=== PAUSE TestAccAWSCloudWatchMetricAlarm_AlarmActions_SNSTopic
=== RUN   TestAccAWSCloudWatchMetricAlarm_AlarmActions_SWFAction
=== PAUSE TestAccAWSCloudWatchMetricAlarm_AlarmActions_SWFAction
=== RUN   TestAccAWSCloudWatchMetricAlarm_datapointsToAlarm
=== PAUSE TestAccAWSCloudWatchMetricAlarm_datapointsToAlarm
=== RUN   TestAccAWSCloudWatchMetricAlarm_treatMissingData
=== PAUSE TestAccAWSCloudWatchMetricAlarm_treatMissingData
=== RUN   TestAccAWSCloudWatchMetricAlarm_evaluateLowSampleCountPercentiles
=== PAUSE TestAccAWSCloudWatchMetricAlarm_evaluateLowSampleCountPercentiles
=== RUN   TestAccAWSCloudWatchMetricAlarm_extendedStatistic
=== PAUSE TestAccAWSCloudWatchMetricAlarm_extendedStatistic
=== RUN   TestAccAWSCloudWatchMetricAlarm_expression
=== PAUSE TestAccAWSCloudWatchMetricAlarm_expression
=== RUN   TestAccAWSCloudWatchMetricAlarm_missingStatistic
=== PAUSE TestAccAWSCloudWatchMetricAlarm_missingStatistic
=== RUN   TestAccAWSCloudWatchMetricAlarm_tags
=== PAUSE TestAccAWSCloudWatchMetricAlarm_tags
=== RUN   TestAccAWSCloudWatchMetricAlarm_disappears
=== PAUSE TestAccAWSCloudWatchMetricAlarm_disappears
=== CONT  TestAccAWSCloudWatchMetricAlarm_basic
=== CONT  TestAccAWSCloudWatchMetricAlarm_expression
=== CONT  TestAccAWSCloudWatchMetricAlarm_missingStatistic
=== CONT  TestAccAWSCloudWatchMetricAlarm_AlarmActions_SNSTopic
=== CONT  TestAccAWSCloudWatchMetricAlarm_extendedStatistic
=== CONT  TestAccAWSCloudWatchMetricAlarm_disappears
=== CONT  TestAccAWSCloudWatchMetricAlarm_datapointsToAlarm
=== CONT  TestAccAWSCloudWatchMetricAlarm_evaluateLowSampleCountPercentiles
=== CONT  TestAccAWSCloudWatchMetricAlarm_tags
=== CONT  TestAccAWSCloudWatchMetricAlarm_treatMissingData
=== CONT  TestAccAWSCloudWatchMetricAlarm_AlarmActions_EC2Automate
=== CONT  TestAccAWSCloudWatchMetricAlarm_AlarmActions_SWFAction
--- PASS: TestAccAWSCloudWatchMetricAlarm_missingStatistic (13.38s)
--- PASS: TestAccAWSCloudWatchMetricAlarm_disappears (28.86s)
--- PASS: TestAccAWSCloudWatchMetricAlarm_extendedStatistic (31.31s)
--- PASS: TestAccAWSCloudWatchMetricAlarm_datapointsToAlarm (33.68s)
--- PASS: TestAccAWSCloudWatchMetricAlarm_basic (33.92s)
--- PASS: TestAccAWSCloudWatchMetricAlarm_AlarmActions_SWFAction (37.23s)
--- PASS: TestAccAWSCloudWatchMetricAlarm_AlarmActions_SNSTopic (37.45s)
--- PASS: TestAccAWSCloudWatchMetricAlarm_evaluateLowSampleCountPercentiles (46.18s)
--- PASS: TestAccAWSCloudWatchMetricAlarm_treatMissingData (48.27s)
--- PASS: TestAccAWSCloudWatchMetricAlarm_tags (64.96s)
--- PASS: TestAccAWSCloudWatchMetricAlarm_expression (93.19s)
--- PASS: TestAccAWSCloudWatchMetricAlarm_AlarmActions_EC2Automate (234.36s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	241.381s

@ewbankkit ewbankkit merged commit 1bb7f67 into hashicorp:main Jun 2, 2021
@github-actions github-actions bot added this to the v3.44.0 milestone Jun 2, 2021
@ghost
Copy link

ghost commented Jun 3, 2021

This has been released in version 3.44.0 of the Terraform AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template for triage. Thanks!

@aristotelesneto
Copy link

aristotelesneto commented Jun 4, 2021

Hi Guys,

While this change has introduced a fix to ensure that the statistic is validated, this has made it stop accepting 'percentile' extended statistics (eg. p95) from being used as part of a metric query stat.

According to the AWS documentation, the metric stat can contain either a statistic or an extended statistic:
https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/API_MetricStat.html

Stat
The statistic to return. It can include any CloudWatch statistic or extended statistic.

Type: String

Required: Yes

The error we're seeing:

Error: expected metric_query.6.metric.0.stat to be one of [SampleCount Average Sum Minimum Maximum], got p95

Should the ValidateFunc be the snippet below?

  							"stat": {
  								Type:         schema.TypeString,
  								Required:     true,
  								ValidateFunc: validation.Any(
  											validation.StringInSlice(cloudwatch.Statistic_Values(), false),
  											validation.StringMatch(regexp.MustCompile(`p(\d{1,2}(\.\d{0,2})?|100)`), "must specify a value between p0.0 and p100"),
  								)
  							},

Regards,

Neto

@tdmalone
Copy link
Contributor

tdmalone commented Jun 4, 2021

@aristotelesneto I'm also experiencing this; I've created a new issue (#19665) in case it doesn't get the necessary visibility here on the PR.

@DrFaust92 DrFaust92 deleted the r/metric_alarm_split branch June 4, 2021 16:37
@github-actions
Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 10, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
service/cloudwatch Issues and PRs that pertain to the cloudwatch service. size/XL Managed by automation to categorize the size of a PR. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

aws_cloudwatch_metric_alarm metric_query fields should be validated
4 participants