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

[NET-5399] Improve token fetching performance for endpoints controller. #2910

Merged
merged 3 commits into from
Sep 8, 2023

Conversation

hashi-derek
Copy link
Member

@hashi-derek hashi-derek commented Sep 6, 2023

Prior to this change, the endpoints controller would list all ACL tokens in a namespace when a service instance is being deleted. This commit improves the performance by querying only the necessary subset of tokens by service-identity / service-name.

Changes proposed in this PR:

  • Update the Consul API version
  • Modify the endpoints controller to utilize the new API and fetch fewer tokens.

How I've tested this PR:

  • Ensured that calling /v1/acl/tokens?servicename=mysvc does not throw an error on prior versions of Consul 1.16 and simply returns the full list of tokens. This means that updating consul-k8s to use the new query param will still be backwards compatible (because it can still loop and filter on the full list of tokens in-memory, rather than looping on the subset).
  • Ensured that calling /v1/acl/tokens?servicename=mysvc returns the proper subset of tokens on a consul-k8s install using this new build.
  • Created a consul-k8s cluster with services and ensured that tokens are still created / deleted properly.

How I expect reviewers to test this PR:

Checklist:

Prior to this change, the endpoints controller would list all ACL tokens in a
namespace when a service instance is being deleted. This commit improves the
performance by querying only the necessary subset of tokens by service-identity
/ service-name.
@hashi-derek hashi-derek force-pushed the derekm/NET-5399/improve-token-fetch branch from 6f37bfd to 3c4b8f9 Compare September 6, 2023 19:43
@hashi-derek hashi-derek changed the title Improve token fetching performance for endpoints controller. [NET-5399] Improve token fetching performance for endpoints controller. Sep 7, 2023
@hashi-derek hashi-derek marked this pull request as ready for review September 8, 2023 13:10
@hashi-derek hashi-derek added the pr/no-backport signals that a PR will not contain a backport label label Sep 8, 2023
@hashi-derek
Copy link
Member Author

This PR is marked as no-backport due to go.mod changes. There will be manual backports created for 1.0.X -> 1.2.X

count++
}
}
require.Greater(r, count, 0)
Copy link
Member Author

Choose a reason for hiding this comment

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

Another assertion exists further down that ensures the token is deleted properly. This was just added here to make sure that the token exists in the first place.

Copy link
Contributor

@curtbushko curtbushko left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Contributor

@wilkermichael wilkermichael left a comment

Choose a reason for hiding this comment

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

LGTM too!

tokens, _, err := apiClient.ACL().TokenList(&api.QueryOptions{
Namespace: svc.Namespace,
})
// Note that while the `TokenListFiltered` query below should only return a subset
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the comment!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr/no-backport signals that a PR will not contain a backport label
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants