Skip to content

Commit 884d3a8

Browse files
authored
chore(cfnspec): update canned metrics (#18233)
---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 01bbe4c commit 884d3a8

File tree

11 files changed

+20094
-10257
lines changed

11 files changed

+20094
-10257
lines changed

packages/@aws-cdk/aws-dynamodb/lib/table.ts

+15-1
Original file line numberDiff line numberDiff line change
@@ -833,9 +833,23 @@ abstract class TableBase extends Resource implements ITable {
833833
* How many requests are throttled on this table
834834
*
835835
* Default: sum over 5 minutes
836+
*
837+
* @deprecated Do not use this function. It returns an invalid metric. Use `metricThrottledRequestsForOperation` instead.
836838
*/
837839
public metricThrottledRequests(props?: cloudwatch.MetricOptions): cloudwatch.Metric {
838-
return this.cannedMetric(DynamoDBMetrics.throttledRequestsSum, props);
840+
return this.metric('ThrottledRequests', { statistic: 'sum', ...props });
841+
}
842+
843+
/**
844+
* How many requests are throttled on this table, for the given operation
845+
*
846+
* Default: sum over 5 minutes
847+
*/
848+
public metricThrottledRequestsForOperation(operation: string, props?: cloudwatch.MetricOptions): cloudwatch.Metric {
849+
return new cloudwatch.Metric({
850+
...DynamoDBMetrics.throttledRequestsSum({ Operation: operation, TableName: this.tableName }),
851+
...props,
852+
}).attachTo(this);
839853
}
840854

841855
/**

packages/@aws-cdk/aws-elasticloadbalancingv2/lib/nlb/network-load-balancer.ts

+9-6
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,7 @@ export class NetworkLoadBalancer extends BaseLoadBalancer implements INetworkLoa
184184
* @default Average over 5 minutes
185185
*/
186186
public metricActiveFlowCount(props?: cloudwatch.MetricOptions) {
187-
return this.cannedMetric(NetworkELBMetrics.activeFlowCountSum, {
188-
statistic: 'Average', // Doesn't make sense to me but backwards compatibility and all that
189-
...props,
190-
});
187+
return this.cannedMetric(NetworkELBMetrics.activeFlowCountAverage, props);
191188
}
192189

193190
/**
@@ -209,7 +206,10 @@ export class NetworkLoadBalancer extends BaseLoadBalancer implements INetworkLoa
209206
* @deprecated use ``NetworkTargetGroup.metricHealthyHostCount`` instead
210207
*/
211208
public metricHealthyHostCount(props?: cloudwatch.MetricOptions) {
212-
return this.cannedMetric(NetworkELBMetrics.healthyHostCountAverage, props);
209+
return this.metric('HealthyHostCount', {
210+
statistic: 'Average',
211+
...props,
212+
});
213213
}
214214

215215
/**
@@ -219,7 +219,10 @@ export class NetworkLoadBalancer extends BaseLoadBalancer implements INetworkLoa
219219
* @deprecated use ``NetworkTargetGroup.metricUnHealthyHostCount`` instead
220220
*/
221221
public metricUnHealthyHostCount(props?: cloudwatch.MetricOptions) {
222-
return this.cannedMetric(NetworkELBMetrics.unHealthyHostCountAverage, props);
222+
return this.metric('UnHealthyHostCount', {
223+
statistic: 'Average',
224+
...props,
225+
});
223226
}
224227

225228
/**

packages/@aws-cdk/aws-kinesis/lib/kinesis-fixed-canned-metrics.ts

+25-6
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,16 @@ export class KinesisMetrics {
6161
return CannedMetrics.getRecordsIteratorAgeMillisecondsMaximum(dimensions);
6262
}
6363
public static putRecordSuccessAverage(dimensions: { StreamName: string }) {
64-
return CannedMetrics.putRecordSuccessAverage(dimensions);
64+
return {
65+
...CannedMetrics.putRecordSuccessSum(dimensions),
66+
statistic: 'Average',
67+
};
6568
}
6669
public static putRecordsBytesAverage(dimensions: { StreamName: string }) {
67-
return CannedMetrics.putRecordsBytesAverage(dimensions);
70+
return {
71+
...CannedMetrics.putRecordsBytesSum(dimensions),
72+
statistic: 'Average',
73+
};
6874
}
6975
public static putRecordsLatencyAverage(dimensions: { StreamName: string }) {
7076
return {
@@ -115,15 +121,28 @@ export class KinesisMetrics {
115121
};
116122
}
117123
public static incomingBytesAverage(dimensions: { StreamName: string }) {
118-
return CannedMetrics.incomingBytesAverage(dimensions);
124+
return {
125+
...CannedMetrics.incomingBytesSum(dimensions),
126+
statistic: 'Average',
127+
};
119128
}
120129
public static incomingRecordsAverage(dimensions: { StreamName: string }) {
121-
return CannedMetrics.incomingRecordsAverage(dimensions);
130+
return {
131+
...CannedMetrics.incomingRecordsSum(dimensions),
132+
statistic: 'Average',
133+
};
134+
122135
}
123136
public static readProvisionedThroughputExceededAverage(dimensions: { StreamName: string }) {
124-
return CannedMetrics.readProvisionedThroughputExceededAverage(dimensions);
137+
return {
138+
...CannedMetrics.readProvisionedThroughputExceededSum(dimensions),
139+
statistic: 'Average',
140+
};
125141
}
126142
public static writeProvisionedThroughputExceededAverage(dimensions: { StreamName: string }) {
127-
return CannedMetrics.writeProvisionedThroughputExceededAverage(dimensions);
143+
return {
144+
...CannedMetrics.writeProvisionedThroughputExceededSum(dimensions),
145+
statistic: 'Average',
146+
};
128147
}
129148
}

packages/@aws-cdk/aws-kinesisfirehose/lib/delivery-stream.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -132,23 +132,23 @@ abstract class DeliveryStreamBase extends cdk.Resource implements IDeliveryStrea
132132
}
133133

134134
public metricIncomingBytes(props?: cloudwatch.MetricOptions): cloudwatch.Metric {
135-
return this.cannedMetric(FirehoseMetrics.incomingBytesAverage, props);
135+
return this.cannedMetric(FirehoseMetrics.incomingBytesSum, props);
136136
}
137137

138138
public metricIncomingRecords(props?: cloudwatch.MetricOptions): cloudwatch.Metric {
139-
return this.cannedMetric(FirehoseMetrics.incomingRecordsAverage, props);
139+
return this.cannedMetric(FirehoseMetrics.incomingRecordsSum, props);
140140
}
141141

142142
public metricBackupToS3Bytes(props?: cloudwatch.MetricOptions): cloudwatch.Metric {
143-
return this.cannedMetric(FirehoseMetrics.backupToS3BytesAverage, props);
143+
return this.cannedMetric(FirehoseMetrics.backupToS3BytesSum, props);
144144
}
145145

146146
public metricBackupToS3DataFreshness(props?: cloudwatch.MetricOptions): cloudwatch.Metric {
147147
return this.cannedMetric(FirehoseMetrics.backupToS3DataFreshnessAverage, props);
148148
}
149149

150150
public metricBackupToS3Records(props?: cloudwatch.MetricOptions): cloudwatch.Metric {
151-
return this.cannedMetric(FirehoseMetrics.backupToS3RecordsAverage, props);
151+
return this.cannedMetric(FirehoseMetrics.backupToS3RecordsSum, props);
152152
}
153153

154154
private cannedMetric(fn: (dims: { DeliveryStreamName: string }) => cloudwatch.MetricProps, props?: cloudwatch.MetricOptions): cloudwatch.Metric {

packages/@aws-cdk/aws-kinesisfirehose/test/delivery-stream.test.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ describe('delivery stream', () => {
371371
region: stack.region,
372372
namespace: 'AWS/Firehose',
373373
metricName: 'IncomingBytes',
374-
statistic: cloudwatch.Statistic.AVERAGE,
374+
statistic: cloudwatch.Statistic.SUM,
375375
dimensions: {
376376
DeliveryStreamName: deliveryStream.deliveryStreamName,
377377
},
@@ -386,7 +386,7 @@ describe('delivery stream', () => {
386386
region: stack.region,
387387
namespace: 'AWS/Firehose',
388388
metricName: 'IncomingRecords',
389-
statistic: cloudwatch.Statistic.AVERAGE,
389+
statistic: cloudwatch.Statistic.SUM,
390390
dimensions: {
391391
DeliveryStreamName: deliveryStream.deliveryStreamName,
392392
},
@@ -401,7 +401,7 @@ describe('delivery stream', () => {
401401
region: stack.region,
402402
namespace: 'AWS/Firehose',
403403
metricName: 'BackupToS3.Bytes',
404-
statistic: cloudwatch.Statistic.AVERAGE,
404+
statistic: cloudwatch.Statistic.SUM,
405405
dimensions: {
406406
DeliveryStreamName: deliveryStream.deliveryStreamName,
407407
},
@@ -431,7 +431,7 @@ describe('delivery stream', () => {
431431
region: stack.region,
432432
namespace: 'AWS/Firehose',
433433
metricName: 'BackupToS3.Records',
434-
statistic: cloudwatch.Statistic.AVERAGE,
434+
statistic: cloudwatch.Statistic.SUM,
435435
dimensions: {
436436
DeliveryStreamName: deliveryStream.deliveryStreamName,
437437
},

packages/@aws-cdk/aws-stepfunctions/lib/state-machine.ts

+4-16
Original file line numberDiff line numberDiff line change
@@ -268,10 +268,7 @@ abstract class StateMachineBase extends Resource implements IStateMachine {
268268
* @default - sum over 5 minutes
269269
*/
270270
public metricFailed(props?: cloudwatch.MetricOptions): cloudwatch.Metric {
271-
return this.cannedMetric(StatesMetrics.executionsFailedAverage, {
272-
statistic: 'sum',
273-
...props,
274-
});
271+
return this.cannedMetric(StatesMetrics.executionsFailedSum, props);
275272
}
276273

277274
/**
@@ -290,10 +287,7 @@ abstract class StateMachineBase extends Resource implements IStateMachine {
290287
* @default - sum over 5 minutes
291288
*/
292289
public metricAborted(props?: cloudwatch.MetricOptions): cloudwatch.Metric {
293-
return this.cannedMetric(StatesMetrics.executionsAbortedAverage, {
294-
statistic: 'sum',
295-
...props,
296-
});
290+
return this.cannedMetric(StatesMetrics.executionsAbortedSum, props);
297291
}
298292

299293
/**
@@ -302,10 +296,7 @@ abstract class StateMachineBase extends Resource implements IStateMachine {
302296
* @default - sum over 5 minutes
303297
*/
304298
public metricSucceeded(props?: cloudwatch.MetricOptions): cloudwatch.Metric {
305-
return this.cannedMetric(StatesMetrics.executionsSucceededAverage, {
306-
statistic: 'sum',
307-
...props,
308-
});
299+
return this.cannedMetric(StatesMetrics.executionsSucceededSum, props);
309300
}
310301

311302
/**
@@ -314,10 +305,7 @@ abstract class StateMachineBase extends Resource implements IStateMachine {
314305
* @default - sum over 5 minutes
315306
*/
316307
public metricTimedOut(props?: cloudwatch.MetricOptions): cloudwatch.Metric {
317-
return this.cannedMetric(StatesMetrics.executionsTimedOutAverage, {
318-
statistic: 'sum',
319-
...props,
320-
});
308+
return this.cannedMetric(StatesMetrics.executionsTimedOutSum, props);
321309
}
322310

323311
/**

packages/@aws-cdk/aws-synthetics/lib/canary.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,11 @@ export class Canary extends cdk.Resource {
256256
* @default avg over 5 minutes
257257
*/
258258
public metricDuration(options?: MetricOptions): Metric {
259-
return this.cannedMetric(CloudWatchSyntheticsMetrics.durationAverage, options);
259+
return new Metric({
260+
...CloudWatchSyntheticsMetrics.durationMaximum({ CanaryName: this.canaryName }),
261+
...{ statistic: 'Average' },
262+
...options,
263+
}).attachTo(this);
260264
}
261265

262266
/**

packages/@aws-cdk/cfnspec/build-tools/update-metrics.sh

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/bin/bash
22
set -eu
33

4+
# Run this script on the tarball found in the release artifacts of the CloudWatchConsoleServiceDirectory package.
5+
46
explorer_tarball="$1"
57

68
target_file=lib/canned-metrics/services.json

packages/@aws-cdk/cfnspec/lib/canned-metrics/README.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -160,4 +160,9 @@ these metrics as templates, they are free to change them at any time. For
160160
example, when they decide that a `defaultStatistic` of `Average` should have
161161
been `Sum`, for example. On the other hand, we have a fixed statistic
162162
contract -- once a metric object emits under a particular statistic, we can
163-
never change it or we will break downstream users.
163+
never change it or we will break downstream users.
164+
165+
166+
## Updating
167+
168+
To update these metrics, see the `build-tools/update-metrics.sh` script.

0 commit comments

Comments
 (0)