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

New proxy server counting logic for agent and server #635

Closed
wants to merge 21 commits into from

Conversation

carreter
Copy link
Contributor

Accidentally close #634, reopening it here.

An initial pass at the groundwork for #358 and #273 (i.e. allowing a dynamic proxy server count on both the server and the agent in a backwards-compatible manner). Currently a draft, depends on #632. Design doc here.

Changes

New package: pkg/servercounter

This package is structured around the ServerCounter interface:

// A ServerCounter counts the number of available proxy servers.
type ServerCounter interface {
	CountServers() int
}

Currently provided are StaticServerCounter, which simply returns a stored int, and CachedServerCounter, which wraps another ServerCounter and provides catching functionality with a configurable cache expiry time.

Proxy server

This PR wires the ServerCounter into the proxy server without changing its behavior by creating a StaticServerCounter with the command-line provided count.

Proxy agent

This PR wires the ServerCounter into the proxy agent without changing its behavior by creating a StaticServerCounter with a default count of 0.

This PR also adds the respectReceivedServerCount field to the agent ClientSet struct. This field toggles whether the server count received from the proxy server should overwrite the proxy agent's server counter. Since I didn't want to change the behavior of the agent yet, this is set to true by default.

Open questions

Should CountServers() return an error?

Sometimes the ServerCounter will fail to get an updated server count. In this case, we could have CountServers() return (int, error) instead.

I opted against this because we can handle errors in the ServerCounter itself. This simplifies things on the caller side and allows for including a fallback server count in the ServerCounter.

Should ServerCounter include an UpdateCount(int) method?

It might be useful for clients to (a) temporarily override the server count or (b) request an update to any cached server counts. They could do this by calling UpdateCount() with a non-negative value to temporarily override the count or with -1 to reset the override and request a count update.

I opted against this because the client can accomplish (a) using a StaticServerCounter (downside: this overwrites the previous ServerCounter if stored in the same field), and (b) seems like it would have limited use as the ServerCounter should be completely responsible for managing the server count.

A possible workaround is to add the UpdateCount() method to just CachedServerCounter rather than the entire interface. This allows for finer control of caching while maintaining a simple API for the general case.

Should respectReceivedServerCount be true or false by default?

My take: have it true by default unless an alternative server count method is provided in the commandline args to the proxy agent. This ensures backwards compatibility with old proxy servers.

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jun 20, 2024
@k8s-ci-robot
Copy link
Contributor

Hi @carreter. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: carreter
Once this PR has been reviewed and has the lgtm label, please assign jkh52 for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot requested review from ipochi and tallclair June 20, 2024 19:58
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jun 20, 2024
@carreter
Copy link
Contributor Author

@avrittrohwer MVP server lease counter with unit tests is done, just need to make e2e tests!

@jkh52
Copy link
Contributor

jkh52 commented Jun 22, 2024

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jun 22, 2024
@k8s-ci-robot
Copy link
Contributor

@carreter: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-apiserver-network-proxy-make-lint-master c07ff4e link true /test pull-apiserver-network-proxy-make-lint-master

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

@carreter
Copy link
Contributor Author

I think it's working now, at least on the agent side! It successfully detects the 2 apiserver leases when I configure it with the proper label selector, and establishes connections accordingly.

image

The code still needs some cleaning up though...

@carreter
Copy link
Contributor Author

carreter commented Jun 26, 2024

Consider the code under pkg/servercounter ready for review. Remaining tasks:

  • e2e tests
  • clean up commandline options
  • linting
  • more logging/metrics

@carreter
Copy link
Contributor Author

carreter commented Jul 8, 2024

Currently blocked by #639, which adds an e2e framework with which the lease-based counting system can be tested.

@carreter
Copy link
Contributor Author

Going to close this PR and open a new one as the commit history is incredibly messy.

@carreter carreter closed this Jul 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants