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: fix scheme when tls config not match #7901

Merged
merged 19 commits into from
Mar 12, 2024

Conversation

CabinfeverB
Copy link
Member

@CabinfeverB CabinfeverB commented Mar 8, 2024

What problem does this PR solve?

Issue Number: Close #7900 close #7902

What is changed and how does it work?

  1. replace httpAddr and addr with url field which includes scheme info.
  2. modify related fields and function name which mix url and address.
  3. pick the URL which matches TLS config from member resp.

Check List

Tests

  • Unit test

Code changes

Side effects

  • Possible performance regression
  • Increased code complexity
  • Breaking backward compatibility

Related changes

Release note

None.

Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
Copy link
Contributor

ti-chi-bot bot commented Mar 8, 2024

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • HuSharp
  • rleungx

To complete the pull request process, please ask the reviewers in the list to review by filling /cc @reviewer in the comment.
After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the list by filling /assign @committer in the comment to help you merge this pull request.

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

Reviewer can indicate their review by submitting an approval review.
Reviewer can cancel approval by submitting a request changes review.

@ti-chi-bot ti-chi-bot bot added the release-note-none Denotes a PR that doesn't merit a release note. label Mar 8, 2024
@ti-chi-bot ti-chi-bot bot requested review from JmPotato and lhy1024 March 8, 2024 09:41
@ti-chi-bot ti-chi-bot bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Mar 8, 2024
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
@@ -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.
Copy link
Member

@HuSharp HuSharp Mar 8, 2024

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 <cabinfeveroier@gmail.com>
addr = fmt.Sprintf("%s%s", httpScheme, addr)
}
} else {
if strings.HasPrefix(addr, httpScheme) {
Copy link
Member Author

@CabinfeverB CabinfeverB Mar 8, 2024

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 <cabinfeveroier@gmail.com>
@ti-chi-bot ti-chi-bot bot added the status/LGT1 Indicates that a PR has LGTM 1. label Mar 8, 2024
@ti-chi-bot ti-chi-bot bot added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Mar 11, 2024
@CabinfeverB
Copy link
Member Author

/hold

@ti-chi-bot ti-chi-bot bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Mar 11, 2024
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
@ti-chi-bot ti-chi-bot bot added 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 Mar 11, 2024
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
}

func addrsToUrls(addrs []string) []string {
func addrsToUrls(addrs []string, tlsCfg *tls.Config) []string {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
func addrsToUrls(addrs []string, tlsCfg *tls.Config) []string {
func addrsToURLs(addrs []string, tlsCfg *tls.Config) []string {

Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
}
}
log.Warn("[pd] no matched url found", zap.Strings("urls", urls), zap.Bool("tls-enabled", tlsCfg != nil))
return urls[0]
Copy link
Member

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]?

Copy link
Member Author

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 <cabinfeveroier@gmail.com>
@rleungx
Copy link
Member

rleungx commented Mar 11, 2024

@iosmanthus PTAL

Copy link
Contributor

ti-chi-bot bot commented Mar 11, 2024

@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:

/cc @iosmanthus

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 <cabinfeveroier@gmail.com>
Copy link

codecov bot commented Mar 12, 2024

Codecov Report

Merging #7901 (5f21733) into master (efffcc5) will decrease coverage by 0.13%.
The diff coverage is 78.24%.

❗ Current head 5f21733 differs from pull request most recent head 26de3db. Consider uploading reports for the commit 26de3db to get more accurate results

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     
Flag Coverage Δ
unittests 73.33% <78.24%> (-0.13%) ⬇️

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

@rleungx
Copy link
Member

rleungx commented Mar 12, 2024

/hold cancel

@ti-chi-bot ti-chi-bot bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Mar 12, 2024
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
@@ -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())
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 changing the definition of func BuildForwardContext to BuildForwardContext(..., url string).

Comment on lines 1150 to 1165
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
}
Copy link
Member

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()

Copy link
Member Author

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 <cabinfeveroier@gmail.com>
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
@CabinfeverB
Copy link
Member Author

/merge

Copy link
Contributor

ti-chi-bot bot commented Mar 12, 2024

@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 /merge once, and 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.

If you have any questions about the PR merge process, please refer to pr process.

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.

Copy link
Contributor

ti-chi-bot bot commented Mar 12, 2024

This pull request has been accepted and is ready to merge.

Commit hash: 5f21733

@ti-chi-bot ti-chi-bot bot added the status/can-merge Indicates a PR has been approved by a committer. label Mar 12, 2024
Copy link
Contributor

ti-chi-bot bot commented Mar 12, 2024

@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.

@ti-chi-bot ti-chi-bot bot merged commit c1eabda into tikv:master Mar 12, 2024
22 checks passed
@CabinfeverB CabinfeverB deleted the client/fix_scheme branch March 14, 2024 03:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-note-none Denotes a PR that doesn't merit a release note. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2.
Projects
None yet
4 participants