diff --git a/API.md b/API.md index e7f51b17..42fb0e7f 100644 --- a/API.md +++ b/API.md @@ -8913,6 +8913,17 @@ https://docs.aws.amazon.com/elasticloadbalancing/latest/network/load-balancer-cl --- +### BaseMetricFactoryProps + +#### Initializer + +```typescript +import { BaseMetricFactoryProps } from 'cdk-monitoring-constructs' + +const baseMetricFactoryProps: BaseMetricFactoryProps = { ... } +``` + + ### BaseMonitoringProps Base class for properties passed to each monitoring construct. @@ -50709,6 +50720,39 @@ public getStateMachineUrl(stateMachineArn: string): string +### BaseMetricFactory + +#### Initializers + +```typescript +import { BaseMetricFactory } from 'cdk-monitoring-constructs' + +new BaseMetricFactory(metricFactory: MetricFactory, _props: BaseMetricFactoryProps) +``` + +| **Name** | **Type** | **Description** | +| --- | --- | --- | +| metricFactory | MetricFactory | *No description.* | +| _props | BaseMetricFactoryProps | *No description.* | + +--- + +##### `metricFactory`Required + +- *Type:* MetricFactory + +--- + +##### `_props`Required + +- *Type:* BaseMetricFactoryProps + +--- + + + + + ### BaseServiceMetricFactory Metric factory for a base service (parent class for e.g. Fargate and EC2 services). diff --git a/lib/common/metric/BaseMetricFactory.ts b/lib/common/metric/BaseMetricFactory.ts new file mode 100644 index 00000000..49fcb79b --- /dev/null +++ b/lib/common/metric/BaseMetricFactory.ts @@ -0,0 +1,15 @@ +import { MetricFactory } from "./MetricFactory"; + +export interface BaseMetricFactoryProps { + // TODO: this will eventually include other common things like account/region +} + +export abstract class BaseMetricFactory< + PropsType extends BaseMetricFactoryProps +> { + protected readonly metricFactory: MetricFactory; + + constructor(metricFactory: MetricFactory, _props: PropsType) { + this.metricFactory = metricFactory; + } +} diff --git a/lib/common/metric/MetricFactory.ts b/lib/common/metric/MetricFactory.ts index 115b3b2e..320e3771 100644 --- a/lib/common/metric/MetricFactory.ts +++ b/lib/common/metric/MetricFactory.ts @@ -7,6 +7,7 @@ import { } from "aws-cdk-lib/aws-cloudwatch"; import { AnomalyDetectionMathExpression } from "./AnomalyDetectionMathExpression"; +import { BaseMetricFactoryProps } from "./BaseMetricFactory"; import { MetricStatistic } from "./MetricStatistic"; import { MetricWithAlarmSupport } from "./MetricWithAlarmSupport"; import { RateComputationMethod } from "./RateComputationMethod"; @@ -19,7 +20,7 @@ export const DefaultMetricPeriod = Duration.minutes(5); /** * These are the globals used for each metric, unless there is some kind of override. */ -export interface MetricFactoryDefaults { +export interface MetricFactoryDefaults extends BaseMetricFactoryProps { /** * Each metric exists in a namespace. AWS Services have their own namespace, but here you can specify your custom one. */ diff --git a/lib/common/metric/index.ts b/lib/common/metric/index.ts index 0d8aa780..18c6e081 100644 --- a/lib/common/metric/index.ts +++ b/lib/common/metric/index.ts @@ -1,4 +1,5 @@ export * from "./AnomalyDetectionMathExpression"; +export * from "./BaseMetricFactory"; export * from "./MetricFactory"; export * from "./MetricStatistic"; export * from "./MetricWithAlarmSupport"; diff --git a/lib/common/monitoring/Monitoring.ts b/lib/common/monitoring/Monitoring.ts index 282b066b..d3332c62 100644 --- a/lib/common/monitoring/Monitoring.ts +++ b/lib/common/monitoring/Monitoring.ts @@ -9,6 +9,7 @@ import { UserProvidedNames, } from "../../dashboard"; import { AlarmWithAnnotation } from "../alarm"; +import { BaseMetricFactoryProps } from "../metric"; export interface IAlarmConsumer { consume(alarms: AlarmWithAnnotation[]): void; @@ -19,7 +20,8 @@ export interface IAlarmConsumer { * It contains (mostly optional) properties to specify naming, placement, and so on. */ export interface BaseMonitoringProps - extends UserProvidedNames, + extends BaseMetricFactoryProps, + UserProvidedNames, MonitoringDashboardsOverrideProps { /** * Calls provided function to process all alarms created. diff --git a/lib/monitoring/aws-acm/CertificateManagerMetricFactory.ts b/lib/monitoring/aws-acm/CertificateManagerMetricFactory.ts index 4c7b765d..1ce395c7 100644 --- a/lib/monitoring/aws-acm/CertificateManagerMetricFactory.ts +++ b/lib/monitoring/aws-acm/CertificateManagerMetricFactory.ts @@ -2,6 +2,8 @@ import { ICertificate } from "aws-cdk-lib/aws-certificatemanager"; import { DimensionsMap } from "aws-cdk-lib/aws-cloudwatch"; import { + BaseMetricFactory, + BaseMetricFactoryProps, MetricFactory, MetricStatistic, MetricWithAlarmSupport, @@ -9,19 +11,20 @@ import { const Namespace = "AWS/CertificateManager"; -export interface CertificateManagerMetricFactoryProps { +export interface CertificateManagerMetricFactoryProps + extends BaseMetricFactoryProps { readonly certificate: ICertificate; } -export class CertificateManagerMetricFactory { - protected readonly metricFactory: MetricFactory; +export class CertificateManagerMetricFactory extends BaseMetricFactory { protected readonly dimensionsMap: DimensionsMap; constructor( metricFactory: MetricFactory, props: CertificateManagerMetricFactoryProps ) { - this.metricFactory = metricFactory; + super(metricFactory, props); + this.dimensionsMap = { CertificateArn: props.certificate.certificateArn, }; diff --git a/lib/monitoring/aws-apigateway/ApiGatewayMetricFactory.ts b/lib/monitoring/aws-apigateway/ApiGatewayMetricFactory.ts index f916e4c2..1b49bfd1 100644 --- a/lib/monitoring/aws-apigateway/ApiGatewayMetricFactory.ts +++ b/lib/monitoring/aws-apigateway/ApiGatewayMetricFactory.ts @@ -2,6 +2,8 @@ import { IRestApi } from "aws-cdk-lib/aws-apigateway"; import { DimensionsMap } from "aws-cdk-lib/aws-cloudwatch"; import { + BaseMetricFactory, + BaseMetricFactoryProps, getLatencyTypeLabel, getLatencyTypeStatistic, LatencyType, @@ -12,7 +14,7 @@ import { const ApiGatewayNamespace = "AWS/ApiGateway"; -export interface ApiGatewayMetricFactoryProps { +export interface ApiGatewayMetricFactoryProps extends BaseMetricFactoryProps { /** * API to monitor */ @@ -39,8 +41,7 @@ export interface ApiGatewayMetricFactoryProps { readonly rateComputationMethod?: RateComputationMethod; } -export class ApiGatewayMetricFactory { - protected readonly metricFactory: MetricFactory; +export class ApiGatewayMetricFactory extends BaseMetricFactory { protected readonly fillTpsWithZeroes: boolean; protected readonly rateComputationMethod: RateComputationMethod; protected readonly dimensionsMap: DimensionsMap; @@ -49,7 +50,8 @@ export class ApiGatewayMetricFactory { metricFactory: MetricFactory, props: ApiGatewayMetricFactoryProps ) { - this.metricFactory = metricFactory; + super(metricFactory, props); + this.fillTpsWithZeroes = props.fillTpsWithZeroes ?? true; this.rateComputationMethod = props.rateComputationMethod ?? RateComputationMethod.AVERAGE; diff --git a/lib/monitoring/aws-apigatewayv2/ApiGatewayV2HttpApiMetricFactory.ts b/lib/monitoring/aws-apigatewayv2/ApiGatewayV2HttpApiMetricFactory.ts index 659a6429..295c88ad 100644 --- a/lib/monitoring/aws-apigatewayv2/ApiGatewayV2HttpApiMetricFactory.ts +++ b/lib/monitoring/aws-apigatewayv2/ApiGatewayV2HttpApiMetricFactory.ts @@ -2,6 +2,8 @@ import { IHttpApi } from "aws-cdk-lib/aws-apigatewayv2"; import { DimensionsMap } from "aws-cdk-lib/aws-cloudwatch"; import { + BaseMetricFactory, + BaseMetricFactoryProps, getLatencyTypeLabel, getLatencyTypeStatistic, LatencyType, @@ -12,7 +14,8 @@ import { const ApiGatewayNamespace = "AWS/ApiGateway"; -export interface ApiGatewayV2HttpApiMetricFactoryProps { +export interface ApiGatewayV2HttpApiMetricFactoryProps + extends BaseMetricFactoryProps { readonly api: IHttpApi; /** * @default - $default @@ -36,8 +39,7 @@ export interface ApiGatewayV2HttpApiMetricFactoryProps { readonly rateComputationMethod?: RateComputationMethod; } -export class ApiGatewayV2HttpApiMetricFactory { - protected readonly metricFactory: MetricFactory; +export class ApiGatewayV2HttpApiMetricFactory extends BaseMetricFactory { protected readonly fillTpsWithZeroes: boolean; protected readonly rateComputationMethod: RateComputationMethod; protected readonly dimensionsMap: DimensionsMap; @@ -46,7 +48,8 @@ export class ApiGatewayV2HttpApiMetricFactory { metricFactory: MetricFactory, props: ApiGatewayV2HttpApiMetricFactoryProps ) { - this.metricFactory = metricFactory; + super(metricFactory, props); + this.fillTpsWithZeroes = props.fillTpsWithZeroes ?? true; this.rateComputationMethod = props.rateComputationMethod ?? RateComputationMethod.AVERAGE; diff --git a/lib/monitoring/aws-appsync/AppSyncMetricFactory.ts b/lib/monitoring/aws-appsync/AppSyncMetricFactory.ts index 9b38dccc..e644e7fd 100644 --- a/lib/monitoring/aws-appsync/AppSyncMetricFactory.ts +++ b/lib/monitoring/aws-appsync/AppSyncMetricFactory.ts @@ -2,6 +2,8 @@ import { IGraphqlApi } from "aws-cdk-lib/aws-appsync"; import { DimensionsMap } from "aws-cdk-lib/aws-cloudwatch"; import { + BaseMetricFactory, + BaseMetricFactoryProps, MetricFactory, MetricStatistic, RateComputationMethod, @@ -9,7 +11,7 @@ import { const Namespace = "AWS/AppSync"; -export interface AppSyncMetricFactoryProps { +export interface AppSyncMetricFactoryProps extends BaseMetricFactoryProps { /** * the GraphQL API to monitor */ @@ -26,14 +28,14 @@ export interface AppSyncMetricFactoryProps { readonly rateComputationMethod?: RateComputationMethod; } -export class AppSyncMetricFactory { - protected readonly metricFactory: MetricFactory; +export class AppSyncMetricFactory extends BaseMetricFactory { protected readonly fillTpsWithZeroes: boolean; protected readonly rateComputationMethod: RateComputationMethod; protected readonly dimensionsMap: DimensionsMap; constructor(metricFactory: MetricFactory, props: AppSyncMetricFactoryProps) { - this.metricFactory = metricFactory; + super(metricFactory, props); + this.fillTpsWithZeroes = props.fillTpsWithZeroes ?? true; this.rateComputationMethod = props.rateComputationMethod ?? RateComputationMethod.AVERAGE; diff --git a/lib/monitoring/aws-cloudfront/CloudFrontDistributionMetricFactory.ts b/lib/monitoring/aws-cloudfront/CloudFrontDistributionMetricFactory.ts index 28ae1a3c..2d5c9780 100644 --- a/lib/monitoring/aws-cloudfront/CloudFrontDistributionMetricFactory.ts +++ b/lib/monitoring/aws-cloudfront/CloudFrontDistributionMetricFactory.ts @@ -2,6 +2,8 @@ import { IDistribution } from "aws-cdk-lib/aws-cloudfront"; import { DimensionsMap } from "aws-cdk-lib/aws-cloudwatch"; import { + BaseMetricFactory, + BaseMetricFactoryProps, MetricFactory, MetricStatistic, RateComputationMethod, @@ -11,7 +13,8 @@ const CloudFrontNamespace = "AWS/CloudFront"; const CloudFrontGlobalRegion = "Global"; const CloudFrontDefaultMetricRegion = "us-east-1"; -export interface CloudFrontDistributionMetricFactoryProps { +export interface CloudFrontDistributionMetricFactoryProps + extends BaseMetricFactoryProps { readonly distribution: IDistribution; /** @@ -39,8 +42,7 @@ export interface CloudFrontDistributionMetricFactoryProps { * To get the CloudFront metrics from the CloudWatch API, you must use the US East (N. Virginia) Region (us-east-1). * https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/programming-cloudwatch-metrics.html */ -export class CloudFrontDistributionMetricFactory { - private readonly metricFactory: MetricFactory; +export class CloudFrontDistributionMetricFactory extends BaseMetricFactory { private readonly fillTpsWithZeroes: boolean; private readonly rateComputationMethod: RateComputationMethod; private readonly dimensionsMap: DimensionsMap; @@ -49,7 +51,8 @@ export class CloudFrontDistributionMetricFactory { metricFactory: MetricFactory, props: CloudFrontDistributionMetricFactoryProps ) { - this.metricFactory = metricFactory; + super(metricFactory, props); + this.fillTpsWithZeroes = props.fillTpsWithZeroes ?? true; this.rateComputationMethod = props.rateComputationMethod ?? RateComputationMethod.AVERAGE; diff --git a/lib/monitoring/aws-cloudwatch/CloudWatchLogsMetricFactory.ts b/lib/monitoring/aws-cloudwatch/CloudWatchLogsMetricFactory.ts index 9cee162d..799cb565 100644 --- a/lib/monitoring/aws-cloudwatch/CloudWatchLogsMetricFactory.ts +++ b/lib/monitoring/aws-cloudwatch/CloudWatchLogsMetricFactory.ts @@ -1,25 +1,31 @@ import { DimensionsMap } from "aws-cdk-lib/aws-cloudwatch"; -import { MetricFactory, MetricStatistic } from "../../common"; +import { + BaseMetricFactory, + BaseMetricFactoryProps, + MetricFactory, + MetricStatistic, +} from "../../common"; const CloudWatchLogsNamespace = "AWS/Logs"; -export interface CloudWatchLogsMetricFactoryProps { +export interface CloudWatchLogsMetricFactoryProps + extends BaseMetricFactoryProps { /** * Name of the log group to monitor. */ readonly logGroupName: string; } -export class CloudWatchLogsMetricFactory { - private readonly metricFactory: MetricFactory; +export class CloudWatchLogsMetricFactory extends BaseMetricFactory { private readonly dimensionsMap: DimensionsMap; constructor( metricFactory: MetricFactory, props: CloudWatchLogsMetricFactoryProps ) { - this.metricFactory = metricFactory; + super(metricFactory, props); + this.dimensionsMap = { LogGroupName: props.logGroupName, }; diff --git a/lib/monitoring/aws-codebuild/CodeBuildProjectMetricFactory.ts b/lib/monitoring/aws-codebuild/CodeBuildProjectMetricFactory.ts index 03e8186e..75e1f375 100644 --- a/lib/monitoring/aws-codebuild/CodeBuildProjectMetricFactory.ts +++ b/lib/monitoring/aws-codebuild/CodeBuildProjectMetricFactory.ts @@ -1,14 +1,19 @@ import { DimensionsMap } from "aws-cdk-lib/aws-cloudwatch"; import { IProject } from "aws-cdk-lib/aws-codebuild"; -import { MetricFactory, MetricStatistic } from "../../common"; +import { + BaseMetricFactory, + BaseMetricFactoryProps, + MetricFactory, + MetricStatistic, +} from "../../common"; -export interface CodeBuildProjectMetricFactoryProps { +export interface CodeBuildProjectMetricFactoryProps + extends BaseMetricFactoryProps { readonly project: IProject; } -export class CodeBuildProjectMetricFactory { - protected readonly metricFactory: MetricFactory; +export class CodeBuildProjectMetricFactory extends BaseMetricFactory { protected readonly dimensionsMap: DimensionsMap; protected readonly project: IProject; @@ -16,7 +21,8 @@ export class CodeBuildProjectMetricFactory { metricFactory: MetricFactory, props: CodeBuildProjectMetricFactoryProps ) { - this.metricFactory = metricFactory; + super(metricFactory, props); + this.project = props.project; this.dimensionsMap = { ProjectName: props.project.projectName, diff --git a/lib/monitoring/aws-docdb/DocumentDbMetricFactory.ts b/lib/monitoring/aws-docdb/DocumentDbMetricFactory.ts index 03da55d4..01d209f4 100644 --- a/lib/monitoring/aws-docdb/DocumentDbMetricFactory.ts +++ b/lib/monitoring/aws-docdb/DocumentDbMetricFactory.ts @@ -2,6 +2,8 @@ import { DimensionsMap } from "aws-cdk-lib/aws-cloudwatch"; import { IDatabaseCluster } from "aws-cdk-lib/aws-docdb"; import { + BaseMetricFactory, + BaseMetricFactoryProps, getLatencyTypeLabel, getLatencyTypeStatistic, LatencyType, @@ -11,23 +13,23 @@ import { const DocumentDbNamespace = "AWS/DocDB"; -export interface DocumentDbMetricFactoryProps { +export interface DocumentDbMetricFactoryProps extends BaseMetricFactoryProps { /** * database cluster */ readonly cluster: IDatabaseCluster; } -export class DocumentDbMetricFactory { +export class DocumentDbMetricFactory extends BaseMetricFactory { readonly clusterIdentifier: string; - protected readonly metricFactory: MetricFactory; protected readonly dimensionsMap: DimensionsMap; constructor( metricFactory: MetricFactory, props: DocumentDbMetricFactoryProps ) { - this.metricFactory = metricFactory; + super(metricFactory, props); + this.clusterIdentifier = props.cluster.clusterIdentifier; this.dimensionsMap = { DBClusterIdentifier: this.clusterIdentifier }; } diff --git a/lib/monitoring/aws-dynamo/DynamoTableGlobalSecondaryIndexMetricFactory.ts b/lib/monitoring/aws-dynamo/DynamoTableGlobalSecondaryIndexMetricFactory.ts index ead3114d..2be315f1 100644 --- a/lib/monitoring/aws-dynamo/DynamoTableGlobalSecondaryIndexMetricFactory.ts +++ b/lib/monitoring/aws-dynamo/DynamoTableGlobalSecondaryIndexMetricFactory.ts @@ -1,17 +1,22 @@ import { DimensionsMap } from "aws-cdk-lib/aws-cloudwatch"; import { ITable } from "aws-cdk-lib/aws-dynamodb"; -import { MetricFactory, MetricStatistic } from "../../common"; +import { + BaseMetricFactory, + BaseMetricFactoryProps, + MetricFactory, + MetricStatistic, +} from "../../common"; const DynamoDbNamespace = "AWS/DynamoDB"; -export interface DynamoTableGlobalSecondaryIndexMetricFactoryProps { +export interface DynamoTableGlobalSecondaryIndexMetricFactoryProps + extends BaseMetricFactoryProps { readonly table: ITable; readonly globalSecondaryIndexName: string; } -export class DynamoTableGlobalSecondaryIndexMetricFactory { - protected readonly metricFactory: MetricFactory; +export class DynamoTableGlobalSecondaryIndexMetricFactory extends BaseMetricFactory { protected readonly table: ITable; protected readonly dimensionsMap: DimensionsMap; @@ -19,7 +24,8 @@ export class DynamoTableGlobalSecondaryIndexMetricFactory { metricFactory: MetricFactory, props: DynamoTableGlobalSecondaryIndexMetricFactoryProps ) { - this.metricFactory = metricFactory; + super(metricFactory, props); + this.table = props.table; this.dimensionsMap = { TableName: props.table.tableName, diff --git a/lib/monitoring/aws-dynamo/DynamoTableMetricFactory.ts b/lib/monitoring/aws-dynamo/DynamoTableMetricFactory.ts index e3536eb9..70315c49 100644 --- a/lib/monitoring/aws-dynamo/DynamoTableMetricFactory.ts +++ b/lib/monitoring/aws-dynamo/DynamoTableMetricFactory.ts @@ -1,7 +1,12 @@ import { IMetric } from "aws-cdk-lib/aws-cloudwatch"; import { BillingMode, ITable, Operation } from "aws-cdk-lib/aws-dynamodb"; -import { MetricFactory, MetricStatistic } from "../../common"; +import { + BaseMetricFactory, + BaseMetricFactoryProps, + MetricFactory, + MetricStatistic, +} from "../../common"; const DynamoDbNamespace = "AWS/DynamoDB"; const ProvisionedLabel = "Provisioned"; @@ -9,7 +14,7 @@ const ConsumedLabel = "Consumed"; const ReadThrottleEventsLabel = "Read"; const WriteThrottleEventsLabel = "Write"; -export interface DynamoTableMetricFactoryProps { +export interface DynamoTableMetricFactoryProps extends BaseMetricFactoryProps { /** * table to monitor */ @@ -22,15 +27,15 @@ export interface DynamoTableMetricFactoryProps { readonly billingMode?: BillingMode; } -export class DynamoTableMetricFactory { - protected readonly metricFactory: MetricFactory; +export class DynamoTableMetricFactory extends BaseMetricFactory { protected readonly table: ITable; constructor( metricFactory: MetricFactory, props: DynamoTableMetricFactoryProps ) { - this.metricFactory = metricFactory; + super(metricFactory, props); + this.table = props.table; } diff --git a/lib/monitoring/aws-ec2/AutoScalingGroupMetricFactory.ts b/lib/monitoring/aws-ec2/AutoScalingGroupMetricFactory.ts index d239a3e8..eee95dda 100644 --- a/lib/monitoring/aws-ec2/AutoScalingGroupMetricFactory.ts +++ b/lib/monitoring/aws-ec2/AutoScalingGroupMetricFactory.ts @@ -1,23 +1,29 @@ import { IAutoScalingGroup } from "aws-cdk-lib/aws-autoscaling"; import { DimensionsMap } from "aws-cdk-lib/aws-cloudwatch"; -import { MetricFactory, MetricStatistic } from "../../common"; +import { + BaseMetricFactory, + BaseMetricFactoryProps, + MetricFactory, + MetricStatistic, +} from "../../common"; const AutoScalingNamespace = "AWS/AutoScaling"; -export interface AutoScalingGroupMetricFactoryProps { +export interface AutoScalingGroupMetricFactoryProps + extends BaseMetricFactoryProps { readonly autoScalingGroup: IAutoScalingGroup; } -export class AutoScalingGroupMetricFactory { - protected readonly metricFactory: MetricFactory; +export class AutoScalingGroupMetricFactory extends BaseMetricFactory { protected readonly dimensionsMap: DimensionsMap; constructor( metricFactory: MetricFactory, props: AutoScalingGroupMetricFactoryProps ) { - this.metricFactory = metricFactory; + super(metricFactory, props); + this.dimensionsMap = { AutoScalingGroupName: props.autoScalingGroup.autoScalingGroupName, }; diff --git a/lib/monitoring/aws-ec2/EC2MetricFactory.ts b/lib/monitoring/aws-ec2/EC2MetricFactory.ts index a422ae2e..dbbb4daa 100644 --- a/lib/monitoring/aws-ec2/EC2MetricFactory.ts +++ b/lib/monitoring/aws-ec2/EC2MetricFactory.ts @@ -1,7 +1,12 @@ import { IAutoScalingGroup } from "aws-cdk-lib/aws-autoscaling"; import { DimensionsMap, IMetric } from "aws-cdk-lib/aws-cloudwatch"; -import { MetricFactory, MetricStatistic } from "../../common"; +import { + BaseMetricFactory, + BaseMetricFactoryProps, + MetricFactory, + MetricStatistic, +} from "../../common"; const EC2Namespace = "AWS/EC2"; @@ -123,7 +128,7 @@ function resolveStrategy( } } -export interface EC2MetricFactoryProps { +export interface EC2MetricFactoryProps extends BaseMetricFactoryProps { /** * Auto-Scaling Group to monitor. * @default - no Auto-Scaling Group filter @@ -136,12 +141,12 @@ export interface EC2MetricFactoryProps { readonly instanceIds?: string[]; } -export class EC2MetricFactory { - protected readonly metricFactory: MetricFactory; +export class EC2MetricFactory extends BaseMetricFactory { protected readonly strategy: IEC2MetricFactoryStrategy; constructor(metricFactory: MetricFactory, props: EC2MetricFactoryProps) { - this.metricFactory = metricFactory; + super(metricFactory, props); + this.strategy = resolveStrategy(props); } diff --git a/lib/monitoring/aws-ecs-patterns/BaseServiceMetricFactory.ts b/lib/monitoring/aws-ecs-patterns/BaseServiceMetricFactory.ts index 5113f722..188931b5 100644 --- a/lib/monitoring/aws-ecs-patterns/BaseServiceMetricFactory.ts +++ b/lib/monitoring/aws-ecs-patterns/BaseServiceMetricFactory.ts @@ -1,7 +1,12 @@ import { DimensionsMap } from "aws-cdk-lib/aws-cloudwatch"; import { IBaseService } from "aws-cdk-lib/aws-ecs"; -import { MetricFactory, MetricStatistic } from "../../common"; +import { + BaseMetricFactory, + BaseMetricFactoryProps, + MetricFactory, + MetricStatistic, +} from "../../common"; const EcsNamespace = "AWS/ECS"; const EcsContainerInsightsNamespace = "ECS/ContainerInsights"; @@ -9,15 +14,14 @@ const EcsContainerInsightsNamespace = "ECS/ContainerInsights"; /** * Props to create BaseServiceMetricFactory. */ -export interface BaseServiceMetricFactoryProps { +export interface BaseServiceMetricFactoryProps extends BaseMetricFactoryProps { readonly service: IBaseService; } /** * Metric factory for a base service (parent class for e.g. Fargate and EC2 services). */ -export class BaseServiceMetricFactory { - protected readonly metricFactory: MetricFactory; +export class BaseServiceMetricFactory extends BaseMetricFactory { protected readonly dimensionsMap: DimensionsMap; /** * @deprecated This isn't required by cdk-monitoring-constructs anymore; use your own reference. @@ -28,7 +32,8 @@ export class BaseServiceMetricFactory { metricFactory: MetricFactory, props: BaseServiceMetricFactoryProps ) { - this.metricFactory = metricFactory; + super(metricFactory, props); + this.dimensionsMap = { ClusterName: props.service.cluster.clusterName, ServiceName: props.service.serviceName, diff --git a/lib/monitoring/aws-elasticache/ElastiCacheClusterMetricFactory.ts b/lib/monitoring/aws-elasticache/ElastiCacheClusterMetricFactory.ts index 89c13b8c..225cc841 100644 --- a/lib/monitoring/aws-elasticache/ElastiCacheClusterMetricFactory.ts +++ b/lib/monitoring/aws-elasticache/ElastiCacheClusterMetricFactory.ts @@ -1,6 +1,11 @@ import { DimensionsMap } from "aws-cdk-lib/aws-cloudwatch"; -import { MetricFactory, MetricStatistic } from "../../common"; +import { + BaseMetricFactory, + BaseMetricFactoryProps, + MetricFactory, + MetricStatistic, +} from "../../common"; const Namespace = "AWS/ElastiCache"; @@ -9,7 +14,8 @@ export enum ElastiCacheClusterType { REDIS, } -export interface ElastiCacheClusterMetricFactoryProps { +export interface ElastiCacheClusterMetricFactoryProps + extends BaseMetricFactoryProps { /** * Cluster to monitor * @default - monitor all clusters @@ -20,15 +26,15 @@ export interface ElastiCacheClusterMetricFactoryProps { /** * @see https://docs.aws.amazon.com/AmazonElastiCache/latest/mem-ug/CacheMetrics.html */ -export class ElastiCacheClusterMetricFactory { - protected readonly metricFactory: MetricFactory; +export class ElastiCacheClusterMetricFactory extends BaseMetricFactory { protected readonly dimensionsMap: DimensionsMap; constructor( metricFactory: MetricFactory, props: ElastiCacheClusterMetricFactoryProps ) { - this.metricFactory = metricFactory; + super(metricFactory, props); + this.dimensionsMap = {}; if (props.clusterId) { this.dimensionsMap.CacheClusterId = props.clusterId; diff --git a/lib/monitoring/aws-glue/GlueJobMetricFactory.ts b/lib/monitoring/aws-glue/GlueJobMetricFactory.ts index ea1b982a..11f323ee 100644 --- a/lib/monitoring/aws-glue/GlueJobMetricFactory.ts +++ b/lib/monitoring/aws-glue/GlueJobMetricFactory.ts @@ -1,6 +1,8 @@ import { DimensionsMap } from "aws-cdk-lib/aws-cloudwatch"; import { + BaseMetricFactory, + BaseMetricFactoryProps, MetricFactory, MetricStatistic, RateComputationMethod, @@ -8,7 +10,7 @@ import { const GlueNamespace = "Glue"; -export interface GlueJobMetricFactoryProps { +export interface GlueJobMetricFactoryProps extends BaseMetricFactoryProps { readonly jobName: string; /** * @default - average @@ -16,14 +18,14 @@ export interface GlueJobMetricFactoryProps { readonly rateComputationMethod?: RateComputationMethod; } -export class GlueJobMetricFactory { - protected readonly metricFactory: MetricFactory; +export class GlueJobMetricFactory extends BaseMetricFactory { protected readonly rateComputationMethod: RateComputationMethod; protected readonly dimensionsMap: DimensionsMap; protected readonly typeCountDimensionsMap: DimensionsMap; constructor(metricFactory: MetricFactory, props: GlueJobMetricFactoryProps) { - this.metricFactory = metricFactory; + super(metricFactory, props); + this.rateComputationMethod = props.rateComputationMethod ?? RateComputationMethod.AVERAGE; this.dimensionsMap = { diff --git a/lib/monitoring/aws-kinesis/KinesisDataStreamMetricFactory.ts b/lib/monitoring/aws-kinesis/KinesisDataStreamMetricFactory.ts index 5933d01d..86d15b94 100644 --- a/lib/monitoring/aws-kinesis/KinesisDataStreamMetricFactory.ts +++ b/lib/monitoring/aws-kinesis/KinesisDataStreamMetricFactory.ts @@ -1,25 +1,31 @@ import { DimensionsMap } from "aws-cdk-lib/aws-cloudwatch"; -import { MetricFactory, MetricStatistic } from "../../common"; +import { + BaseMetricFactory, + BaseMetricFactoryProps, + MetricFactory, + MetricStatistic, +} from "../../common"; const DataStreamNamespace = "AWS/Kinesis"; -export interface KinesisDataStreamMetricFactoryProps { +export interface KinesisDataStreamMetricFactoryProps + extends BaseMetricFactoryProps { readonly streamName: string; } /** * @see https://docs.aws.amazon.com/streams/latest/dev/monitoring-with-cloudwatch.html */ -export class KinesisDataStreamMetricFactory { - protected readonly metricFactory: MetricFactory; +export class KinesisDataStreamMetricFactory extends BaseMetricFactory { protected readonly dimensionsMap: DimensionsMap; constructor( metricFactory: MetricFactory, props: KinesisDataStreamMetricFactoryProps ) { - this.metricFactory = metricFactory; + super(metricFactory, props); + this.dimensionsMap = { StreamName: props.streamName, }; diff --git a/lib/monitoring/aws-kinesis/KinesisFirehoseMetricFactory.ts b/lib/monitoring/aws-kinesis/KinesisFirehoseMetricFactory.ts index d778a474..7c713815 100644 --- a/lib/monitoring/aws-kinesis/KinesisFirehoseMetricFactory.ts +++ b/lib/monitoring/aws-kinesis/KinesisFirehoseMetricFactory.ts @@ -1,25 +1,31 @@ import { DimensionsMap } from "aws-cdk-lib/aws-cloudwatch"; -import { MetricFactory, MetricStatistic } from "../../common"; +import { + BaseMetricFactory, + BaseMetricFactoryProps, + MetricFactory, + MetricStatistic, +} from "../../common"; const FirehoseNamespace = "AWS/Firehose"; -export interface KinesisFirehoseMetricFactoryProps { +export interface KinesisFirehoseMetricFactoryProps + extends BaseMetricFactoryProps { readonly deliveryStreamName: string; } /** * @see https://docs.aws.amazon.com/firehose/latest/dev/monitoring-with-cloudwatch-metrics.html */ -export class KinesisFirehoseMetricFactory { - protected readonly metricFactory: MetricFactory; +export class KinesisFirehoseMetricFactory extends BaseMetricFactory { protected readonly dimensionsMap: DimensionsMap; constructor( metricFactory: MetricFactory, props: KinesisFirehoseMetricFactoryProps ) { - this.metricFactory = metricFactory; + super(metricFactory, props); + this.dimensionsMap = { DeliveryStreamName: props.deliveryStreamName, }; diff --git a/lib/monitoring/aws-kinesisanalytics/KinesisDataAnalyticsMetricFactory.ts b/lib/monitoring/aws-kinesisanalytics/KinesisDataAnalyticsMetricFactory.ts index 6c53aa1c..1229dab4 100644 --- a/lib/monitoring/aws-kinesisanalytics/KinesisDataAnalyticsMetricFactory.ts +++ b/lib/monitoring/aws-kinesisanalytics/KinesisDataAnalyticsMetricFactory.ts @@ -1,8 +1,14 @@ import { DimensionsMap } from "aws-cdk-lib/aws-cloudwatch"; -import { MetricFactory, MetricStatistic } from "../../common"; - -export interface KinesisDataAnalyticsMetricFactoryProps { +import { + BaseMetricFactory, + BaseMetricFactoryProps, + MetricFactory, + MetricStatistic, +} from "../../common"; + +export interface KinesisDataAnalyticsMetricFactoryProps + extends BaseMetricFactoryProps { readonly application: string; } @@ -18,15 +24,15 @@ interface MetricsSpec { /** * @see https://docs.aws.amazon.com/kinesisanalytics/latest/java/metrics-dimensions.html */ -export class KinesisDataAnalyticsMetricFactory { - protected readonly metricFactory: MetricFactory; +export class KinesisDataAnalyticsMetricFactory extends BaseMetricFactory { protected readonly dimensionsMap: DimensionsMap; constructor( metricFactory: MetricFactory, props: KinesisDataAnalyticsMetricFactoryProps ) { - this.metricFactory = metricFactory; + super(metricFactory, props); + this.dimensionsMap = { Application: props.application, }; diff --git a/lib/monitoring/aws-lambda/LambdaFunctionMetricFactory.ts b/lib/monitoring/aws-lambda/LambdaFunctionMetricFactory.ts index 8aa54234..c1de89ca 100644 --- a/lib/monitoring/aws-lambda/LambdaFunctionMetricFactory.ts +++ b/lib/monitoring/aws-lambda/LambdaFunctionMetricFactory.ts @@ -1,6 +1,8 @@ import { IFunction } from "aws-cdk-lib/aws-lambda"; import { + BaseMetricFactory, + BaseMetricFactoryProps, LatencyType, MetricFactory, MetricStatistic, @@ -9,7 +11,8 @@ import { getLatencyTypeStatistic, } from "../../common"; -export interface LambdaFunctionMetricFactoryProps { +export interface LambdaFunctionMetricFactoryProps + extends BaseMetricFactoryProps { readonly lambdaFunction: IFunction; /** * @default - true @@ -30,8 +33,7 @@ export interface LambdaFunctionMetricFactoryProps { readonly lambdaInsightsEnabled?: boolean; } -export class LambdaFunctionMetricFactory { - protected readonly metricFactory: MetricFactory; +export class LambdaFunctionMetricFactory extends BaseMetricFactory { protected readonly lambdaFunction: IFunction; protected readonly fillTpsWithZeroes: boolean; protected readonly rateComputationMethod: RateComputationMethod; @@ -40,7 +42,8 @@ export class LambdaFunctionMetricFactory { metricFactory: MetricFactory, props: LambdaFunctionMetricFactoryProps ) { - this.metricFactory = metricFactory; + super(metricFactory, props); + this.lambdaFunction = props.lambdaFunction; this.fillTpsWithZeroes = props.fillTpsWithZeroes ?? true; this.rateComputationMethod = diff --git a/lib/monitoring/aws-loadbalancing/ApplicationLoadBalancerMetricFactory.ts b/lib/monitoring/aws-loadbalancing/ApplicationLoadBalancerMetricFactory.ts index 0c9bca6b..20c1f1f6 100644 --- a/lib/monitoring/aws-loadbalancing/ApplicationLoadBalancerMetricFactory.ts +++ b/lib/monitoring/aws-loadbalancing/ApplicationLoadBalancerMetricFactory.ts @@ -8,6 +8,8 @@ import { BaseLoadBalancerMetricFactoryProps, } from "./LoadBalancerMetricFactory"; import { + BaseMetricFactory, + BaseMetricFactoryProps, HealthyMetricColor, MetricFactory, MetricStatistic, @@ -18,7 +20,8 @@ import { * Props to create ApplicationLoadBalancerMetricFactory. */ export interface ApplicationLoadBalancerMetricFactoryProps - extends BaseLoadBalancerMetricFactoryProps { + extends BaseLoadBalancerMetricFactoryProps, + BaseMetricFactoryProps { readonly applicationLoadBalancer: IApplicationLoadBalancer; readonly applicationTargetGroup: IApplicationTargetGroup; } @@ -27,9 +30,9 @@ export interface ApplicationLoadBalancerMetricFactoryProps * Metric factory to create metrics for application load-balanced service. */ export class ApplicationLoadBalancerMetricFactory + extends BaseMetricFactory implements ILoadBalancerMetricFactory { - protected readonly metricFactory: MetricFactory; protected readonly applicationLoadBalancer: IApplicationLoadBalancer; protected readonly applicationTargetGroup: IApplicationTargetGroup; protected readonly invertStatisticsOfTaskCountEnabled: boolean; @@ -38,7 +41,8 @@ export class ApplicationLoadBalancerMetricFactory metricFactory: MetricFactory, props: ApplicationLoadBalancerMetricFactoryProps ) { - this.metricFactory = metricFactory; + super(metricFactory, props); + this.applicationLoadBalancer = props.applicationLoadBalancer; this.applicationTargetGroup = props.applicationTargetGroup; this.invertStatisticsOfTaskCountEnabled = diff --git a/lib/monitoring/aws-loadbalancing/NetworkLoadBalancerMetricFactory.ts b/lib/monitoring/aws-loadbalancing/NetworkLoadBalancerMetricFactory.ts index 6dec32f8..825d7420 100644 --- a/lib/monitoring/aws-loadbalancing/NetworkLoadBalancerMetricFactory.ts +++ b/lib/monitoring/aws-loadbalancing/NetworkLoadBalancerMetricFactory.ts @@ -8,6 +8,8 @@ import { BaseLoadBalancerMetricFactoryProps, } from "./LoadBalancerMetricFactory"; import { + BaseMetricFactory, + BaseMetricFactoryProps, HealthyMetricColor, MetricFactory, MetricStatistic, @@ -18,7 +20,8 @@ import { * Props to create NetworkLoadBalancerMetricFactory. */ export interface NetworkLoadBalancerMetricFactoryProps - extends BaseLoadBalancerMetricFactoryProps { + extends BaseLoadBalancerMetricFactoryProps, + BaseMetricFactoryProps { readonly networkLoadBalancer: INetworkLoadBalancer; readonly networkTargetGroup: INetworkTargetGroup; } @@ -27,9 +30,9 @@ export interface NetworkLoadBalancerMetricFactoryProps * Metric factory to create metrics for network load-balanced service. */ export class NetworkLoadBalancerMetricFactory + extends BaseMetricFactory implements ILoadBalancerMetricFactory { - protected readonly metricFactory: MetricFactory; protected readonly networkLoadBalancer: INetworkLoadBalancer; protected readonly networkTargetGroup: INetworkTargetGroup; protected readonly invertStatisticsOfTaskCountEnabled: boolean; @@ -38,7 +41,8 @@ export class NetworkLoadBalancerMetricFactory metricFactory: MetricFactory, props: NetworkLoadBalancerMetricFactoryProps ) { - this.metricFactory = metricFactory; + super(metricFactory, props); + this.networkLoadBalancer = props.networkLoadBalancer; this.networkTargetGroup = props.networkTargetGroup; this.invertStatisticsOfTaskCountEnabled = diff --git a/lib/monitoring/aws-opensearch/OpenSearchClusterMetricFactory.ts b/lib/monitoring/aws-opensearch/OpenSearchClusterMetricFactory.ts index 237d781f..6ea0e1a9 100644 --- a/lib/monitoring/aws-opensearch/OpenSearchClusterMetricFactory.ts +++ b/lib/monitoring/aws-opensearch/OpenSearchClusterMetricFactory.ts @@ -5,12 +5,15 @@ import { OpenSearchBackportedMetrics, } from "./OpenSearchBackportedMetrics"; import { + BaseMetricFactory, + BaseMetricFactoryProps, MetricFactory, MetricStatistic, RateComputationMethod, } from "../../common"; -export interface OpenSearchClusterMetricFactoryProps { +export interface OpenSearchClusterMetricFactoryProps + extends BaseMetricFactoryProps { readonly domain: Domain; /** * @default - true @@ -22,8 +25,7 @@ export interface OpenSearchClusterMetricFactoryProps { readonly rateComputationMethod?: RateComputationMethod; } -export class OpenSearchClusterMetricFactory { - protected readonly metricFactory: MetricFactory; +export class OpenSearchClusterMetricFactory extends BaseMetricFactory { protected readonly domainMetrics: OpenSearchBackportedMetrics; protected readonly fillTpsWithZeroes: boolean; protected readonly rateComputationMethod: RateComputationMethod; @@ -32,7 +34,8 @@ export class OpenSearchClusterMetricFactory { metricFactory: MetricFactory, props: OpenSearchClusterMetricFactoryProps ) { - this.metricFactory = metricFactory; + super(metricFactory, props); + this.domainMetrics = new OpenSearchBackportedMetrics(props.domain); this.fillTpsWithZeroes = props.fillTpsWithZeroes ?? true; this.rateComputationMethod = diff --git a/lib/monitoring/aws-rds/RdsClusterMetricFactory.ts b/lib/monitoring/aws-rds/RdsClusterMetricFactory.ts index 04dcf9b7..1f3d8f64 100644 --- a/lib/monitoring/aws-rds/RdsClusterMetricFactory.ts +++ b/lib/monitoring/aws-rds/RdsClusterMetricFactory.ts @@ -1,11 +1,16 @@ import { DimensionsMap } from "aws-cdk-lib/aws-cloudwatch"; import { IDatabaseCluster, ServerlessCluster } from "aws-cdk-lib/aws-rds"; -import { MetricFactory, MetricStatistic } from "../../common"; +import { + BaseMetricFactory, + BaseMetricFactoryProps, + MetricFactory, + MetricStatistic, +} from "../../common"; const RdsNamespace = "AWS/RDS"; -export interface RdsClusterMetricFactoryProps { +export interface RdsClusterMetricFactoryProps extends BaseMetricFactoryProps { /** * database cluster identifier (either this or `cluster` need to be specified) * @deprecated please use `cluster` instead @@ -17,17 +22,17 @@ export interface RdsClusterMetricFactoryProps { readonly cluster?: IDatabaseCluster | ServerlessCluster; } -export class RdsClusterMetricFactory { +export class RdsClusterMetricFactory extends BaseMetricFactory { readonly clusterIdentifier: string; readonly cluster?: IDatabaseCluster | ServerlessCluster; - protected readonly metricFactory: MetricFactory; protected readonly dimensionsMap: DimensionsMap; constructor( metricFactory: MetricFactory, props: RdsClusterMetricFactoryProps ) { - this.metricFactory = metricFactory; + super(metricFactory, props); + this.cluster = props.cluster; this.clusterIdentifier = RdsClusterMetricFactory.resolveDbClusterIdentifier(props); diff --git a/lib/monitoring/aws-rds/RdsInstanceMetricFactory.ts b/lib/monitoring/aws-rds/RdsInstanceMetricFactory.ts index a6b13f0f..0fbece63 100644 --- a/lib/monitoring/aws-rds/RdsInstanceMetricFactory.ts +++ b/lib/monitoring/aws-rds/RdsInstanceMetricFactory.ts @@ -2,6 +2,8 @@ import { DimensionsMap } from "aws-cdk-lib/aws-cloudwatch"; import { IDatabaseInstance } from "aws-cdk-lib/aws-rds"; import { + BaseMetricFactory, + BaseMetricFactoryProps, LatencyType, MetricFactory, MetricStatistic, @@ -11,24 +13,24 @@ import { const RdsNamespace = "AWS/RDS"; -export interface RdsInstanceMetricFactoryProps { +export interface RdsInstanceMetricFactoryProps extends BaseMetricFactoryProps { /** * database instance */ readonly instance: IDatabaseInstance; } -export class RdsInstanceMetricFactory { +export class RdsInstanceMetricFactory extends BaseMetricFactory { readonly instanceIdentifier: string; readonly instance: IDatabaseInstance; - protected readonly metricFactory: MetricFactory; protected readonly dimensionsMap: DimensionsMap; constructor( metricFactory: MetricFactory, props: RdsInstanceMetricFactoryProps ) { - this.metricFactory = metricFactory; + super(metricFactory, props); + this.instance = props.instance; this.instanceIdentifier = props.instance.instanceIdentifier; this.dimensionsMap = { diff --git a/lib/monitoring/aws-redshift/RedshiftClusterMetricFactory.ts b/lib/monitoring/aws-redshift/RedshiftClusterMetricFactory.ts index 3c0f6077..ea18d007 100644 --- a/lib/monitoring/aws-redshift/RedshiftClusterMetricFactory.ts +++ b/lib/monitoring/aws-redshift/RedshiftClusterMetricFactory.ts @@ -1,24 +1,30 @@ import { DimensionsMap } from "aws-cdk-lib/aws-cloudwatch"; -import { MetricFactory, MetricStatistic } from "../../common"; +import { + BaseMetricFactory, + BaseMetricFactoryProps, + MetricFactory, + MetricStatistic, +} from "../../common"; const RedshiftNamespace = "AWS/Redshift"; type QueryLatencyClass = "short" | "medium" | "long"; -export interface RedshiftClusterMetricFactoryProps { +export interface RedshiftClusterMetricFactoryProps + extends BaseMetricFactoryProps { readonly clusterIdentifier: string; } -export class RedshiftClusterMetricFactory { - protected readonly metricFactory: MetricFactory; +export class RedshiftClusterMetricFactory extends BaseMetricFactory { protected readonly dimensionsMap: DimensionsMap; constructor( metricFactory: MetricFactory, props: RedshiftClusterMetricFactoryProps ) { - this.metricFactory = metricFactory; + super(metricFactory, props); + this.dimensionsMap = { ClusterIdentifier: props.clusterIdentifier, }; diff --git a/lib/monitoring/aws-s3/S3BucketMetricFactory.ts b/lib/monitoring/aws-s3/S3BucketMetricFactory.ts index 1f0f86f3..5249c32e 100644 --- a/lib/monitoring/aws-s3/S3BucketMetricFactory.ts +++ b/lib/monitoring/aws-s3/S3BucketMetricFactory.ts @@ -1,6 +1,11 @@ import { IBucket } from "aws-cdk-lib/aws-s3"; -import { MetricFactory, MetricStatistic } from "../../common"; +import { + BaseMetricFactory, + BaseMetricFactoryProps, + MetricFactory, + MetricStatistic, +} from "../../common"; const Namespace = "AWS/S3"; @@ -23,17 +28,17 @@ export enum StorageType { STANDARD_STORAGE = "StandardStorage", } -export interface S3BucketMetricFactoryProps { +export interface S3BucketMetricFactoryProps extends BaseMetricFactoryProps { readonly bucket: IBucket; readonly storageType?: StorageType; } -export class S3BucketMetricFactory { - protected readonly metricFactory: MetricFactory; +export class S3BucketMetricFactory extends BaseMetricFactory { protected readonly props: S3BucketMetricFactoryProps; constructor(metricFactory: MetricFactory, props: S3BucketMetricFactoryProps) { - this.metricFactory = metricFactory; + super(metricFactory, props); + this.props = props; } diff --git a/lib/monitoring/aws-secretsmanager/SecretsManagerSecretMetricFactory.ts b/lib/monitoring/aws-secretsmanager/SecretsManagerSecretMetricFactory.ts index e0b66ff1..ff6d62bd 100644 --- a/lib/monitoring/aws-secretsmanager/SecretsManagerSecretMetricFactory.ts +++ b/lib/monitoring/aws-secretsmanager/SecretsManagerSecretMetricFactory.ts @@ -1,17 +1,22 @@ import { DimensionsMap } from "aws-cdk-lib/aws-cloudwatch"; import { ISecret } from "aws-cdk-lib/aws-secretsmanager"; -import { MetricFactory, MetricStatistic } from "../../common"; +import { + BaseMetricFactory, + BaseMetricFactoryProps, + MetricFactory, + MetricStatistic, +} from "../../common"; -export interface SecretsManagerSecretMetricFactoryProps { +export interface SecretsManagerSecretMetricFactoryProps + extends BaseMetricFactoryProps { readonly secret: ISecret; } -export class SecretsManagerSecretMetricFactory { +export class SecretsManagerSecretMetricFactory extends BaseMetricFactory { static readonly Namespace = "SecretsManager"; static readonly MetricNameDaysSinceLastChange = "DaysSinceLastChange"; static readonly MetricNameDaysSinceLastRotation = "DaysSinceLastRotation"; - protected readonly metricFactory: MetricFactory; protected readonly dimensionsMap: DimensionsMap; protected readonly secret: ISecret; @@ -19,7 +24,8 @@ export class SecretsManagerSecretMetricFactory { metricFactory: MetricFactory, props: SecretsManagerSecretMetricFactoryProps ) { - this.metricFactory = metricFactory; + super(metricFactory, props); + this.secret = props.secret; this.dimensionsMap = { SecretName: props.secret.secretName, diff --git a/lib/monitoring/aws-sns/SnsTopicMetricFactory.ts b/lib/monitoring/aws-sns/SnsTopicMetricFactory.ts index 64fef54c..422ec363 100644 --- a/lib/monitoring/aws-sns/SnsTopicMetricFactory.ts +++ b/lib/monitoring/aws-sns/SnsTopicMetricFactory.ts @@ -1,17 +1,21 @@ import { ITopic } from "aws-cdk-lib/aws-sns"; -import { MetricFactory } from "../../common"; +import { + BaseMetricFactory, + BaseMetricFactoryProps, + MetricFactory, +} from "../../common"; -export interface SnsTopicMetricFactoryProps { +export interface SnsTopicMetricFactoryProps extends BaseMetricFactoryProps { readonly topic: ITopic; } -export class SnsTopicMetricFactory { - protected readonly metricFactory: MetricFactory; +export class SnsTopicMetricFactory extends BaseMetricFactory { protected readonly topic: ITopic; constructor(metricFactory: MetricFactory, props: SnsTopicMetricFactoryProps) { - this.metricFactory = metricFactory; + super(metricFactory, props); + this.topic = props.topic; } diff --git a/lib/monitoring/aws-sqs/SqsQueueMetricFactory.ts b/lib/monitoring/aws-sqs/SqsQueueMetricFactory.ts index 2b8e1ca2..77b74879 100644 --- a/lib/monitoring/aws-sqs/SqsQueueMetricFactory.ts +++ b/lib/monitoring/aws-sqs/SqsQueueMetricFactory.ts @@ -1,17 +1,22 @@ import { IQueue } from "aws-cdk-lib/aws-sqs"; -import { MetricFactory, MetricStatistic } from "../../common"; +import { + BaseMetricFactory, + BaseMetricFactoryProps, + MetricFactory, + MetricStatistic, +} from "../../common"; -export interface SqsQueueMetricFactoryProps { +export interface SqsQueueMetricFactoryProps extends BaseMetricFactoryProps { readonly queue: IQueue; } -export class SqsQueueMetricFactory { - protected readonly metricFactory: MetricFactory; +export class SqsQueueMetricFactory extends BaseMetricFactory { protected readonly queue: IQueue; constructor(metricFactory: MetricFactory, props: SqsQueueMetricFactoryProps) { - this.metricFactory = metricFactory; + super(metricFactory, props); + this.queue = props.queue; } diff --git a/lib/monitoring/aws-step-functions/StepFunctionActivityMetricFactory.ts b/lib/monitoring/aws-step-functions/StepFunctionActivityMetricFactory.ts index e333c405..0c279321 100644 --- a/lib/monitoring/aws-step-functions/StepFunctionActivityMetricFactory.ts +++ b/lib/monitoring/aws-step-functions/StepFunctionActivityMetricFactory.ts @@ -2,6 +2,8 @@ import { DimensionsMap } from "aws-cdk-lib/aws-cloudwatch"; import { IActivity } from "aws-cdk-lib/aws-stepfunctions"; import { + BaseMetricFactory, + BaseMetricFactoryProps, MetricFactory, MetricStatistic, RateComputationMethod, @@ -9,7 +11,8 @@ import { const Namespace = "AWS/States"; -export interface StepFunctionActivityMetricFactoryProps { +export interface StepFunctionActivityMetricFactoryProps + extends BaseMetricFactoryProps { readonly activity: IActivity; /** * @default - average @@ -17,8 +20,7 @@ export interface StepFunctionActivityMetricFactoryProps { readonly rateComputationMethod?: RateComputationMethod; } -export class StepFunctionActivityMetricFactory { - protected readonly metricFactory: MetricFactory; +export class StepFunctionActivityMetricFactory extends BaseMetricFactory { protected readonly rateComputationMethod: RateComputationMethod; protected readonly dimensionsMap: DimensionsMap; @@ -26,7 +28,8 @@ export class StepFunctionActivityMetricFactory { metricFactory: MetricFactory, props: StepFunctionActivityMetricFactoryProps ) { - this.metricFactory = metricFactory; + super(metricFactory, props); + this.rateComputationMethod = RateComputationMethod.AVERAGE; this.dimensionsMap = { ActivityArn: props.activity.activityArn, diff --git a/lib/monitoring/aws-step-functions/StepFunctionLambdaIntegrationMetricFactory.ts b/lib/monitoring/aws-step-functions/StepFunctionLambdaIntegrationMetricFactory.ts index c20ff2dc..36294836 100644 --- a/lib/monitoring/aws-step-functions/StepFunctionLambdaIntegrationMetricFactory.ts +++ b/lib/monitoring/aws-step-functions/StepFunctionLambdaIntegrationMetricFactory.ts @@ -2,6 +2,8 @@ import { DimensionsMap } from "aws-cdk-lib/aws-cloudwatch"; import { IFunction } from "aws-cdk-lib/aws-lambda"; import { + BaseMetricFactory, + BaseMetricFactoryProps, MetricFactory, MetricStatistic, RateComputationMethod, @@ -9,7 +11,8 @@ import { const Namespace = "AWS/States"; -export interface StepFunctionLambdaIntegrationMetricFactoryProps { +export interface StepFunctionLambdaIntegrationMetricFactoryProps + extends BaseMetricFactoryProps { readonly lambdaFunction: IFunction; /** * @default - average @@ -17,8 +20,7 @@ export interface StepFunctionLambdaIntegrationMetricFactoryProps { readonly rateComputationMethod?: RateComputationMethod; } -export class StepFunctionLambdaIntegrationMetricFactory { - protected readonly metricFactory: MetricFactory; +export class StepFunctionLambdaIntegrationMetricFactory extends BaseMetricFactory { protected readonly rateComputationMethod: RateComputationMethod; protected readonly dimensionsMap: DimensionsMap; @@ -26,7 +28,8 @@ export class StepFunctionLambdaIntegrationMetricFactory { metricFactory: MetricFactory, props: StepFunctionLambdaIntegrationMetricFactoryProps ) { - this.metricFactory = metricFactory; + super(metricFactory, props); + this.rateComputationMethod = RateComputationMethod.AVERAGE; this.dimensionsMap = { LambdaFunctionArn: props.lambdaFunction.functionArn, diff --git a/lib/monitoring/aws-step-functions/StepFunctionMetricFactory.ts b/lib/monitoring/aws-step-functions/StepFunctionMetricFactory.ts index b337e10c..68172f58 100644 --- a/lib/monitoring/aws-step-functions/StepFunctionMetricFactory.ts +++ b/lib/monitoring/aws-step-functions/StepFunctionMetricFactory.ts @@ -2,6 +2,8 @@ import { DimensionsMap } from "aws-cdk-lib/aws-cloudwatch"; import { IStateMachine } from "aws-cdk-lib/aws-stepfunctions"; import { + BaseMetricFactory, + BaseMetricFactoryProps, MetricFactory, MetricStatistic, RateComputationMethod, @@ -9,7 +11,7 @@ import { const Namespace = "AWS/States"; -export interface StepFunctionMetricFactoryProps { +export interface StepFunctionMetricFactoryProps extends BaseMetricFactoryProps { readonly stateMachine: IStateMachine; /** * @default - average @@ -17,8 +19,7 @@ export interface StepFunctionMetricFactoryProps { readonly rateComputationMethod?: RateComputationMethod; } -export class StepFunctionMetricFactory { - protected readonly metricFactory: MetricFactory; +export class StepFunctionMetricFactory extends BaseMetricFactory { protected readonly rateComputationMethod: RateComputationMethod; protected readonly dimensionsMap: DimensionsMap; @@ -26,7 +27,8 @@ export class StepFunctionMetricFactory { metricFactory: MetricFactory, props: StepFunctionMetricFactoryProps ) { - this.metricFactory = metricFactory; + super(metricFactory, props); + this.rateComputationMethod = RateComputationMethod.AVERAGE; this.dimensionsMap = { StateMachineArn: props.stateMachine.stateMachineArn, diff --git a/lib/monitoring/aws-step-functions/StepFunctionServiceIntegrationMetricFactory.ts b/lib/monitoring/aws-step-functions/StepFunctionServiceIntegrationMetricFactory.ts index e806b5bf..37d71a19 100644 --- a/lib/monitoring/aws-step-functions/StepFunctionServiceIntegrationMetricFactory.ts +++ b/lib/monitoring/aws-step-functions/StepFunctionServiceIntegrationMetricFactory.ts @@ -1,6 +1,8 @@ import { DimensionsMap } from "aws-cdk-lib/aws-cloudwatch"; import { + BaseMetricFactory, + BaseMetricFactoryProps, MetricFactory, MetricStatistic, RateComputationMethod, @@ -8,7 +10,8 @@ import { const Namespace = "AWS/States"; -export interface StepFunctionServiceIntegrationMetricFactoryProps { +export interface StepFunctionServiceIntegrationMetricFactoryProps + extends BaseMetricFactoryProps { readonly serviceIntegrationResourceArn: string; /** * @default - average @@ -16,8 +19,7 @@ export interface StepFunctionServiceIntegrationMetricFactoryProps { readonly rateComputationMethod?: RateComputationMethod; } -export class StepFunctionServiceIntegrationMetricFactory { - protected readonly metricFactory: MetricFactory; +export class StepFunctionServiceIntegrationMetricFactory extends BaseMetricFactory { protected readonly rateComputationMethod: RateComputationMethod; protected readonly dimensionsMap: DimensionsMap; @@ -25,7 +27,8 @@ export class StepFunctionServiceIntegrationMetricFactory { metricFactory: MetricFactory, props: StepFunctionServiceIntegrationMetricFactoryProps ) { - this.metricFactory = metricFactory; + super(metricFactory, props); + this.rateComputationMethod = RateComputationMethod.AVERAGE; this.dimensionsMap = { ServiceIntegrationResourceArn: props.serviceIntegrationResourceArn, diff --git a/lib/monitoring/aws-synthetics/SyntheticsCanaryMetricFactory.ts b/lib/monitoring/aws-synthetics/SyntheticsCanaryMetricFactory.ts index a8f6e78b..dc3c5b5f 100644 --- a/lib/monitoring/aws-synthetics/SyntheticsCanaryMetricFactory.ts +++ b/lib/monitoring/aws-synthetics/SyntheticsCanaryMetricFactory.ts @@ -1,6 +1,8 @@ import { DimensionsMap } from "aws-cdk-lib/aws-cloudwatch"; import { Canary } from "aws-cdk-lib/aws-synthetics"; import { + BaseMetricFactory, + BaseMetricFactoryProps, MetricFactory, MetricStatistic, RateComputationMethod, @@ -8,7 +10,8 @@ import { const MetricNamespace = "CloudWatchSynthetics"; -export interface SyntheticsCanaryMetricFactoryProps { +export interface SyntheticsCanaryMetricFactoryProps + extends BaseMetricFactoryProps { /** * CloudWatch Canary to monitor */ @@ -20,9 +23,8 @@ export interface SyntheticsCanaryMetricFactoryProps { readonly rateComputationMethod?: RateComputationMethod; } -export class SyntheticsCanaryMetricFactory { +export class SyntheticsCanaryMetricFactory extends BaseMetricFactory { protected readonly canary: Canary; - protected readonly metricFactory: MetricFactory; protected readonly rateComputationMethod: RateComputationMethod; protected readonly dimensionsMap: DimensionsMap; @@ -30,8 +32,9 @@ export class SyntheticsCanaryMetricFactory { metricFactory: MetricFactory, props: SyntheticsCanaryMetricFactoryProps ) { + super(metricFactory, props); + this.canary = props.canary; - this.metricFactory = metricFactory; this.rateComputationMethod = props.rateComputationMethod ?? RateComputationMethod.AVERAGE; this.dimensionsMap = { diff --git a/lib/monitoring/aws-wafv2/WafV2MetricFactory.ts b/lib/monitoring/aws-wafv2/WafV2MetricFactory.ts index b6106494..eb69e0e4 100644 --- a/lib/monitoring/aws-wafv2/WafV2MetricFactory.ts +++ b/lib/monitoring/aws-wafv2/WafV2MetricFactory.ts @@ -1,11 +1,16 @@ import { DimensionHash } from "aws-cdk-lib/aws-cloudwatch"; import { CfnWebACL } from "aws-cdk-lib/aws-wafv2"; -import { MetricFactory, MetricStatistic } from "../../common"; +import { + BaseMetricFactory, + BaseMetricFactoryProps, + MetricFactory, + MetricStatistic, +} from "../../common"; const MetricNamespace = "AWS/WAFV2"; const AllRulesDimensionValue = "ALL"; -export interface WafV2MetricFactoryProps { +export interface WafV2MetricFactoryProps extends BaseMetricFactoryProps { readonly acl: CfnWebACL; /** @@ -17,12 +22,12 @@ export interface WafV2MetricFactoryProps { /** * https://docs.aws.amazon.com/waf/latest/developerguide/monitoring-cloudwatch.html */ -export class WafV2MetricFactory { - protected readonly metricFactory: MetricFactory; +export class WafV2MetricFactory extends BaseMetricFactory { protected readonly dimensions: DimensionHash; constructor(metricFactory: MetricFactory, props: WafV2MetricFactoryProps) { - this.metricFactory = metricFactory; + super(metricFactory, props); + this.dimensions = { Rule: AllRulesDimensionValue, WebACL: props.acl.name,