Skip to content

fix(core): implicit Aspect applications do not override custom Aspect applications #34132

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

Merged
merged 12 commits into from
Apr 14, 2025

Conversation

rix0rrr
Copy link
Contributor

@rix0rrr rix0rrr commented Apr 14, 2025

Some CDK methods apply mutating Aspects on behalf of users. Since #32333, these Aspects have a priority of MUTATING to classify their behavior.

If a user-applied Aspect (priority DEFAULT) now configures the same property as an implicitly added Aspect:

  • Before that change, the relative execution order depended on the location of the Aspects in the construct tree.
  • After that change, the user Aspect always "wins" (executes last) because its priority is higher.

In this change, we roll back to the behavior from pre-2.172.0, and introduce a feature flag which gives the Aspects a priority only if the feature flag is enabled. This introduces the feature flag:

{
  "context": {
    "@aws-cdk/core:aspectPrioritiesMutating": true
  }
}

Which sets the priority of Aspects added on your behalf a priority of MUTATING (200) (instead of the default DEFAULT, 500).

  • If you have given your own Aspect a priority of MUTATING already to make sure it can get overridden by another Aspect of priority MUTATING, this current change will not affect you (either with or without feature flag).
  • If you have come to rely on the new default priority being low already, you can set the above feature flag to re-enable the new behavior.

Did not touch the following Aspects:

  • In integ-tests-alpha: overriding logical IDs in assertions stacks does not affect production infrastructure.
  • Tags: tags are exclusively manipulated through the official APIs, so there no conflict between custom and implicit Aspects.
  • CDK Pipelines: there cannot be a conflict because the customer can't create a default pipeline before the implicit Aspect.

This PR also introduces some slight rendering and documentation changes to the feature flags to improve clarity of the purpose of certain fields and the produced report.

rix0rrr added 2 commits March 27, 2025 14:17
… applications

Some CDK methods apply mutatinhg Aspects on behalf of users. Since
#32333, these Aspects have a priority
of `MUTATING` to classify their behavior.

If a user-applied Aspect (priority `DEFAULT`) now configures the same
property as an implicitly added Aspect:

* Before that change, the relative execution order depended on the
  location of the Aspects in the construct tree.
* After that change, the user Aspect always "wins" (executes last)
  because its priority is higher.

In this change, we introduce a feature flag which gives the Aspects
introduced in #32333 that users are
likely to override a priority only if the feature flag is enabled. This
change does not affect users have given their own Aspects a `MUTATING`
priority as well since 2.172.0.

Did not touch the following Aspects:

- In `integ-tests-alpha`: overriding logical IDs in assertions stacks
  does not affect production infrastructure.
- Tags: tags are exclusively manipulated through the official APIs,
  so there no conflict between custom and implicit Aspects.
- CDK Pipelines: there cannot be a conflict because the customer
  can't create a default pipeline before the implicit Aspect.
@rix0rrr rix0rrr requested a review from a team as a code owner April 14, 2025 06:44
@aws-cdk-automation aws-cdk-automation requested a review from a team April 14, 2025 06:44
@github-actions github-actions bot added the p2 label Apr 14, 2025
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Apr 14, 2025
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.

(This review is outdated)

@rix0rrr rix0rrr added the pr-linter/exempt-integ-test The PR linter will not require integ test changes label Apr 14, 2025
@aws-cdk-automation aws-cdk-automation dismissed their stale review April 14, 2025 07:24

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

@aws-cdk-automation aws-cdk-automation added the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Apr 14, 2025
Copy link
Contributor

mergify bot commented Apr 14, 2025

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

Copy link
Contributor

@iliapolo iliapolo left a comment

Choose a reason for hiding this comment

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

What about:

priority: props.priority ?? AspectPriority.MUTATING,

Aspects.of(this.scope).add(new CustomResourceRemovalPolicy(removalPolicy), { priority: AspectPriority.MUTATING });

Aspects.of(this.scope).add(new CustomResourceLambdaRuntime(lambdaRuntime), { priority: AspectPriority.MUTATING });

