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 Jun 25, 2024
1 parent f8778a1 commit e845d15
Show file tree
Hide file tree
Showing 46 changed files with 4,966 additions and 277 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
5 changes: 4 additions & 1 deletion lib/monitoring/aws-acm/CertificateManagerMetricFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ export class CertificateManagerMetricFactory extends BaseMetricFactory<Certifica
"Days to expiry",
this.dimensionsMap,
undefined,
Namespace
Namespace,
undefined,
this.region,
this.account
);
}
}
20 changes: 16 additions & 4 deletions lib/monitoring/aws-apigateway/ApiGatewayMetricFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,10 @@ export class ApiGatewayMetricFactory extends BaseMetricFactory<ApiGatewayMetricF
"Count",
this.dimensionsMap,
undefined,
ApiGatewayNamespace
ApiGatewayNamespace,
undefined,
this.region,
this.account
);
}

Expand All @@ -104,7 +107,10 @@ export class ApiGatewayMetricFactory extends BaseMetricFactory<ApiGatewayMetricF
"4XX Error",
this.dimensionsMap,
undefined,
ApiGatewayNamespace
ApiGatewayNamespace,
undefined,
this.region,
this.account
);
}

Expand All @@ -125,7 +131,10 @@ export class ApiGatewayMetricFactory extends BaseMetricFactory<ApiGatewayMetricF
"5XX Fault",
this.dimensionsMap,
undefined,
ApiGatewayNamespace
ApiGatewayNamespace,
undefined,
this.region,
this.account
);
}

Expand Down Expand Up @@ -168,7 +177,10 @@ export class ApiGatewayMetricFactory extends BaseMetricFactory<ApiGatewayMetricF
label,
this.dimensionsMap,
undefined,
ApiGatewayNamespace
ApiGatewayNamespace,
undefined,
this.region,
this.account
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,10 @@ export class ApiGatewayV2HttpApiMetricFactory extends BaseMetricFactory<ApiGatew
"4xx",
this.dimensionsMap,
undefined,
ApiGatewayNamespace
ApiGatewayNamespace,
undefined,
this.region,
this.account
);
}

Expand All @@ -121,7 +124,10 @@ export class ApiGatewayV2HttpApiMetricFactory extends BaseMetricFactory<ApiGatew
"5xx",
this.dimensionsMap,
undefined,
ApiGatewayNamespace
ApiGatewayNamespace,
undefined,
this.region,
this.account
);
}

Expand Down Expand Up @@ -185,7 +191,10 @@ export class ApiGatewayV2HttpApiMetricFactory extends BaseMetricFactory<ApiGatew
label,
this.dimensionsMap,
undefined,
ApiGatewayNamespace
ApiGatewayNamespace,
undefined,
this.region,
this.account
);
}

Expand All @@ -197,7 +206,10 @@ export class ApiGatewayV2HttpApiMetricFactory extends BaseMetricFactory<ApiGatew
label,
this.dimensionsMap,
undefined,
ApiGatewayNamespace
ApiGatewayNamespace,
undefined,
this.region,
this.account
);
}
}
30 changes: 24 additions & 6 deletions lib/monitoring/aws-appsync/AppSyncMetricFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,10 @@ export class AppSyncMetricFactory extends BaseMetricFactory<AppSyncMetricFactory
"Requests",
this.dimensionsMap,
undefined,
Namespace
Namespace,
undefined,
this.region,
this.account
);
}

Expand All @@ -85,7 +88,10 @@ export class AppSyncMetricFactory extends BaseMetricFactory<AppSyncMetricFactory
"P50",
this.dimensionsMap,
undefined,
Namespace
Namespace,
undefined,
this.region,
this.account
);
}

Expand All @@ -96,7 +102,10 @@ export class AppSyncMetricFactory extends BaseMetricFactory<AppSyncMetricFactory
"P90",
this.dimensionsMap,
undefined,
Namespace
Namespace,
undefined,
this.region,
this.account
);
}

Expand All @@ -107,7 +116,10 @@ export class AppSyncMetricFactory extends BaseMetricFactory<AppSyncMetricFactory
"P99",
this.dimensionsMap,
undefined,
Namespace
Namespace,
undefined,
this.region,
this.account
);
}

Expand All @@ -118,7 +130,10 @@ export class AppSyncMetricFactory extends BaseMetricFactory<AppSyncMetricFactory
"4XX Error",
this.dimensionsMap,
undefined,
Namespace
Namespace,
undefined,
this.region,
this.account
);
}

Expand All @@ -139,7 +154,10 @@ export class AppSyncMetricFactory extends BaseMetricFactory<AppSyncMetricFactory
"5XX Fault",
this.dimensionsMap,
undefined,
Namespace
Namespace,
undefined,
this.region,
this.account
);
}

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

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

Expand All @@ -120,7 +122,8 @@ export class CloudFrontDistributionMetricFactory extends BaseMetricFactory<Cloud
undefined,
CloudFrontNamespace,
undefined,
CloudFrontDefaultMetricRegion
CloudFrontDefaultMetricRegion,
this.account
);
}

Expand All @@ -138,7 +141,8 @@ export class CloudFrontDistributionMetricFactory extends BaseMetricFactory<Cloud
undefined,
CloudFrontNamespace,
undefined,
CloudFrontDefaultMetricRegion
CloudFrontDefaultMetricRegion,
this.account
);
}

Expand All @@ -151,7 +155,8 @@ export class CloudFrontDistributionMetricFactory extends BaseMetricFactory<Cloud
undefined,
CloudFrontNamespace,
undefined,
CloudFrontDefaultMetricRegion
CloudFrontDefaultMetricRegion,
this.account
);
}

Expand All @@ -164,7 +169,8 @@ export class CloudFrontDistributionMetricFactory extends BaseMetricFactory<Cloud
undefined,
CloudFrontNamespace,
undefined,
CloudFrontDefaultMetricRegion
CloudFrontDefaultMetricRegion,
this.account
);
}

Expand All @@ -177,7 +183,8 @@ export class CloudFrontDistributionMetricFactory extends BaseMetricFactory<Cloud
undefined,
CloudFrontNamespace,
undefined,
CloudFrontDefaultMetricRegion
CloudFrontDefaultMetricRegion,
this.account
);
}
}
5 changes: 4 additions & 1 deletion lib/monitoring/aws-cloudwatch/CloudWatchLogsMetricFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ export class CloudWatchLogsMetricFactory extends BaseMetricFactory<CloudWatchLog
"Logs",
this.dimensionsMap,
undefined,
CloudWatchLogsNamespace
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
5 changes: 4 additions & 1 deletion lib/monitoring/aws-docdb/DocumentDbMetricFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,10 @@ export class DocumentDbMetricFactory extends BaseMetricFactory<DocumentDbMetricF
label,
this.dimensionsMap,
undefined,
DocumentDbNamespace
DocumentDbNamespace,
undefined,
this.region,
this.account
);
}
}
Loading

0 comments on commit e845d15

Please sign in to comment.