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

chore: hide diffs of mangled unicode strings #25912

Merged
merged 2 commits into from
Jun 15, 2023
Merged

chore: hide diffs of mangled unicode strings #25912

merged 2 commits into from
Jun 15, 2023

Conversation

laverdet
Copy link
Contributor

@laverdet laverdet commented Jun 9, 2023

I am reopening this from #25525

and following up on my comments here:
#24557 (comment)
#24557 (comment)
#25008 (comment)
#25008 (comment)
#25008 (comment)
#25008 (comment)
#25008 (comment)
#25008 (comment)
#25525 (comment)
#25525 (comment)
🫠 #25525 (comment) 🫠


Fixes #25309
Fixes #22203
Fixes #20212
Fixes #13634
Fixes #10523
Fixes #10219
See also: aws-cloudformation/cloudformation-coverage-roadmap#1220
See also: aws-cloudformation/cloudformation-coverage-roadmap#814


👻 I have retitled this PR as a chore instead of a fix because @aws-cdk-automation keeps closing my PRs as abandoned even though they are clearly not abandoned.

This PR has been deemed to be abandoned, and will be automatically closed. Please create a new PR for these changes if you think this decision has been made in error.


@otaviomacedo @rix0rrr @TheRealAmazonKendra - I'm happy to adjust the approach, add more tests, or do what else needs to be done. I'm not getting any feedback from the team so I'm not sure how to proceed. The diff noise with non-ASCII information in cdk diff makes it difficult to find meaningful changes to our stacks.

🗿🗞️📬 Crucially, this change only affects the CLI output and therefore an integration test isn't possible.


CloudFormation's GetStackTemplate irrecoverably mangles any character not in the 7-bit ASCII range. This causes noisy output from cdk diff when a template contains non-English languages or emoji. We can detect this case and consider these strings equal.

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

Many AWS services accept non-ASCII input, eg many "description" fields. CloudFormation will correctly dispatch these templates but when invoking GetStackTemplate the result is mangled. This causes annoying noise in the output of cdk diff:

Resources
[~] AWS::Lambda::Function Lambda/Resource
 └─ [~] Description
     ├─ [-] ?????
     └─ [+] 🤦🏻‍♂️

This change modifies the diff algorithm to consider the string equal if the lvalue is a mangled version of the rvalue.

Of course this runs the risk of hiding changesets which modify only a single non-ASCII character to another non-ASCII character, but these fields already tend to be informative in nature.

CloudFormation's `GetStackTemplate` irrecoverably mangles any character
not in the 7-bit ASCII range. This causes noisy output from `cdk diff`
when a template contains non-English languages or emoji. We can detect
this case and consider these strings equal. This can be disabled by
passing `--strict`.

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@gitpod-io
Copy link

gitpod-io bot commented Jun 9, 2023

@github-actions github-actions bot added the beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK label Jun 9, 2023
@aws-cdk-automation aws-cdk-automation requested a review from a team June 9, 2023 00:32
@github-actions github-actions bot added bug This issue is a bug. effort/medium Medium work item – several days of effort p1 labels Jun 9, 2023
@aws-cdk-automation aws-cdk-automation added the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Jun 9, 2023
Copy link
Contributor

@otaviomacedo otaviomacedo left a comment

Choose a reason for hiding this comment

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

Hi, @laverdet. Sorry for missing your previous PR. I understand that CloudFormation is lossy in this respect, by putting all non-ASCII characters in the same equivalence class. But this fact would become more evident to both users and developers if we separated transformation from comparison:

  1. Transform the original local template into its mangled version (in memory).
  2. Compare the mangled version with the CFN result using deepEquals() as it is today.
  3. If original !== mangled, display a warning to let users know that the result of this diff may contain false negatives.

@corymhall corymhall removed the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Jun 13, 2023
@laverdet
Copy link
Contributor Author

@otaviomacedo thank you for following up. I agree that the suggested approach is more informative and now has no downsides. I've updated the PR to implement that idea, and piggy-backed on the --strict flag to switch it off.

@mergify mergify bot dismissed otaviomacedo’s stale review June 13, 2023 18:35

Pull request has been modified.

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 aws-cdk-automation added the pr/needs-cli-test-run This PR needs CLI tests run against it. label Jun 13, 2023
@otaviomacedo otaviomacedo added the pr-linter/cli-integ-tested Assert that any CLI changes have been integ tested label Jun 15, 2023
@aws-cdk-automation aws-cdk-automation dismissed their stale review June 15, 2023 07:55

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

@aws-cdk-automation aws-cdk-automation removed the pr/needs-cli-test-run This PR needs CLI tests run against it. label Jun 15, 2023
@mergify
Copy link
Contributor

mergify bot commented Jun 15, 2023

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).

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

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

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

@mergify mergify bot merged commit 9c8f549 into aws:main Jun 15, 2023
5 checks passed
@mergify
Copy link
Contributor

mergify bot commented Jun 15, 2023

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).

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 p1 pr-linter/cli-integ-tested Assert that any CLI changes have been integ tested
Projects
None yet
4 participants