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

Support ping endpoint #456

Merged
merged 6 commits into from
Sep 8, 2024
Merged

Conversation

hulk8
Copy link
Contributor

@hulk8 hulk8 commented Aug 27, 2024

Description

It's similar with #127 issue.

chproxy returns HTTP 200 response for /ping endpoint and not proxying this request.
I want to add /ping endpoint to proxy, because some of BI instruments use this endpoint by default for healthchecks.

Pull request type

Feature

  • added support for proxying /ping endpoint.
  • added option allow_ping to config on global scope for enabling ping endpoint proxying.

Does this introduce a breaking change?

  • No

Further comments

I've created config option on global scope in first version. If you think that it's necessary to create it on network_groups or server section (to allow ping endpoint only from some networks), then I can do that.

@mga-chka
Copy link
Collaborator

FYI, we're already handling the /ping, so there must be a recent issue, cf this PR. So if there is an issue, it's better to fix the heartbeat logic than creating a new ping logic.

@hulk8
Copy link
Contributor Author

hulk8 commented Aug 28, 2024

@mga-chka
It's different from heartbeat logic.

As I understand, chproxy can create heartbeats to ClickHouse cluster. Heartbeat config can be configured for /ping endpoint in ClickHouse nodes (configured via section clusters/heartbeat).
Something like this:

...
clusters:
  - name: "dl"
    scheme: "http"
    nodes: ["click1:8123"]
    heartbeat:
      interval: 15s
      timeout: 10s
      request: "/ping"
      response: "Ok.\n"
...

But on chproxy level I can't create /ping request to proxy as if it was ClickHouse node. This is what I'm trying to add in this PR and It seems to me what in issue #127 was requested (in this comment for example).
When I'm trying to send ping request I have this exception:

> curl --request GET --url http://some_chproxy:8123/ping                                                                                                                                              
"172.23.0.1:54784": unsupported path: "/ping"

We faced this problem while integrating some BI instruments to chproxy which use /ping endpoint for self connection healthcheck. These changes helped solve this problem in our cases.

@mga-chka
Copy link
Collaborator

my bad, you're right.
can you check the golangci-lint issue?

@mga-chka
Copy link
Collaborator

Can you add tests (in main_test.go) to ensure the /ping works when it's put on and doesn't work when it's off.
You also need to remove you debug.yml since no one will understand the meaning of this conf and it's not used.

@hulk8
Copy link
Contributor Author

hulk8 commented Aug 30, 2024

Ok, I will add tests and remove debug.yml.

@hulk8
Copy link
Contributor Author

hulk8 commented Sep 2, 2024

@mga-chka, hi!

I've:

  • added two tests:
    • http ping request - http /ping request without auth args mapped to default user in config.
    • https ping request - https /ping request with auth args provided.
  • removed debug.yml from examples.
  • done some refactoring to minimize changes to the source code.

All tests are passed.

@mga-chka
Copy link
Collaborator

mga-chka commented Sep 4, 2024

great, the linter is still not happy, cf the last build
Error: string `/ping` has 4 occurrences, make it a constant (goconst)
Can you also add one test when the ping is not activated (for example by taking the conf testdata/http.yml)?

@hulk8
Copy link
Contributor Author

hulk8 commented Sep 4, 2024

@mga-chka I've:

  • created pingEndpoint constant for linter.
  • added test for disabled ping by default (conf testdata/http.yml).

Copy link
Collaborator

@mga-chka mga-chka left a comment

Choose a reason for hiding this comment

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

looks good to me. I'm waiting a few days before merging in case another reviewer wants to look at the PR

@mga-chka mga-chka merged commit ec66a85 into ContentSquare:master Sep 8, 2024
5 of 6 checks passed
@mga-chka mga-chka mentioned this pull request Sep 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants