Skip to content

Commit 4801636

Browse files
author
Eugene Cheung
authored
feat: allow specifying regions/accounts at a more granular level (#533)
This allows users to target different regions/account for specific things within a facade rather than relying on 1 facade per region/account with the facade's global settings, so something like: ```ts this.facade .monitorDynamoTable({ ..., }) .monitorDynamoTable({ ..., region: <some_other_region>, account: <some_other_account>, }) ``` --- _By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license_
1 parent 8ee4010 commit 4801636

File tree

46 files changed

+4703
-92
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+4703
-92
lines changed

API.md

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

README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,48 @@ Now, this widget will be added to both dashboards and will show different conten
417417
* Dashboard Name: "ExampleDashboards-Infrastructure"
418418
* Content: "This shows metrics for the AWS Infrastructure supporting your hosted service"
419419

420+
### Cross-account cross-Region Dashboards
421+
422+
Facades can be configured for different regions/accounts as a whole:
423+
424+
```ts
425+
new MonitoringFacade(stack, "Monitoring", {
426+
metricFactoryDefaults: {
427+
// Different region/account than what you're deploying to
428+
region: "us-west-2",
429+
account: "01234567890",
430+
}
431+
});
432+
```
433+
434+
Or at a more granular level:
435+
436+
```ts
437+
monitoring
438+
.monitorDynamoTable({
439+
// Table from the same account/region
440+
table: Table.fromTableName(stack, "ImportedTable", "MyTableName"),
441+
})
442+
.monitorDynamoTable({
443+
// Table from another account/region
444+
table: Table.fromTableArn(
445+
stack,
446+
"XaXrImportedTable",
447+
"arn:aws:dynamodb:us-west-2:01234567890:table/my-other-table",
448+
),
449+
region: "us-west-2",
450+
account: "01234567890",
451+
});
452+
```
453+
454+
The order of precedence of the region/account values is:
455+
456+
1. The individual metric factory's props (e.g. via the `monitorDynamoTable` props).
457+
1. The facade's `metricFactoryDefaults` props.
458+
1. The region/account that the stack is deployed to.
459+
460+
Note that certain metrics are based on [math expressions](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/using-metric-math.html) and cannot be alarmed upon in a cross-account cross-Region context, and you will see an error at synthesis time.
461+
420462
### Monitoring scopes
421463

422464
You can monitor complete CDK construct scopes using an aspect. It will automatically discover all monitorable resources within the scope recursively and add them to your dashboard.
Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,33 @@
11
import { MetricFactory } from "./MetricFactory";
22

33
export interface BaseMetricFactoryProps {
4-
// TODO: this will eventually include other common things like account/region
4+
/**
5+
* Region where the metrics exist.
6+
*
7+
* @default The region configured by the construct holding the Monitoring construct
8+
* @see https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Cross-Account-Cross-Region.html
9+
*/
10+
readonly region?: string;
11+
12+
/**
13+
* Account where the metrics exist.
14+
*
15+
* @default The account configured by the construct holding the Monitoring construct
16+
* @see https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Cross-Account-Cross-Region.html
17+
*/
18+
readonly account?: string;
519
}
620

721
export abstract class BaseMetricFactory<
822
PropsType extends BaseMetricFactoryProps,
923
> {
1024
protected readonly metricFactory: MetricFactory;
25+
protected readonly account?: string;
26+
protected readonly region?: string;
1127

12-
constructor(metricFactory: MetricFactory, _props: PropsType) {
28+
constructor(metricFactory: MetricFactory, props: PropsType) {
1329
this.metricFactory = metricFactory;
30+
this.account = props.account;
31+
this.region = props.region;
1432
}
1533
}

lib/common/metric/MetricFactory.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,6 @@ export interface MetricFactoryDefaults extends BaseMetricFactoryProps {
3131
* @default - DefaultMetricPeriod
3232
*/
3333
readonly period?: Duration;
34-
35-
/**
36-
* Region where the metrics exist.
37-
*
38-
* @default The region configured by the construct holding the Monitoring construct
39-
* @see https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Cross-Account-Cross-Region.html
40-
*/
41-
readonly region?: string;
42-
/**
43-
* Account where the metrics exist.
44-
*
45-
* @default The account configured by the construct holding the Monitoring construct
46-
* @see https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Cross-Account-Cross-Region.html
47-
*/
48-
readonly account?: string;
4934
}
5035

5136
export interface MetricFactoryProps {

lib/monitoring/aws-acm/CertificateManagerMetricFactory.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ export class CertificateManagerMetricFactory extends BaseMetricFactory<Certifica
3838
this.dimensionsMap,
3939
undefined,
4040
Namespace,
41+
undefined,
42+
this.region,
43+
this.account,
4144
);
4245
}
4346
}

