Skip to content

Commit

Permalink
feat: use one minute granularity for 5XX alarms (#454)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobwinch authored Apr 16, 2021
1 parent e79b15c commit b46f749
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ Object {
"MetricName": "HTTPCode_ELB_5XX_Count",
"Namespace": "AWS/ApplicationELB",
},
"Period": 300,
"Period": 60,
"Stat": "Sum",
},
"ReturnData": false,
Expand All @@ -193,7 +193,7 @@ Object {
"MetricName": "HTTPCode_Target_5XX_Count",
"Namespace": "AWS/ApplicationELB",
},
"Period": 300,
"Period": 60,
"Stat": "Sum",
},
"ReturnData": false,
Expand All @@ -216,7 +216,7 @@ Object {
"MetricName": "RequestCount",
"Namespace": "AWS/ApplicationELB",
},
"Period": 300,
"Period": 60,
"Stat": "Sum",
},
"ReturnData": false,
Expand Down
2 changes: 1 addition & 1 deletion src/constructs/cloudwatch/ec2-alarms.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ describe("The Gu5xxPercentageAlarm construct", () => {
const alb = new GuApplicationLoadBalancer(stack, "ApplicationLoadBalancer", { ...app, vpc });
const props = {
tolerated5xxPercentage: 1,
numberOfFiveMinutePeriodsToEvaluate: 3,
numberOfMinutesAboveThresholdBeforeAlarm: 3,
snsTopicName: "test-topic",
};
new Gu5xxPercentageAlarm(stack, "test", { ...app, loadBalancer: alb, ...props });
Expand Down
6 changes: 4 additions & 2 deletions src/constructs/cloudwatch/ec2-alarms.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ComparisonOperator, MathExpression, TreatMissingData } from "@aws-cdk/aws-cloudwatch";
import { HttpCodeElb, HttpCodeTarget } from "@aws-cdk/aws-elasticloadbalancingv2";
import { Duration } from "@aws-cdk/core";
import type { GuStack } from "../core";
import type { AppIdentity } from "../core/identity";
import type { GuApplicationLoadBalancer } from "../loadbalancing";
Expand All @@ -14,7 +15,7 @@ export interface Gu5xxPercentageMonitoringProps
extends Omit<GuAlarmProps, "evaluationPeriods" | "metric" | "period" | "threshold" | "treatMissingData">,
AppIdentity {
tolerated5xxPercentage: number;
numberOfFiveMinutePeriodsToEvaluate?: number;
numberOfMinutesAboveThresholdBeforeAlarm?: number;
noMonitoring?: false;
}

Expand All @@ -32,6 +33,7 @@ export class Gu5xxPercentageAlarm extends GuAlarm {
m3: props.loadBalancer.metricRequestCount(),
},
label: `% of 5XX responses served for ${props.app} (load balancer and instances combined)`,
period: Duration.minutes(1),
});
const defaultAlarmName = `High 5XX error % from ${props.app} in ${scope.stage}`;
const defaultDescription = `${props.app} exceeded ${props.tolerated5xxPercentage}% error rate`;
Expand All @@ -43,7 +45,7 @@ export class Gu5xxPercentageAlarm extends GuAlarm {
comparisonOperator: ComparisonOperator.GREATER_THAN_THRESHOLD,
alarmName: props.alarmName ?? defaultAlarmName,
alarmDescription: props.alarmDescription ?? defaultDescription,
evaluationPeriods: props.numberOfFiveMinutePeriodsToEvaluate ?? 1,
evaluationPeriods: props.numberOfMinutesAboveThresholdBeforeAlarm ?? 1,
};
super(scope, id, alarmProps);
}
Expand Down

0 comments on commit b46f749

Please sign in to comment.