Skip to content

Commit f2ad980

Browse files
authored
fix(cloudwatch): unrecognized statistic warning when using percentileRank statistic in Stats helper (#29498)
### Issue # (if applicable) Closes #29465. ### Reason for this change There shouldn't be a warning when `Stats.percentileRank` ### Description of changes Add a new parser for percentileRank statistic ### Description of how you validated changes unit test ### Checklist - [ ] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 87139ab commit f2ad980

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

packages/aws-cdk-lib/aws-cloudwatch/lib/private/statistic.ts

+9
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ export interface PercentileStatistic extends SingleStatistic {
3434
statName: 'percentile';
3535
}
3636

37+
export interface PercentileRankStatistic extends PairStatistic {
38+
statName: 'percentileRank';
39+
}
40+
3741
export interface TrimmedMeanStatistic extends PairStatistic {
3842
statName: 'trimmedMean';
3943
}
@@ -154,6 +158,7 @@ export function parseStatistic(
154158
):
155159
| SimpleStatistic
156160
| PercentileStatistic
161+
| PercentileRankStatistic
157162
| TrimmedMeanStatistic
158163
| WinsorizedMeanStatistic
159164
| TrimmedCountStatistic
@@ -188,6 +193,10 @@ export function parseStatistic(
188193
m = parseSingleStatistic(stat, 'p');
189194
if (m) return { ...m, statName: 'percentile' } as PercentileStatistic;
190195

196+
// Percentile Rank statistics
197+
m = parsePairStatistic(stat, 'pr');
198+
if (m) return { ...m, statName: 'percentileRank' } as PercentileRankStatistic;
199+
191200
// Trimmed mean statistics
192201
m = parseSingleStatistic(stat, 'tm') || parsePairStatistic(stat, 'tm');
193202
if (m) return { ...m, statName: 'trimmedMean' } as TrimmedMeanStatistic;

packages/aws-cdk-lib/aws-cloudwatch/test/stats.test.ts

+15
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
1+
import { Metric, Stats } from '../../aws-cloudwatch';
12
import * as cloudwatch from '../lib';
23

4+
it.each([
5+
Stats.percentileRank(0),
6+
Stats.percentileRank(0, 1),
7+
Stats.percentileRank(0, undefined),
8+
])('Stats can create valid statistics %s without causing warnings', (statistic) => {
9+
const metric = new Metric({
10+
namespace: 'example',
11+
metricName: 'example',
12+
statistic,
13+
});
14+
15+
expect(metric.warningsV2).toEqual(undefined);
16+
});
17+
318
test('spot check some constants', () => {
419
expect(cloudwatch.Stats.AVERAGE).toEqual('Average');
520
expect(cloudwatch.Stats.IQM).toEqual('IQM');

0 commit comments

Comments
 (0)