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

feat(cloudwatch): parse all metrics statistics and support long format #23095

Merged
merged 27 commits into from Feb 20, 2023

Conversation

rigwild
Copy link
Contributor

@rigwild rigwild commented Nov 26, 2022

Description

Previous PR added support for missing statistics #23074
This PR implements a proper parsing of all these statistics.

  • Support "short" format ts99
  • Support "long" format
    • TS(10%:90%) | TS(10:90)
    • TS(:90) | TS(:90%)
    • TS(10:) | TS(10%:)
  • Formats are case insensitive (no breaking changes)
  • If "long" format and only upper boundary% TS(:90%), can be translated to "short" format ts90 (stat.asSingleStatStr)

Note

I noticed that the following code expected the parsing to throw if it failed, but it actually will not fail in any case (it just return GenericStatistic if no format matched).
I will not change this behavior here as I'm not willing to spend more effort testing if this breaks stuff elsewhere.

// Try parsing, this will throw if it's not a valid stat
this.statistic = normalizeStatistic(props.statistic || 'Average');

Followup work

As is, this PR does not change any customer-facing logic. To make use of it, make the parsing throw if no format is recognized.

At the end of the parser function, just replace

return {
  type: 'generic',
  statistic: stat,
} as GenericStatistic;

with

throw new UnrecognizedStatisticFormatError()

You can see all tested inputs here: https://regexr.com/7351s

2022-11-24_15-52-57


All Submissions:

Adding new Unconventional Dependencies:

  • This PR adds new unconventional dependencies following the process described here

New Features

  • Have you added the new feature to an integration test?
    • Did you use yarn integ to deploy the infrastructure and generate the snapshot (i.e. yarn integ without --dry-run)?

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@gitpod-io
Copy link

gitpod-io bot commented Nov 26, 2022

@aws-cdk-automation aws-cdk-automation requested a review from a team November 26, 2022 02:11
@github-actions github-actions bot added beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK p2 labels Nov 26, 2022
Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

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

The pull request linter has failed. See the aws-cdk-automation comment below for failure reasons. If you believe this pull request should receive an exemption, please comment and provide a justification.

@aws-cdk-automation aws-cdk-automation dismissed their stale review November 27, 2022 22:32

✅ Updated pull request passes all PRLinter validations. Dissmissing previous PRLinter review.

@rigwild
Copy link
Contributor Author

rigwild commented Nov 28, 2022

This is ready for review

@rix0rrr
Copy link
Contributor

rix0rrr commented Nov 30, 2022

Hi @rigwild!

Heads up, that enum you modified in your previous PR was exposed by accident, and was never supposed to be public! 🫣

I've moved your new enum values to a class with factory functions in this PR here: #23172

Thanks for updating the parsing logic as well, but I'm unclear on whether this changes any output. Is it just for completeness of the internal typing?

@rigwild
Copy link
Contributor Author

rigwild commented Nov 30, 2022

Thanks for updating the parsing logic as well, but I'm unclear on whether this changes any output. Is it just for completeness of the internal typing?

See quote

Followup work
As is, this PR does not change any customer-facing logic. To make use of it, make the parsing throw if no format is recognized.

The current parser was supposed to throw on parsing error, but that's not the case.

This specific PR only does internal stuff, a future change has to be implemented to make it actually throw and be useful

@rigwild
Copy link
Contributor Author

rigwild commented Nov 30, 2022

Your new factories would solve this, but most code is currently passing raw strings, so this may still be useful to detect errors early before deploying stacks

@rix0rrr
Copy link
Contributor

rix0rrr commented Nov 30, 2022

I'm pretty sure we used to do validation, and then the generic case got added because CloudWatch was adding new metrics we didn't recognize yet, and it was added as a catch-all to handle "whatever else" (I would need to do software archeology to confirm that).

So the question is: how valuable is validation, and is it going to get in the way of future additions to CloudWatch? I think we're going to have to resign ourselves to the validation only ever being able to be, at best, a warning: we can't block infra because it might be using some statistic we don't recognize yet. It might be a valid stat we just haven't gotten around to adding quite yet.

