Skip to content

NET-4135 - Fix NodeMeta filtering Catalog List Services API#18322

Merged
asheshvidyut merged 40 commits into
mainfrom
NET-4135
Oct 8, 2023
Merged

NET-4135 - Fix NodeMeta filtering Catalog List Services API#18322
asheshvidyut merged 40 commits into
mainfrom
NET-4135

Conversation

@asheshvidyut
Copy link
Copy Markdown
Contributor

@asheshvidyut asheshvidyut commented Jul 28, 2023

Description

Fixed the working of filter query parameter in /v1/catalog/services API. Fixes - #17422

Testing & Reproduction steps

Followed this tutorial and setup workloads in K8s.
Did curl -

asheshvidyut@asheshvidyut-H2GX766V9T ~/consul (NET-4135) » curl -ks -G http://localhost:8500/v1/catalog/services --data-urlencode filter="NodeMeta[\"consul-network-segment\"] == \"\" and NodeMeta[\"consul-version\"] == \"1.17.0\"" | jq
{
  "consul": []
}
asheshvidyut@asheshvidyut-H2GX766V9T ~/consul (NET-4135) » curl -ks -G http://localhost:8500/v1/catalog/services --data-urlencode filter="NodeMeta[\"synthetic-node\"] == true" | jq
{
  "frontend": [],
  "frontend-sidecar-proxy": [],
  "nginx": [],
  "nginx-sidecar-proxy": [],
  "payments": [],
  "payments-sidecar-proxy": [],
  "postgres": [],
  "postgres-sidecar-proxy": [],
  "products-api": [],
  "products-api-sidecar-proxy": [],
  "public-api": [],
  "public-api-sidecar-proxy": []
}

PR Checklist

  • updated test coverage
  • external facing docs updated
  • appropriate backport labels added
  • not a security concern

@asheshvidyut asheshvidyut marked this pull request as ready for review July 28, 2023 18:11
@asheshvidyut asheshvidyut changed the title NET-4135 NET-4135 - Fix NodeMeta filtering Catalog List Services API Jul 28, 2023
@asheshvidyut asheshvidyut requested review from a team, JadhavPoonam, github-team-consul-core-pr-approver, hc-github-team-consul-core and lkysow and removed request for a team July 28, 2023 18:13
@asheshvidyut
Copy link
Copy Markdown
Contributor Author

@david-yu - please help me with the backports.

Comment thread agent/consul/state/catalog.go Outdated
Comment on lines +1239 to +1243
parsedResult, err := parseServiceNodes(tx, ws, result, entMeta, peerName)
if err != nil {
return 0, nil, fmt.Errorf("failed querying and parsing services :%s", err)
}
return idx, parsedResult, nil
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@rboyer I saw you were the one that added parseServiceNodes to a bunch of other endpoints back in 2022. Is there any performance implications we need to think about for adding this to this endpoint as well? This change is needed to fill in nodemeta so it can be filtered on.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Currently we only do the expensive join against the nodes table when the user provides the NodeMeta parameter on the original API query. When they do this we call a completely different function link.

If we were concerned like that, we could instead alter the Store.Services method to take an extra boolean parameter to conditionally join the NodeMeta as in this PR.

Then the calling code in agent/consul/catalog_endpoint.go could set the flag to true when filter != "" OR just when:

strings.Contains(strings.ToLower(filter), "nodemeta")

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@rboyer I have updated the PR can I merge this now? please approve.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@rboyer I have updated the PR can I merge this now? please approve.

@lkysow
Copy link
Copy Markdown
Contributor

lkysow commented Jul 28, 2023

Can we simplify this if/else now:

if len(args.NodeMetaFilters) > 0 {
reply.Index, serviceNodes, err = state.ServicesByNodeMeta(ws, args.NodeMetaFilters, &args.EnterpriseMeta, args.PeerName)
} else {
reply.Index, serviceNodes, err = state.Services(ws, &args.EnterpriseMeta, args.PeerName)
}

@asheshvidyut
Copy link
Copy Markdown
Contributor Author

Can we simplify this if/else now:

if len(args.NodeMetaFilters) > 0 {
reply.Index, serviceNodes, err = state.ServicesByNodeMeta(ws, args.NodeMetaFilters, &args.EnterpriseMeta, args.PeerName)
} else {
reply.Index, serviceNodes, err = state.Services(ws, &args.EnterpriseMeta, args.PeerName)
}

I think we want to node-meta also. What do you think?

@lkysow
Copy link
Copy Markdown
Contributor

lkysow commented Jul 28, 2023

I was wondering if NodeMetaFilters can be encoded as a bexpr expression.

absolutelightning added 2 commits July 29, 2023 00:09
@asheshvidyut
Copy link
Copy Markdown
Contributor Author

