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

deck diff shows different plugin configuration than sync creates #538

Closed
odsock opened this issue Dec 4, 2021 · 4 comments
Closed

deck diff shows different plugin configuration than sync creates #538

odsock opened this issue Dec 4, 2021 · 4 comments

Comments

@odsock
Copy link

odsock commented Dec 4, 2021

Using decK v1.8.2 (b538f70).
When updating a request-transformer plugin configuration to change list of headers to remove, the diff output is incorrect. I'm changing the config from removing one header, to removing two different headers. Syncing the change has the correct result, only the diff output is wrong (output in both diff and sync).

Original state yaml:

      remove:
        body: []
        headers:
        - x-posting-ip
        querystring: []

The change:

      remove:
        body: []
        headers:
        - accept-encoding
        - x-forwarded-for
        querystring: []

The diff output shows the original single entry being removed, and then the first of the two new entries twice:

       "headers": [
-        "x-posting-ip"
+        "accept-encoding"
+        "accept-encoding"
       ],

It should be this:

       "headers": [
-        "x-posting-ip"
+        "accept-encoding"
+        "x-forwarded-for"
       ],

Example configuration and output attached.
deck-test.zip

@GGabriele
Copy link
Collaborator

Hi @odsock,

thanks for highlighting this!

I dug this a bit and apparently this is related to the third-party library deck uses to compute JSON diffs, and I was able to reproduce this entirely in gojsondiff:

$ jd before.json after.json

               "headers": [
-                0: "x-posting-ip"
+                0: "accept-encoding"
+                0: "accept-encoding"
               ],

Not only that, the library seems to be pretty much unreliable when dealing with arrays, as changing the content of the initial one affects the final output as well:

$ cat before.json
...
...
                      "headers": [
                         "blabla" // instead of "x-posting-ip"
                      ],
...
...

$ jd before.json after.json

               "headers": [
+                0: "accept-encoding"
               ],

There are already some GH issues related to this (yudai/gojsondiff#30 and yudai/gojsondiff#24), but the repo has not been updated in the last 4 years, so maybe we should evaluate something else.

@GGabriele
Copy link
Collaborator

GGabriele commented Jan 11, 2022

This looks like a good candidate:

	opts := jsondiff.DefaultConsoleOptions()
	opts.PrintTypes = false
	opts.Added = jsondiff.Tag{Begin: "+ "}
	opts.Removed = jsondiff.Tag{Begin: "- "}
	opts.Changed = jsondiff.Tag{Begin: "+ "}
	_, diffString := jsondiff.Compare(aJSON, bJSON, &opts)
updating plugin request-transformer for service 9972eec7-2aab-42c3-bc45-af1dcdfc50ef {
    "config": {
        "add": {
            "body": [],
            "headers": [],
            "querystring": []
        },
        "append": {
            "body": [],
            "headers": [],
            "querystring": []
        },
        "http_method": null,
        "remove": {
            "body": [],
            "headers": [
                + "x-posting-ip" => "accept-encoding",
                + "x-forwarded-for"
            ],
            "querystring": []
        },
        "rename": {
            "body": [],
            "headers": [],
            "querystring": []
        },
        "replace": {
            "body": [],
            "headers": [],
            "querystring": [],
            "uri": null
        }
    },
    "enabled": true,
    "id": "b5904c75-8494-420a-9865-9a93d04b5d76",
    "name": "request-transformer",
    "protocols": [
        "grpc",
        "grpcs",
        "http",
        "https"
    ],
    "service": {
        "id": "9972eec7-2aab-42c3-bc45-af1dcdfc50ef"
    },
    "tags": [
        "deck-test"
    ]
}
Summary:
  Created: 0
  Updated: 1
  Deleted: 0

Also this, although it doesn't return the matched lines:

	before, _ := jd.ReadJsonString(string(aJSON))
	after, _ := jd.ReadJsonString(string(bJSON))
	diffString := before.Diff(after).Render()
updating plugin request-transformer for service 9972eec7-2aab-42c3-bc45-af1dcdfc50ef @ ["config","remove","headers",0]
- "x-posting-ip"
+ "accept-encoding"
@ ["config","remove","headers",1]
+ "x-forwarded-for"

Summary:
  Created: 0
  Updated: 1
  Deleted: 0

@hbagdi
Copy link
Member

hbagdi commented Jan 11, 2022

@GGabriele Can we try fixing the bug in the third-party library that we are currently using? That path maybe simpler.
Changing libraries could have significant differences and break our users.

@GGabriele
Copy link
Collaborator

#635 has been merged. Closing this. Please feel free to comment back or open a new issue if something weird pops out!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants