(cloudwatch): Not able to create blank widgets without metrics as stated in docs
- Dominant language
- TypeScript
- Stars
- 12.9k
- Forks
- 4.6k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 83
Description
### Describe the feature
Whenever you create a `GraphWidget`, it errors unless it contains a metric in either `left=[]` or `right=[]`.
### Use Case
I have a base stack with shared resources, then any number of leaf stacks that take in the base stack as input. ("one to many" basically. Each leaf stack is the same infrastructure, deployed with different flags/configs).
What I'd like to do is create a dashboard with blank widgets in the base stack, then each leaf stack can add themselves to all the widgets. This way you get a nice graph of how each leaf stack is doing, along with how they compare to one another.
### Proposed Solution
The ability to create blank widgets, without any metrics inside of them.
### Other Information
With something like:
```python
self.dashboard = cloudwatch.Dashboard(
self,
"CloudwatchDashboard",
dashboard_name=f"{construct_id}-dashboard",
)
self.widget = cloudwatch.GraphWidget(
height=6,
width=12,
left=[],
)
self.dashboard.add_widgets(self.widget)
# In another stack, the plan is to call `base_stack.widget.add_left_metric(metric)`
```
I get the error:
```
The stack named failed to deploy: UPDATE_ROLLBACK_COMPLETE: Resource handler returned message: "The dashboard body is invalid, there are 3 validation errors:
[
{
"dataPath": "/widgets/0/properties",
"message": "Should have required property 'metrics'"
},
{
"dataPath": "/widgets/0/properties",
"message": "The metric widget should have specified a region and a data source or an alarm annotation"
},
{
"dataPath": "/widgets/0/properties",
"message": "Should have required property 'annotations'"
}
]
```
However when I instead do:
```python
self.dashboard = cloudwatch.Dashboard(
self,
"CloudwatchDashboard",
dashboard_name=f"{construct_id}-dashboard",
)
self.widget = cloudwatch.GraphWidget(
height=6,
width=12,
# The only thing I change is here:
left=[cloudwatch.Metric(
metric_name="ECS",
namespace="AWS/AutoScaling",
)],
)
self.dashboard.add_widgets(self.widget)
```
Then it deploys fine. It just has a metric in the dashboard without any data. Having a blank metric you ignore feels hacky though.
Semi-related issues:
- https://github.com/aws/aws-cdk/issues/11305 suggests this should work now? But I'm having issues.
- https://github.com/aws/aws-cdk/issues/7627#issuecomment-716746611 Same error as me. I wonder if this error is related to **all** `ConcreteWidget`?
### Acknowledgements
- [ ] I may be able to implement this feature request
- [ ] This feature might incur a breaking change
### CDK version used
2.157.0 (build 7315a59)
### Environment details (OS name and version, etc.)
Fedora 40, python3.12.5, npm 10.8.3
Contributor guide
Research direction
Start by reproducing the deployment with an empty cloudwatch.GraphWidget using left=[] and compare it with the placeholder Metric example. Read the GraphWidget, Dashboard, ConcreteWidget, and add_left_metric entry points, along with related issues 11305 and 7627. Done means a blank widget can be created and deployed, then receive metrics from another stack without a placeholder metric.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, python, typescript
- Domain
- cloud, observability-sre
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100