factor out unnecessary inputs to log handler (ts_sec)

This commit is contained in:
Chris Beck
2025-12-06 19:36:52 -07:00
parent 63ab1a62d3
commit 225b308a26
3 changed files with 8 additions and 10 deletions
+3 -6
View File
@@ -158,9 +158,7 @@ impl LogHandler {
/// Consume a new log message from the given 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, ts_sec).await;
let rate_limit_result = self.check_rate_limiters(&log_msg, &origin).await;
if let Err(reason) = &rate_limit_result {
let sev = log_msg.level.to_str();
@@ -223,7 +221,6 @@ impl LogHandler {
&self,
log_msg: &LogMessage,
origin: &Origin,
ts_sec: i64,
) -> Result<Option<Destination>, SuppressionReason> {
let mut route_failures: Vec<(usize, LimitResult)> = Vec::new();
let mut first_passed_destination: Option<Option<Destination>> = None;
@@ -241,7 +238,7 @@ impl LogHandler {
}
// 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 {
LimitResult::Passed => {
@@ -267,7 +264,7 @@ impl LogHandler {
// At least one route passed, now check overall limits
for (idx, (filter, limiter)) in self.overall_limits.iter().enumerate() {
// 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)));
}
}
@@ -51,12 +51,12 @@ impl LimiterSet {
/// Returns [`LimitResult::Passed`] if the event passes all limits.
/// 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`.
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
let origin_result = self.limiters.get(origin, |origin_limiters| {
for (i, (filter, limiter)) in origin_limiters.iter().enumerate() {
// 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));
}
}
@@ -70,7 +70,7 @@ impl LimiterSet {
// Check global limiters
for (i, (filter, limiter)) in self.global_limiters.iter().enumerate() {
// 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);
}
}
+2 -1
View File
@@ -107,7 +107,8 @@ impl Limiter {
///
/// Returns `true` if the event should be allowed (not rate-limited),
/// `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 {
Limiter::Multi(limiter) => limiter.evaluate(ts_sec),
Limiter::SourceLocation(limiter) => {