-
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
fix(core): message including tokens from annotations cannot output correctly #33706
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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 fails with the following errors:
❌ Fixes must contain a change to an integration test file and the resulting snapshot.
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.
✅ A exemption request has been requested. Please wait for a maintainer's review.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #33706 +/- ##
==========================================
+ Coverage 82.24% 82.25% +0.01%
==========================================
Files 119 119
Lines 6875 6879 +4
Branches 1161 1162 +1
==========================================
+ Hits 5654 5658 +4
Misses 1118 1118
Partials 103 103
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
Exemption Request: This PR could covered with unit tests only. And I think the integration test is unnecessary, as it should originally not allow tokens to be included in annotations. (CDK CLI would expect the type of string.) Also integ tests for annotations with tokens will make differences in manifest.json for every run. |
Dear team, I came up with the approach to change the data type to a string type after resolve if the data is by annotations with tokens. (see This approach doesn't make differences in manifest.json for every run and the original format (with 'Ref' or 'Fn::Join') is kept. However, the issue for this PR and comments in the PR submitted (aws-cdk-cli) has proposed the approach with unresolved tokens, I decided the approach 1 for now. Please let me know if the approach would be better. if (node.node.metadata.length > 0) {
// Make the path absolute
output[Node.PATH_SEP + node.node.path] = node.node.metadata.map(md => {
const resolved = stack.resolve(md) as cxschema.MetadataEntry;
const isAnnotation = [
cxschema.ArtifactMetadataEntryType.ERROR,
cxschema.ArtifactMetadataEntryType.WARN,
cxschema.ArtifactMetadataEntryType.INFO,
].includes(md.type as cxschema.ArtifactMetadataEntryType);
// Transform the data to a string for the case where Annotations include a token.
// Otherwise, the message is resolved and output as `[object Object]` after synth
// because the message will be object type using 'Ref' or 'Fn::Join'.
const mdWithStringData: cxschema.MetadataEntry = {
...resolved,
data: (isAnnotation && typeof resolved.data === 'object') ? JSON.stringify(resolved.data) : resolved.data,
};
return mdWithStringData;
});
} This approach outputs the message as the following style:
|
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
Issue # (if applicable)
Closes #33707
Reason for this change
If a stack with name 'some-stack' includes an info annotation
then the following output results:
That's because data comes from Annotations and the data can be of object type containing 'Fn::Join' or 'Ref' when tokens are included in Annotations.
The issue mentioned a proposal to output the data in the form of tokens like
[Info at /CdkSampleStack] ${Token[AWS::StackId.1116]}
.Description of changes
Approach 1 for now. (I am still wondering if approach 3 would be better...)
See below:
Approach 1
The PR makes messages with tokens by annotations unresolved.
NOTE
This change would also output a token format in
manifest.json
.If users run integ tests with annotations including tokens, the manifest.json would change for every run. (like
${Token[AWS::StackId.1119]}
->${Token[AWS::StackId.123]}
->${Token[AWS::StackId.521]}
-> ...)Approach 2
Change the type for the
msg.entry.data
(MetadataEntryData
forMetadataEntry
) to a string type withJSON.stringify
if the type is an objective type in cdk-cli.https://github.com/aws/aws-cdk-cli/blob/cdk%40v2.1003.0/packages/%40aws-cdk/toolkit-lib/lib/toolkit/toolkit.ts#L771
Then I had submitted the PR in aws-cdk-cli.
But talked with Rico that the change should be made inside cdk-lib and leave the token unrendered.
aws/aws-cdk-cli#101 (comment)
Approach 3
Change the data type to a string type after resolve if the data is by annotations with tokens.
This approach doesn't make differences in manifest.json for every run and the original format (with 'Ref' or 'Fn::Join') is kept.
However, the issue for this PR and comments in the PR submitted (aws-cdk-cli) has proposed the approach with unresolved tokens, I decided the approach 1 for now.
63fd78b
This approach outputs the message as the following style:
Additional Information
see:
#33707 (comment)
aws/aws-cdk-cli#101 (comment)
Describe any new or updated permissions being added
Description of how you validated changes
Unit tests.
Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license