-
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
mcs: forward current http request to mcs #7078
Conversation
[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. |
dca91b5
to
eb64cd5
Compare
Signed-off-by: lhy1024 <[email protected]>
Signed-off-by: lhy1024 <[email protected]>
Signed-off-by: lhy1024 <[email protected]>
eb64cd5
to
4012981
Compare
Codecov Report
@@ 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
Flags with carried forward coverage won't be shown. Click here to find out more. |
Signed-off-by: lhy1024 <[email protected]>
Signed-off-by: lhy1024 <[email protected]>
@@ -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) { |
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 to know if the output comes from the scheduling 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.
Because we have already disabled PD scheduling in api mode? How about adding info in the response header for further confirmation?
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 using a more concrete name? TestMicroservice
is too general.
Signed-off-by: lhy1024 <[email protected]>
5449b2d
to
32a81e3
Compare
Signed-off-by: lhy1024 <[email protected]>
b1b7542
to
7eafe59
Compare
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", |
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 the config or other paths?
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.
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" { |
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.
I have a concern about it and am not sure if only two keys will affect it.
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.
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) |
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 using the custom way to do the transfer? Because we might change the previous path parameters to query parameters.
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.
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) { |
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 using a more concrete name? TestMicroservice
is too general.
Signed-off-by: lhy1024 <[email protected]>
Signed-off-by: lhy1024 <[email protected]>
cmd := pdctlCmd.GetRootCmd() | ||
args := []string{"-u", backendEndpoints, "operator", "show"} | ||
var slice []string | ||
output, err := pdctl.ExecuteCommand(cmd, args...) |
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 should we make sure this request is forwarded rather than being handled directly in this test?
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.
@@ -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) { |
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.
Ditto.
Signed-off-by: lhy1024 <[email protected]>
75ee330
to
2193aff
Compare
@@ -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") |
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.
Is it only used for testing?
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.
Yes, it is now.
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.
Then, I think we shouldn't add it in the header, the testing code should not affect the normal situation.
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.
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?
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.
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") |
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.
If we keep this header filed, what about setting its value to the microservice name rather than a true
?
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.
e.g scheduling?tso?Is it necessary?
12eab46
to
47eb529
Compare
Signed-off-by: lhy1024 <[email protected]>
81e49f8
to
f070884
Compare
/merge |
@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
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: f070884
|
@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. |
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>
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
Release note