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

ctl: replace doRequest with HTTP client to get health status #8212

Merged
merged 18 commits into from
May 27, 2024

Conversation

okJiang
Copy link
Member

@okJiang okJiang commented May 23, 2024

What problem does this PR solve?

Issue Number: Ref #7300

What is changed and how does it work?

Check List

Tests

  • Unit test

Code changes

Release note

None.

Copy link
Contributor

ti-chi-bot bot commented May 23, 2024

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • JmPotato
  • nolouch

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 May 23, 2024
@ti-chi-bot ti-chi-bot bot requested review from JmPotato and rleungx May 23, 2024 08:22
@ti-chi-bot ti-chi-bot bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label May 23, 2024
client/http/interface.go Show resolved Hide resolved
tools/pd-ctl/pdctl/command/health_command.go Outdated Show resolved Hide resolved
okJiang and others added 5 commits May 23, 2024 16:35
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>
Copy link
Member

@JmPotato JmPotato left a comment

Choose a reason for hiding this comment

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

The rest LGTM.

client/http/request_info.go Outdated Show resolved Hide resolved
tools/pd-ctl/pdctl/command/health_command.go Outdated Show resolved Hide resolved
@ti-chi-bot ti-chi-bot bot added the status/LGT1 Indicates that a PR has LGTM 1. label May 23, 2024
@@ -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) {
Copy link
Member

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?

Copy link
Member Author

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>
Signed-off-by: okJiang <819421878@qq.com>
@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 May 23, 2024
@JmPotato
Copy link
Member

/merge

Copy link
Contributor

ti-chi-bot bot commented May 23, 2024

@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 /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 ti-chi-bot bot added the status/can-merge Indicates a PR has been approved by a committer. label May 23, 2024
Run: showHealthCommandFunc,
Use: "health",
Short: "show all node's health information of the PD cluster",
PersistentPreRunE: requirePDClient,
Copy link
Member

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 function shouldInitPDClient, which requires querying pd/api/v1/cluster.

  • The handler is replaced in TestSendAndGetComponent, so you need to add this router to the handler in TestSendAndGetComponent.

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

Copy link
Member

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

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
}

Copy link
Member Author

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.

@HuSharp HuSharp removed the status/can-merge Indicates a PR has been approved by a committer. label May 23, 2024
@ti-chi-bot ti-chi-bot bot added the status/can-merge Indicates a PR has been approved by a committer. label May 23, 2024
@JmPotato
Copy link
Member

/merge cancel

@ti-chi-bot ti-chi-bot bot removed the status/can-merge Indicates a PR has been approved by a committer. label May 23, 2024
@ti-chi-bot ti-chi-bot bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels May 24, 2024
Signed-off-by: okJiang <819421878@qq.com>
Copy link

codecov bot commented May 24, 2024

Codecov Report

Attention: Patch coverage is 87.50000% with 2 lines in your changes are missing coverage. Please review.

Project coverage is 77.41%. Comparing base (7cc3b4e) to head (132fe16).

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     
Flag Coverage Δ
unittests 77.41% <87.50%> (+0.11%) ⬆️

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

Signed-off-by: okJiang <819421878@qq.com>
Signed-off-by: okJiang <819421878@qq.com>
Comment on lines 56 to 63
healths := []api.Health{
{
Name: "test",
},
}
healthsBytes, err := json.Marshal(healths)
re.NoError(err)
w.Write(healthsBytes)
Copy link
Member

@HuSharp HuSharp May 24, 2024

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.

FYI https://github.com/tikv/pd/pull/4491/files#diff-05102750a57e22445f5760fb1545227c9130a3a093f3b879e1f6e48ce27ea890

change cluster API because it is a required path

Copy link
Member Author

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.

cmd "github.com/tikv/pd/tools/pd-ctl/pdctl"
"go.uber.org/zap"
)

const pdControlCallerID = "pd-ctl"
const pdControlCallerID = "pd-http-client"
Copy link
Member

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

pdControlCallerID = "pd-ctl"

FYI

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
}

Copy link
Member Author

@okJiang okJiang May 24, 2024

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

Copy link
Member Author

Choose a reason for hiding this comment

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

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.

Copy link
Member

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

Copy link
Member Author

@okJiang okJiang May 24, 2024

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.

Copy link
Member

@HuSharp HuSharp May 24, 2024

Choose a reason for hiding this comment

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

I think this is a different issue, maybe with a new pr will be a little clearer 0 0

Because some background information is needed

After replacing HTTP with SDK #7490, we need to add the calledID explicitly to keep consistent with #4491
And source ID can be consistent with caller ID, #7565

Copy link
Member Author

@okJiang okJiang May 24, 2024

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

@ti-chi-bot ti-chi-bot bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels May 27, 2024
@@ -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.
Copy link
Member

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>
@HuSharp
Copy link
Member

HuSharp commented May 27, 2024

/merge

Copy link
Contributor

ti-chi-bot bot commented May 27, 2024

@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 /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 May 27, 2024

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

Commit hash: 132fe16

@ti-chi-bot ti-chi-bot bot added the status/can-merge Indicates a PR has been approved by a committer. label May 27, 2024
@ti-chi-bot ti-chi-bot bot merged commit dd7f2a7 into tikv:master May 27, 2024
19 checks passed
@HuSharp HuSharp mentioned this pull request May 27, 2024
7 tasks
@okJiang okJiang deleted the pdctl-health branch June 7, 2024 03:21
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/M Denotes a PR that changes 30-99 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.

4 participants