diff --git a/src/common/error/src/status_code.rs b/src/common/error/src/status_code.rs index baf366ae9f..747514ba44 100644 --- a/src/common/error/src/status_code.rs +++ b/src/common/error/src/status_code.rs @@ -83,10 +83,12 @@ pub enum StatusCode { } impl StatusCode { + /// Returns `true` if `code` is success. pub fn is_success(code: u32) -> bool { Self::Success as u32 == code } + /// Returns `true` if the error with this code is retryable. pub fn is_retryable(&self) -> bool { match self { StatusCode::StorageUnavailable @@ -114,6 +116,35 @@ impl StatusCode { | StatusCode::AccessDenied => false, } } + + /// Returns `true` if we should print an error log for an error with + /// this status code. + pub fn should_log_error(&self) -> bool { + match self { + StatusCode::Unknown + | StatusCode::Unsupported + | StatusCode::Unexpected + | StatusCode::Internal + | StatusCode::PlanQuery + | StatusCode::EngineExecuteQuery + | StatusCode::StorageUnavailable + | StatusCode::RuntimeResourcesExhausted => true, + StatusCode::Success + | StatusCode::InvalidArguments + | StatusCode::InvalidSyntax + | StatusCode::TableAlreadyExists + | StatusCode::TableNotFound + | StatusCode::TableColumnNotFound + | StatusCode::TableColumnExists + | StatusCode::DatabaseNotFound + | StatusCode::UserNotFound + | StatusCode::UnsupportedPasswordType + | StatusCode::UserPasswordMismatch + | StatusCode::AuthHeaderNotFound + | StatusCode::InvalidAuthHeader + | StatusCode::AccessDenied => false, + } + } } impl fmt::Display for StatusCode { diff --git a/src/servers/src/grpc/handler.rs b/src/servers/src/grpc/handler.rs index f28ef70e87..aa4c6f8a16 100644 --- a/src/servers/src/grpc/handler.rs +++ b/src/servers/src/grpc/handler.rs @@ -19,7 +19,7 @@ use api::v1::{Basic, GreptimeRequest, RequestHeader}; use common_error::prelude::ErrorExt; use common_query::Output; use common_runtime::Runtime; -use common_telemetry::timer; +use common_telemetry::{logging, timer}; use metrics::increment_counter; use session::context::{QueryContext, QueryContextRef}; use snafu::OptionExt; @@ -73,11 +73,22 @@ impl GreptimeRequestHandler { // - Obtaining a `JoinHandle` to get the panic message (if there's any). // From its docs, `JoinHandle` is cancel safe. The task keeps running even it's handle been dropped. // 2. avoid the handler blocks the gRPC runtime incidentally. - let handle = self - .runtime - .spawn(async move { handler.do_query(query, query_ctx).await }); + let handle = self.runtime.spawn(async move { + handler.do_query(query, query_ctx).await.map_err(|e| { + if e.status_code().should_log_error() { + logging::error!(e; "Failed to handle request"); + } else { + // Currently, we still print a debug log. + logging::debug!("Failed to handle request, err: {}", e); + } + e + }) + }); let output = handle.await.map_err(|e| { + // logs the runtime join error. + logging::error!("Failed to join handle, err: {}", e); + if e.is_cancelled() { Status::cancelled(e.to_string()) } else if e.is_panic() {