lib/monitoring/aws-apigateway/ApiGatewayMetricFactory.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ export class ApiGatewayMetricFactory extends BaseMetricFactory<ApiGatewayMetricF
9494
this.dimensionsMap,
9595
undefined,
9696
ApiGatewayNamespace,
97+
undefined,
98+
this.region,
99+
this.account,
97100
);
98101
}
99102

@@ -105,6 +108,9 @@ export class ApiGatewayMetricFactory extends BaseMetricFactory<ApiGatewayMetricF
105108
this.dimensionsMap,
106109
undefined,
107110
ApiGatewayNamespace,
111+
undefined,
112+
this.region,
113+
this.account,
108114
);
109115
}
110116

@@ -126,6 +132,9 @@ export class ApiGatewayMetricFactory extends BaseMetricFactory<ApiGatewayMetricF
126132
this.dimensionsMap,
127133
undefined,
128134
ApiGatewayNamespace,
135+
undefined,
136+
this.region,
137+
this.account,
129138
);
130139
}
131140

@@ -169,6 +178,9 @@ export class ApiGatewayMetricFactory extends BaseMetricFactory<ApiGatewayMetricF
169178
this.dimensionsMap,
170179
undefined,
171180
ApiGatewayNamespace,
181+
undefined,
182+
this.region,
183+
this.account,
172184
);
173185
}
174186
}

lib/monitoring/aws-apigatewayv2/ApiGatewayV2HttpApiMetricFactory.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ export class ApiGatewayV2HttpApiMetricFactory extends BaseMetricFactory<ApiGatew
101101
this.dimensionsMap,
102102
undefined,
103103
ApiGatewayNamespace,
104+
undefined,
105+
this.region,
106+
this.account,
104107
);
105108
}
106109

@@ -122,6 +125,9 @@ export class ApiGatewayV2HttpApiMetricFactory extends BaseMetricFactory<ApiGatew
122125
this.dimensionsMap,
123126
undefined,
124127
ApiGatewayNamespace,
128+
undefined,
129+
this.region,
130+
this.account,
125131
);
126132
}
127133

@@ -186,6 +192,9 @@ export class ApiGatewayV2HttpApiMetricFactory extends BaseMetricFactory<ApiGatew
186192
this.dimensionsMap,
187193
undefined,
188194
ApiGatewayNamespace,
195+
undefined,
196+
this.region,
197+
this.account,
189198
);
190199
}
191200

@@ -198,6 +207,9 @@ export class ApiGatewayV2HttpApiMetricFactory extends BaseMetricFactory<ApiGatew
198207
this.dimensionsMap,
199208
undefined,
200209
ApiGatewayNamespace,
210+
undefined,
211+
this.region,
212+
this.account,
201213
);
202214
}
203215
}

lib/monitoring/aws-appsync/AppSyncMetricFactory.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ export class AppSyncMetricFactory extends BaseMetricFactory<AppSyncMetricFactory
7575
this.dimensionsMap,
7676
undefined,
7777
Namespace,
78+
undefined,
79+
this.region,
80+
this.account,
7881
);
7982
}
8083

