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

feat(translator): JsonPath in PatchPolicy #3757

Merged
merged 1 commit into from
Aug 13, 2024

Conversation

denniskniep
Copy link
Contributor

@denniskniep denniskniep commented Jul 4, 2024

JsonPath can be utilized to select elements for JSONPatch in EnvoyPatchPolicy

Fixes #1686

EnvoyPatchPolicy API Changes:

  • Added jsonPath
  • path is optional

These changes are backwards compatible

Change Summary:
jsonPath is evaluated based on the json and the patch is done for all found items (pointers)

We can only "find" existing items in the json with jsonPath. Therefore we need a way to extend the found items (pointers). This enables us to add not existing properties. This is implemented by adding the string of the path to the end of the found items (pointers)

Example:
jsonPath: "filter_chains[*].filters[*].typed_config"
path: "/preserve_external_request_id"

will find following items (pointers):
/filter_chains/0/filters/0/typed_config
/filter_chains/0/filters/1/typed_config

Final jsonPointers which are used withing the JSONPatch:
/filter_chains/0/filters/0/typed_config/preserve_external_request_id
/filter_chains/0/filters/1/typed_config/preserve_external_request_id

@denniskniep
Copy link
Contributor Author

@arkodg can you plz have a quick look if this is the right direction?
If yes, I will start working on the docs or should that be handled by a different PR?

Copy link

codecov bot commented Jul 18, 2024

Codecov Report

Attention: Patch coverage is 59.30233% with 70 lines in your changes missing coverage. Please review.

Project coverage is 67.64%. Comparing base (866a6ce) to head (72b8113).
Report is 11 commits behind head on main.

Files Patch % Lines
internal/xds/translator/jsonpatch.go 33.33% 52 Missing and 16 partials ⚠️
internal/xds/translator/jsonpathtopointer.go 97.10% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##             main    #3757    +/-   ##
========================================
  Coverage   67.64%   67.64%            
========================================
  Files         185      187     +2     
  Lines       22578    22859   +281     
========================================
+ Hits        15272    15464   +192     
- Misses       6213     6282    +69     
- Partials     1093     1113    +20     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@denniskniep denniskniep force-pushed the feature/envoypatch-jsonpath branch from ff58774 to e3ff2eb Compare August 8, 2024 15:04
@denniskniep denniskniep marked this pull request as ready for review August 8, 2024 15:07
@denniskniep denniskniep requested a review from a team as a code owner August 8, 2024 15:07
@denniskniep denniskniep force-pushed the feature/envoypatch-jsonpath branch from e3ff2eb to c8a10a5 Compare August 9, 2024 13:08
@@ -0,0 +1,163 @@
envoyPatchPolicies:
Copy link
Contributor

Choose a reason for hiding this comment

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

can we add examples with filters, which is the real value prop for using jsonpatch over path since its hard to figure out index

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will add this test. It makes clear, that you do not need to go through all parent nested properties and you can select explicitly the route by name, which is much more reliable then selecting via index:

  - type: "type.googleapis.com/envoy.config.route.v3.RouteConfiguration"
    name: "first-listener"
    operation:
      op: "replace"
      jsonPath: "..routes[?(@.name=='second-route')].route.upgrade_configs"
      value:
      - upgrade_type: CONNECT
        connect_config:
          {}

but there is already this scenario:
jsonPath: "..endpoints[*].load_balancing_weight"
which addresses ALL endpoints, which is not possible right now

"github.com/stretchr/testify/require"
)

type pointerTest struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

to maintain uniformity, can these tests be represented in this

tests := []struct {
format ? (moving the struct def inside the test itself)

@arkodg
Copy link
Contributor

arkodg commented Aug 12, 2024

hey @denniskniep sorry for the delay in review, the diff looks good !
added a few minor comments

JsonPath can be utilized to select elements for JSONPatch
in EnvoyPatchPolicy

Signed-off-by: Dennis Kniep <[email protected]>
@denniskniep denniskniep force-pushed the feature/envoypatch-jsonpath branch from c8a10a5 to 72b8113 Compare August 13, 2024 13:21
@denniskniep
Copy link
Contributor Author

hey @denniskniep sorry for the delay in review, the diff looks good ! added a few minor comments

cool, thx

@arkodg addressed your comments

Copy link
Contributor

@arkodg arkodg left a comment

Choose a reason for hiding this comment

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

LGTM thanks for adding this feature !
hopefully this makes it easier to author EnvoyPatchPolicies for modifying elements within a list

@arkodg arkodg requested review from a team August 13, 2024 14:26
@arkodg arkodg added this to the v1.2.0-rc1 milestone Aug 13, 2024
@arkodg arkodg merged commit d6ad7de into envoyproxy:main Aug 13, 2024
27 checks passed
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

Successfully merging this pull request may close these issues.

Allowing matching a filterchain when applying EnvoyPatchPolicy
3 participants