Skip to content

Commit

Permalink
chore: add log handler file
Browse files Browse the repository at this point in the history
  • Loading branch information
paomian committed May 27, 2024
1 parent 2e51c16 commit fbc66ec
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 7 deletions.
14 changes: 7 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

57 changes: 57 additions & 0 deletions src/frontend/src/instance/log_handler.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Copyright 2023 Greptime Team
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use api::v1::RowInsertRequests;
use async_trait::async_trait;
use auth::{PermissionChecker, PermissionCheckerRef, PermissionReq};
use client::Output;
use common_error::ext::BoxedError;
use servers::error::{AuthSnafu, ExecuteGrpcRequestSnafu};
use servers::query_handler::LogHandler;
use session::context::QueryContextRef;
use snafu::ResultExt;

use super::Instance;

#[async_trait]
impl LogHandler for Instance {
async fn insert_log(
&self,
log: RowInsertRequests,
ctx: QueryContextRef,
) -> servers::error::Result<Output> {
self.plugins
.get::<PermissionCheckerRef>()
.as_ref()
// This is a bug, it should be PermissionReq::LogWrite
.check_permission(ctx.current_user(), PermissionReq::PromStoreWrite)
.context(AuthSnafu)?;

self.handle_log_inserts(log, ctx).await
}
}

impl Instance {
pub async fn handle_log_inserts(
&self,
log: RowInsertRequests,
ctx: QueryContextRef,
) -> servers::error::Result<Output> {
self.inserter
.handle_log_inserts(log, ctx, self.statement_executor.as_ref())
.await
.map_err(BoxedError::new)
.context(ExecuteGrpcRequestSnafu)
}
}

0 comments on commit fbc66ec

Please sign in to comment.