-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(cloudwatch): metric
label
not rendered into Alarms (#13070)
Cloudwatch allows adding labels to metrics. These can be seen when viewing alarms. Currently labels only work for math expression metrics. This change will fix it to work for single alarm metrics too. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
- Loading branch information
1 parent
6f7cebd
commit cbcc712
Showing
3 changed files
with
116 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
packages/@aws-cdk/aws-cloudwatch/test/integ.alarm-with-label.expected.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
{ | ||
"Resources": { | ||
"Alarm1F9009D71": { | ||
"Type": "AWS::CloudWatch::Alarm", | ||
"Properties": { | ||
"Metrics": [ | ||
{ | ||
"Id": "Metric", | ||
"Label": "Metric [AVG: ${AVG}]", | ||
"MetricStat": { | ||
"Metric": { | ||
"MetricName": "Metric", | ||
"Namespace": "CDK/Test" | ||
}, | ||
"Period": 300, | ||
"Stat": "Average" | ||
}, | ||
"ReturnData": true | ||
} | ||
], | ||
"ComparisonOperator": "GreaterThanOrEqualToThreshold", | ||
"EvaluationPeriods": 3, | ||
"Threshold": 100 | ||
} | ||
}, | ||
"Alarm2A7122E13": { | ||
"Type": "AWS::CloudWatch::Alarm", | ||
"Properties": { | ||
"Metrics": [ | ||
{ | ||
"Id": "Metric", | ||
"Label": "Metric [AVG: ${AVG}]", | ||
"MetricStat": { | ||
"Metric": { | ||
"MetricName": "Metric", | ||
"Namespace": "CDK/Test" | ||
}, | ||
"Period": 300, | ||
"Stat": "Average" | ||
}, | ||
"ReturnData": true | ||
} | ||
], | ||
"ComparisonOperator": "GreaterThanOrEqualToThreshold", | ||
"EvaluationPeriods": 3, | ||
"Threshold": 100 | ||
} | ||
} | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
packages/@aws-cdk/aws-cloudwatch/test/integ.alarm-with-label.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { App, Stack, StackProps } from '@aws-cdk/core'; | ||
import { Alarm, Metric } from '../lib'; | ||
|
||
class AlarmWithLabelIntegrationTest extends Stack { | ||
|
||
constructor(scope: App, id: string, props?: StackProps) { | ||
super(scope, id, props); | ||
|
||
const testMetric = new Metric({ | ||
namespace: 'CDK/Test', | ||
metricName: 'Metric', | ||
label: 'Metric [AVG: ${AVG}]', | ||
}); | ||
|
||
new Alarm(this, 'Alarm1', { | ||
metric: testMetric, | ||
threshold: 100, | ||
evaluationPeriods: 3, | ||
}); | ||
|
||
testMetric.createAlarm(this, 'Alarm2', { | ||
threshold: 100, | ||
evaluationPeriods: 3, | ||
}); | ||
} | ||
} | ||
|
||
const app = new App(); | ||
|
||
new AlarmWithLabelIntegrationTest(app, 'AlarmWithLabelIntegrationTest'); | ||
|
||
app.synth(); |
Is this OK?
Some of the metric names start with number (4xx, 5xx for api gateway), but the ID has following limitation: "The first character must be a lowercase letter."