Skip to content

Commit

Permalink
chore: update validator signature (#4548)
Browse files Browse the repository at this point in the history
  • Loading branch information
shuiyisong authored Aug 13, 2024
1 parent 72a1732 commit 5aa4c70
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ humantime = "2.1"
humantime-serde = "1.1"
itertools = "0.10"
lazy_static = "1.4"
meter-core = { git = "https://github.com/GreptimeTeam/greptime-meter.git", rev = "049171eb16cb4249d8099751a0c46750d1fe88e7" }
meter-core = { git = "https://github.com/GreptimeTeam/greptime-meter.git", rev = "80eb97c24c88af4dd9a86f8bbaf50e741d4eb8cd" }
mockall = "0.11.4"
moka = "0.12"
notify = "6.1"
Expand Down Expand Up @@ -243,7 +243,7 @@ table = { path = "src/table" }

[workspace.dependencies.meter-macros]
git = "https://github.com/GreptimeTeam/greptime-meter.git"
rev = "049171eb16cb4249d8099751a0c46750d1fe88e7"
rev = "80eb97c24c88af4dd9a86f8bbaf50e741d4eb8cd"

[profile.release]
debug = 1
Expand Down
19 changes: 12 additions & 7 deletions src/servers/src/http/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,14 @@ pub async fn log_ingester(
TypedHeader(content_type): TypedHeader<ContentType>,
payload: String,
) -> Result<HttpResponse> {
if let Some(log_validator) = log_state.log_validator {
if let Some(response) = log_validator.validate(query_params.source.clone(), &payload) {
return response;
}
// validate source and payload
let source = query_params.source.as_deref();
let response = match &log_state.log_validator {
Some(validator) => validator.validate(source, &payload).await,
None => None,
};
if let Some(response) = response {
return response;
}

let handler = log_state.log_handler;
Expand Down Expand Up @@ -367,13 +371,14 @@ async fn ingest_logs_inner(
Ok(response)
}

pub trait LogValidator {
#[async_trait]
pub trait LogValidator: Send + Sync {
/// validate payload by source before processing
/// Return a `Some` result to indicate validation failure.
fn validate(&self, source: Option<String>, payload: &str) -> Option<Result<HttpResponse>>;
async fn validate(&self, source: Option<&str>, payload: &str) -> Option<Result<HttpResponse>>;
}

pub type LogValidatorRef = Arc<dyn LogValidator + Send + Sync>;
pub type LogValidatorRef = Arc<dyn LogValidator + 'static>;

/// axum state struct to hold log handler and validator
#[derive(Clone)]
Expand Down

0 comments on commit 5aa4c70

Please sign in to comment.