Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
nburtsev authored Mar 15, 2024
2 parents c332aff + f2ad980 commit 8d73b83
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
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

0 comments on commit 8d73b83

Please sign in to comment.