-
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
ctl: replace doRequest with HTTP client to get health status #8212
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. |
Signed-off-by: okJiang <819421878@qq.com>
Signed-off-by: okJiang <819421878@qq.com>
ref tikv#7969 add parallel parameter Signed-off-by: husharp <jinhao.hu@pingcap.com> Signed-off-by: okJiang <819421878@qq.com>
ref tikv#7897 metrics: fix the duplicate avg metrics Signed-off-by: nolouch <nolouch@gmail.com> Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com> Signed-off-by: okJiang <819421878@qq.com>
Co-authored-by: JmPotato <github@ipotato.me> Signed-off-by: okJiang <819421878@qq.com>
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.
The rest LGTM.
Signed-off-by: okJiang <819421878@qq.com>
@@ -337,6 +338,20 @@ func (c *client) SetStoreLabels(ctx context.Context, storeID int64, storeLabels | |||
WithBody(jsonInput)) | |||
} | |||
|
|||
// GetHealthStatus gets the health status of the cluster. | |||
func (c *client) GetHealthStatus(ctx context.Context) ([]Health, error) { |
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.
BTW, could you please add tests for this new method in /tests/integrations/client/http_client_test.go
?
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.
Signed-off-by: okJiang <819421878@qq.com>
/merge |
@JmPotato: 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. |
Run: showHealthCommandFunc, | ||
Use: "health", | ||
Short: "show all node's health information of the PD cluster", | ||
PersistentPreRunE: requirePDClient, |
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.
TestSendAndGetComponent
ci failed :(
-
This is because the
requirePDClient
command executes the functionshouldInitPDClient
, which requires queryingpd/api/v1/cluster
. -
The handler is replaced in
TestSendAndGetComponent
, so you need to add this router to the handler inTestSendAndGetComponent
.
mux.HandleFunc("/pd/api/v1/cluster", func(w http.ResponseWriter, r *http.Request) {
cluster := &metapb.Cluster{
Id: 0,
}
var rd render.Render
rd.JSON(w, http.StatusOK, cluster)
})
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.
You can check code here
pd/tools/pd-ctl/tests/global_test.go
Lines 37 to 52 in 7e18a69
handler := func(context.Context, *server.Server) (http.Handler, apiutil.APIServiceGroup, error) { | |
mux := http.NewServeMux() | |
mux.HandleFunc("/pd/api/v1/health", func(w http.ResponseWriter, r *http.Request) { | |
callerID := apiutil.GetCallerIDOnHTTP(r) | |
for k := range r.Header { | |
log.Info("header", zap.String("key", k)) | |
} | |
log.Info("caller id", zap.String("caller-id", callerID)) | |
re.Equal(pdControlCallerID, callerID) | |
fmt.Fprint(w, callerID) | |
}) | |
info := apiutil.APIServiceGroup{ | |
IsCore: true, | |
} | |
return mux, info, nil | |
} |
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.
Thanks for your reminder and suggestion. I will fix it tomorrow.
/merge cancel |
Signed-off-by: okJiang <819421878@qq.com>
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #8212 +/- ##
==========================================
+ Coverage 77.30% 77.41% +0.11%
==========================================
Files 471 471
Lines 61445 61456 +11
==========================================
+ Hits 47498 47577 +79
+ Misses 10386 10315 -71
- Partials 3561 3564 +3
Flags with carried forward coverage won't be shown. Click here to find out more. |
Signed-off-by: okJiang <819421878@qq.com>
tools/pd-ctl/tests/global_test.go
Outdated
healths := []api.Health{ | ||
{ | ||
Name: "test", | ||
}, | ||
} | ||
healthsBytes, err := json.Marshal(healths) | ||
re.NoError(err) | ||
w.Write(healthsBytes) |
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 seems like this test wants to focus on calledID
, so I think it's no need to change it.
change cluster
API because it is a required path
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.
L55 has tested it. If we keep returning calledID
, json.UnMarshal will be failed.
tools/pd-ctl/tests/global_test.go
Outdated
cmd "github.com/tikv/pd/tools/pd-ctl/pdctl" | ||
"go.uber.org/zap" | ||
) | ||
|
||
const pdControlCallerID = "pd-ctl" | ||
const pdControlCallerID = "pd-http-client" |
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.
there need to be pd-ctl
, maybe You can reuse the variables in the global.go
file directly
pd/tools/pd-ctl/pdctl/command/global.go
Line 36 in 7e18a69
pdControlCallerID = "pd-ctl" |
FYI
pd/tools/pd-ctl/pdctl/command/global.go
Lines 103 to 112 in 7e18a69
func initNewPDClient(cmd *cobra.Command, opts ...pd.ClientOption) error { | |
if should, err := shouldInitPDClient(cmd); !should || err != nil { | |
return err | |
} | |
if PDCli != nil { | |
PDCli.Close() | |
} | |
PDCli = pd.NewClient(pdControlCallerID, getEndpoints(cmd), opts...) | |
return nil | |
} |
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 a little strange here. The unit test requires it to be pd-http-client
. I'll take a look for 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.
Line 310 in 4cd42b3
c := &client{inner: newClientInner(ctx, cancel, source), callerID: defaultCallerID} |
The HTTP client created in the pd-ctl
is assigned by defaultCallerID
. Do we need to change it to source
. source
equals to "pd-ctl" 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.
It is a bug :( Have been fixed in this pr. #8214
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 think you don't need open a new pr to fix it. We even need to modify the conflict for it. If it is bug, I can fix it in this pr easily. How was my propose?
Create an issue, link this pr, and then I can fix 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.
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 is ok for me. Let's wait for #8214 merged
Signed-off-by: okJiang <819421878@qq.com>
@@ -45,12 +45,6 @@ func TestSendAndGetComponent(t *testing.T) { | |||
w.Write(clusterBytes) | |||
}) | |||
// check http client api | |||
// TODO: remove this comment after replacing dialClient with the PD HTTP client completely. |
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.
please retain this comment, rest LGTM!
Signed-off-by: okJiang <819421878@qq.com>
/merge |
@HuSharp: 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: 132fe16
|
What problem does this PR solve?
Issue Number: Ref #7300
What is changed and how does it work?
Check List
Tests
Code changes
Release note