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

Free APF seats for watches handled by an aggregated apiserver. #105511

Merged
merged 1 commit into from Oct 21, 2021

Conversation

benluddy
Copy link
Contributor

@benluddy benluddy commented Oct 6, 2021

What type of PR is this?

/kind bug

What this PR does / why we need it:

Fires the APF initialization signal before proxying a request to an aggregated apiserver.

Which issue(s) this PR fixes:

Fixes #105409.

Special notes for your reviewer:

Does this PR introduce a user-facing change?

Fix a 1.22 regression where watch requests that are delegated to aggregated apiservers no longer reserve concurrency units (seats) in the API Priority and Fairness dispatcher for their entire duration.

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/bug Categorizes issue or PR as related to a bug. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Oct 6, 2021
@k8s-ci-robot
Copy link
Contributor

Welcome @benluddy!

It looks like this is your first PR to kubernetes/kubernetes 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes/kubernetes has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Oct 6, 2021
@k8s-ci-robot
Copy link
Contributor

Hi @benluddy. Thanks for your PR.

I'm waiting for a kubernetes 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/test-infra repository.

@k8s-ci-robot k8s-ci-robot added the needs-priority Indicates a PR lacks a `priority/foo` label and requires one. label Oct 6, 2021
@k8s-ci-robot k8s-ci-robot added area/apiserver sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Oct 6, 2021
@benluddy
Copy link
Contributor Author

benluddy commented Oct 6, 2021

/assign @wojtek-t @deads2k

@wojtek-t
Copy link
Member

wojtek-t commented Oct 6, 2021

/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 Oct 6, 2021
@wojtek-t
Copy link
Member

wojtek-t commented Oct 6, 2021

This LGTM - but I would prefer @deads2k to also take a look before approving - I'm not that super familiar with the aggregtion part.

@benluddy @tkashem - once this merged, we should open a cherrypick to 1.22.

@fedebongio
Copy link
Contributor

/triage accepted

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Oct 7, 2021
@@ -123,6 +124,8 @@ func (r *proxyHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
return
}

utilflowcontrol.RequestDelegated(req.Context())
Copy link
Contributor

Choose a reason for hiding this comment

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

Why does it make more sense to do this here rather than after the cost has been paid to get the new transport ready, just before the proxy connection is made around line 190?

If we want to account for the cost of a request, that seems to be more in keeping with accounting for as much of the cost as-is reasonable.

Copy link
Contributor

Choose a reason for hiding this comment

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

@deads2k could you please explain what you mean by the cost of getting the new transport ready?

@deads2k
Copy link
Contributor

deads2k commented Oct 8, 2021

Other than the placement of the call, this lgtm

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 9, 2021
@k8s-ci-robot k8s-ci-robot removed the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Oct 13, 2021
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Oct 13, 2021
@benluddy benluddy force-pushed the apf-delegated-signal branch 2 times, most recently from e0bd6d9 to 56db85d Compare October 13, 2021 17:19
@@ -175,6 +176,12 @@ func (r *proxyHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
handler := proxy.NewUpgradeAwareHandler(location, proxyRoundTripper, true, upgrade, &responder{w: w})
handler.InterceptRedirects = utilfeature.DefaultFeatureGate.Enabled(genericfeatures.StreamingProxyRedirects)
handler.RequireSameHostRedirects = utilfeature.DefaultFeatureGate.Enabled(genericfeatures.ValidateProxyRedirects)

if upgrade {
// Don't block the delegation signal on upgrade direct dialing.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should unblock the non-upgrade requests as well.

Copy link
Contributor

Choose a reason for hiding this comment

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

do we need it since we have ?

?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Upgrades dial the backend without calling RoundTrip. The RoundTripper is passed here, but only to use a custom Dialer (e.g. if configured here

if r.egressSelector != nil {
networkContext := egressselector.Cluster.AsNetworkContext()
var egressDialer utilnet.DialFunc
egressDialer, err := r.egressSelector.Lookup(networkContext)
if err != nil {
klog.Warning(err.Error())
} else {
newInfo.restConfig.Dial = egressDialer
}
} else if r.proxyTransport != nil && r.proxyTransport.DialContext != nil {
newInfo.restConfig.Dial = r.proxyTransport.DialContext
}
) when the RoundTripper's concrete type is *http.Transport or when it can be unwrapped to *http.Transport via WrappedRoundTripper() (in
func DialerFor(transport http.RoundTripper) (DialFunc, error) {
if transport == nil {
return nil, nil
}
switch transport := transport.(type) {
case *http.Transport:
// transport.DialContext takes precedence over transport.Dial
if transport.DialContext != nil {
return transport.DialContext, nil
}
// adapt transport.Dial to the DialWithContext signature
if transport.Dial != nil {
return func(ctx context.Context, net, addr string) (net.Conn, error) {
return transport.Dial(net, addr)
}, nil
}
// otherwise return nil
return nil, nil
case RoundTripperWrapper:
return DialerFor(transport.WrappedRoundTripper())
default:
return nil, fmt.Errorf("unknown transport type: %T", transport)
}
}
).

This special handling for upgrade avoids the case where a dial for upgrade takes a long time. From my understanding, all other requests dial via (*http.Transport).RoundTrip(...).

}

