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

Support modern extended statistics for CloudWatch metric alarm #22942

Merged
merged 3 commits into from
Mar 1, 2022

Conversation

EpicWink
Copy link
Contributor

@EpicWink EpicWink commented Feb 4, 2022

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

Details

Adds complexity to the extended-statistic reg-ex to support the current statistics defined in the AWS docs during validation. Also parametrises tests for example statistics.

Closes #22078
Relates #13622

Test output

$ make test TEST=internal/service/cloudwatch/metric_alarm_test.go 
==> Checking that code complies with gofmt requirements...
go test internal/service/cloudwatch/metric_alarm_test.go  -timeout=5m
ok  	command-line-arguments	0.046s

Output from acceptance testing

$ make testacc TESTS=TestAccCloudWatchMetricAlarm_extendedStatistic PKG=cloudwatch
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./internal/service/cloudwatch/... -v -count 1 -parallel 20 -run='TestAccCloudWatchMetricAlarm_extendedStatistic'  -timeout 180m
=== RUN   TestAccCloudWatchMetricAlarm_extendedStatistic
=== PAUSE TestAccCloudWatchMetricAlarm_extendedStatistic
=== CONT  TestAccCloudWatchMetricAlarm_extendedStatistic
    testing_new.go:70: Error running post-test destroy, there may be dangling resources: exit status 1
        
        Error: invalid value for extended_statistic (invalid statistic, see: https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Statistics-definitions.html)
        
          with aws_cloudwatch_metric_alarm.test,
          on terraform_plugin_test.tf line 9, in resource "aws_cloudwatch_metric_alarm" "test":
           9:   extended_statistic        = "cd42"
        
--- FAIL: TestAccCloudWatchMetricAlarm_extendedStatistic (103.60s)
FAIL
FAIL	github.com/hashicorp/terraform-provider-aws/internal/service/cloudwatch	103.644s
FAIL
make: *** [GNUmakefile:36: testacc] Error 1

How do I test for invalid input? The test isn't catching the raised error, but running the test in non-acceptance mode passes

@github-actions github-actions bot added needs-triage Waiting for first response or review from a maintainer. size/L Managed by automation to categorize the size of a PR. service/cloudwatch Issues and PRs that pertain to the cloudwatch service. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. labels Feb 4, 2022
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Welcome @EpicWink 👋

It looks like this is your first Pull Request submission to the Terraform AWS Provider! If you haven’t already done so please make sure you have checked out our CONTRIBUTING guide and FAQ to make sure your contribution is adhering to best practice and has all the necessary elements in place for a successful approval.

Also take a look at our FAQ which details how we prioritize Pull Requests for inclusion.

Thanks again, and welcome to the community! 😃

@EpicWink EpicWink force-pushed the metric-alarm-extended-statistics branch from 689c64b to ee3aa66 Compare February 4, 2022 07:23
@EpicWink EpicWink marked this pull request as ready for review February 6, 2022 23:59
@justinretzolk justinretzolk added enhancement Requests to existing resources that expand the functionality or scope. and removed needs-triage Waiting for first response or review from a maintainer. labels Feb 16, 2022
…uccessful cases.

Acceptance test output:

% make testacc TESTS=TestAccCloudWatchMetricAlarm_extendedStatistic PKG=cloudwatch
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./internal/service/cloudwatch/... -v -count 1 -parallel 20 -run='TestAccCloudWatchMetricAlarm_extendedStatistic'  -timeout 180m
=== RUN   TestAccCloudWatchMetricAlarm_extendedStatistic
=== PAUSE TestAccCloudWatchMetricAlarm_extendedStatistic
=== CONT  TestAccCloudWatchMetricAlarm_extendedStatistic
--- PASS: TestAccCloudWatchMetricAlarm_extendedStatistic (229.89s)
PASS
ok  	github.com/hashicorp/terraform-provider-aws/internal/service/cloudwatch	233.753s
@ewbankkit
Copy link
Contributor

@EpicWink Thanks for the contribution 🎉 👏.
The behavior you noticed is a "feature" of the acceptance testing framework.
Any test cases with ExpectError should be before the successful cases:

% make testacc TESTS=TestAccCloudWatchMetricAlarm_extendedStatistic PKG=cloudwatch
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./internal/service/cloudwatch/... -v -count 1 -parallel 20 -run='TestAccCloudWatchMetricAlarm_extendedStatistic'  -timeout 180m
=== RUN   TestAccCloudWatchMetricAlarm_extendedStatistic
=== PAUSE TestAccCloudWatchMetricAlarm_extendedStatistic
=== CONT  TestAccCloudWatchMetricAlarm_extendedStatistic
--- PASS: TestAccCloudWatchMetricAlarm_extendedStatistic (229.89s)
PASS
ok  	github.com/hashicorp/terraform-provider-aws/internal/service/cloudwatch	233.753s

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 🚀.

