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(aws-cloudwatch): add missing cloudwatch statistics in exported enum (p, tm, iqm, wm, tc, ts) #23074

Merged
merged 4 commits into from
Nov 25, 2022

Conversation

rigwild
Copy link
Contributor

@rigwild rigwild commented Nov 24, 2022

Some statistics were missing from the lib p, tm, iqm, wm, tc, ts.

I added the most common ones in the exported enum, with a good documentation pulled from AWS CloudWatch documentation - Statistics definitions

Fixes #21666 #14688


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 24, 2022

@github-actions github-actions bot added beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p2 labels Nov 24, 2022
@aws-cdk-automation aws-cdk-automation requested a review from a team November 24, 2022 14:08
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
Copy link
Contributor Author

rigwild commented Nov 24, 2022

The pull request linter fails with the following errors:

❌ Features must contain a change to a README file.
❌ Features must contain a change to a test file.
❌ Features must contain a change to an integration test file and the resulting snapshot.

PRs must pass status checks before we can provide a meaningful review.

Don't think that's needed for this change.

@mrgrain mrgrain added pr-linter/exempt-readme The PR linter will not require README changes pr-linter/exempt-test The PR linter will not require test changes pr-linter/exempt-integ-test The PR linter will not require integ test changes labels Nov 25, 2022
@aws-cdk-automation aws-cdk-automation dismissed their stale review November 25, 2022 13:38

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

@mergify
Copy link
Contributor

mergify bot commented Nov 25, 2022

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

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

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

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

@mergify mergify bot merged commit 47943d2 into aws:main Nov 25, 2022
@mergify
Copy link
Contributor

mergify bot commented Nov 25, 2022

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

rix0rrr added a commit that referenced this pull request Nov 30, 2022
The `Statistic` enum type was incorrectly publicly exposed (it should
only have been visible internally to the package), and was enhanced in
PR #23074 to have more enum values such as `P10`, `P50`, `P99_9`, etc.

The stringification of this `Statistic` type would only have worked in
TypeScript anyway (in JSII languages like Java and Python we cannot rely
on the string values of enums), and the fact that enums cannot be
parameterized made it so that we used to have a lot of redundant enum
values.

Introduce a new factory class, `Stats`, whose sole purpose is to
produce formatted strings to use as CloudWatch `statistic` values,
and advertise the use of this class.

(We probably shouldn't have been using `string` as the type in the first
place, but given that we are factories to produce them seems to be the
next best thing).
mergify bot pushed a commit that referenced this pull request Nov 30, 2022
The `Statistic` enum type was incorrectly publicly exposed (it should only have been visible internally to the package), and was enhanced in PR #23074 to have more enum values such as `P10`, `P50`, `P99_9`, etc.

The stringification of this `Statistic` type would only have worked in TypeScript anyway (in JSII languages like Java and Python we cannot rely on the string values of enums), and the fact that enums cannot be parameterized made it so that we used to have a lot of redundant enum values.

Deprecate the `Statistic` type, and introduce a new factory class, `Stats`, whose sole purpose is to produce formatted strings to use as CloudWatch `statistic` values, and advertise the use of this class.

(We probably shouldn't have been using `string` as the type in the first place, but given that we are factories to produce them seems to be the next best thing).


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
brennanho pushed a commit to brennanho/aws-cdk that referenced this pull request Dec 9, 2022
The `Statistic` enum type was incorrectly publicly exposed (it should only have been visible internally to the package), and was enhanced in PR aws#23074 to have more enum values such as `P10`, `P50`, `P99_9`, etc.

The stringification of this `Statistic` type would only have worked in TypeScript anyway (in JSII languages like Java and Python we cannot rely on the string values of enums), and the fact that enums cannot be parameterized made it so that we used to have a lot of redundant enum values.

Deprecate the `Statistic` type, and introduce a new factory class, `Stats`, whose sole purpose is to produce formatted strings to use as CloudWatch `statistic` values, and advertise the use of this class.

(We probably shouldn't have been using `string` as the type in the first place, but given that we are factories to produce them seems to be the next best thing).


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
brennanho pushed a commit to brennanho/aws-cdk that referenced this pull request Jan 20, 2023
The `Statistic` enum type was incorrectly publicly exposed (it should only have been visible internally to the package), and was enhanced in PR aws#23074 to have more enum values such as `P10`, `P50`, `P99_9`, etc.

The stringification of this `Statistic` type would only have worked in TypeScript anyway (in JSII languages like Java and Python we cannot rely on the string values of enums), and the fact that enums cannot be parameterized made it so that we used to have a lot of redundant enum values.

Deprecate the `Statistic` type, and introduce a new factory class, `Stats`, whose sole purpose is to produce formatted strings to use as CloudWatch `statistic` values, and advertise the use of this class.

(We probably shouldn't have been using `string` as the type in the first place, but given that we are factories to produce them seems to be the next best thing).


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
mergify bot pushed a commit that referenced this pull request Feb 20, 2023
#23095)

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

https://github.com/aws/aws-cdk/blob/47943d206c8ff28923e19028acd5991d8e387ac9/packages/%40aws-cdk/aws-cloudwatch/lib/metric.ts#L295-L296

### 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

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

with 

```ts
throw new UnrecognizedStatisticFormatError()
```

---

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

![2022-11-24_15-52-57](https://user-images.githubusercontent.com/26366184/204067982-05b7bd4f-1c56-4466-8c97-c626e8ac31b2.png)


----

### All Submissions:

* [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md)

### Adding new Unconventional Dependencies:

* [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-new-unconventional-dependencies)

### New Features

* [x] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)?
	* [ ] 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*
brennanho pushed a commit to brennanho/aws-cdk that referenced this pull request Feb 22, 2023
The `Statistic` enum type was incorrectly publicly exposed (it should only have been visible internally to the package), and was enhanced in PR aws#23074 to have more enum values such as `P10`, `P50`, `P99_9`, etc.

The stringification of this `Statistic` type would only have worked in TypeScript anyway (in JSII languages like Java and Python we cannot rely on the string values of enums), and the fact that enums cannot be parameterized made it so that we used to have a lot of redundant enum values.

Deprecate the `Statistic` type, and introduce a new factory class, `Stats`, whose sole purpose is to produce formatted strings to use as CloudWatch `statistic` values, and advertise the use of this class.

(We probably shouldn't have been using `string` as the type in the first place, but given that we are factories to produce them seems to be the next best thing).


----

*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 effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p2 pr-linter/exempt-integ-test The PR linter will not require integ test changes pr-linter/exempt-readme The PR linter will not require README changes pr-linter/exempt-test The PR linter will not require test changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

aws-cloudwatch: Metrics must support 6 new advanced statistics
3 participants