-
Notifications
You must be signed in to change notification settings - Fork 720
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: fix scheme when tls config not match #7901
Conversation
Signed-off-by: Cabinfever_B <[email protected]>
Signed-off-by: Cabinfever_B <[email protected]>
[REVIEW NOTIFICATION] This pull request has been approved by:
To complete the pull request process, please ask the reviewers in the list to review by filling The full list of commands accepted by this bot can be found here. Reviewer can indicate their review by submitting an approval review. |
Signed-off-by: Cabinfever_B <[email protected]>
504486e
to
0d69a07
Compare
client/pd_service_discovery.go
Outdated
@@ -124,10 +124,8 @@ type ServiceDiscovery interface { | |||
|
|||
// ServiceClient is an interface that defines a set of operations for a raw PD gRPC client to specific PD server. | |||
type ServiceClient interface { | |||
// GetAddress returns the address information of the PD server. | |||
// GetAddress returns the address with HTTP scheme of the PD server. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tests seems like will return https scheme?
Signed-off-by: Cabinfever_B <[email protected]>
client/pd_service_discovery.go
Outdated
addr = fmt.Sprintf("%s%s", httpScheme, addr) | ||
} | ||
} else { | ||
if strings.HasPrefix(addr, httpScheme) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is only used for url.Parse
. If we don't add scheme, it will return error when creating gRPC connection.
If etcd member URL is not the same as this, the connection map will add a new KV pair(holds both https://127.0.0.1 and http://127.0.0.1)
Signed-off-by: Cabinfever_B <[email protected]>
/hold |
Signed-off-by: Cabinfever_B <[email protected]>
Signed-off-by: Cabinfever_B <[email protected]>
client/pd_service_discovery.go
Outdated
} | ||
|
||
func addrsToUrls(addrs []string) []string { | ||
func addrsToUrls(addrs []string, tlsCfg *tls.Config) []string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func addrsToUrls(addrs []string, tlsCfg *tls.Config) []string { | |
func addrsToURLs(addrs []string, tlsCfg *tls.Config) []string { |
Signed-off-by: Cabinfever_B <[email protected]>
Signed-off-by: Cabinfever_B <[email protected]>
client/pd_service_discovery.go
Outdated
} | ||
} | ||
log.Warn("[pd] no matched url found", zap.Strings("urls", urls), zap.Bool("tls-enabled", tlsCfg != nil)) | ||
return urls[0] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to change the URL according to the tlscfg instead of return [0]?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch.
Signed-off-by: Cabinfever_B <[email protected]>
@iosmanthus PTAL |
@rleungx: GitHub didn't allow me to request PR reviews from the following users: iosmanthus. Note that only tikv members and repo collaborators can review this PR, and authors cannot review their own PRs. In response to this:
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. |
Signed-off-by: Cabinfever_B <[email protected]>
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## master #7901 +/- ##
==========================================
- Coverage 73.46% 73.33% -0.13%
==========================================
Files 435 435
Lines 48197 48195 -2
==========================================
- Hits 35406 35346 -60
- Misses 9739 9780 +41
- Partials 3052 3069 +17
Flags with carried forward coverage won't be shown. Click here to find out more. |
/hold cancel |
Signed-off-by: Cabinfever_B <[email protected]>
@@ -162,7 +162,7 @@ func (c *client) Get(ctx context.Context, key []byte, opts ...OpOption) (*meta_s | |||
Limit: options.limit, | |||
Revision: options.revision, | |||
} | |||
ctx = grpcutil.BuildForwardContext(ctx, c.GetLeaderAddr()) | |||
ctx = grpcutil.BuildForwardContext(ctx, c.GetLeaderURL()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about changing the definition of func BuildForwardContext
to BuildForwardContext(..., url string)
.
client/pd_service_discovery.go
Outdated
func modifyURLScheme(url string, tlsCfg *tls.Config) string { | ||
if tlsCfg == nil { | ||
if strings.HasPrefix(url, httpsScheme) { | ||
url = fmt.Sprintf("%s%s", httpScheme, strings.TrimPrefix(url, httpsScheme)) | ||
} else if !strings.HasPrefix(url, httpScheme) { | ||
url = fmt.Sprintf("%s%s", httpScheme, url) | ||
} | ||
} else { | ||
if strings.HasPrefix(url, httpScheme) { | ||
url = fmt.Sprintf("%s%s", httpsScheme, strings.TrimPrefix(url, httpScheme)) | ||
} else if !strings.HasPrefix(url, httpsScheme) { | ||
url = fmt.Sprintf("%s%s", httpsScheme, url) | ||
} | ||
} | ||
return url | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion:
u, err := url.Parse(url)
if err != nil {
return url
}
if tls != nil {
u.Scheme = "https"
}
return u.String()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Has addressed this, PTAL
Signed-off-by: Cabinfever_B <[email protected]>
Signed-off-by: Cabinfever_B <[email protected]>
Signed-off-by: Cabinfever_B <[email protected]>
Signed-off-by: Cabinfever_B <[email protected]>
/merge |
@CabinfeverB: It seems you want to merge this PR, I will help you trigger all the tests: /run-all-tests You only need to trigger
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 ti-community-infra/tichi repository. |
This pull request has been accepted and is ready to merge. Commit hash: 5f21733
|
@CabinfeverB: Your PR was out of date, I have automatically updated it for you. If the CI test fails, you just re-trigger the test that failed and the bot will merge the PR for you after the CI passes. 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 ti-community-infra/tichi repository. |
What problem does this PR solve?
Issue Number: Close #7900 close #7902
What is changed and how does it work?
httpAddr
andaddr
withurl
field which includes scheme info.Check List
Tests
Code changes
Side effects
Related changes
pingcap/docs
/pingcap/docs-cn
:pingcap/tiup
:Release note