Skip to content

Commit fdd5ac1

Browse files
author
Eugene Cheung
authored
fix(waf-v2): include Region dimension if specified (#317)
The metrics specifically have a `Region` dimension when using a regional Web ACL (as opposed to a global Cloudfront one that lacks that dimension). Also explicitly specify a `name` for the test resources, as it seems like `CfnWebACL` doesn't return a `name` if you don't set it. --- _By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license_
1 parent 9002122 commit fdd5ac1

File tree

4 files changed

+43
-18
lines changed

4 files changed

+43
-18
lines changed

API.md

Lines changed: 6 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/monitoring/aws-wafv2/WafV2MetricFactory.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@ const MetricNamespace = "AWS/WAFV2";
66
const AllRulesDimensionValue = "ALL";
77

88
export interface WafV2MetricFactoryProps {
9-
readonly region?: string;
109
readonly acl: CfnWebACL;
10+
11+
/**
12+
* Required if acl has a "REGIONAL" scope.
13+
*/
14+
readonly region?: string;
1115
}
1216

1317
/**
@@ -22,6 +26,7 @@ export class WafV2MetricFactory {
2226
this.dimensions = {
2327
Rule: AllRulesDimensionValue,
2428
WebACL: props.acl.name,
29+
...(props.region && { Region: props.region }),
2530
};
2631
}
2732

test/monitoring/aws-wafv2/WafV2Monitoring.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { TestMonitoringScope } from "../TestMonitoringScope";
99
test("snapshot test: no alarms", () => {
1010
const stack = new Stack();
1111
const acl = new CfnWebACL(stack, "DummyAcl", {
12+
name: "DummyAclName",
1213
defaultAction: { allow: {} },
1314
scope: "REGIONAL",
1415
visibilityConfig: {
@@ -20,7 +21,7 @@ test("snapshot test: no alarms", () => {
2021

2122
const scope = new TestMonitoringScope(stack, "Scope");
2223

23-
const monitoring = new WafV2Monitoring(scope, { acl });
24+
const monitoring = new WafV2Monitoring(scope, { acl, region: "us-east-1" });
2425

2526
addMonitoringDashboardsToStack(stack, monitoring);
2627
expect(Template.fromStack(stack)).toMatchSnapshot();
@@ -29,8 +30,9 @@ test("snapshot test: no alarms", () => {
2930
test("snapshot test: all alarms", () => {
3031
const stack = new Stack();
3132
const acl = new CfnWebACL(stack, "DummyAcl", {
33+
name: "DummyAclName",
3234
defaultAction: { allow: {} },
33-
scope: "REGIONAL",
35+
scope: "CLOUDFRONT",
3436
visibilityConfig: {
3537
sampledRequestsEnabled: true,
3638
cloudWatchMetricsEnabled: true,

test/monitoring/aws-wafv2/__snapshots__/WafV2Monitoring.test.ts.snap

Lines changed: 27 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)