Skip to content

Commit

Permalink
feat(cloudwatch): revert trimmed mean stat in graph widgets (#15368)
Browse files Browse the repository at this point in the history
This reverts commit 60f6d82.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
njlynch authored Jun 30, 2021
1 parent 5d0954a commit d630d7f
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 59 deletions.
3 changes: 0 additions & 3 deletions packages/@aws-cdk/aws-cloudwatch/lib/alarm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -393,9 +393,6 @@ function renderIfExtendedStatistic(statistic?: string): string | undefined {
// floating point rounding issues, return as-is but lowercase the p.
return statistic.toLowerCase();
}
if (parsed.type === 'trimmedMean') {
throw new Error('tmNN.NN stat is not supported in CloudWatch alarms');
}
return undefined;
}

Expand Down
1 change: 0 additions & 1 deletion packages/@aws-cdk/aws-cloudwatch/lib/metric.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ export interface CommonMetricOptions {
* - "Sum" | "sum"
* - "SampleCount | "n"
* - "pNN.NN"
* - "tmNN.NN"
*
* @default Average
*/
Expand Down
25 changes: 6 additions & 19 deletions packages/@aws-cdk/aws-cloudwatch/lib/private/statistic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,10 @@ export interface PercentileStatistic {
type: 'percentile';
percentile: number;
}

export interface TrimmedMeanStatistic {
type: 'trimmedMean';
trimmedMean: number;
}

/**
* Parse a statistic, returning the type of metric that was used (simple or percentile)
*/
export function parseStatistic(stat: string): SimpleStatistic | PercentileStatistic | TrimmedMeanStatistic {
export function parseStatistic(stat: string): SimpleStatistic | PercentileStatistic {
const lowerStat = stat.toLowerCase();

// Simple statistics
Expand All @@ -41,24 +35,17 @@ export function parseStatistic(stat: string): SimpleStatistic | PercentileStatis
};
}

// Percentile or Trimmed Mean statistics
const re = /^(p|tm)([\d.]+)$/;
// Percentile statistics
const re = /^p([\d.]+)$/;
const m = re.exec(lowerStat);
if (m && m[1] === 'p') {
if (m) {
return {
type: 'percentile',
percentile: parseFloat(m[2]),
};
}
if (m && m[1] === 'tm') {
return {
type: 'trimmedMean',
trimmedMean: parseFloat(m[2]),
percentile: parseFloat(m[1]),
};
}

const supportedStats = ['Average', 'Minimum', 'Maximum', 'SampleCount', 'Sum', 'pNN.NN', 'tmNN.NN'];
throw new Error(`Not a valid statistic: '${stat}', must be one of ${supportedStats.join(' | ')}`);
throw new Error(`Not a valid statistic: '${stat}', must be one of Average | Minimum | Maximum | SampleCount | Sum | pNN.NN`);
}

export function normalizeStatistic(stat: string): string {
Expand Down
13 changes: 0 additions & 13 deletions packages/@aws-cdk/aws-cloudwatch/test/test.alarm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,19 +161,6 @@ export = {
test.done();
},

'trimmedMean not supported'(test: Test) {
const stack = new Stack();

test.throws(() => new Alarm(stack, 'Alarm', {
metric: testMetric,
statistic: 'TM99',
threshold: 1000,
evaluationPeriods: 3,
}), /tmNN.NN stat is not supported/);

test.done();
},

'can set DatapointsToAlarm'(test: Test) {
// GIVEN
const stack = new Stack();
Expand Down
23 changes: 0 additions & 23 deletions packages/@aws-cdk/aws-cloudwatch/test/test.graphs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -717,27 +717,4 @@ export = {

test.done();
},

'trimmedMean stat is rendered'(test: Test) {
// GIVEN
const stack = new Stack();
const widget = new GraphWidget({
statistic: 'tm90',
});

// THEN
test.deepEqual(stack.resolve(widget.toJson()), [{
type: 'metric',
width: 6,
height: 6,
properties: {
view: 'timeSeries',
region: { Ref: 'AWS::Region' },
yAxis: {},
stat: 'tm90',
},
}]);

test.done();
},
};

0 comments on commit d630d7f

Please sign in to comment.