I was wondering if NodeMetaFilters can be encoded as a bexpr expression.

I think no, because node-meta is a json like structure but filter takes expression with == , "and" or "or"

Comment thread agent/catalog_endpoint.go Outdated
@david-yu
Copy link
Copy Markdown
Contributor

Added backports to 1.16.x, 1.15.x, and 1.14.x.

@david-yu david-yu linked an issue Jul 29, 2023 that may be closed by this pull request
@asheshvidyut asheshvidyut requested a review from lkysow July 29, 2023 03:53
@asheshvidyut
Copy link
Copy Markdown
Contributor Author

@rboyer @lkysow please let me know the next steps.

@david-yu
Copy link
Copy Markdown
Contributor

david-yu commented Oct 6, 2023

Thank you for the review. @absolutelightning could you go ahead and merge and follow up with the backports?

@asheshvidyut asheshvidyut enabled auto-merge (squash) October 8, 2023 12:34
@asheshvidyut asheshvidyut merged commit a30ccdf into main Oct 8, 2023
@asheshvidyut asheshvidyut deleted the NET-4135 branch October 8, 2023 12:48
asheshvidyut added a commit that referenced this pull request Oct 8, 2023
* logs for debugging

* Init

* white spaces fix

* added change log

* Fix tests

* fix typo

* using queryoptionfilter to populate args.filter

* tests

* fix test

* fix tests

* fix tests

* fix tests

* fix tests

* fix variable name

* fix tests

* fix tests

* fix tests

* Update .changelog/18322.txt

Co-authored-by: Ganesh S <ganesh.seetharaman@hashicorp.com>

* fix change log

* address nits

* removed unused line

* doing join only when filter has nodemeta

* fix tests

* fix tests

* Update agent/consul/catalog_endpoint.go

Co-authored-by: R.B. Boyer <4903+rboyer@users.noreply.github.com>

* fix tests

* removed unwanted code

---------

Co-authored-by: Ganesh S <ganesh.seetharaman@hashicorp.com>
Co-authored-by: R.B. Boyer <4903+rboyer@users.noreply.github.com>
asheshvidyut added a commit that referenced this pull request Oct 8, 2023
* logs for debugging

* Init

* white spaces fix

* added change log

* Fix tests

* fix typo

* using queryoptionfilter to populate args.filter

* tests

* fix test

* fix tests

* fix tests

* fix tests

* fix tests

* fix variable name

* fix tests

* fix tests

* fix tests

* Update .changelog/18322.txt

Co-authored-by: Ganesh S <ganesh.seetharaman@hashicorp.com>

* fix change log

* address nits

* removed unused line

* doing join only when filter has nodemeta

* fix tests

* fix tests

* Update agent/consul/catalog_endpoint.go

Co-authored-by: R.B. Boyer <4903+rboyer@users.noreply.github.com>

* fix tests

* removed unwanted code

---------

Co-authored-by: Ganesh S <ganesh.seetharaman@hashicorp.com>
Co-authored-by: R.B. Boyer <4903+rboyer@users.noreply.github.com>
asheshvidyut added a commit that referenced this pull request Oct 8, 2023
* logs for debugging

* Init

* white spaces fix

* added change log

* Fix tests

* fix typo

* using queryoptionfilter to populate args.filter

* tests

* fix test

* fix tests

* fix tests

* fix tests

* fix tests

* fix variable name

* fix tests

* fix tests

* fix tests

* Update .changelog/18322.txt

Co-authored-by: Ganesh S <ganesh.seetharaman@hashicorp.com>

* fix change log

* address nits

* removed unused line

* doing join only when filter has nodemeta

* fix tests

* fix tests

* Update agent/consul/catalog_endpoint.go

Co-authored-by: R.B. Boyer <4903+rboyer@users.noreply.github.com>

* fix tests

* removed unwanted code

---------

