Skip to content

Commit

Permalink
feat(logs): add addMaxIncomingLogsAlarm (#504)
Browse files Browse the repository at this point in the history
Closes #495

---

_By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache-2.0 license_
  • Loading branch information
echeung-amzn authored Mar 22, 2024
1 parent 040845d commit b9176a5
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 3 deletions.
11 changes: 11 additions & 0 deletions API.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions lib/monitoring/aws-cloudwatch/LogMonitoring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
DefaultLogWidgetHeight,
DefaultSummaryWidgetHeight,
FullWidth,
MaxUsageCountThreshold,
MetricWithAlarmSupport,
MinUsageCountThreshold,
Monitoring,
Expand Down Expand Up @@ -55,6 +56,7 @@ export interface LogMonitoringProps
readonly limit?: number;

readonly addMinIncomingLogsAlarm?: Record<string, MinUsageCountThreshold>;
readonly addMaxIncomingLogsAlarm?: Record<string, MaxUsageCountThreshold>;
}

/**
Expand Down Expand Up @@ -116,6 +118,17 @@ export class LogMonitoring extends Monitoring {
this.addAlarm(createdAlarm);
}

for (const disambiguator in props.addMaxIncomingLogsAlarm) {
const alarmProps = props.addMaxIncomingLogsAlarm[disambiguator];
const createdAlarm = this.usageAlarmFactory.addMaxCountAlarm(
this.incomingLogEventsMetric,
alarmProps,
disambiguator
);
this.usageAnnotations.push(createdAlarm.annotation);
this.addAlarm(createdAlarm);
}

props.useCreatedAlarms?.consume(this.createdAlarms());
}

Expand Down
7 changes: 6 additions & 1 deletion test/monitoring/aws-cloudwatch/LogMonitoring.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ test("snapshot test: with alarms", () => {
treatMissingDataOverride: TreatMissingData.BREACHING,
},
},
addMaxIncomingLogsAlarm: {
Critical: {
maxCount: 9001,
},
},
useCreatedAlarms: {
consume(alarms) {
numAlarmsCreated = alarms.length;
Expand All @@ -73,6 +78,6 @@ test("snapshot test: with alarms", () => {
});

addMonitoringDashboardsToStack(stack, monitoring);
expect(numAlarmsCreated).toStrictEqual(1);
expect(numAlarmsCreated).toStrictEqual(2);
expect(Template.fromStack(stack)).toMatchSnapshot();
});

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b9176a5

Please sign in to comment.