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

mcs: forward current http request to mcs #7078

Merged
merged 13 commits into from
Sep 18, 2023
Merged

Conversation

lhy1024
Copy link
Contributor

@lhy1024 lhy1024 commented Sep 11, 2023

What problem does this PR solve?

Issue Number: Ref #5839

What is changed and how does it work?

It can be reviewed after #7072 merged.

Check List

Tests

  • Unit test

Release note

None.

@ti-chi-bot
Copy link
Contributor

ti-chi-bot bot commented Sep 11, 2023

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • JmPotato
  • 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 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. labels Sep 11, 2023
@ti-chi-bot ti-chi-bot bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Sep 11, 2023
@codecov
Copy link

codecov bot commented Sep 11, 2023

Codecov Report

Merging #7078 (2193aff) into master (d7d4756) will increase coverage by 0.13%.
The diff coverage is 98.07%.

❗ Current head 2193aff differs from pull request most recent head 338058d. Consider uploading reports for the commit 338058d to get more accurate results

@@            Coverage Diff             @@
##           master    #7078      +/-   ##
==========================================
+ Coverage   74.33%   74.47%   +0.13%     
==========================================
  Files         437      437              
  Lines       46821    46854      +33     
==========================================
+ Hits        34805    34894      +89     
+ Misses       8957     8904      -53     
+ Partials     3059     3056       -3     
Flag Coverage Δ
unittests 74.47% <98.07%> (+0.13%) ⬆️

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

pkg/utils/apiutil/serverapi/middleware.go Show resolved Hide resolved
pkg/utils/apiutil/serverapi/middleware.go Outdated Show resolved Hide resolved
@@ -530,3 +530,28 @@ func mightExec(re *require.Assertions, cmd *cobra.Command, args []string, v inte
}
json.Unmarshal(output, v)
}

func TestMicroservice(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

How to know if the output comes from the scheduling server?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because we have already disabled PD scheduling in api mode? How about adding info in the response header for further confirmation?

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 a more concrete name? TestMicroservice is too general.

Signed-off-by: lhy1024 <[email protected]>
@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 Sep 13, 2023
server/api/server.go Outdated Show resolved Hide resolved
Signed-off-by: lhy1024 <[email protected]>
@@ -45,19 +45,25 @@ func NewHandler(_ context.Context, svr *server.Server) (http.Handler, apiutil.AP
serverapi.MicroserviceRedirectRule(
prefix+"/admin/reset-ts",
tsoapi.APIPathPrefix+"/admin/reset-ts",
mcs.TSOServiceName),
mcs.TSOServiceName,
[]string{http.MethodPost}),
serverapi.MicroserviceRedirectRule(
prefix+"/operators",
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 the config or other paths?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will resolve them in other PRs, this PR only forwards the current HTTP method in scheduling server.

func copyHeader(dst, src http.Header) {
for k, vv := range src {
if k == "Content-Encoding" || k == "Content-Length" {
Copy link
Member

Choose a reason for hiding this comment

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

I have a concern about it and am not sure if only two keys will affect it.

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 possible, but for now gzip only affects these two, and we'll do more testing as we add interfaces.

// e.g. r.URL.Path = /pd/api/v1/operators/1 (before redirect)
// matchPath = /pd/api/v1/operators
// targetPath = /scheduling/api/v1/operators
// r.URL.Path = /scheduling/api/v1/operator/1 (after redirect)
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 the custom way to do the transfer? Because we might change the previous path parameters to query parameters.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will add TODO when meet other interfaces, which not support restful

@@ -530,3 +530,28 @@ func mightExec(re *require.Assertions, cmd *cobra.Command, args []string, v inte
}
json.Unmarshal(output, v)
}

func TestMicroservice(t *testing.T) {
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 a more concrete name? TestMicroservice is too general.

Signed-off-by: lhy1024 <[email protected]>
Signed-off-by: lhy1024 <[email protected]>
@ti-chi-bot ti-chi-bot bot added the status/LGT1 Indicates that a PR has LGTM 1. label Sep 15, 2023
cmd := pdctlCmd.GetRootCmd()
args := []string{"-u", backendEndpoints, "operator", "show"}
var slice []string
output, err := pdctl.ExecuteCommand(cmd, args...)
Copy link
Member

Choose a reason for hiding this comment

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

How should we make sure this request is forwarded rather than being handled directly in this test?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -530,3 +530,28 @@ func mightExec(re *require.Assertions, cmd *cobra.Command, args []string, v inte
}
json.Unmarshal(output, v)
}

func TestForwardSchedulerRequest(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

Ditto.

@ti-chi-bot ti-chi-bot bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Sep 15, 2023
Signed-off-by: lhy1024 <[email protected]>
@@ -171,6 +171,7 @@ func (h *redirector) ServeHTTP(w http.ResponseWriter, r *http.Request, next http
return
}
clientUrls = append(clientUrls, targetAddr)
w.Header().Set(apiutil.ForwardToMicroServiceHeader, "true")
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 only used for testing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it is now.

Copy link
Member

Choose a reason for hiding this comment

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

Then, I think we shouldn't add it in the header, the testing code should not affect the normal situation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If it is not added to resp, is there any other way to tell whether it is processed by the PD server or the scheduling server?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When debugging on a real cluster, it may also be useful to identify the origin of the server handling the request.

if len(targetAddr) == 0 {
http.Error(w, apiutil.ErrRedirectFailed, http.StatusInternalServerError)
return
}
clientUrls = append(clientUrls, targetAddr)
w.Header().Set(apiutil.ForwardToMicroServiceHeader, "true")
Copy link
Member

Choose a reason for hiding this comment

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

If we keep this header filed, what about setting its value to the microservice name rather than a true?

Copy link
Contributor Author

@lhy1024 lhy1024 Sep 18, 2023

Choose a reason for hiding this comment

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

e.g scheduling?tso?Is it necessary?

@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 Sep 18, 2023
@lhy1024
Copy link
Contributor Author

lhy1024 commented Sep 18, 2023

/merge

@ti-chi-bot
Copy link
Contributor

ti-chi-bot bot commented Sep 18, 2023

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

@ti-chi-bot
Copy link
Contributor

ti-chi-bot bot commented Sep 18, 2023

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

Commit hash: f070884

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

ti-chi-bot bot commented Sep 18, 2023

@lhy1024: 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 0888ef6 into tikv:master Sep 18, 2023
22 checks passed
rleungx pushed a commit to rleungx/pd that referenced this pull request Dec 1, 2023
ref tikv#5839

Signed-off-by: lhy1024 <[email protected]>

Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com>
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/XL Denotes a PR that changes 500-999 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
Development

Successfully merging this pull request may close these issues.

3 participants