From a750176db38d826667983721775d6e3a0063cc42 Mon Sep 17 00:00:00 2001 From: Yang Xiufeng Date: Fri, 18 Oct 2024 17:14:59 +0800 Subject: [PATCH 1/2] refactor: some http APIs do not need sticky. --- .../src/servers/http/middleware/session.rs | 16 +++++++++++----- .../src/servers/http/v1/http_query_handlers.rs | 6 +++--- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/query/service/src/servers/http/middleware/session.rs b/src/query/service/src/servers/http/middleware/session.rs index edcc9546289e..a413921eb31b 100644 --- a/src/query/service/src/servers/http/middleware/session.rs +++ b/src/query/service/src/servers/http/middleware/session.rs @@ -79,6 +79,8 @@ pub enum EndpointKind { Clickhouse, NoAuth, Verify, + UploadToStage, + SystemInfo, } impl EndpointKind { @@ -94,18 +96,22 @@ impl EndpointKind { } pub fn require_databend_token_type(&self) -> Result> { match self { - EndpointKind::Verify => Ok(None), + EndpointKind::Verify | EndpointKind::NoAuth => Ok(None), EndpointKind::Refresh => Ok(Some(TokenType::Refresh)), - EndpointKind::StartQuery | EndpointKind::PollQuery | EndpointKind::Logout => { + EndpointKind::StartQuery + | EndpointKind::PollQuery + | EndpointKind::Logout + | EndpointKind::SystemInfo + | EndpointKind::UploadToStage => { if GlobalConfig::instance().query.management_mode { Ok(None) } else { Ok(Some(TokenType::Session)) } } - _ => Err(ErrorCode::AuthenticateFailure(format!( - "should not use databend token for {self:?}", - ))), + EndpointKind::Login | EndpointKind::Clickhouse => Err(ErrorCode::AuthenticateFailure( + format!("should not use databend token for {self:?}",), + )), } } } diff --git a/src/query/service/src/servers/http/v1/http_query_handlers.rs b/src/query/service/src/servers/http/v1/http_query_handlers.rs index 1eacdd5c9dd2..98b9034609f5 100644 --- a/src/query/service/src/servers/http/v1/http_query_handlers.rs +++ b/src/query/service/src/servers/http/v1/http_query_handlers.rs @@ -450,17 +450,17 @@ pub fn query_route() -> Route { ( "/upload_to_stage", put(upload_to_stage), - EndpointKind::StartQuery, + EndpointKind::UploadToStage, ), ( "/suggested_background_tasks", get(list_suggestions), - EndpointKind::StartQuery, + EndpointKind::SystemInfo, ), ( "/discovery_nodes", get(discovery_nodes), - EndpointKind::StartQuery, + EndpointKind::SystemInfo, ), ]; From 70dcbe604e76217bc62b5e87f3f1729fc3b0b2b0 Mon Sep 17 00:00:00 2001 From: Yang Xiufeng Date: Sun, 20 Oct 2024 14:13:18 +0800 Subject: [PATCH 2/2] fix forward log. --- src/query/service/src/servers/http/middleware/session.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/query/service/src/servers/http/middleware/session.rs b/src/query/service/src/servers/http/middleware/session.rs index a413921eb31b..15921ef49549 100644 --- a/src/query/service/src/servers/http/middleware/session.rs +++ b/src/query/service/src/servers/http/middleware/session.rs @@ -461,7 +461,7 @@ impl Endpoint for HTTPSessionEndpoint { .map_err(HttpErrorCode::server_error)? { log::info!( - "forwarding {} from {local_id} to {sticky_node_id}", + "forwarding /v1{} from {local_id} to {sticky_node_id}", req.uri() ); forward_request(req, node).await