factor out unnecessary inputs to log handler (ts_sec)
This commit is contained in:
@@ -158,9 +158,7 @@ impl LogHandler {
|
|||||||
|
|
||||||
/// Consume a new log message from the given origin
|
/// Consume a new log message from the given origin
|
||||||
pub async fn handle_log_message(&self, log_msg: LogMessage, origin: Origin) {
|
pub async fn handle_log_message(&self, log_msg: LogMessage, origin: Origin) {
|
||||||
let ts_sec = log_msg.get_timestamp_or_fallback();
|
let rate_limit_result = self.check_rate_limiters(&log_msg, &origin).await;
|
||||||
|
|
||||||
let rate_limit_result = self.check_rate_limiters(&log_msg, &origin, ts_sec).await;
|
|
||||||
|
|
||||||
if let Err(reason) = &rate_limit_result {
|
if let Err(reason) = &rate_limit_result {
|
||||||
let sev = log_msg.level.to_str();
|
let sev = log_msg.level.to_str();
|
||||||
@@ -223,7 +221,6 @@ impl LogHandler {
|
|||||||
&self,
|
&self,
|
||||||
log_msg: &LogMessage,
|
log_msg: &LogMessage,
|
||||||
origin: &Origin,
|
origin: &Origin,
|
||||||
ts_sec: i64,
|
|
||||||
) -> Result<Option<Destination>, SuppressionReason> {
|
) -> Result<Option<Destination>, SuppressionReason> {
|
||||||
let mut route_failures: Vec<(usize, LimitResult)> = Vec::new();
|
let mut route_failures: Vec<(usize, LimitResult)> = Vec::new();
|
||||||
let mut first_passed_destination: Option<Option<Destination>> = None;
|
let mut first_passed_destination: Option<Option<Destination>> = None;
|
||||||
@@ -241,7 +238,7 @@ impl LogHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Filter matched, evaluate the limiter set
|
// Filter matched, evaluate the limiter set
|
||||||
let result = limiter_set.evaluate(log_msg, origin, ts_sec);
|
let result = limiter_set.evaluate(log_msg, origin);
|
||||||
|
|
||||||
match result {
|
match result {
|
||||||
LimitResult::Passed => {
|
LimitResult::Passed => {
|
||||||
@@ -267,7 +264,7 @@ impl LogHandler {
|
|||||||
// At least one route passed, now check overall limits
|
// At least one route passed, now check overall limits
|
||||||
for (idx, (filter, limiter)) in self.overall_limits.iter().enumerate() {
|
for (idx, (filter, limiter)) in self.overall_limits.iter().enumerate() {
|
||||||
// Only evaluate the limiter if the message matches the filter
|
// Only evaluate the limiter if the message matches the filter
|
||||||
if filter.matches(log_msg) && !limiter.evaluate(log_msg, ts_sec) {
|
if filter.matches(log_msg) && !limiter.evaluate(log_msg) {
|
||||||
return Err(SuppressionReason::Overall(LimitResult::OverallLimiter(idx)));
|
return Err(SuppressionReason::Overall(LimitResult::OverallLimiter(idx)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,12 +51,12 @@ impl LimiterSet {
|
|||||||
/// Returns [`LimitResult::Passed`] if the event passes all limits.
|
/// Returns [`LimitResult::Passed`] if the event passes all limits.
|
||||||
/// Returns [`LimitResult::Limiter(i)`] if blocked by per-origin limiter at index `i`.
|
/// Returns [`LimitResult::Limiter(i)`] if blocked by per-origin limiter at index `i`.
|
||||||
/// Returns [`LimitResult::GlobalLimiter(i)`] if blocked by global limiter at index `i`.
|
/// Returns [`LimitResult::GlobalLimiter(i)`] if blocked by global limiter at index `i`.
|
||||||
pub fn evaluate(&self, log_msg: &LogMessage, origin: &Origin, ts_sec: i64) -> LimitResult {
|
pub fn evaluate(&self, log_msg: &LogMessage, origin: &Origin) -> LimitResult {
|
||||||
// Check per-origin limiters
|
// Check per-origin limiters
|
||||||
let origin_result = self.limiters.get(origin, |origin_limiters| {
|
let origin_result = self.limiters.get(origin, |origin_limiters| {
|
||||||
for (i, (filter, limiter)) in origin_limiters.iter().enumerate() {
|
for (i, (filter, limiter)) in origin_limiters.iter().enumerate() {
|
||||||
// Only evaluate the limiter if the message matches the filter
|
// Only evaluate the limiter if the message matches the filter
|
||||||
if filter.matches(log_msg) && !limiter.evaluate(log_msg, ts_sec) {
|
if filter.matches(log_msg) && !limiter.evaluate(log_msg) {
|
||||||
return Some(LimitResult::Limiter(i));
|
return Some(LimitResult::Limiter(i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -70,7 +70,7 @@ impl LimiterSet {
|
|||||||
// Check global limiters
|
// Check global limiters
|
||||||
for (i, (filter, limiter)) in self.global_limiters.iter().enumerate() {
|
for (i, (filter, limiter)) in self.global_limiters.iter().enumerate() {
|
||||||
// Only evaluate the limiter if the message matches the filter
|
// Only evaluate the limiter if the message matches the filter
|
||||||
if filter.matches(log_msg) && !limiter.evaluate(log_msg, ts_sec) {
|
if filter.matches(log_msg) && !limiter.evaluate(log_msg) {
|
||||||
return LimitResult::GlobalLimiter(i);
|
return LimitResult::GlobalLimiter(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -107,7 +107,8 @@ impl Limiter {
|
|||||||
///
|
///
|
||||||
/// Returns `true` if the event should be allowed (not rate-limited),
|
/// Returns `true` if the event should be allowed (not rate-limited),
|
||||||
/// `false` if it should be suppressed.
|
/// `false` if it should be suppressed.
|
||||||
pub fn evaluate(&self, log_msg: &LogMessage, ts_sec: i64) -> bool {
|
pub fn evaluate(&self, log_msg: &LogMessage) -> bool {
|
||||||
|
let ts_sec = log_msg.get_timestamp_or_fallback();
|
||||||
match self {
|
match self {
|
||||||
Limiter::Multi(limiter) => limiter.evaluate(ts_sec),
|
Limiter::Multi(limiter) => limiter.evaluate(ts_sec),
|
||||||
Limiter::SourceLocation(limiter) => {
|
Limiter::SourceLocation(limiter) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user