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

JSON diffs don't pretty print for nested properties #13981

Closed
jaxxstorm opened this issue Sep 18, 2023 · 7 comments · Fixed by #15171
Closed

JSON diffs don't pretty print for nested properties #13981

jaxxstorm opened this issue Sep 18, 2023 · 7 comments · Fixed by #15171
Assignees
Labels
area/cli UX of using the CLI (args, output, logs) kind/bug Some behavior is incorrect or out of spec resolution/fixed This issue was fixed
Milestone

Comments

@jaxxstorm
Copy link
Contributor

What happened?

We made some changes in #5831 whereby we pretty print JSON diffs for things like IAM roles to help with debugging.

However, this doesn't appear to work for nested properties, specifically for an AWS ECS Task Definition with a nested container definition, see the attached screenshot

Example

**
CleanShot 2023-09-18 at 11 26 36
**

Output of pulumi about

N/A

Additional context

No response

Contributing

Vote on this issue by adding a 👍 reaction.
To contribute a fix for this issue, leave a comment (and link to your pull request, if you've opened one already).

@jaxxstorm jaxxstorm added kind/bug Some behavior is incorrect or out of spec needs-triage Needs attention from the triage team labels Sep 18, 2023
@Frassle Frassle added area/cli UX of using the CLI (args, output, logs) and removed needs-triage Needs attention from the triage team labels Sep 18, 2023
@gunzy83
Copy link

gunzy83 commented Sep 20, 2023

This is still happening for IAM Policy objects on update as well:

image

This diff was far worse before I ran the generated policy document through JSON.stringify(JSON.parse(policyDoc), null, 0) to minify it.

Create operations seem to identify the input as JSON:
image

I think this might have something to do with how the JSON is stored in state which prevents the JSON diff from happening, we get a plaintext diff instead.

Both of the diffs above are running through the same codepaths in the same project/stack.

Pulumi version: 3.60.1
@pulumi/aws: 5.31.0

@gunzy83
Copy link

gunzy83 commented Nov 13, 2023

I believe this change #11803 introduced a bug where the json diff is never reached because the string comparison before it will cause it to always print the string diff.

Someone who is less green with go can correct me if I am wrong but if I am understanding this correctly, it might make more sense to implement this later in the function:

if diff == nil {
    if old != new {
        p.printTextDiff(strconv.Quote(old), strconv.Quote(new))
        return true
    }
    p.withOp(deploy.OpSame).printPropertyValue(oldValue)
    return true
}

@Frassle
Copy link
Member

Frassle commented Nov 13, 2023

I don't think that's a bug, looks like #11803 is doing what it was intended to do. There is no semantic JSON diff between the text strings so it shows the text diff instead.
It looks like that's the same for Lee's example in the initial message here as well.

This behaviour was suggested by @lukehoban at #11799 (comment) because the original behaviour was confusing but clearly this current style is also confusing just in a different way.

Maybe something as simple as prefixing it with "(json equivalent, showing text diff)" would help?

@gunzy83
Copy link

gunzy83 commented Nov 13, 2023

I have added more to my comment above, maybe I am misunderstanding where the json diff is being done, to me it looks like the text diff is being done before the json diff. See my screenshot below for what I mean:

image

The json is clearly not equivalent, I added an extra character only :)

@gunzy83
Copy link

gunzy83 commented Nov 13, 2023

This behaviour was suggested by @lukehoban at #11799 (comment) because the original behaviour was confusing but clearly this current style is also confusing just in a different way.

I just read that thread, I agree with the logic. I am just not convinced the json diff is getting printed with priority which makes the previews we get from this for large policy changes next to useless.

Maybe something as simple as prefixing it with "(json equivalent, showing text diff)" would help?

I think that would help in the case it is just a diff in the input vs stored text in state but I think we are talking about different things here?

@Frassle
Copy link
Member

Frassle commented Nov 14, 2023

The json is clearly not equivalent, I added an extra character only :)

Yeh ok that's clearly bugged then. I think your assessment that #11803 broke it is correct.

@D3-LucaPiombino
Copy link

D3-LucaPiombino commented Jan 14, 2024

We are hitting a similar issue.
We have a lot of json resources (e.g. in config maps), and diffs are very difficult to parse at the moment.
It seems to works (recognize the string as (json)) on creation or for example if the whole string is changed (e.g. changing from secret to non secret)

Is there any plan to pick this up/revisit?

Sorry, i did an attempt to see if i could contribute (instead of simply complaining :)) by playing around a little bit with the codebase.
Unfortunately i did not have much success as i am not very familiar with the go ecosystem/stack.

@Frassle Frassle self-assigned this Jan 18, 2024
Frassle added a commit that referenced this issue Jan 18, 2024
Frassle added a commit that referenced this issue Jan 18, 2024
@Frassle Frassle mentioned this issue Jan 18, 2024
6 tasks
@justinvp justinvp added this to the 0.99 milestone Jan 18, 2024
github-merge-queue bot pushed a commit that referenced this issue Jan 18, 2024
<!--- 
Thanks so much for your contribution! If this is your first time
contributing, please ensure that you have read the
[CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md)
documentation.
-->

# Description

<!--- Please include a summary of the change and which issue is fixed.
Please also include relevant motivation and context. -->

Fixes #13981.

This regressed in #11803. I've
added tests to this PR to show both the value diffing and text diffing
for when the JSON/YAML string is different but the values are the same.

## Checklist

- [x] I have run `make tidy` to update any new dependencies
- [x] I have run `make lint` to verify my code passes the lint check
  - [x] I have formatted my code using `gofumpt`

<!--- Please provide details if the checkbox below is to be left
unchecked. -->
- [x] I have added tests that prove my fix is effective or that my
feature works
<!--- 
User-facing changes require a CHANGELOG entry.
-->
- [x] I have run `make changelog` and committed the
`changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the
Pulumi Cloud,
then the service should honor older versions of the CLI where this
change would not exist.
You must then bump the API version in
/pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi
Cloud API version
<!-- @pulumi employees: If yes, you must submit corresponding changes in
the service repo. -->
@pulumi-bot pulumi-bot added the resolution/fixed This issue was fixed label Jan 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/cli UX of using the CLI (args, output, logs) kind/bug Some behavior is incorrect or out of spec resolution/fixed This issue was fixed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants