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

api: Support to get http client ip #4495

Merged
merged 8 commits into from
Jan 5, 2022

Conversation

CabinfeverB
Copy link
Member

Signed-off-by: Cabinfever_B cabinfeveroier@gmail.com

What problem does this PR solve?

close #4494

What is changed and how it works?

According to related blogs, it gets client IP from header X-Forwarded-For to header X-Real-Ip to request.RemoteAddr

Check List

Tests

  • Unit test

Release note

None.

Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
@ti-chi-bot
Copy link
Member

ti-chi-bot commented Dec 23, 2021

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • nolouch
  • 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 added the release-note-none Denotes a PR that doesn't merit a release note. label Dec 23, 2021
server/server_test.go Outdated Show resolved Hide resolved
pkg/apiutil/apiutil.go Outdated Show resolved Hide resolved
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
@CabinfeverB
Copy link
Member Author

/run-all-tests

bodyBytes, err := io.ReadAll(resp.Body)
c.Assert(err, IsNil)
bodyString := string(bodyBytes)
c.Assert(bodyString, Equals, "Hello World\n")
Copy link
Contributor

Choose a reason for hiding this comment

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

why delete these lines?

Copy link
Member Author

@CabinfeverB CabinfeverB Dec 30, 2021

Choose a reason for hiding this comment

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

seems it should be reserved. Because it should not break the original test

@CabinfeverB
Copy link
Member Author

/run-all-tests

@codecov
Copy link

codecov bot commented Jan 4, 2022

Codecov Report

Merging #4495 (6dcd750) into master (20c08d2) will decrease coverage by 0.02%.
The diff coverage is 80.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #4495      +/-   ##
==========================================
- Coverage   74.95%   74.92%   -0.03%     
==========================================
  Files         265      265              
  Lines       27851    27861      +10     
==========================================
  Hits        20875    20875              
- Misses       5122     5129       +7     
- Partials     1854     1857       +3     
Flag Coverage Δ
unittests 74.92% <80.00%> (-0.03%) ⬇️

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

Impacted Files Coverage Δ
pkg/apiutil/apiutil.go 67.74% <80.00%> (+2.35%) ⬆️
pkg/errs/errs.go 75.00% <0.00%> (-25.00%) ⬇️
pkg/tempurl/tempurl.go 45.00% <0.00%> (-15.00%) ⬇️
server/schedulers/shuffle_hot_region.go 55.55% <0.00%> (-10.11%) ⬇️
server/id/id.go 76.19% <0.00%> (-9.53%) ⬇️
server/region_syncer/server.go 81.41% <0.00%> (-5.13%) ⬇️
server/config/persist_options.go 91.66% <0.00%> (-1.90%) ⬇️
server/schedule/checker/rule_checker.go 78.97% <0.00%> (-1.03%) ⬇️
server/server.go 71.94% <0.00%> (-0.75%) ⬇️
server/schedule/operator/builder.go 89.31% <0.00%> (-0.41%) ⬇️
... and 11 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 20c08d2...6dcd750. Read the comment docs.

@@ -204,6 +205,9 @@ func (s *testServerHandlerSuite) TestRegisterServerHandler(c *C) {
mux := http.NewServeMux()
mux.HandleFunc("/pd/apis/mok/v1/hello", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "Hello World")
// test getting ip
clientIP := apiutil.GetIPAddrFromHTTPRequest(r)
Copy link
Member

Choose a reason for hiding this comment

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

It's better to cover all cases in our test.

Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Jan 5, 2022
Copy link
Contributor

@nolouch nolouch left a comment

Choose a reason for hiding this comment

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

lgtm

@ti-chi-bot ti-chi-bot added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Jan 5, 2022
@nolouch
Copy link
Contributor

nolouch commented Jan 5, 2022

/merge

@ti-chi-bot
Copy link
Member

@nolouch: It seems you want to merge this PR, I will help you trigger all the tests:

/run-all-tests

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
Member

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

Commit hash: 7efb6ff

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Jan 5, 2022
@CabinfeverB
Copy link
Member Author

/run-all-tests

1 similar comment
@nolouch
Copy link
Contributor

nolouch commented Jan 5, 2022

/run-all-tests

@ti-chi-bot ti-chi-bot merged commit a901999 into tikv:master Jan 5, 2022
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. 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.

Support to Get real HTTP Client IP
5 participants