func (fcrt *flowcontrolRoundTripper) RoundTrip(r *http.Request) (*http.Response, error) {
utilflowcontrol.RequestDelegated(r.Context())
Copy link
Contributor

Choose a reason for hiding this comment

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

ah, okay this is the code that will unblock non-upgrade requests

@@ -271,3 +278,16 @@ func (r *proxyHandler) updateAPIService(apiService *apiregistrationv1api.APIServ
}
r.handlingInfo.Store(newInfo)
}

type flowcontrolRoundTripper struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

please add a comment explaining the purpose of this custom RT

Copy link
Contributor

Choose a reason for hiding this comment

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

please make sure we don't need the CancelRequest method.

for some reason, you had to provide the WrappedRoundTripper method

case utilnet.RoundTripperWrapper:

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 do. I responded in another comment (https://github.com/kubernetes/kubernetes/pull/105511/files#r729021620) with the reason for implementing RoundTripperWrapper.

// boundaries, so we generously fire it as soon as we know
// that the request won't be serviced locally. Safe to call
// for non-watch requests.
WatchInitialized(ctx)
Copy link
Contributor

Choose a reason for hiding this comment

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

what happens with a request calling this function on a cluster with disabled p&f?

Copy link
Contributor

Choose a reason for hiding this comment

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

will this method infer that the request was a watch request? or do we need to call it only for watch requests?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's always safe to call because it's a no-op unless the context contains a signal value. Same with the feature gate disabled -- without the p&f filter, the signal value won't be added to the context.

@@ -160,7 +161,7 @@ func (r *proxyHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
return
}

proxyRoundTripper := handlingInfo.proxyRoundTripper
var proxyRoundTripper http.RoundTripper = &flowcontrolRoundTripper{rt: handlingInfo.proxyRoundTripper}
Copy link
Member

Choose a reason for hiding this comment

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

I'm wondering if I didn't prefer the previous simple version, for the reason that we want to cherrypick it.

How about just in the first commit simply calling RequestDelegated() before calling ServeHTTP, cherrypicking this one and then improving further at head?

Copy link
Contributor

Choose a reason for hiding this comment

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

yes, that's why I asked @deads2k to share more details about the cost of setting up a transport, here #105511 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

SGTM. I'd also feel more confident about this second approach with a sanity check from @deads2k. I'll go ahead and split this PR now.

@benluddy
Copy link
Contributor Author

Just pushed the simpler option (#105511 (comment)). @wojtek-t

@wojtek-t
Copy link
Member

This LGTM, but I would prefer to have an explicit ACK from @deads2k on it.

/approve

/hold

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Oct 14, 2021
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: benluddy, wojtek-t

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

The pull request process is described 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 added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 14, 2021
@deads2k
Copy link
Contributor

deads2k commented Oct 21, 2021

this lgtm

/lgtm
/hold cancel

@k8s-ci-robot k8s-ci-robot added lgtm "Looks good to me", indicates that a PR is ready to be merged. and removed do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. labels Oct 21, 2021
@wojtek-t
Copy link
Member

/retest

@k8s-triage-robot
Copy link

The Kubernetes project has merge-blocking tests that are currently too flaky to consistently pass.

This bot retests PRs for certain kubernetes repos according to the following rules:

  • The PR does have any do-not-merge/* labels
  • The PR does not have the needs-ok-to-test label
  • The PR is mergeable (does not have a needs-rebase label)
  • The PR is approved (has cncf-cla: yes, lgtm, approved labels)
  • The PR is failing tests required for merge

You can:

/retest

@k8s-ci-robot k8s-ci-robot merged commit 313b43a into kubernetes:master Oct 21, 2021
@k8s-ci-robot k8s-ci-robot added this to the v1.23 milestone Oct 21, 2021
k8s-ci-robot added a commit that referenced this pull request Nov 4, 2021
…5511-upstream-release-1.22

Automated cherry pick of #105511: Free APF seats for watches handled by an aggregated
@liggitt liggitt added the kind/regression Categorizes issue or PR as related to a regression from a prior release. label Apr 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/apiserver cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. kind/regression Categorizes issue or PR as related to a regression from a prior release. lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

apf: watches served by aggregated apiservers occupy seat for entire duration of request
8 participants