@@ -86,6 +89,9 @@ export class AppSyncMetricFactory extends BaseMetricFactory<AppSyncMetricFactory
8689
this.dimensionsMap,
8790
undefined,
8891
Namespace,
92+
undefined,
93+
this.region,
94+
this.account,
8995
);
9096
}
9197

@@ -97,6 +103,9 @@ export class AppSyncMetricFactory extends BaseMetricFactory<AppSyncMetricFactory
97103
this.dimensionsMap,
98104
undefined,
99105
Namespace,
106+
undefined,
107+
this.region,
108+
this.account,
100109
);
101110
}
102111

@@ -108,6 +117,9 @@ export class AppSyncMetricFactory extends BaseMetricFactory<AppSyncMetricFactory
108117
this.dimensionsMap,
109118
undefined,
110119
Namespace,
120+
undefined,
121+
this.region,
122+
this.account,
111123
);
112124
}
113125

@@ -119,6 +131,9 @@ export class AppSyncMetricFactory extends BaseMetricFactory<AppSyncMetricFactory
119131
this.dimensionsMap,
120132
undefined,
121133
Namespace,
134+
undefined,
135+
this.region,
136+
this.account,
122137
);
123138
}
124139

@@ -140,6 +155,9 @@ export class AppSyncMetricFactory extends BaseMetricFactory<AppSyncMetricFactory
140155
this.dimensionsMap,
141156
undefined,
142157
Namespace,
158+
undefined,
159+
this.region,
160+
this.account,
143161
);
144162
}
145163

lib/monitoring/aws-cloudfront/CloudFrontDistributionMetricFactory.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ export class CloudFrontDistributionMetricFactory extends BaseMetricFactory<Cloud
7272
CloudFrontNamespace,
7373
undefined,
7474
CloudFrontDefaultMetricRegion,
75+
this.account,
7576
);
7677
}
7778

@@ -108,6 +109,7 @@ export class CloudFrontDistributionMetricFactory extends BaseMetricFactory<Cloud
108109
CloudFrontNamespace,
109110
undefined,
110111
CloudFrontDefaultMetricRegion,
112+
this.account,
111113
);
112114
}
113115

@@ -121,6 +123,7 @@ export class CloudFrontDistributionMetricFactory extends BaseMetricFactory<Cloud
121123
CloudFrontNamespace,
122124
undefined,
123125
CloudFrontDefaultMetricRegion,
126+
this.account,
124127
);
125128
}
126129

@@ -139,6 +142,7 @@ export class CloudFrontDistributionMetricFactory extends BaseMetricFactory<Cloud
139142
CloudFrontNamespace,
140143
undefined,
141144
CloudFrontDefaultMetricRegion,
145+
this.account,
142146
);
143147
}
144148

@@ -152,6 +156,7 @@ export class CloudFrontDistributionMetricFactory extends BaseMetricFactory<Cloud
152156
CloudFrontNamespace,
153157
undefined,
154158
CloudFrontDefaultMetricRegion,
159+
this.account,
155160
);
156161
}
157162

@@ -165,6 +170,7 @@ export class CloudFrontDistributionMetricFactory extends BaseMetricFactory<Cloud
165170
CloudFrontNamespace,
166171
undefined,
167172
CloudFrontDefaultMetricRegion,
173+
this.account,
168174
);
169175
}
170176

@@ -178,6 +184,7 @@ export class CloudFrontDistributionMetricFactory extends BaseMetricFactory<Cloud
178184
CloudFrontNamespace,
179185
undefined,
180186
CloudFrontDefaultMetricRegion,
187+
this.account,
181188
);
182189
}
183190
}

lib/monitoring/aws-cloudwatch/CloudWatchLogsMetricFactory.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ export class CloudWatchLogsMetricFactory extends BaseMetricFactory<CloudWatchLog
3939
this.dimensionsMap,
4040
undefined,
4141
CloudWatchLogsNamespace,
42+
undefined,
43+
this.region,
44+
this.account,
4245
);
4346
}
4447
}

0 commit comments

Comments
 (0)