Also, you mention:

Tags: tags are exclusively manipulated through the official APIs, so there no conflict between custom and implicit Aspects

Can you elaborate? is it not possible that both Tags and a user defined aspect look at the same .tags property of construct?

@@ -1464,6 +1469,39 @@ export const FLAGS: Record<string, FlagInfo> = {
},

//////////////////////////////////////////////////////////////////////
[ASPECT_PRIORITIES_MUTATING]: {
type: FlagType.ApiDefault,
summary: 'When set to true, Aspects added by the construct library on your behalf will be given a priority of MUTATING.',
Copy link
Contributor

Choose a reason for hiding this comment

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

All aspects will be given MUTATING, or just ones that actually mutate?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think we add any non-mutating aspects.

Copy link
Contributor

Choose a reason for hiding this comment

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

right now

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well this only affects pre-2.172.0 aspects anyway. Aspects added in the future don't have backwards compatibility concerns.

@iliapolo iliapolo added the pr/do-not-merge This PR should not be merged at this time. label Apr 14, 2025
Copy link
Contributor

mergify bot commented Apr 14, 2025

This pull request has been removed from the queue for the following reason: pull request dequeued.

Pull request #34132 has been dequeued, merge conditions unmatch:

  • -label~=(blocked|do-not-merge|no-squash|priority-pr)
  • status-success~=AWS CodeBuild us-east-1
  • any of [🛡 GitHub branch protection]:
    • check-neutral = AWS CodeBuild us-east-1 (AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv)
    • check-skipped = AWS CodeBuild us-east-1 (AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv)
    • check-success = AWS CodeBuild us-east-1 (AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv)
  • #approved-reviews-by >= 1 [🛡 GitHub branch protection]
  • #approved-reviews-by>=1
  • #changes-requested-reviews-by = 0 [🛡 GitHub branch protection]
  • #changes-requested-reviews-by=0
  • -approved-reviews-by~=author
  • -closed
  • -merged
  • -title~=(WIP|wip)
  • base!=release
  • status-success=validate-pr
  • any of [🛡 GitHub branch protection]:
    • check-success = validate-pr
    • check-neutral = validate-pr
    • check-skipped = validate-pr

You should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it.
If you do update this pull request, it will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue instead, you can requeue the pull request, without updating it, by posting a @mergifyio requeue comment.

@aws-cdk-automation aws-cdk-automation removed the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Apr 14, 2025
@rix0rrr
Copy link
Contributor Author

rix0rrr commented Apr 14, 2025

Re: RemovalPolicies and Tags.

is it not possible that both Tags and a user defined aspect look at the same .tags property of construct?

The reason I didn't do those initially was "blast radius reduction". It is of course possible that a user defined aspect touches those values, but there are well-established and well-known APIs for manipulating them. Since we are protecting solely against the case where a custom aspect picks a default value, and relies on a built-in API to override that default... I figured it is just just unlikely that people would do that, plus they are so widely-used that I considered changing them (again) a little scary.

On the other hand, given that we changed their behavior months ago and we haven't heard anyone complain about it, it should be equally safe to change that behavior back for consistency's sake. Guess I'll do that.

@rix0rrr rix0rrr removed the pr/do-not-merge This PR should not be merged at this time. label Apr 14, 2025
@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: b59f93f
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

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

Copy link
Contributor

mergify bot commented Apr 14, 2025

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@mergify mergify bot merged commit 9a76fdc into main Apr 14, 2025
13 of 14 checks passed
@mergify mergify bot deleted the huijbers/pb-fix branch April 14, 2025 13:25
Copy link
Contributor

Comments on closed issues and PRs are hard for our team to see.
If you need help, please open a new issue that references this one.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 14, 2025
@rix0rrr rix0rrr self-assigned this Apr 17, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
contribution/core This is a PR that came from AWS. p2 pr-linter/exempt-integ-test The PR linter will not require integ test changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants