Skip to content

Commit 1e5f331

Browse files
author
Eugene Cheung
authored
fix(custom): explicitly throw error when trying to add both a regular and anomaly detection alarm (#70)
Instead of silently dropping the anomaly detection alarm config. --- _By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license_
1 parent ac7335d commit 1e5f331

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

lib/monitoring/custom/CustomMonitoring.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,12 @@ export class CustomMonitoring extends Monitoring {
249249
}
250250

251251
metricGroup.metrics.forEach((metric) => {
252+
if (this.hasAlarm(metric) && this.hasAnomalyDetection(metric)) {
253+
throw new Error(
254+
"Adding both a regular alarm and an anomoly detection alarm at the same time is not supported"
255+
);
256+
}
257+
252258
if (this.hasAlarm(metric)) {
253259
this.setupAlarm(metricGroupWithAnnotation, metric);
254260
} else if (this.hasAnomalyDetection(metric)) {

test/monitoring/custom/CustomMonitoring.test.ts

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,5 +368,53 @@ test("throws error if attempting to add alarm on a search query", () => {
368368
},
369369
],
370370
})
371-
).toThrow();
371+
).toThrow("Alarming on search queries is not supported by CloudWatch");
372+
});
373+
374+
test("throws error if attempting to add both a regular alarm and an anomoly detection alarm", () => {
375+
const stack = new Stack();
376+
const scope = new TestMonitoringScope(stack, "Scope");
377+
378+
expect(
379+
() =>
380+
new CustomMonitoring(scope, {
381+
alarmFriendlyName: "DummyAlarmName",
382+
humanReadableName: "DummyName",
383+
description: "This is a very long description.",
384+
metricGroups: [
385+
{
386+
title: "DummyGroup1",
387+
important: true,
388+
metrics: [
389+
{
390+
metric: new Metric({
391+
metricName: "DNSQueries",
392+
namespace: "AWS/Route53",
393+
dimensions: {
394+
HostedZoneId: "ID",
395+
},
396+
}),
397+
alarmFriendlyName: "DNSQueries anomaly",
398+
addAlarm: {
399+
Warning: {
400+
threshold: 90,
401+
comparisonOperator: ComparisonOperator.LESS_THAN_THRESHOLD,
402+
},
403+
},
404+
anomalyDetectionStandardDeviationToRender: 1,
405+
addAlarmOnAnomaly: {
406+
CriticalAnomaly: {
407+
standardDeviationForAlarm: 1,
408+
alarmWhenBelowTheBand: true,
409+
alarmWhenAboveTheBand: true,
410+
},
411+
},
412+
},
413+
],
414+
},
415+
],
416+
})
417+
).toThrow(
418+
"Adding both a regular alarm and an anomoly detection alarm at the same time is not supported"
419+
);
372420
});

0 commit comments

Comments
 (0)