Co-authored-by: Ganesh S <ganesh.seetharaman@hashicorp.com>
Co-authored-by: R.B. Boyer <4903+rboyer@users.noreply.github.com>
asheshvidyut added a commit that referenced this pull request Oct 9, 2023
…PI into release/1.16.x (#19113)

* backport of commit cef8e3d

* NET-4135 - Fix NodeMeta filtering Catalog List Services API (#18322)

* logs for debugging

* Init

* white spaces fix

* added change log

* Fix tests

* fix typo

* using queryoptionfilter to populate args.filter

* tests

* fix test

* fix tests

* fix tests

* fix tests

* fix tests

* fix variable name

* fix tests

* fix tests

* fix tests

* Update .changelog/18322.txt

Co-authored-by: Ganesh S <ganesh.seetharaman@hashicorp.com>

* fix change log

* address nits

* removed unused line

* doing join only when filter has nodemeta

* fix tests

* fix tests

* Update agent/consul/catalog_endpoint.go

Co-authored-by: R.B. Boyer <4903+rboyer@users.noreply.github.com>

* fix tests

* removed unwanted code

---------

Co-authored-by: Ganesh S <ganesh.seetharaman@hashicorp.com>
Co-authored-by: R.B. Boyer <4903+rboyer@users.noreply.github.com>

* removed unwanted log lines

* removed unwanted log lines

---------

Co-authored-by: absolutelightning <ashesh.vidyut@hashicorp.com>
Co-authored-by: Ashesh Vidyut <134911583+absolutelightning@users.noreply.github.com>
Co-authored-by: Ganesh S <ganesh.seetharaman@hashicorp.com>
Co-authored-by: R.B. Boyer <4903+rboyer@users.noreply.github.com>
asheshvidyut added a commit that referenced this pull request Oct 9, 2023
* logs for debugging

* Init

* white spaces fix

* added change log

* Fix tests

* fix typo

* using queryoptionfilter to populate args.filter

* tests

* fix test

* fix tests

* fix tests

* fix tests

* fix tests

* fix variable name

* fix tests

* fix tests

* fix tests

* Update .changelog/18322.txt

Co-authored-by: Ganesh S <ganesh.seetharaman@hashicorp.com>

* fix change log

* address nits

* removed unused line

* doing join only when filter has nodemeta

* fix tests

* fix tests

* Update agent/consul/catalog_endpoint.go

Co-authored-by: R.B. Boyer <4903+rboyer@users.noreply.github.com>

* fix tests

* removed unwanted code

---------

Co-authored-by: Ganesh S <ganesh.seetharaman@hashicorp.com>
Co-authored-by: R.B. Boyer <4903+rboyer@users.noreply.github.com>
asheshvidyut added a commit that referenced this pull request Oct 9, 2023
* logs for debugging

* Init

* white spaces fix

* added change log

* Fix tests

* fix typo

* using queryoptionfilter to populate args.filter

* tests

* fix test

* fix tests

* fix tests

* fix tests

* fix tests

* fix variable name

* fix tests

* fix tests

* fix tests

* Update .changelog/18322.txt

Co-authored-by: Ganesh S <ganesh.seetharaman@hashicorp.com>

* fix change log

* address nits

* removed unused line

* doing join only when filter has nodemeta

* fix tests

* fix tests

* Update agent/consul/catalog_endpoint.go

Co-authored-by: R.B. Boyer <4903+rboyer@users.noreply.github.com>

* fix tests

* removed unwanted code

---------

Co-authored-by: Ganesh S <ganesh.seetharaman@hashicorp.com>
Co-authored-by: R.B. Boyer <4903+rboyer@users.noreply.github.com>
asheshvidyut added a commit that referenced this pull request Oct 9, 2023
#18322) (#19115)

NET-4135 - Fix NodeMeta filtering Catalog List Services API (#18322)

* logs for debugging

* Init

* white spaces fix

* added change log

* Fix tests

* fix typo

* using queryoptionfilter to populate args.filter

* tests

* fix test

* fix tests

* fix tests

* fix tests

* fix tests

* fix variable name

* fix tests

* fix tests

* fix tests

* Update .changelog/18322.txt



* fix change log

* address nits

* removed unused line

* doing join only when filter has nodemeta

* fix tests

* fix tests

* Update agent/consul/catalog_endpoint.go



* fix tests

* removed unwanted code

---------

Co-authored-by: Ganesh S <ganesh.seetharaman@hashicorp.com>
Co-authored-by: R.B. Boyer <4903+rboyer@users.noreply.github.com>
asheshvidyut added a commit that referenced this pull request Oct 9, 2023
…18322)  (#19116)

NET-4135 - Fix NodeMeta filtering Catalog List Services API (#18322)

* logs for debugging

* Init

* white spaces fix

* added change log

* Fix tests

* fix typo

* using queryoptionfilter to populate args.filter

* tests

* fix test

* fix tests

* fix tests

* fix tests

* fix tests

* fix variable name

* fix tests

* fix tests

* fix tests

* Update .changelog/18322.txt



* fix change log

* address nits

* removed unused line

* doing join only when filter has nodemeta

* fix tests

* fix tests

* Update agent/consul/catalog_endpoint.go



* fix tests

* removed unwanted code

---------

Co-authored-by: Ganesh S <ganesh.seetharaman@hashicorp.com>
Co-authored-by: R.B. Boyer <4903+rboyer@users.noreply.github.com>
@missylbytes
Copy link
Copy Markdown
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

consul-india PRs/Issues assigned to Consul India team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NodeMeta filtering Catalog List Services API is not working

7 participants