-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cloudwatch: Explicitly set region and accountId fields are removed from metrics when they match the stack #28731
Comments
Looks like all conditions here have to be satisfied aws-cdk/packages/aws-cdk-lib/aws-cloudwatch/lib/metric.ts Lines 339 to 349 in 20ad55e
Otherwise a new Matric will be created and
IMO, yes, if you specify the region explicitly, it should be passed and defined explicitly. I am making it a p2 but we welcome and appreciate any pull requests. |
I am in the same situation, when the 2 metrics are rendered, the second metric doesn't have a region specified and so the region for the above metric is used, breaking the second metric this is the same graph generated manually without CDK: I guess that happens because when a metric doesn't have a specific region and the one above has one, the metric inherits that region and not the stack region, so the logic around how cdk hides the region if not required (because it's in the environment) doesn't really follow how cloudwatch dashboards work. |
Describe the bug
In my dashboard created from the CDK, I noticed that the
region
property was missing from metrics when that metric matched the stack. For example, for a stack in us-east-1, the metrics would look like this:This broke some region-based filtering logic in my UI application.
Expected Behavior
I expected the
region
field to exist for all of my metrics, since I was setting it explicitly:Current Behavior
During serialization, the
region
andaccountId
fields are removed if they match the correspondingregion
andaccount
values on the stack.Reproduction Steps
You can confirm the behavior by adding this unit test to
cross-environment.test.ts
:Possible Solution
The problem arises from these two lines in the
metricGraphJson
function:aws-cdk/packages/aws-cdk-lib/aws-cloudwatch/lib/private/rendering.ts
Lines 50 to 51 in 109b2ab
I'm not sure, but I think the intent here is to prevent the
region
andaccount
from being included in the output if they were set implicitly by theattachTo
function. As that function's description says:I'm not sure why it's so important to prevent the
region
andaccount
fields from being included when they match the stack, but if it is, you could haveattachTo
attach a placeholder thatmetricGraphJson
can process appropriately (e.g."${ifDifferentFromStack(us-east-1)}"
) rather than attaching a value that's indistinguishable from one that's been explicitly set.Additional Information/Context
No response
CDK CLI Version
2.121.1
Framework Version
No response
Node.js Version
18.15.0
OS
macOS 13.6.3
Language
TypeScript
Language Version
No response
Other information
Possibly related to #18951?
The text was updated successfully, but these errors were encountered: