From 8e391ea6fedded314fa95b96d50ae5d6405d4bda Mon Sep 17 00:00:00 2001 From: Eugene Cheung Date: Fri, 12 Jul 2024 13:35:50 -0400 Subject: [PATCH] fix: apply account/region to more metrics --- README.md | 2 +- lib/common/metric/MetricFactory.ts | 24 ++++++ .../aws-apigateway/ApiGatewayMetricFactory.ts | 6 +- .../ApiGatewayV2HttpApiMetricFactory.ts | 6 +- .../aws-appsync/AppSyncMetricFactory.ts | 6 +- .../aws-billing/BillingMetricFactory.ts | 1 - .../aws-docdb/DocumentDbMetricFactory.ts | 6 +- ...oTableGlobalSecondaryIndexMetricFactory.ts | 4 + .../aws-dynamo/DynamoTableMetricFactory.ts | 20 +++++ .../BaseServiceMetricFactory.ts | 8 +- .../KinesisFirehoseMetricFactory.ts | 12 +++ .../LambdaFunctionEnhancedMetricFactory.ts | 2 + .../aws-lambda/LambdaFunctionMetricFactory.ts | 8 +- .../ApplicationLoadBalancerMetricFactory.ts | 7 +- .../NetworkLoadBalancerMetricFactory.ts | 7 +- .../aws-rds/RdsClusterMetricFactory.ts | 8 +- .../aws-rds/RdsInstanceMetricFactory.ts | 6 +- .../RedshiftClusterMetricFactory.ts | 20 +++++ .../aws-sqs/SqsQueueMetricFactory.ts | 12 +++ ...pFunctionLambdaIntegrationMetricFactory.ts | 3 +- .../StepFunctionMetricFactory.ts | 3 +- ...FunctionServiceIntegrationMetricFactory.ts | 6 +- .../SyntheticsCanaryMetricFactory.ts | 6 +- .../aws-wafv2/WafV2MetricFactory.ts | 4 + test/common/metric/MetricFactory.test.ts | 15 +++- .../__snapshots__/MetricFactory.test.ts.snap | 77 +++++++++++------- test/facade/MonitoringFacade.test.ts | 17 +++- .../MonitoringAspect.test.ts.snap | 12 ++- .../MonitoringFacade.test.ts.snap | 80 ++++++++----------- .../WafV2Monitoring.test.ts.snap | 4 +- 30 files changed, 259 insertions(+), 133 deletions(-) diff --git a/README.md b/README.md index d9f39d62..f2eaec23 100644 --- a/README.md +++ b/README.md @@ -457,7 +457,7 @@ The order of precedence of the region/account values is: 1. The facade's `metricFactoryDefaults` props. 1. The region/account that the stack is deployed to. -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. +Note that while this allows for cross-account cross-Region dashboarding, cross-Region alarming is not supported by CloudWatch. ### Monitoring scopes diff --git a/lib/common/metric/MetricFactory.ts b/lib/common/metric/MetricFactory.ts index 2cfebb65..173d94a4 100644 --- a/lib/common/metric/MetricFactory.ts +++ b/lib/common/metric/MetricFactory.ts @@ -351,6 +351,8 @@ export class MetricFactory { avgLabel, avgMetric.color, avgMetric.period, + this.getRegion(avgMetric), + this.getAccount(avgMetric), ); } return avgMetric; @@ -370,6 +372,8 @@ export class MetricFactory { perSecondLabel, metric.color, metric.period, + this.getRegion(metric), + this.getAccount(metric), ); case RateComputationMethod.PER_MINUTE: return this.createMetricMath( @@ -378,6 +382,8 @@ export class MetricFactory { `${labelPrefix}/m${labelAppendix}`, metric.color, metric.period, + this.getRegion(metric), + this.getAccount(metric), ); case RateComputationMethod.PER_HOUR: return this.createMetricMath( @@ -386,6 +392,8 @@ export class MetricFactory { `${labelPrefix}/h${labelAppendix}`, metric.color, metric.period, + this.getRegion(metric), + this.getAccount(metric), ); case RateComputationMethod.PER_DAY: return this.createMetricMath( @@ -394,6 +402,8 @@ export class MetricFactory { `${labelPrefix}/d${labelAppendix}`, metric.color, metric.period, + this.getRegion(metric), + this.getAccount(metric), ); } } @@ -452,4 +462,18 @@ export class MetricFactory { return copy; } + + private getAccount(metric: MetricWithAlarmSupport): string | undefined { + if (metric instanceof MathExpression) { + return metric.searchAccount; + } + return metric.account; + } + + private getRegion(metric: MetricWithAlarmSupport): string | undefined { + if (metric instanceof MathExpression) { + return metric.searchRegion; + } + return metric.region; + } } diff --git a/lib/monitoring/aws-apigateway/ApiGatewayMetricFactory.ts b/lib/monitoring/aws-apigateway/ApiGatewayMetricFactory.ts index 7dfc9829..6ec4ced0 100644 --- a/lib/monitoring/aws-apigateway/ApiGatewayMetricFactory.ts +++ b/lib/monitoring/aws-apigateway/ApiGatewayMetricFactory.ts @@ -115,9 +115,8 @@ export class ApiGatewayMetricFactory extends BaseMetricFactory { "Metric", MetricStatistic.SUM, "Label", + undefined, + Color.ORANGE, + "Namespace", + undefined, + "eu-west-1", + "01234567890", ); const metricAverage = metricFactory.toRate( @@ -186,6 +192,13 @@ test("snapshot test: toRate with detail", () => { ); expect(metricAverage).toMatchSnapshot(); + const metricAverageWithAccount = metricFactory.toRate( + metric.with({ account: "1111111111" }), + RateComputationMethod.AVERAGE, + true, + ); + expect(metricAverageWithAccount).toMatchSnapshot(); + const metricPerSecond = metricFactory.toRate( metric, RateComputationMethod.PER_SECOND, diff --git a/test/common/metric/__snapshots__/MetricFactory.test.ts.snap b/test/common/metric/__snapshots__/MetricFactory.test.ts.snap index 32f8e0fc..ee49d18b 100644 --- a/test/common/metric/__snapshots__/MetricFactory.test.ts.snap +++ b/test/common/metric/__snapshots__/MetricFactory.test.ts.snap @@ -889,12 +889,12 @@ Object { exports[`snapshot test: toRate with detail 1`] = ` Metric { - "account": undefined, - "color": undefined, + "account": "01234567890", + "color": "#ff7f0e", "dimensions": undefined, "label": "Label (avg) (min: \${MIN}, max: \${MAX})", "metricName": "Metric", - "namespace": "DummyNamespace", + "namespace": "Namespace", "period": Duration { "amount": 5, "unit": TimeUnit { @@ -903,7 +903,7 @@ Metric { "label": "minutes", }, }, - "region": undefined, + "region": "eu-west-1", "statistic": "Average", "unit": undefined, "warnings": undefined, @@ -911,8 +911,31 @@ Metric { `; exports[`snapshot test: toRate with detail 2`] = ` +Metric { + "account": "1111111111", + "color": "#ff7f0e", + "dimensions": undefined, + "label": "Label (avg) (min: \${MIN}, max: \${MAX})", + "metricName": "Metric", + "namespace": "Namespace", + "period": Duration { + "amount": 5, + "unit": TimeUnit { + "inMillis": 60000, + "isoLabel": "M", + "label": "minutes", + }, + }, + "region": "eu-west-1", + "statistic": "Average", + "unit": undefined, + "warnings": undefined, +} +`; + +exports[`snapshot test: toRate with detail 3`] = ` MathExpression { - "color": undefined, + "color": "#ff7f0e", "expression": "m1 / PERIOD(m1)", "label": "Label/s (min: \${MIN}, max: \${MAX}, avg: \${AVG})", "period": Duration { @@ -927,12 +950,12 @@ MathExpression { "searchRegion": undefined, "usingMetrics": Object { "m1": Metric { - "account": undefined, - "color": undefined, + "account": "01234567890", + "color": "#ff7f0e", "dimensions": undefined, "label": "Label", "metricName": "Metric", - "namespace": "DummyNamespace", + "namespace": "Namespace", "period": Duration { "amount": 5, "unit": TimeUnit { @@ -941,7 +964,7 @@ MathExpression { "label": "minutes", }, }, - "region": undefined, + "region": "eu-west-1", "statistic": "Sum", "unit": undefined, "warnings": undefined, @@ -950,9 +973,9 @@ MathExpression { } `; -exports[`snapshot test: toRate with detail 3`] = ` +exports[`snapshot test: toRate with detail 4`] = ` MathExpression { - "color": undefined, + "color": "#ff7f0e", "expression": "(60 * m1) / PERIOD(m1)", "label": "Label/m (min: \${MIN}, max: \${MAX}, avg: \${AVG})", "period": Duration { @@ -967,12 +990,12 @@ MathExpression { "searchRegion": undefined, "usingMetrics": Object { "m1": Metric { - "account": undefined, - "color": undefined, + "account": "01234567890", + "color": "#ff7f0e", "dimensions": undefined, "label": "Label", "metricName": "Metric", - "namespace": "DummyNamespace", + "namespace": "Namespace", "period": Duration { "amount": 5, "unit": TimeUnit { @@ -981,7 +1004,7 @@ MathExpression { "label": "minutes", }, }, - "region": undefined, + "region": "eu-west-1", "statistic": "Sum", "unit": undefined, "warnings": undefined, @@ -990,9 +1013,9 @@ MathExpression { } `; -exports[`snapshot test: toRate with detail 4`] = ` +exports[`snapshot test: toRate with detail 5`] = ` MathExpression { - "color": undefined, + "color": "#ff7f0e", "expression": "(3600 * m1) / PERIOD(m1)", "label": "Label/h (min: \${MIN}, max: \${MAX}, avg: \${AVG})", "period": Duration { @@ -1007,12 +1030,12 @@ MathExpression { "searchRegion": undefined, "usingMetrics": Object { "m1": Metric { - "account": undefined, - "color": undefined, + "account": "01234567890", + "color": "#ff7f0e", "dimensions": undefined, "label": "Label", "metricName": "Metric", - "namespace": "DummyNamespace", + "namespace": "Namespace", "period": Duration { "amount": 5, "unit": TimeUnit { @@ -1021,7 +1044,7 @@ MathExpression { "label": "minutes", }, }, - "region": undefined, + "region": "eu-west-1", "statistic": "Sum", "unit": undefined, "warnings": undefined, @@ -1030,9 +1053,9 @@ MathExpression { } `; -exports[`snapshot test: toRate with detail 5`] = ` +exports[`snapshot test: toRate with detail 6`] = ` MathExpression { - "color": undefined, + "color": "#ff7f0e", "expression": "(86400 * m1) / PERIOD(m1)", "label": "Label/d (min: \${MIN}, max: \${MAX}, avg: \${AVG})", "period": Duration { @@ -1047,12 +1070,12 @@ MathExpression { "searchRegion": undefined, "usingMetrics": Object { "m1": Metric { - "account": undefined, - "color": undefined, + "account": "01234567890", + "color": "#ff7f0e", "dimensions": undefined, "label": "Label", "metricName": "Metric", - "namespace": "DummyNamespace", + "namespace": "Namespace", "period": Duration { "amount": 5, "unit": TimeUnit { @@ -1061,7 +1084,7 @@ MathExpression { "label": "minutes", }, }, - "region": undefined, + "region": "eu-west-1", "statistic": "Sum", "unit": undefined, "warnings": undefined, diff --git a/test/facade/MonitoringFacade.test.ts b/test/facade/MonitoringFacade.test.ts index 579a9aaf..b79142fb 100644 --- a/test/facade/MonitoringFacade.test.ts +++ b/test/facade/MonitoringFacade.test.ts @@ -2,6 +2,7 @@ import { Duration, Stack } from "aws-cdk-lib"; import { Capture, Template } from "aws-cdk-lib/assertions"; import { TextWidget } from "aws-cdk-lib/aws-cloudwatch"; import { Table } from "aws-cdk-lib/aws-dynamodb"; +import { Function } from "aws-cdk-lib/aws-lambda"; import { Topic } from "aws-cdk-lib/aws-sns"; import { DefaultDashboardFactory, @@ -92,6 +93,7 @@ describe("test of defaults", () => { action: notifySns(onAlarmTopic), }, }); + facade .addLargeHeader("My App Dashboard") .monitorDynamoTable({ @@ -110,11 +112,18 @@ describe("test of defaults", () => { ), region: "us-west-2", account: "01234567890", - addAverageSuccessfulGetItemLatencyAlarm: { - Critical: { - maxLatency: Duration.seconds(10), + }) + .monitorLambdaFunction({ + account: "01234567890", + region: "us-west-2", + lambdaFunction: Function.fromFunctionAttributes( + stack, + "XaXrImportedFunction", + { + functionArn: `arn:aws:lambda:us-west-2:01234567890:function:MyFunction`, + sameEnvironment: false, }, - }, + ), }); expect(Template.fromStack(stack)).toMatchSnapshot(); diff --git a/test/facade/__snapshots__/MonitoringAspect.test.ts.snap b/test/facade/__snapshots__/MonitoringAspect.test.ts.snap index cfa5c01f..33942d8a 100644 --- a/test/facade/__snapshots__/MonitoringAspect.test.ts.snap +++ b/test/facade/__snapshots__/MonitoringAspect.test.ts.snap @@ -9236,7 +9236,11 @@ Object { Object { "Ref": "AWS::Region", }, - "\\",\\"metrics\\":[[{\\"label\\":\\"Blocked (rate)\\",\\"expression\\":\\"100 * (blocked / (allowed + blocked))\\"}],[\\"AWS/WAFV2\\",\\"AllowedRequests\\",\\"Region\\",\\"", + "\\",\\"metrics\\":[[{\\"label\\":\\"Blocked (rate)\\",\\"expression\\":\\"100 * (blocked / (allowed + blocked))\\",\\"region\\":\\"", + Object { + "Ref": "AWS::Region", + }, + "\\"}],[\\"AWS/WAFV2\\",\\"AllowedRequests\\",\\"Region\\",\\"", Object { "Ref": "AWS::Region", }, @@ -9294,7 +9298,11 @@ Object { Object { "Ref": "AWS::Region", }, - "\\",\\"metrics\\":[[{\\"label\\":\\"Blocked (rate)\\",\\"expression\\":\\"100 * (blocked / (allowed + blocked))\\"}],[\\"AWS/WAFV2\\",\\"AllowedRequests\\",\\"Region\\",\\"", + "\\",\\"metrics\\":[[{\\"label\\":\\"Blocked (rate)\\",\\"expression\\":\\"100 * (blocked / (allowed + blocked))\\",\\"region\\":\\"", + Object { + "Ref": "AWS::Region", + }, + "\\"}],[\\"AWS/WAFV2\\",\\"AllowedRequests\\",\\"Region\\",\\"", Object { "Ref": "AWS::Region", }, diff --git a/test/facade/__snapshots__/MonitoringFacade.test.ts.snap b/test/facade/__snapshots__/MonitoringFacade.test.ts.snap index 065dec82..bc3d20c0 100644 --- a/test/facade/__snapshots__/MonitoringFacade.test.ts.snap +++ b/test/facade/__snapshots__/MonitoringFacade.test.ts.snap @@ -40,15 +40,15 @@ Object { Object { "Ref": "AWS::Region", }, - "\\",\\"metrics\\":[[{\\"label\\":\\"Consumed\\",\\"expression\\":\\"consumed_rcu_sum/PERIOD(consumed_rcu_sum)\\",\\"accountId\\":\\"09876543210\\",\\"region\\":\\"us-east-1\\",\\"id\\":\\"consumed_read_cap\\"}],[\\"AWS/DynamoDB\\",\\"ConsumedReadCapacityUnits\\",\\"TableName\\",\\"my-other-table\\",{\\"accountId\\":\\"01234567890\\",\\"region\\":\\"us-west-2\\",\\"stat\\":\\"Sum\\",\\"visible\\":false,\\"id\\":\\"consumed_rcu_sum\\"}],[\\"AWS/DynamoDB\\",\\"ProvisionedReadCapacityUnits\\",\\"TableName\\",\\"my-other-table\\",{\\"label\\":\\"Provisioned\\",\\"accountId\\":\\"01234567890\\",\\"region\\":\\"us-west-2\\",\\"id\\":\\"provisioned_read_cap\\"}],[{\\"label\\":\\"Utilization\\",\\"expression\\":\\"100*(consumed_read_cap/provisioned_read_cap)\\",\\"accountId\\":\\"09876543210\\",\\"region\\":\\"us-east-1\\",\\"yAxis\\":\\"right\\"}]],\\"yAxis\\":{\\"left\\":{\\"min\\":0,\\"label\\":\\"Count\\",\\"showUnits\\":false},\\"right\\":{\\"min\\":0,\\"max\\":100,\\"label\\":\\"%\\",\\"showUnits\\":false}},\\"legend\\":{\\"position\\":\\"right\\"}}},{\\"type\\":\\"metric\\",\\"width\\":6,\\"height\\":3,\\"x\\":0,\\"y\\":12,\\"properties\\":{\\"view\\":\\"timeSeries\\",\\"title\\":\\"Write Usage\\",\\"region\\":\\"", + "\\",\\"metrics\\":[[{\\"label\\":\\"Consumed\\",\\"expression\\":\\"consumed_rcu_sum/PERIOD(consumed_rcu_sum)\\",\\"accountId\\":\\"01234567890\\",\\"region\\":\\"us-west-2\\",\\"id\\":\\"consumed_read_cap\\"}],[\\"AWS/DynamoDB\\",\\"ConsumedReadCapacityUnits\\",\\"TableName\\",\\"my-other-table\\",{\\"accountId\\":\\"01234567890\\",\\"region\\":\\"us-west-2\\",\\"stat\\":\\"Sum\\",\\"visible\\":false,\\"id\\":\\"consumed_rcu_sum\\"}],[\\"AWS/DynamoDB\\",\\"ProvisionedReadCapacityUnits\\",\\"TableName\\",\\"my-other-table\\",{\\"label\\":\\"Provisioned\\",\\"accountId\\":\\"01234567890\\",\\"region\\":\\"us-west-2\\",\\"id\\":\\"provisioned_read_cap\\"}],[{\\"label\\":\\"Utilization\\",\\"expression\\":\\"100*(consumed_read_cap/provisioned_read_cap)\\",\\"accountId\\":\\"01234567890\\",\\"region\\":\\"us-west-2\\",\\"yAxis\\":\\"right\\"}]],\\"yAxis\\":{\\"left\\":{\\"min\\":0,\\"label\\":\\"Count\\",\\"showUnits\\":false},\\"right\\":{\\"min\\":0,\\"max\\":100,\\"label\\":\\"%\\",\\"showUnits\\":false}},\\"legend\\":{\\"position\\":\\"right\\"}}},{\\"type\\":\\"metric\\",\\"width\\":6,\\"height\\":3,\\"x\\":0,\\"y\\":12,\\"properties\\":{\\"view\\":\\"timeSeries\\",\\"title\\":\\"Write Usage\\",\\"region\\":\\"", Object { "Ref": "AWS::Region", }, - "\\",\\"metrics\\":[[{\\"label\\":\\"Consumed\\",\\"expression\\":\\"consumed_wcu_sum/PERIOD(consumed_wcu_sum)\\",\\"accountId\\":\\"09876543210\\",\\"region\\":\\"us-east-1\\",\\"id\\":\\"consumed_write_cap\\"}],[\\"AWS/DynamoDB\\",\\"ConsumedWriteCapacityUnits\\",\\"TableName\\",\\"my-other-table\\",{\\"accountId\\":\\"01234567890\\",\\"region\\":\\"us-west-2\\",\\"stat\\":\\"Sum\\",\\"visible\\":false,\\"id\\":\\"consumed_wcu_sum\\"}],[\\"AWS/DynamoDB\\",\\"ProvisionedWriteCapacityUnits\\",\\"TableName\\",\\"my-other-table\\",{\\"label\\":\\"Provisioned\\",\\"accountId\\":\\"01234567890\\",\\"region\\":\\"us-west-2\\",\\"id\\":\\"provisioned_write_cap\\"}],[{\\"label\\":\\"Utilization\\",\\"expression\\":\\"100*(consumed_write_cap/provisioned_write_cap)\\",\\"accountId\\":\\"09876543210\\",\\"region\\":\\"us-east-1\\",\\"yAxis\\":\\"right\\"}]],\\"yAxis\\":{\\"left\\":{\\"min\\":0,\\"label\\":\\"Count\\",\\"showUnits\\":false},\\"right\\":{\\"min\\":0,\\"max\\":100,\\"label\\":\\"%\\",\\"showUnits\\":false}},\\"legend\\":{\\"position\\":\\"right\\"}}},{\\"type\\":\\"metric\\",\\"width\\":9,\\"height\\":6,\\"x\\":6,\\"y\\":9,\\"properties\\":{\\"view\\":\\"timeSeries\\",\\"title\\":\\"Latency (Average)\\",\\"region\\":\\"", + "\\",\\"metrics\\":[[{\\"label\\":\\"Consumed\\",\\"expression\\":\\"consumed_wcu_sum/PERIOD(consumed_wcu_sum)\\",\\"accountId\\":\\"01234567890\\",\\"region\\":\\"us-west-2\\",\\"id\\":\\"consumed_write_cap\\"}],[\\"AWS/DynamoDB\\",\\"ConsumedWriteCapacityUnits\\",\\"TableName\\",\\"my-other-table\\",{\\"accountId\\":\\"01234567890\\",\\"region\\":\\"us-west-2\\",\\"stat\\":\\"Sum\\",\\"visible\\":false,\\"id\\":\\"consumed_wcu_sum\\"}],[\\"AWS/DynamoDB\\",\\"ProvisionedWriteCapacityUnits\\",\\"TableName\\",\\"my-other-table\\",{\\"label\\":\\"Provisioned\\",\\"accountId\\":\\"01234567890\\",\\"region\\":\\"us-west-2\\",\\"id\\":\\"provisioned_write_cap\\"}],[{\\"label\\":\\"Utilization\\",\\"expression\\":\\"100*(consumed_write_cap/provisioned_write_cap)\\",\\"accountId\\":\\"01234567890\\",\\"region\\":\\"us-west-2\\",\\"yAxis\\":\\"right\\"}]],\\"yAxis\\":{\\"left\\":{\\"min\\":0,\\"label\\":\\"Count\\",\\"showUnits\\":false},\\"right\\":{\\"min\\":0,\\"max\\":100,\\"label\\":\\"%\\",\\"showUnits\\":false}},\\"legend\\":{\\"position\\":\\"right\\"}}},{\\"type\\":\\"metric\\",\\"width\\":9,\\"height\\":6,\\"x\\":6,\\"y\\":9,\\"properties\\":{\\"view\\":\\"timeSeries\\",\\"title\\":\\"Latency (Average)\\",\\"region\\":\\"", Object { "Ref": "AWS::Region", }, - "\\",\\"metrics\\":[[{\\"label\\":\\" \\",\\"expression\\":\\"SEARCH('{AWS/DynamoDB,TableName,Operation} TableName=\\\\\\"my-other-table\\\\\\" MetricName=\\\\\\"SuccessfulRequestLatency\\\\\\"', 'Average', 300)\\",\\"accountId\\":\\"09876543210\\",\\"region\\":\\"us-east-1\\"}]],\\"annotations\\":{\\"horizontal\\":[{\\"label\\":\\"GetItem > 10000 for 3 datapoints within 15 minutes\\",\\"value\\":10000,\\"yAxis\\":\\"left\\"}]},\\"yAxis\\":{\\"left\\":{\\"min\\":0,\\"label\\":\\"ms\\",\\"showUnits\\":false}},\\"legend\\":{\\"position\\":\\"right\\"}}},{\\"type\\":\\"metric\\",\\"width\\":3,\\"height\\":6,\\"x\\":15,\\"y\\":9,\\"properties\\":{\\"view\\":\\"timeSeries\\",\\"title\\":\\"Throttles\\",\\"region\\":\\"", + "\\",\\"metrics\\":[[{\\"label\\":\\" \\",\\"expression\\":\\"SEARCH('{AWS/DynamoDB,TableName,Operation} TableName=\\\\\\"my-other-table\\\\\\" MetricName=\\\\\\"SuccessfulRequestLatency\\\\\\"', 'Average', 300)\\",\\"accountId\\":\\"01234567890\\",\\"region\\":\\"us-west-2\\"}]],\\"yAxis\\":{\\"left\\":{\\"min\\":0,\\"label\\":\\"ms\\",\\"showUnits\\":false}},\\"legend\\":{\\"position\\":\\"right\\"}}},{\\"type\\":\\"metric\\",\\"width\\":3,\\"height\\":6,\\"x\\":15,\\"y\\":9,\\"properties\\":{\\"view\\":\\"timeSeries\\",\\"title\\":\\"Throttles\\",\\"region\\":\\"", Object { "Ref": "AWS::Region", }, @@ -56,7 +56,35 @@ Object { Object { "Ref": "AWS::Region", }, - "\\",\\"metrics\\":[[{\\"label\\":\\"System Errors\\",\\"expression\\":\\"systemErrorGetItem+systemErrorBatchGetItem+systemErrorScan+systemErrorQuery+systemErrorGetRecords+systemErrorPutItem+systemErrorDeleteItem+systemErrorUpdateItem+systemErrorBatchWriteItem\\",\\"accountId\\":\\"09876543210\\",\\"region\\":\\"us-east-1\\"}],[\\"AWS/DynamoDB\\",\\"SystemErrors\\",\\"Operation\\",\\"GetItem\\",\\"TableName\\",\\"my-other-table\\",{\\"accountId\\":\\"01234567890\\",\\"region\\":\\"us-west-2\\",\\"stat\\":\\"Sum\\",\\"visible\\":false,\\"id\\":\\"systemErrorGetItem\\"}],[\\"AWS/DynamoDB\\",\\"SystemErrors\\",\\"Operation\\",\\"BatchGetItem\\",\\"TableName\\",\\"my-other-table\\",{\\"accountId\\":\\"01234567890\\",\\"region\\":\\"us-west-2\\",\\"stat\\":\\"Sum\\",\\"visible\\":false,\\"id\\":\\"systemErrorBatchGetItem\\"}],[\\"AWS/DynamoDB\\",\\"SystemErrors\\",\\"Operation\\",\\"Scan\\",\\"TableName\\",\\"my-other-table\\",{\\"accountId\\":\\"01234567890\\",\\"region\\":\\"us-west-2\\",\\"stat\\":\\"Sum\\",\\"visible\\":false,\\"id\\":\\"systemErrorScan\\"}],[\\"AWS/DynamoDB\\",\\"SystemErrors\\",\\"Operation\\",\\"Query\\",\\"TableName\\",\\"my-other-table\\",{\\"accountId\\":\\"01234567890\\",\\"region\\":\\"us-west-2\\",\\"stat\\":\\"Sum\\",\\"visible\\":false,\\"id\\":\\"systemErrorQuery\\"}],[\\"AWS/DynamoDB\\",\\"SystemErrors\\",\\"Operation\\",\\"GetRecords\\",\\"TableName\\",\\"my-other-table\\",{\\"accountId\\":\\"01234567890\\",\\"region\\":\\"us-west-2\\",\\"stat\\":\\"Sum\\",\\"visible\\":false,\\"id\\":\\"systemErrorGetRecords\\"}],[\\"AWS/DynamoDB\\",\\"SystemErrors\\",\\"Operation\\",\\"PutItem\\",\\"TableName\\",\\"my-other-table\\",{\\"accountId\\":\\"01234567890\\",\\"region\\":\\"us-west-2\\",\\"stat\\":\\"Sum\\",\\"visible\\":false,\\"id\\":\\"systemErrorPutItem\\"}],[\\"AWS/DynamoDB\\",\\"SystemErrors\\",\\"Operation\\",\\"DeleteItem\\",\\"TableName\\",\\"my-other-table\\",{\\"accountId\\":\\"01234567890\\",\\"region\\":\\"us-west-2\\",\\"stat\\":\\"Sum\\",\\"visible\\":false,\\"id\\":\\"systemErrorDeleteItem\\"}],[\\"AWS/DynamoDB\\",\\"SystemErrors\\",\\"Operation\\",\\"UpdateItem\\",\\"TableName\\",\\"my-other-table\\",{\\"accountId\\":\\"01234567890\\",\\"region\\":\\"us-west-2\\",\\"stat\\":\\"Sum\\",\\"visible\\":false,\\"id\\":\\"systemErrorUpdateItem\\"}],[\\"AWS/DynamoDB\\",\\"SystemErrors\\",\\"Operation\\",\\"BatchWriteItem\\",\\"TableName\\",\\"my-other-table\\",{\\"accountId\\":\\"01234567890\\",\\"region\\":\\"us-west-2\\",\\"stat\\":\\"Sum\\",\\"visible\\":false,\\"id\\":\\"systemErrorBatchWriteItem\\"}]],\\"yAxis\\":{\\"left\\":{\\"min\\":0,\\"label\\":\\"Count\\",\\"showUnits\\":false}}}}]}", + "\\",\\"metrics\\":[[{\\"label\\":\\"System Errors\\",\\"expression\\":\\"systemErrorGetItem+systemErrorBatchGetItem+systemErrorScan+systemErrorQuery+systemErrorGetRecords+systemErrorPutItem+systemErrorDeleteItem+systemErrorUpdateItem+systemErrorBatchWriteItem\\",\\"accountId\\":\\"09876543210\\",\\"region\\":\\"us-east-1\\"}],[\\"AWS/DynamoDB\\",\\"SystemErrors\\",\\"Operation\\",\\"GetItem\\",\\"TableName\\",\\"my-other-table\\",{\\"accountId\\":\\"01234567890\\",\\"region\\":\\"us-west-2\\",\\"stat\\":\\"Sum\\",\\"visible\\":false,\\"id\\":\\"systemErrorGetItem\\"}],[\\"AWS/DynamoDB\\",\\"SystemErrors\\",\\"Operation\\",\\"BatchGetItem\\",\\"TableName\\",\\"my-other-table\\",{\\"accountId\\":\\"01234567890\\",\\"region\\":\\"us-west-2\\",\\"stat\\":\\"Sum\\",\\"visible\\":false,\\"id\\":\\"systemErrorBatchGetItem\\"}],[\\"AWS/DynamoDB\\",\\"SystemErrors\\",\\"Operation\\",\\"Scan\\",\\"TableName\\",\\"my-other-table\\",{\\"accountId\\":\\"01234567890\\",\\"region\\":\\"us-west-2\\",\\"stat\\":\\"Sum\\",\\"visible\\":false,\\"id\\":\\"systemErrorScan\\"}],[\\"AWS/DynamoDB\\",\\"SystemErrors\\",\\"Operation\\",\\"Query\\",\\"TableName\\",\\"my-other-table\\",{\\"accountId\\":\\"01234567890\\",\\"region\\":\\"us-west-2\\",\\"stat\\":\\"Sum\\",\\"visible\\":false,\\"id\\":\\"systemErrorQuery\\"}],[\\"AWS/DynamoDB\\",\\"SystemErrors\\",\\"Operation\\",\\"GetRecords\\",\\"TableName\\",\\"my-other-table\\",{\\"accountId\\":\\"01234567890\\",\\"region\\":\\"us-west-2\\",\\"stat\\":\\"Sum\\",\\"visible\\":false,\\"id\\":\\"systemErrorGetRecords\\"}],[\\"AWS/DynamoDB\\",\\"SystemErrors\\",\\"Operation\\",\\"PutItem\\",\\"TableName\\",\\"my-other-table\\",{\\"accountId\\":\\"01234567890\\",\\"region\\":\\"us-west-2\\",\\"stat\\":\\"Sum\\",\\"visible\\":false,\\"id\\":\\"systemErrorPutItem\\"}],[\\"AWS/DynamoDB\\",\\"SystemErrors\\",\\"Operation\\",\\"DeleteItem\\",\\"TableName\\",\\"my-other-table\\",{\\"accountId\\":\\"01234567890\\",\\"region\\":\\"us-west-2\\",\\"stat\\":\\"Sum\\",\\"visible\\":false,\\"id\\":\\"systemErrorDeleteItem\\"}],[\\"AWS/DynamoDB\\",\\"SystemErrors\\",\\"Operation\\",\\"UpdateItem\\",\\"TableName\\",\\"my-other-table\\",{\\"accountId\\":\\"01234567890\\",\\"region\\":\\"us-west-2\\",\\"stat\\":\\"Sum\\",\\"visible\\":false,\\"id\\":\\"systemErrorUpdateItem\\"}],[\\"AWS/DynamoDB\\",\\"SystemErrors\\",\\"Operation\\",\\"BatchWriteItem\\",\\"TableName\\",\\"my-other-table\\",{\\"accountId\\":\\"01234567890\\",\\"region\\":\\"us-west-2\\",\\"stat\\":\\"Sum\\",\\"visible\\":false,\\"id\\":\\"systemErrorBatchWriteItem\\"}]],\\"yAxis\\":{\\"left\\":{\\"min\\":0,\\"label\\":\\"Count\\",\\"showUnits\\":false}}}},{\\"type\\":\\"text\\",\\"width\\":24,\\"height\\":1,\\"x\\":0,\\"y\\":15,\\"properties\\":{\\"markdown\\":\\"### Lambda Function **[XaXrImportedFunction](https://us-east-1.console.aws.amazon.com/lambda/home?region=us-east-1#/functions/MyFunction)**\\"}},{\\"type\\":\\"metric\\",\\"width\\":6,\\"height\\":5,\\"x\\":0,\\"y\\":16,\\"properties\\":{\\"view\\":\\"timeSeries\\",\\"title\\":\\"TPS\\",\\"region\\":\\"", + Object { + "Ref": "AWS::Region", + }, + "\\",\\"metrics\\":[[{\\"label\\":\\"TPS\\",\\"expression\\":\\"FILL(requests,0) / PERIOD(requests)\\",\\"accountId\\":\\"09876543210\\",\\"region\\":\\"us-east-1\\"}],[\\"AWS/Lambda\\",\\"Invocations\\",\\"FunctionName\\",\\"MyFunction\\",{\\"label\\":\\"Invocations\\",\\"accountId\\":\\"01234567890\\",\\"region\\":\\"us-west-2\\",\\"stat\\":\\"Sum\\",\\"visible\\":false,\\"id\\":\\"requests\\"}]],\\"yAxis\\":{\\"left\\":{\\"min\\":0,\\"label\\":\\"Rate\\",\\"showUnits\\":false}}}},{\\"type\\":\\"metric\\",\\"width\\":6,\\"height\\":5,\\"x\\":6,\\"y\\":16,\\"properties\\":{\\"view\\":\\"timeSeries\\",\\"title\\":\\"Latency\\",\\"region\\":\\"", + Object { + "Ref": "AWS::Region", + }, + "\\",\\"metrics\\":[[\\"AWS/Lambda\\",\\"Duration\\",\\"FunctionName\\",\\"MyFunction\\",{\\"label\\":\\"P50 (avg: \${AVG})\\",\\"accountId\\":\\"01234567890\\",\\"region\\":\\"us-west-2\\",\\"stat\\":\\"p50\\"}],[\\"AWS/Lambda\\",\\"Duration\\",\\"FunctionName\\",\\"MyFunction\\",{\\"label\\":\\"P90 (avg: \${AVG})\\",\\"accountId\\":\\"01234567890\\",\\"region\\":\\"us-west-2\\",\\"stat\\":\\"p90\\"}],[\\"AWS/Lambda\\",\\"Duration\\",\\"FunctionName\\",\\"MyFunction\\",{\\"label\\":\\"P99 (avg: \${AVG})\\",\\"accountId\\":\\"01234567890\\",\\"region\\":\\"us-west-2\\",\\"stat\\":\\"p99\\"}]],\\"yAxis\\":{\\"left\\":{\\"min\\":0,\\"label\\":\\"ms\\",\\"showUnits\\":false}}}},{\\"type\\":\\"metric\\",\\"width\\":6,\\"height\\":5,\\"x\\":12,\\"y\\":16,\\"properties\\":{\\"view\\":\\"timeSeries\\",\\"title\\":\\"Errors (rate)\\",\\"region\\":\\"", + Object { + "Ref": "AWS::Region", + }, + "\\",\\"metrics\\":[[\\"AWS/Lambda\\",\\"Errors\\",\\"FunctionName\\",\\"MyFunction\\",{\\"label\\":\\"Faults (avg)\\",\\"accountId\\":\\"01234567890\\",\\"region\\":\\"us-west-2\\"}]],\\"yAxis\\":{\\"left\\":{\\"min\\":0,\\"label\\":\\"Rate\\",\\"showUnits\\":false}}}},{\\"type\\":\\"metric\\",\\"width\\":6,\\"height\\":5,\\"x\\":18,\\"y\\":16,\\"properties\\":{\\"view\\":\\"timeSeries\\",\\"title\\":\\"Rates\\",\\"region\\":\\"", + Object { + "Ref": "AWS::Region", + }, + "\\",\\"metrics\\":[[\\"AWS/Lambda\\",\\"Throttles\\",\\"FunctionName\\",\\"MyFunction\\",{\\"label\\":\\"Throttles (avg)\\",\\"accountId\\":\\"01234567890\\",\\"region\\":\\"us-west-2\\"}],[\\"AWS/Lambda\\",\\"ProvisionedConcurrencySpilloverInvocations\\",\\"FunctionName\\",\\"MyFunction\\",{\\"label\\":\\"Provisioned Concurrency Spillovers (avg)\\",\\"accountId\\":\\"01234567890\\",\\"region\\":\\"us-west-2\\"}]],\\"yAxis\\":{\\"left\\":{\\"min\\":0,\\"label\\":\\"Rate\\",\\"showUnits\\":false}}}},{\\"type\\":\\"metric\\",\\"width\\":8,\\"height\\":5,\\"x\\":0,\\"y\\":21,\\"properties\\":{\\"view\\":\\"timeSeries\\",\\"title\\":\\"Invocations\\",\\"region\\":\\"", + Object { + "Ref": "AWS::Region", + }, + "\\",\\"metrics\\":[[\\"AWS/Lambda\\",\\"Invocations\\",\\"FunctionName\\",\\"MyFunction\\",{\\"label\\":\\"Invocations\\",\\"accountId\\":\\"01234567890\\",\\"region\\":\\"us-west-2\\",\\"stat\\":\\"Sum\\"}],[\\"AWS/Lambda\\",\\"Throttles\\",\\"FunctionName\\",\\"MyFunction\\",{\\"label\\":\\"Throttles\\",\\"accountId\\":\\"01234567890\\",\\"region\\":\\"us-west-2\\",\\"stat\\":\\"Sum\\"}],[\\"AWS/Lambda\\",\\"ConcurrentExecutions\\",\\"FunctionName\\",\\"MyFunction\\",{\\"label\\":\\"Concurrent\\",\\"accountId\\":\\"01234567890\\",\\"region\\":\\"us-west-2\\",\\"stat\\":\\"Maximum\\"}],[\\"AWS/Lambda\\",\\"ProvisionedConcurrencySpilloverInvocations\\",\\"FunctionName\\",\\"MyFunction\\",{\\"label\\":\\"Provisioned Concurrency Spillovers\\",\\"accountId\\":\\"01234567890\\",\\"region\\":\\"us-west-2\\",\\"stat\\":\\"Sum\\"}]],\\"yAxis\\":{\\"left\\":{\\"min\\":0,\\"label\\":\\"Count\\",\\"showUnits\\":false}}}},{\\"type\\":\\"metric\\",\\"width\\":8,\\"height\\":5,\\"x\\":8,\\"y\\":21,\\"properties\\":{\\"view\\":\\"timeSeries\\",\\"title\\":\\"Iterator\\",\\"region\\":\\"", + Object { + "Ref": "AWS::Region", + }, + "\\",\\"metrics\\":[[\\"AWS/Lambda\\",\\"IteratorAge\\",\\"FunctionName\\",\\"MyFunction\\",{\\"label\\":\\"Iterator Age\\",\\"accountId\\":\\"01234567890\\",\\"region\\":\\"us-west-2\\",\\"stat\\":\\"Maximum\\"}]],\\"yAxis\\":{\\"left\\":{\\"min\\":0,\\"label\\":\\"ms\\",\\"showUnits\\":false}}}},{\\"type\\":\\"metric\\",\\"width\\":8,\\"height\\":5,\\"x\\":16,\\"y\\":21,\\"properties\\":{\\"view\\":\\"timeSeries\\",\\"title\\":\\"Errors\\",\\"region\\":\\"", + Object { + "Ref": "AWS::Region", + }, + "\\",\\"metrics\\":[[\\"AWS/Lambda\\",\\"Errors\\",\\"FunctionName\\",\\"MyFunction\\",{\\"label\\":\\"Faults\\",\\"accountId\\":\\"01234567890\\",\\"region\\":\\"us-west-2\\",\\"stat\\":\\"Sum\\"}]],\\"yAxis\\":{\\"left\\":{\\"min\\":0,\\"label\\":\\"Count\\",\\"showUnits\\":false}}}}]}", ], ], }, @@ -107,50 +135,6 @@ Object { }, "Type": "AWS::CloudWatch::Alarm", }, - "MyAppFacadeMyAppXaXrImportedTableLatencyAverageGetItemCritical3480F8E9": Object { - "Properties": Object { - "ActionsEnabled": true, - "AlarmActions": Array [ - Object { - "Ref": "OnAlarmTopicF22649A2", - }, - ], - "AlarmDescription": "Average latency is too high.", - "AlarmName": "MyApp-XaXrImportedTable-Latency-Average-GetItem-Critical", - "ComparisonOperator": "GreaterThanThreshold", - "DatapointsToAlarm": 3, - "EvaluationPeriods": 3, - "Metrics": Array [ - Object { - "AccountId": "01234567890", - "Id": "m1", - "Label": "GetItem", - "MetricStat": Object { - "Metric": Object { - "Dimensions": Array [ - Object { - "Name": "Operation", - "Value": "GetItem", - }, - Object { - "Name": "TableName", - "Value": "my-other-table", - }, - ], - "MetricName": "SuccessfulRequestLatency", - "Namespace": "AWS/DynamoDB", - }, - "Period": 300, - "Stat": "Average", - }, - "ReturnData": true, - }, - ], - "Threshold": 10000, - "TreatMissingData": "notBreaching", - }, - "Type": "AWS::CloudWatch::Alarm", - }, "OnAlarmTopicF22649A2": Object { "Properties": Object { "TopicName": "Alarm", diff --git a/test/monitoring/aws-wafv2/__snapshots__/WafV2Monitoring.test.ts.snap b/test/monitoring/aws-wafv2/__snapshots__/WafV2Monitoring.test.ts.snap index 99d0db60..46b864cf 100644 --- a/test/monitoring/aws-wafv2/__snapshots__/WafV2Monitoring.test.ts.snap +++ b/test/monitoring/aws-wafv2/__snapshots__/WafV2Monitoring.test.ts.snap @@ -294,7 +294,7 @@ Object { Object { "Ref": "AWS::Region", }, - "\\",\\"metrics\\":[[{\\"label\\":\\"Blocked (rate)\\",\\"expression\\":\\"100 * (blocked / (allowed + blocked))\\"}],[\\"AWS/WAFV2\\",\\"AllowedRequests\\",\\"Region\\",\\"us-east-1\\",\\"Rule\\",\\"ALL\\",\\"WebACL\\",\\"DummyAclName\\",{\\"label\\":\\"Allowed\\",\\"region\\":\\"us-east-1\\",\\"stat\\":\\"Sum\\",\\"visible\\":false,\\"id\\":\\"allowed\\"}],[\\"AWS/WAFV2\\",\\"BlockedRequests\\",\\"Region\\",\\"us-east-1\\",\\"Rule\\",\\"ALL\\",\\"WebACL\\",\\"DummyAclName\\",{\\"label\\":\\"Blocked\\",\\"region\\":\\"us-east-1\\",\\"stat\\":\\"Sum\\",\\"visible\\":false,\\"id\\":\\"blocked\\"}]],\\"yAxis\\":{\\"left\\":{\\"min\\":0,\\"label\\":\\"Rate\\",\\"showUnits\\":false}}}}]}", + "\\",\\"metrics\\":[[{\\"label\\":\\"Blocked (rate)\\",\\"expression\\":\\"100 * (blocked / (allowed + blocked))\\",\\"region\\":\\"us-east-1\\"}],[\\"AWS/WAFV2\\",\\"AllowedRequests\\",\\"Region\\",\\"us-east-1\\",\\"Rule\\",\\"ALL\\",\\"WebACL\\",\\"DummyAclName\\",{\\"label\\":\\"Allowed\\",\\"region\\":\\"us-east-1\\",\\"stat\\":\\"Sum\\",\\"visible\\":false,\\"id\\":\\"allowed\\"}],[\\"AWS/WAFV2\\",\\"BlockedRequests\\",\\"Region\\",\\"us-east-1\\",\\"Rule\\",\\"ALL\\",\\"WebACL\\",\\"DummyAclName\\",{\\"label\\":\\"Blocked\\",\\"region\\":\\"us-east-1\\",\\"stat\\":\\"Sum\\",\\"visible\\":false,\\"id\\":\\"blocked\\"}]],\\"yAxis\\":{\\"left\\":{\\"min\\":0,\\"label\\":\\"Rate\\",\\"showUnits\\":false}}}}]}", ], ], }, @@ -319,7 +319,7 @@ Object { Object { "Ref": "AWS::Region", }, - "\\",\\"metrics\\":[[{\\"label\\":\\"Blocked (rate)\\",\\"expression\\":\\"100 * (blocked / (allowed + blocked))\\"}],[\\"AWS/WAFV2\\",\\"AllowedRequests\\",\\"Region\\",\\"us-east-1\\",\\"Rule\\",\\"ALL\\",\\"WebACL\\",\\"DummyAclName\\",{\\"label\\":\\"Allowed\\",\\"region\\":\\"us-east-1\\",\\"stat\\":\\"Sum\\",\\"visible\\":false,\\"id\\":\\"allowed\\"}],[\\"AWS/WAFV2\\",\\"BlockedRequests\\",\\"Region\\",\\"us-east-1\\",\\"Rule\\",\\"ALL\\",\\"WebACL\\",\\"DummyAclName\\",{\\"label\\":\\"Blocked\\",\\"region\\":\\"us-east-1\\",\\"stat\\":\\"Sum\\",\\"visible\\":false,\\"id\\":\\"blocked\\"}]],\\"yAxis\\":{\\"left\\":{\\"min\\":0,\\"label\\":\\"Rate\\",\\"showUnits\\":false}}}}]}", + "\\",\\"metrics\\":[[{\\"label\\":\\"Blocked (rate)\\",\\"expression\\":\\"100 * (blocked / (allowed + blocked))\\",\\"region\\":\\"us-east-1\\"}],[\\"AWS/WAFV2\\",\\"AllowedRequests\\",\\"Region\\",\\"us-east-1\\",\\"Rule\\",\\"ALL\\",\\"WebACL\\",\\"DummyAclName\\",{\\"label\\":\\"Allowed\\",\\"region\\":\\"us-east-1\\",\\"stat\\":\\"Sum\\",\\"visible\\":false,\\"id\\":\\"allowed\\"}],[\\"AWS/WAFV2\\",\\"BlockedRequests\\",\\"Region\\",\\"us-east-1\\",\\"Rule\\",\\"ALL\\",\\"WebACL\\",\\"DummyAclName\\",{\\"label\\":\\"Blocked\\",\\"region\\":\\"us-east-1\\",\\"stat\\":\\"Sum\\",\\"visible\\":false,\\"id\\":\\"blocked\\"}]],\\"yAxis\\":{\\"left\\":{\\"min\\":0,\\"label\\":\\"Rate\\",\\"showUnits\\":false}}}}]}", ], ], },