Skip to content

Commit

Permalink
feat: allow specifying regions/accounts at a more granular level
Browse files Browse the repository at this point in the history
  • Loading branch information
echeung-amzn committed Jul 2, 2024
1 parent cf26388 commit 256985d
Show file tree
Hide file tree
Showing 46 changed files with 4,808 additions and 115 deletions.
3,886 changes: 3,852 additions & 34 deletions API.md

Large diffs are not rendered by default.

22 changes: 20 additions & 2 deletions lib/common/metric/BaseMetricFactory.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,33 @@
import { MetricFactory } from "./MetricFactory";

export interface BaseMetricFactoryProps {
// TODO: this will eventually include other common things like account/region
/**
* Region where the metrics exist.
*
* @default The region configured by the construct holding the Monitoring construct
* @see https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Cross-Account-Cross-Region.html
*/
readonly region?: string;

/**
* Account where the metrics exist.
*
* @default The account configured by the construct holding the Monitoring construct
* @see https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Cross-Account-Cross-Region.html
*/
readonly account?: string;
}

export abstract class BaseMetricFactory<
PropsType extends BaseMetricFactoryProps,
> {
protected readonly metricFactory: MetricFactory;
protected readonly account?: string;
protected readonly region?: string;

constructor(metricFactory: MetricFactory, _props: PropsType) {
constructor(metricFactory: MetricFactory, props: PropsType) {
this.metricFactory = metricFactory;
this.account = props.account;
this.region = props.region;
}
}
15 changes: 0 additions & 15 deletions lib/common/metric/MetricFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,6 @@ export interface MetricFactoryDefaults extends BaseMetricFactoryProps {
* @default - DefaultMetricPeriod
*/
readonly period?: Duration;

/**
* Region where the metrics exist.
*
* @default The region configured by the construct holding the Monitoring construct
* @see https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Cross-Account-Cross-Region.html
*/
readonly region?: string;
/**
* Account where the metrics exist.
*
* @default The account configured by the construct holding the Monitoring construct
* @see https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Cross-Account-Cross-Region.html
*/
readonly account?: string;
}

export interface MetricFactoryProps {
Expand Down
3 changes: 3 additions & 0 deletions lib/monitoring/aws-acm/CertificateManagerMetricFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ export class CertificateManagerMetricFactory extends BaseMetricFactory<Certifica
this.dimensionsMap,
undefined,
Namespace,
undefined,
this.region,
this.account,
);
}
}
12 changes: 12 additions & 0 deletions lib/monitoring/aws-apigateway/ApiGatewayMetricFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ export class ApiGatewayMetricFactory extends BaseMetricFactory<ApiGatewayMetricF
this.dimensionsMap,
undefined,
ApiGatewayNamespace,
undefined,
this.region,
this.account,
);
}

Expand All @@ -105,6 +108,9 @@ export class ApiGatewayMetricFactory extends BaseMetricFactory<ApiGatewayMetricF
this.dimensionsMap,
undefined,
ApiGatewayNamespace,
undefined,
this.region,
this.account,
);
}

Expand All @@ -126,6 +132,9 @@ export class ApiGatewayMetricFactory extends BaseMetricFactory<ApiGatewayMetricF
this.dimensionsMap,
undefined,
ApiGatewayNamespace,
undefined,
this.region,
this.account,
);
}

Expand Down Expand Up @@ -169,6 +178,9 @@ export class ApiGatewayMetricFactory extends BaseMetricFactory<ApiGatewayMetricF
this.dimensionsMap,
undefined,
ApiGatewayNamespace,
undefined,
this.region,
this.account,
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ export class ApiGatewayV2HttpApiMetricFactory extends BaseMetricFactory<ApiGatew
this.dimensionsMap,
undefined,
ApiGatewayNamespace,
undefined,
this.region,
this.account,
);
}

Expand All @@ -122,6 +125,9 @@ export class ApiGatewayV2HttpApiMetricFactory extends BaseMetricFactory<ApiGatew
this.dimensionsMap,
undefined,
ApiGatewayNamespace,
undefined,
this.region,
this.account,
);
}

Expand Down Expand Up @@ -186,6 +192,9 @@ export class ApiGatewayV2HttpApiMetricFactory extends BaseMetricFactory<ApiGatew
this.dimensionsMap,
undefined,
ApiGatewayNamespace,
undefined,
this.region,
this.account,
);
}

Expand All @@ -198,6 +207,9 @@ export class ApiGatewayV2HttpApiMetricFactory extends BaseMetricFactory<ApiGatew
this.dimensionsMap,
undefined,
ApiGatewayNamespace,
undefined,
this.region,
this.account,
);
}
}
18 changes: 18 additions & 0 deletions lib/monitoring/aws-appsync/AppSyncMetricFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ export class AppSyncMetricFactory extends BaseMetricFactory<AppSyncMetricFactory
this.dimensionsMap,
undefined,
Namespace,
undefined,
this.region,
this.account,
);
}

Expand All @@ -86,6 +89,9 @@ export class AppSyncMetricFactory extends BaseMetricFactory<AppSyncMetricFactory
this.dimensionsMap,
undefined,
Namespace,
undefined,
this.region,
this.account,
);
}