% make testacc TESTS=TestAccCloudWatchMetricAlarm_ PKG=cloudwatch 
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./internal/service/cloudwatch/... -v -count 1 -parallel 20 -run='TestAccCloudWatchMetricAlarm_'  -timeout 180m
=== RUN   TestAccCloudWatchMetricAlarm_basic
=== PAUSE TestAccCloudWatchMetricAlarm_basic
=== RUN   TestAccCloudWatchMetricAlarm_AlarmActions_ec2Automate
=== PAUSE TestAccCloudWatchMetricAlarm_AlarmActions_ec2Automate
=== RUN   TestAccCloudWatchMetricAlarm_AlarmActions_snsTopic
=== PAUSE TestAccCloudWatchMetricAlarm_AlarmActions_snsTopic
=== RUN   TestAccCloudWatchMetricAlarm_AlarmActions_swfAction
=== PAUSE TestAccCloudWatchMetricAlarm_AlarmActions_swfAction
=== RUN   TestAccCloudWatchMetricAlarm_dataPointsToAlarm
=== PAUSE TestAccCloudWatchMetricAlarm_dataPointsToAlarm
=== RUN   TestAccCloudWatchMetricAlarm_treatMissingData
=== PAUSE TestAccCloudWatchMetricAlarm_treatMissingData
=== RUN   TestAccCloudWatchMetricAlarm_evaluateLowSampleCountPercentiles
=== PAUSE TestAccCloudWatchMetricAlarm_evaluateLowSampleCountPercentiles
=== RUN   TestAccCloudWatchMetricAlarm_extendedStatistic
=== PAUSE TestAccCloudWatchMetricAlarm_extendedStatistic
=== RUN   TestAccCloudWatchMetricAlarm_expression
=== PAUSE TestAccCloudWatchMetricAlarm_expression
=== RUN   TestAccCloudWatchMetricAlarm_missingStatistic
=== PAUSE TestAccCloudWatchMetricAlarm_missingStatistic
=== RUN   TestAccCloudWatchMetricAlarm_tags
=== PAUSE TestAccCloudWatchMetricAlarm_tags
=== RUN   TestAccCloudWatchMetricAlarm_disappears
=== PAUSE TestAccCloudWatchMetricAlarm_disappears
=== CONT  TestAccCloudWatchMetricAlarm_basic
=== CONT  TestAccCloudWatchMetricAlarm_expression
=== CONT  TestAccCloudWatchMetricAlarm_dataPointsToAlarm
=== CONT  TestAccCloudWatchMetricAlarm_AlarmActions_snsTopic
=== CONT  TestAccCloudWatchMetricAlarm_evaluateLowSampleCountPercentiles
=== CONT  TestAccCloudWatchMetricAlarm_missingStatistic
=== CONT  TestAccCloudWatchMetricAlarm_disappears
=== CONT  TestAccCloudWatchMetricAlarm_treatMissingData
=== CONT  TestAccCloudWatchMetricAlarm_extendedStatistic
=== CONT  TestAccCloudWatchMetricAlarm_tags
=== CONT  TestAccCloudWatchMetricAlarm_AlarmActions_swfAction
=== CONT  TestAccCloudWatchMetricAlarm_AlarmActions_ec2Automate
--- PASS: TestAccCloudWatchMetricAlarm_missingStatistic (13.06s)
--- PASS: TestAccCloudWatchMetricAlarm_disappears (23.94s)
--- PASS: TestAccCloudWatchMetricAlarm_dataPointsToAlarm (25.89s)
--- PASS: TestAccCloudWatchMetricAlarm_basic (32.81s)
--- PASS: TestAccCloudWatchMetricAlarm_AlarmActions_swfAction (32.93s)
--- PASS: TestAccCloudWatchMetricAlarm_AlarmActions_snsTopic (35.35s)
--- PASS: TestAccCloudWatchMetricAlarm_evaluateLowSampleCountPercentiles (45.67s)
--- PASS: TestAccCloudWatchMetricAlarm_tags (64.15s)
--- PASS: TestAccCloudWatchMetricAlarm_treatMissingData (64.17s)
--- PASS: TestAccCloudWatchMetricAlarm_expression (115.10s)
--- PASS: TestAccCloudWatchMetricAlarm_extendedStatistic (239.27s)
--- PASS: TestAccCloudWatchMetricAlarm_AlarmActions_ec2Automate (304.60s)
PASS
ok  	github.com/hashicorp/terraform-provider-aws/internal/service/cloudwatch	308.039s

@ewbankkit ewbankkit merged commit 8791153 into hashicorp:main Mar 1, 2022
@github-actions github-actions bot added this to the v4.4.0 milestone Mar 1, 2022
@EpicWink EpicWink deleted the metric-alarm-extended-statistics branch March 2, 2022 10:46
@github-actions
Copy link

github-actions bot commented Mar 4, 2022

This functionality has been released in v4.4.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. Thank you!

@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 May 12, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement Requests to existing resources that expand the functionality or scope. service/cloudwatch Issues and PRs that pertain to the cloudwatch service. size/L 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.

metric alarm resource does not have support for trimmed mean statistic
3 participants