Skip to content

Commit

Permalink
Merge branch 'master' into route53-target-apigatewayv2
Browse files Browse the repository at this point in the history
  • Loading branch information
shivlaks authored Nov 6, 2020
2 parents c74aa4a + 89a5055 commit 561656e
Show file tree
Hide file tree
Showing 12 changed files with 584 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { Container } from './container';
import { ServiceExtension, ServiceBuild } from './extension-interfaces';

// The version of the App Mesh envoy sidecar to add to the task.
const APP_MESH_ENVOY_SIDECAR_VERSION = 'v1.15.0.0-prod';
const APP_MESH_ENVOY_SIDECAR_VERSION = 'v1.15.1.0-prod';

/**
* The settings for the App Mesh extension.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@
{
"Ref": "AWS::URLSuffix"
},
"/aws-appmesh-envoy:v1.15.0.0-prod"
"/aws-appmesh-envoy:v1.15.1.0-prod"
]
]
},
Expand Down Expand Up @@ -1596,7 +1596,7 @@
{
"Ref": "AWS::URLSuffix"
},
"/aws-appmesh-envoy:v1.15.0.0-prod"
"/aws-appmesh-envoy:v1.15.1.0-prod"
]
]
},
Expand Down Expand Up @@ -2584,7 +2584,7 @@
{
"Ref": "AWS::URLSuffix"
},
"/aws-appmesh-envoy:v1.15.0.0-prod"
"/aws-appmesh-envoy:v1.15.1.0-prod"
]
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1186,7 +1186,7 @@
{
"Ref": "AWS::URLSuffix"
},
"/aws-appmesh-envoy:v1.15.0.0-prod"
"/aws-appmesh-envoy:v1.15.1.0-prod"
]
]
},
Expand Down Expand Up @@ -1710,7 +1710,7 @@
{
"Ref": "AWS::URLSuffix"
},
"/aws-appmesh-envoy:v1.15.0.0-prod"
"/aws-appmesh-envoy:v1.15.1.0-prod"
]
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export = {
{
Ref: 'AWS::URLSuffix',
},
'/aws-appmesh-envoy:v1.15.0.0-prod',
'/aws-appmesh-envoy:v1.15.1.0-prod',
],
],
},
Expand Down
16 changes: 15 additions & 1 deletion packages/@aws-cdk/aws-cloudwatch/lib/alarm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,11 +273,18 @@ export class Alarm extends AlarmBase {
};
},
withExpression(expr, conf) {

const hasSubmetrics = mathExprHasSubmetrics(expr);

if (hasSubmetrics) {
assertSubmetricsCount(expr);
}

return {
expression: expr.expression,
id: entry.id || uniqueMetricId(),
label: conf.renderingProperties?.label,
period: mathExprHasSubmetrics(expr) ? undefined : expr.period,
period: hasSubmetrics ? undefined : expr.period,
returnData: entry.tag ? undefined : false, // Tag stores "primary" attribute, default is "true"
};
},
Expand Down Expand Up @@ -344,4 +351,11 @@ function mathExprHasSubmetrics(expr: MetricExpressionConfig) {
return Object.keys(expr.usingMetrics).length > 0;
}

function assertSubmetricsCount(expr: MetricExpressionConfig) {
if (Object.keys(expr.usingMetrics).length > 10) {
// https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/AlarmThatSendsEmail.html#alarms-on-metric-math-expressions
throw new Error('Alarms on math expressions cannot contain more than 10 individual metrics');
};
}

type Writeable<T> = { -readonly [P in keyof T]: T[P] };
34 changes: 33 additions & 1 deletion packages/@aws-cdk/aws-cloudwatch/test/test.alarm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,46 @@ import { ABSENT, expect, haveResource } from '@aws-cdk/assert';
import { Duration, Stack } from '@aws-cdk/core';
import { Construct } from 'constructs';
import { Test } from 'nodeunit';
import { Alarm, IAlarm, IAlarmAction, Metric } from '../lib';
import { Alarm, IAlarm, IAlarmAction, Metric, MathExpression, IMetric } from '../lib';

const testMetric = new Metric({
namespace: 'CDK/Test',
metricName: 'Metric',
});

export = {

'alarm does not accept a math expression with more than 10 metrics'(test: Test) {

const stack = new Stack();

const usingMetrics: Record<string, IMetric> = {};

for (const i of [...Array(15).keys()]) {
const metricName = `metric${i}`;
usingMetrics[metricName] = new Metric({
namespace: 'CDK/Test',
metricName: metricName,
});
}

const math = new MathExpression({
expression: 'a',
usingMetrics,
});

test.throws(() => {

new Alarm(stack, 'Alarm', {
metric: math,
threshold: 1000,
evaluationPeriods: 3,
});

}, /Alarms on math expressions cannot contain more than 10 individual metrics/);

test.done();
},
'can make simple alarm'(test: Test) {
// GIVEN
const stack = new Stack();
Expand Down
Loading

0 comments on commit 561656e

Please sign in to comment.