Expand All @@ -97,6 +103,9 @@ export class AppSyncMetricFactory extends BaseMetricFactory<AppSyncMetricFactory
this.dimensionsMap,
undefined,
Namespace,
undefined,
this.region,
this.account,
);
}

Expand All @@ -108,6 +117,9 @@ export class AppSyncMetricFactory extends BaseMetricFactory<AppSyncMetricFactory
this.dimensionsMap,
undefined,
Namespace,
undefined,
this.region,
this.account,
);
}

Expand All @@ -119,6 +131,9 @@ export class AppSyncMetricFactory extends BaseMetricFactory<AppSyncMetricFactory
this.dimensionsMap,
undefined,
Namespace,
undefined,
this.region,
this.account,
);
}

Expand All @@ -140,6 +155,9 @@ export class AppSyncMetricFactory extends BaseMetricFactory<AppSyncMetricFactory
this.dimensionsMap,
undefined,
Namespace,
undefined,
this.region,
this.account,
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export class CloudFrontDistributionMetricFactory extends BaseMetricFactory<Cloud
CloudFrontNamespace,
undefined,
CloudFrontDefaultMetricRegion,
this.account,
);
}

Expand Down Expand Up @@ -108,6 +109,7 @@ export class CloudFrontDistributionMetricFactory extends BaseMetricFactory<Cloud
CloudFrontNamespace,
undefined,
CloudFrontDefaultMetricRegion,
this.account,
);
}

Expand All @@ -121,6 +123,7 @@ export class CloudFrontDistributionMetricFactory extends BaseMetricFactory<Cloud
CloudFrontNamespace,
undefined,
CloudFrontDefaultMetricRegion,
this.account,
);
}

Expand All @@ -139,6 +142,7 @@ export class CloudFrontDistributionMetricFactory extends BaseMetricFactory<Cloud
CloudFrontNamespace,
undefined,
CloudFrontDefaultMetricRegion,
this.account,
);
}

Expand All @@ -152,6 +156,7 @@ export class CloudFrontDistributionMetricFactory extends BaseMetricFactory<Cloud
CloudFrontNamespace,
undefined,
CloudFrontDefaultMetricRegion,
this.account,
);
}

Expand All @@ -165,6 +170,7 @@ export class CloudFrontDistributionMetricFactory extends BaseMetricFactory<Cloud
CloudFrontNamespace,
undefined,
CloudFrontDefaultMetricRegion,
this.account,
);
}

Expand All @@ -178,6 +184,7 @@ export class CloudFrontDistributionMetricFactory extends BaseMetricFactory<Cloud
CloudFrontNamespace,
undefined,
CloudFrontDefaultMetricRegion,
this.account,
);
}
}
3 changes: 3 additions & 0 deletions lib/monitoring/aws-cloudwatch/CloudWatchLogsMetricFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ export class CloudWatchLogsMetricFactory extends BaseMetricFactory<CloudWatchLog
this.dimensionsMap,
undefined,
CloudWatchLogsNamespace,
undefined,
this.region,
this.account,
);
}
}
27 changes: 24 additions & 3 deletions lib/monitoring/aws-codebuild/CodeBuildProjectMetricFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,30 @@ export class CodeBuildProjectMetricFactory extends BaseMetricFactory<CodeBuildPr
}

metricBuildCount() {
return this.metricFactory.adaptMetric(this.project.metricBuilds());
return this.metricFactory.adaptMetric(
this.project.metricBuilds({
region: this.region,
account: this.account,
}),
);
}

metricSucceededBuildCount() {
return this.metricFactory.adaptMetric(this.project.metricSucceededBuilds());
return this.metricFactory.adaptMetric(
this.project.metricSucceededBuilds({
region: this.region,
account: this.account,
}),
);
}

metricFailedBuildCount() {
return this.metricFactory.adaptMetric(this.project.metricFailedBuilds());
return this.metricFactory.adaptMetric(
this.project.metricFailedBuilds({
region: this.region,
account: this.account,
}),
);
}

metricFailedBuildRate() {
Expand All @@ -52,6 +67,8 @@ export class CodeBuildProjectMetricFactory extends BaseMetricFactory<CodeBuildPr
this.project.metricDuration({
label: "P99",
statistic: MetricStatistic.P99,
region: this.region,
account: this.account,
}),
);
}
Expand All @@ -61,6 +78,8 @@ export class CodeBuildProjectMetricFactory extends BaseMetricFactory<CodeBuildPr
this.project.metricDuration({
label: "P90",
statistic: MetricStatistic.P90,
region: this.region,
account: this.account,
}),
);
}
Expand All @@ -70,6 +89,8 @@ export class CodeBuildProjectMetricFactory extends BaseMetricFactory<CodeBuildPr
this.project.metricDuration({
label: "P50",
statistic: MetricStatistic.P50,
region: this.region,
account: this.account,
}),
);
}
Expand Down
3 changes: 3 additions & 0 deletions lib/monitoring/aws-docdb/DocumentDbMetricFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ export class DocumentDbMetricFactory extends BaseMetricFactory<DocumentDbMetricF
this.dimensionsMap,
undefined,
DocumentDbNamespace,
undefined,
this.region,
this.account,
);
}
}
Loading

0 comments on commit 256985d

Please sign in to comment.