(aws-cloudwatch): Metric widget can't display composite alarm
- Dominant language
- TypeScript
- Stars
- 12.9k
- Forks
- 4.6k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 83
Description
### Describe the bug
This might actually be a bug in CloudWatch itself, but I didn't know where else to report it.
According to the [documentation](https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/CloudWatch-Dashboard-Body-Structure.html#CloudWatch-Dashboard-Properties-Metric-Widget-Object) of the CW metric widget body structure, it should be possible to use a metric widget to display an alarm, provided that the `annotations` property is used like so:
```json
"annotations": {
"alarms": [ "arn1" ]
}
```
As of today, in my CW dashboards, this only works for metric alarms, but not composite alarms. For a composite alarm, I get the message `Alarm FooCompositeAlarm in region is missing or deleted`. I don't have a good sense of when this stopped working, but it was working on June 9. Editing the dashboard source manually to change the widget type to `alarm`, using the same alarm ARN, results in a working widget that correctly reports the status of my composite alarm.
Things I've tried to isolate the root cause:
* Different browsers: Chrome and Firefox
* Incognito mode to exclude browser caching as a culprit
### Regression Issue
- [ ] Select this option if this issue appears to be a regression.
### Last Known Working CDK Library Version
_No response_
### Expected Behavior
I expect my dashboard metric widget to display my composite alarm.
### Current Behavior
Metric widget claims the composite alarm doesn't exist, while I can clearly see it in CloudWatch, and I can graph it using an alarm widget.
### Reproduction Steps
Create a CloudWatch dashboard with a metric widget which displays a composite alarm.
The CDK code for generating the composite alarm from several individual metric alarms looks like:
```typescript
return new cw.CompositeAlarm(this.scope, `${feature.featureName}Alarm`, {
compositeAlarmName: generateName("AggregateAlarm"),
alarmRule: cw.AlarmRule.anyOf(...alarms),
alarmDescription: `Any alarm from the ${feature.featureName} subsystem has triggered.`,
});
```
Alarms then get added as metric widgets to the dashboard like so:
```typescript
const alarmWidgets = this.alarms.map(
(alarm) =>
new cloudwatch.AlarmWidget({
title: alarm.alarmName,
alarm: alarm,
}),
);
dashboard.addWidgets(new cloudwatch.Row(...alarmWidgets));
```
### Possible Solution
_No response_
### Additional Information/Context
_No response_
### AWS CDK Library version (aws-cdk-lib)
2.201.0
### AWS CDK CLI version
2.1003.0 (build b242c23)
### Node.js Version
v20.18.1
### OS
MacOS Sonoma 14.7.6
### Language
TypeScript
### Language Version
_No response_
### Other information
_No response_
Contributor guide
Research direction
Start at the CDK AlarmWidget entry point and reproduce the reported dashboard using a composite alarm, comparing the metric-widget and alarm-widget JSON it generates. Check whether the discrepancy is in CDK output or CloudWatch behavior; done means composite alarms display correctly or the issue is narrowed to an upstream CloudWatch defect.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, typescript
- Domain
- cloud, infrastructure
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 32/100