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

client: support configuring backoff #8679

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

rleungx
Copy link
Member

@rleungx rleungx commented Oct 9, 2024

What problem does this PR solve?

Issue Number: Close #8047

What is changed and how does it work?

Check List

Tests

  • Unit test

Release note

None.

@ti-chi-bot ti-chi-bot bot added do-not-merge/needs-linked-issue release-note-none Denotes a PR that doesn't merit a release note. dco-signoff: yes Indicates the PR's author has signed the dco. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Oct 9, 2024
@rleungx rleungx requested a review from JmPotato October 9, 2024 08:16
Copy link

codecov bot commented Oct 10, 2024

Codecov Report

Attention: Patch coverage is 83.72093% with 7 lines in your changes missing coverage. Please review.

Project coverage is 75.81%. Comparing base (da0000a) to head (e2d9266).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #8679      +/-   ##
==========================================
- Coverage   75.86%   75.81%   -0.06%     
==========================================
  Files         460      460              
  Lines       70637    70678      +41     
==========================================
- Hits        53591    53581      -10     
- Misses      13673    13709      +36     
- Partials     3373     3388      +15     
Flag Coverage Δ
unittests 75.81% <83.72%> (-0.06%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Copy link
Contributor

ti-chi-bot bot commented Oct 18, 2024

PR needs rebase.

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.

@ti-chi-bot ti-chi-bot bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 18, 2024
@@ -109,6 +109,57 @@ func (bo *Backoffer) Exec(
return err
}

// ExecWithResult is a helper function to exec backoff with result.
func (bo *Backoffer) ExecWithResult(
Copy link
Member

Choose a reason for hiding this comment

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

we can wrap exec to this
image

And export Exec and ExecWithResult separately

client/client.go Outdated
}
return handleRegionResponse(resp), nil
}
if c.option.bo == nil {
Copy link
Member

Choose a reason for hiding this comment

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

How about using client interceptor to do backoff? We can delivery backoff option by context?

return &pdpb.GetMinTSResponse{
Header: s.wrapErrorToHeader(pdpb.ErrorType_UNKNOWN, err.Error()),
}, nil
return nil, status.Error(codes.ResourceExhausted, err.Error())
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we can split these updates to another pr, and merge it firstly. It is simple

@ti-chi-bot ti-chi-bot bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Nov 27, 2024
Signed-off-by: Ryan Leung <[email protected]>
@rleungx rleungx removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 27, 2024
@rleungx rleungx requested a review from okJiang November 27, 2024 05:04
Signed-off-by: Ryan Leung <[email protected]>
@rleungx
Copy link
Member Author

rleungx commented Nov 28, 2024

/retest

@@ -41,6 +42,53 @@ const (
FollowerHandleMetadataKey = "pd-allow-follower-handle"
)

// Add retry related CallOption
type retryCallOption struct {
grpc.EmptyCallOption
Copy link
Contributor

Choose a reason for hiding this comment

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

why need this?

Copy link
Member Author

Choose a reason for hiding this comment

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

Otherwise, we need to implement before and after interfaces.

// Record the start time
start := time.Now()

ctx = retry.WithBackoffer(ctx, bo)
Copy link
Contributor

Choose a reason for hiding this comment

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

Does the user need to specify it?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, but we also can provide a default one if needed.

@ti-chi-bot ti-chi-bot bot added the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Nov 29, 2024
Copy link
Contributor

ti-chi-bot bot commented Nov 29, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-11-29 08:44:29.044208854 +0000 UTC m=+798856.663863394: ☑️ agreed by nolouch.

Copy link
Contributor

ti-chi-bot bot commented Nov 29, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: nolouch

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

@ti-chi-bot ti-chi-bot bot added the approved label Nov 29, 2024
type boCtxKey struct{}

// Key used to store backoffer
var backofferKey = boCtxKey{}
Copy link
Member

Choose a reason for hiding this comment

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

Why using struct{}, not string?

Signed-off-by: Ryan Leung <[email protected]>
Signed-off-by: Ryan Leung <[email protected]>
@rleungx rleungx requested a review from okJiang November 29, 2024 09:44
// Calculate the elapsed time
elapsed := time.Since(start)
// Verify that some backoff occurred by checking if the elapsed time is greater than the base backoff
re.Greater(elapsed, base, "Expected some backoff to have occurred")
Copy link
Member

Choose a reason for hiding this comment

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

Is it better to compare total?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved dco-signoff: yes Indicates the PR's author has signed the dco. needs-1-more-lgtm Indicates a PR needs 1 more LGTM. release-note-none Denotes a PR that doesn't merit a release note. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Introduce the backoff mechanism for gRPC client
3 participants