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

Sticky Sessions: Tolerate ClickHouse Session ID Mechanism #117

Merged
merged 12 commits into from
May 24, 2021

Conversation

pavelnemirovsky
Copy link
Contributor

A proposed naive approach to be able to stick to user session across multiple queries:

Use Case the PR Should be solved :
Query #1:
CREATE TEMPORARY TABLE if not exists analyse AS SELECT * from system.numbers limit 100
Query #2:
SELECT count(*) as total from analyse

For each query same session-id should be passed.

Please review

scope.go Show resolved Hide resolved
Copy link
Contributor

@hagen1778 hagen1778 left a comment

Choose a reason for hiding this comment

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

LGTM! See my comments

scope.go Outdated Show resolved Hide resolved
@@ -99,6 +98,11 @@ func (rp *reverseProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
ReadCloser: req.Body,
}

// publish session_id if needed
if s.sessionId != "" {
rw.Header().Set("X-ClickHouse-Server-Session-Id", s.sessionId)
Copy link
Contributor

Choose a reason for hiding this comment

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

Quick check didn't show any results for "X-ClickHouse-Server-Session-Id" header in CH docs. Could you pls add a comment what exactly this header is used for?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added this header just to make sure ChProxy acknowledged and processed correctly the value was set to session_id

Copy link
Contributor

Choose a reason for hiding this comment

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

I was confused while reading it. I think, it requires a proper comment to explain your intention.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@hagen1778 treat this header as ECHO Service, you pass the value of session_id and you'll want to assure that that value was accepted by server-side correctly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@hagen1778 let's merge it already and let's enable GitHub actions to release versions properly for multiple platforms, what do u think?

main_test.go Outdated
"http POST request with session id",
"testdata/http-session-id.yml",
func(t *testing.T) {
req, err := http.NewRequest("POST", "http://127.0.0.1:9090/?query_id=45395792-a432-4b92-8cc9-536c14e1e1a9&extremes=0&session_id=default-session-id233", bytes.NewBufferString("SELECT * FROM system.numbers LIMIT 10"))
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: would be nice to keep the line length consistent with the rest of the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adjusted

main_test.go Show resolved Hide resolved

h := c.getHost()
Copy link
Contributor

Choose a reason for hiding this comment

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

should we use if-else here to avoid unnecessary counter's increase on line 58 when session_id isn't empty?

scope.go Outdated Show resolved Hide resolved
@@ -99,6 +98,11 @@ func (rp *reverseProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
ReadCloser: req.Body,
}

// publish session_id if needed
if s.sessionId != "" {
rw.Header().Set("X-ClickHouse-Server-Session-Id", s.sessionId)
Copy link
Contributor

Choose a reason for hiding this comment

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

I was confused while reading it. I think, it requires a proper comment to explain your intention.

@hagen1778 hagen1778 merged commit ee67a2d into ContentSquare:master May 24, 2021
@hagen1778
Copy link
Contributor

Thanks for contribution!

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.

3 participants