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

fix(cloudwatch): unrecognized statistic warning when using percentileRank statistic in Stats helper #29498

Merged
merged 3 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions packages/aws-cdk-lib/aws-cloudwatch/lib/private/statistic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ export interface PercentileStatistic extends SingleStatistic {
statName: 'percentile';
}

export interface PercentileRankStatistic extends PairStatistic {
statName: 'percentileRank';
}

export interface TrimmedMeanStatistic extends PairStatistic {
statName: 'trimmedMean';
}
Expand Down Expand Up @@ -154,6 +158,7 @@ export function parseStatistic(
):
| SimpleStatistic
| PercentileStatistic
| PercentileRankStatistic
| TrimmedMeanStatistic
| WinsorizedMeanStatistic
| TrimmedCountStatistic
Expand Down Expand Up @@ -188,6 +193,10 @@ export function parseStatistic(
m = parseSingleStatistic(stat, 'p');
if (m) return { ...m, statName: 'percentile' } as PercentileStatistic;

// Percentile Rank statistics
m = parsePairStatistic(stat, 'pr');
if (m) return { ...m, statName: 'percentileRank' } as PercentileRankStatistic;

// Trimmed mean statistics
m = parseSingleStatistic(stat, 'tm') || parsePairStatistic(stat, 'tm');
if (m) return { ...m, statName: 'trimmedMean' } as TrimmedMeanStatistic;
Expand Down
15 changes: 15 additions & 0 deletions packages/aws-cdk-lib/aws-cloudwatch/test/stats.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
import { Metric, Stats } from '../../aws-cloudwatch';
import * as cloudwatch from '../lib';

it.each([
Stats.percentileRank(0),
Stats.percentileRank(0, 1),
Stats.percentileRank(0, undefined),
])('Stats can create valid statistics %s without causing warnings', (statistic) => {
const metric = new Metric({
namespace: 'example',
metricName: 'example',
statistic,
});

expect(metric.warningsV2).toEqual(undefined);
});

test('spot check some constants', () => {
expect(cloudwatch.Stats.AVERAGE).toEqual('Average');
expect(cloudwatch.Stats.IQM).toEqual('IQM');
Expand Down