From def80bfe644d3c1eb270fced6bb85f4e85a93d4a Mon Sep 17 00:00:00 2001 From: Chris Beck Date: Fri, 5 Dec 2025 22:46:15 -0700 Subject: [PATCH] rearrange code in route.rs for readability --- signal-gateway/src/gateway/route.rs | 76 ++++++++++++++--------------- 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/signal-gateway/src/gateway/route.rs b/signal-gateway/src/gateway/route.rs index 2928c7e..e0eeb2a 100644 --- a/signal-gateway/src/gateway/route.rs +++ b/signal-gateway/src/gateway/route.rs @@ -73,6 +73,34 @@ impl TryFrom for RateThreshold { } } +/// A rate limit rule for suppressing repeated alerts. +/// +/// Combines a filter to match specific log messages with a rate threshold. +#[derive(Clone, Debug, Deserialize)] +#[serde(deny_unknown_fields)] +pub struct Limit { + /// Filter criteria for messages this limit applies to. + #[serde(flatten)] + pub filter: LogFilter, + /// Rate threshold for suppressing alerts. + pub threshold: RateThreshold, + /// If true, rate limit independently per source location (file:line). + /// If false (default), count all matching events together. + #[serde(default)] + pub by_source_location: bool, +} + +impl Limit { + /// Create the appropriate limiter for this limit configuration. + pub fn make_limiter(&self) -> super::rate_limiter::Limiter { + if self.by_source_location { + super::rate_limiter::Limiter::source_location(self.threshold) + } else { + super::rate_limiter::Limiter::multi(self.threshold) + } + } +} + /// A route configuration for processing log messages. /// /// Routes match incoming log messages based on an optional filter, then apply @@ -112,44 +140,6 @@ fn default_alert_level() -> Level { Level::ERROR } -/// Destination override for alert messages. -#[derive(Clone, Debug, Deserialize)] -#[serde(rename_all = "snake_case")] -pub enum Destination { - /// Send to specific recipient UUIDs. - Recipients(Vec), - /// Send to a Signal group by group ID. - Group(String), -} - -/// A rate limit rule for suppressing repeated alerts. -/// -/// Combines a filter to match specific log messages with a rate threshold. -#[derive(Clone, Debug, Deserialize)] -#[serde(deny_unknown_fields)] -pub struct Limit { - /// Filter criteria for messages this limit applies to. - #[serde(flatten)] - pub filter: LogFilter, - /// Rate threshold for suppressing alerts. - pub threshold: RateThreshold, - /// If true, rate limit independently per source location (file:line). - /// If false (default), count all matching events together. - #[serde(default)] - pub by_source_location: bool, -} - -impl Limit { - /// Create the appropriate limiter for this limit configuration. - pub fn make_limiter(&self) -> super::rate_limiter::Limiter { - if self.by_source_location { - super::rate_limiter::Limiter::source_location(self.threshold) - } else { - super::rate_limiter::Limiter::multi(self.threshold) - } - } -} - impl Route { /// Create a limiter set from this route's limit configurations. pub fn make_limiter_set(&self) -> super::rate_limiter::LimiterSet { @@ -168,3 +158,13 @@ impl Default for Route { } } } + +/// Destination override for alert messages. +#[derive(Clone, Debug, Deserialize)] +#[serde(rename_all = "snake_case")] +pub enum Destination { + /// Send to specific recipient UUIDs. + Recipients(Vec), + /// Send to a Signal group by group ID. + Group(String), +}