I wouldn't be opposed to adding validation like that, but I'm going to have to ask to make that the feature and main focus of the change. Changes the parsing logic may or may not be a part of it, but that does not deliver value by itself.

@rigwild
Copy link
Contributor Author

rigwild commented Nov 30, 2022

That makes sense. That's why I didn't add the error throw! 😁

I can add this warning. I don't know if there is a logging system/lib? How to log it? console.warn?

@aws-cdk-automation
Copy link
Collaborator

This PR cannot be merged because it has conflicts. Please resolve them. The PR will be considered stale and closed if it remains in an unmergeable state.

@rigwild
Copy link
Contributor Author

rigwild commented Dec 22, 2022

Btw, this pr is ready

Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

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

The pull request linter has failed. See the aws-cdk-automation comment below for failure reasons. If you believe this pull request should receive an exemption, please comment and provide a justification.

@rigwild rigwild changed the title feat(aws-cloudwatch): parse all metrics statistics and support long format feat(cloudwatch): parse all metrics statistics and support long format Jan 19, 2023
@aws-cdk-automation aws-cdk-automation dismissed their stale review January 19, 2023 00:18

✅ Updated pull request passes all PRLinter validations. Dissmissing previous PRLinter review.

Copy link
Contributor

@TheRealAmazonKendra TheRealAmazonKendra left a comment

Choose a reason for hiding this comment

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

Looks like this is not using Annotations.of(construct).addWarning(...):. Please use this kind of warning instead of a console log statement. With this you can also write a test for the warning showing up or not.

@mergify mergify bot dismissed TheRealAmazonKendra’s stale review February 13, 2023 22:43

Pull request has been modified.

@rigwild
Copy link
Contributor Author

rigwild commented Feb 14, 2023

Oh ok, when rix0rrr@ said:

so maybe it fits in neatly there.

I thought it meant that the console warning was ok 😁

Updated

Copy link
Contributor

@TheRealAmazonKendra TheRealAmazonKendra left a comment

Choose a reason for hiding this comment

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

Just one small requested change so that the warning is grammatically correct with or without the label.

packages/@aws-cdk/aws-cloudwatch/lib/metric.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-cloudwatch/lib/metric.ts Outdated Show resolved Hide resolved
rigwild and others added 2 commits February 20, 2023 20:36
Co-authored-by: Kendra Neil <53584728+TheRealAmazonKendra@users.noreply.github.com>
Co-authored-by: Kendra Neil <53584728+TheRealAmazonKendra@users.noreply.github.com>
@mergify mergify bot dismissed TheRealAmazonKendra’s stale review February 20, 2023 19:37

Pull request has been modified.

@TheRealAmazonKendra
Copy link
Contributor

@Mergifyio update

@mergify
Copy link
Contributor

mergify bot commented Feb 20, 2023

update

❌ Base branch update has failed

refusing to allow a GitHub App to create or update workflow .github/workflows/yarn-upgrade-v1main.yml without workflows permission
err-code: 491EB

Copy link
Contributor

@TheRealAmazonKendra TheRealAmazonKendra left a comment

Choose a reason for hiding this comment

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

Soooo... do you want to write all of our READMEs? This one is fantastic!

Thank you for your contribution!

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: 2391b6a
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify
Copy link
Contributor

mergify bot commented Feb 20, 2023

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@mergify mergify bot merged commit 853e3d6 into aws:main Feb 20, 2023
rix0rrr added a commit that referenced this pull request Apr 7, 2023
Since #23095 (which was released in 2.66.0), the `p100` statistic
is no longer rendered into Alarms.

Fixes #24976.
mergify bot pushed a commit that referenced this pull request Apr 7, 2023
Since #23095 (which was released in 2.66.0), the `p100` statistic is no longer rendered into Alarms.

Fixes #24976.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK p2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants