Skip to content

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

Merged
hashi-derek merged 3 commits intomainfrom
derekm/NET-5399/improve-token-fetch
Sep 8, 2023
Merged

[NET-5399] Improve token fetching performance for endpoints controller.#2910
hashi-derek merged 3 commits intomainfrom
derekm/NET-5399/improve-token-fetch

Conversation

@hashi-derek
Copy link
Copy Markdown
Contributor

@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
Copy Markdown
Contributor 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
Copy Markdown
Contributor 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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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