Skip to content

Commit

Permalink
fix(MonitoringAspect): allow specifying CloudFrontDistribution and Wa…
Browse files Browse the repository at this point in the history
…fV2 alarms (#609)

Fixes #607

Also replaces some things marked as deprecated in the unit tests just to make it less noisy.

---

_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 Dec 7, 2024
1 parent a397b93 commit dc1edac
Show file tree
Hide file tree
Showing 5 changed files with 296 additions and 27 deletions.
66 changes: 66 additions & 0 deletions API.md

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

Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,18 @@ import {
} from "../../dashboard";

export interface CloudFrontDistributionMonitoringOptions
extends BaseMonitoringProps {}

export interface CloudFrontDistributionMonitoringProps
extends CloudFrontDistributionMetricFactoryProps,
CloudFrontDistributionMonitoringOptions {
extends BaseMonitoringProps {
readonly addError4xxRate?: Record<string, ErrorRateThreshold>;
readonly addFault5xxRate?: Record<string, ErrorRateThreshold>;

readonly addLowTpsAlarm?: Record<string, LowTpsThreshold>;
readonly addHighTpsAlarm?: Record<string, HighTpsThreshold>;
}

export interface CloudFrontDistributionMonitoringProps
extends CloudFrontDistributionMetricFactoryProps,
CloudFrontDistributionMonitoringOptions {}

export class CloudFrontDistributionMonitoring extends Monitoring {
readonly title: string;
readonly distributionUrl?: string;
Expand Down
10 changes: 5 additions & 5 deletions lib/monitoring/aws-wafv2/WafV2Monitoring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ import {
MonitoringNamingStrategy,
} from "../../dashboard";

export interface WafV2MonitoringOptions extends BaseMonitoringProps {}

export interface WafV2MonitoringProps
extends WafV2MetricFactoryProps,
WafV2MonitoringOptions {
export interface WafV2MonitoringOptions extends BaseMonitoringProps {
readonly addBlockedRequestsCountAlarm?: Record<string, ErrorCountThreshold>;
readonly addBlockedRequestsRateAlarm?: Record<string, ErrorRateThreshold>;
}

export interface WafV2MonitoringProps
extends WafV2MetricFactoryProps,
WafV2MonitoringOptions {}

/**
* Monitoring for AWS Web Application Firewall.
*
Expand Down
45 changes: 39 additions & 6 deletions test/facade/MonitoringAspect.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,18 @@ describe("MonitoringAspect", () => {
});

// WHEN
facade.monitorScope(stack, defaultAspectProps);
facade.monitorScope(stack, {
...defaultAspectProps,
cloudFront: {
props: {
addError4xxRate: {
Warning: {
maxErrorRate: 0.1,
},
},
},
},
});

// THEN
expect(Template.fromStack(stack)).toMatchSnapshot();
Expand Down Expand Up @@ -402,7 +413,7 @@ describe("MonitoringAspect", () => {
new lambda.Function(stack, "DummyFunction", {
code: lambda.Code.fromInline("lambda"),
handler: "index.handler",
runtime: lambda.Runtime.NODEJS_18_X,
runtime: lambda.Runtime.NODEJS_LATEST,
});

// WHEN
Expand All @@ -419,7 +430,7 @@ describe("MonitoringAspect", () => {

new opensearch.Domain(stack, "DummyOSDomain", {
domainName: "dummy-os-domain",
version: opensearch.EngineVersion.ELASTICSEARCH_7_10,
version: opensearch.EngineVersion.OPENSEARCH_2_15,
});
new elasticsearch.Domain(stack, "DummyESDomain", {
version: elasticsearch.ElasticsearchVersion.V7_10,
Expand Down Expand Up @@ -558,11 +569,22 @@ describe("MonitoringAspect", () => {
code: synthetics.Code.fromInline("/* nothing */"),
handler: "index.handler",
}),
runtime: synthetics.Runtime.SYNTHETICS_NODEJS_PUPPETEER_5_1,
runtime: synthetics.Runtime.SYNTHETICS_NODEJS_PUPPETEER_9_0,
});

// WHEN
facade.monitorScope(stack, defaultAspectProps);
facade.monitorScope(stack, {
...defaultAspectProps,
syntheticsCanaries: {
props: {
add4xxErrorCountAlarm: {
Warning: {
maxErrorCount: 0,
},
},
},
},
});

// THEN
expect(Template.fromStack(stack)).toMatchSnapshot();
Expand All @@ -584,7 +606,18 @@ describe("MonitoringAspect", () => {
});

// WHEN
facade.monitorScope(stack, defaultAspectProps);
facade.monitorScope(stack, {
...defaultAspectProps,
webApplicationFirewallAclV2: {
props: {
addBlockedRequestsCountAlarm: {
Warning: {
maxErrorCount: 0,
},
},
},
},
});

// THEN
expect(Template.fromStack(stack)).toMatchSnapshot();
Expand Down
Loading

0 comments on commit dc1edac

Please sign in to comment.