feat: Log error in GreptimeRequestHandler (#1507)

* feat(common-error): Add should_log_error

* feat(servers): log error in grpc handler
This commit is contained in:
Yingwen
2023-05-04 15:48:38 +08:00
committed by GitHub
parent d7a906e0bd
commit 2818f466d3
2 changed files with 46 additions and 4 deletions
+31
View File
@@ -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 {