Skip to content
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

fix(cloudwatch): render region and accountId when directly set on metrics #32325

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

TrevorBurnham
Copy link

Issue

Closes #28731

Reason for this change

Currently, if a user creates a metric that includes region and accountId, those fields are omitted when the metric renders in a stack with those same values. The intended behavior is to omit those fields when they're implicitly set via metric.attachTo(stack), not to omit them when set directly by the user.

Description of changes

This is a second attempt at #29935, which was auto-closed after the pull request linter complained that there were no integration test changes. This time around I've tried to satisfy the linter. Otherwise, the changes are the same as before:

The key changes here are on the Metric class. Previously, region and account were public properties that were set by metric.attachTo(stack), making it impossible to differentiate whether they were set directly or via attachTo. To differentiate them while maintaining backward compatibility, I took this approach:

  1. attachTo sets internal properties called stackRegion and stackAccount. Setting region and account directly sets internal properties called regionOverride and accountOverride.
  2. The public region and account properties are now getters that return the override (if set) and fall back on the stack properties.
  3. The toMetricConfig() method returns the region and account from the getters, but also includes the regionOverride and accountOverride.

That way, everything that looks at region and account works the same way it did before, except in metricGraphJson, which skips the "if different from stack" tokenization if the overrides are set.

Description of how you validated changes

  1. Confirmed that all existing unit tests pass.
  2. Added a new unit test to show that region and account are now preserved when set directly on a metric.
  3. Modified an integration test to show how setting region and account on a metric affects the snapshot.

Checklist


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@github-actions github-actions bot added bug This issue is a bug. effort/medium Medium work item – several days of effort p2 beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK labels Nov 28, 2024
@aws-cdk-automation aws-cdk-automation requested a review from a team November 28, 2024 20:54
Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pull request linter has failed. See the aws-cdk-automation comment below for failure reasons. If you believe this pull request should receive an exemption, please comment and provide a justification.

A comment requesting an exemption should contain the text Exemption Request. Additionally, if clarification is needed add Clarification Request to a comment.

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: 2595f62
  • Result: FAILED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@TrevorBurnham TrevorBurnham changed the title fix(cloudwatch): Render region and accountId when directly set on metrics fix(cloudwatch): render region and accountId when directly set on metrics Nov 28, 2024
@aws-cdk-automation aws-cdk-automation dismissed their stale review November 28, 2024 21:12

✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.

@TrevorBurnham
Copy link
Author

I don't know what's going on in the build log. It says:

Failed tasks:

- aws-cdk-lib:test
...
�  Last command failed. Scroll up to see errors in log (search for '!!!!!!!!').

But there are no matches for !!!!!!!! anywhere else in the log. 😕

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK bug This issue is a bug. effort/medium Medium work item – several days of effort p2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cloudwatch: Explicitly set region and accountId fields are removed from metrics when they match the stack
2 participants