From c59a155d0758e2fdac012ad3d0e540fea21e7c26 Mon Sep 17 00:00:00 2001 From: Javier Ribal del Rio Date: Sat, 5 Dec 2026 12:05:48 +0100 Subject: [PATCH] refactor(backend, event): Problem becomes Notice, with an Info level for news that is not an error --- backend/crates/station/src/event.rs | 61 +++++++----- backend/crates/station/src/event/README.md | 86 +++++++++------- backend/crates/station/src/event/fault.rs | 6 +- .../crates/station/src/event/manual_tests.rs | 4 +- backend/crates/station/src/event/policy.rs | 21 ++-- backend/crates/station/src/event/router.rs | 99 +++++++++---------- backend/crates/station/src/event/tests.rs | 81 +++++++-------- backend/crates/station/src/main.rs | 33 ++++--- 8 files changed, 207 insertions(+), 184 deletions(-) diff --git a/backend/crates/station/src/event.rs b/backend/crates/station/src/event.rs index 5749e36b3..e8cdf82cf 100644 --- a/backend/crates/station/src/event.rs +++ b/backend/crates/station/src/event.rs @@ -70,8 +70,8 @@ pub trait TcpLink: Send + Sync { pub struct EventConfig { /// Slots in each of `net`'s error queues (①, one per transport). pub errors_queue: usize, - /// Slots in ② (problems from station modules). - pub problems_queue: usize, + /// Slots in ② (notices from station modules). + pub notices_queue: usize, /// Slots in ③ (TCP notifications). pub tcp_queue: usize, /// Slots in ④ (UDP notifications). The only stretch of queue between the @@ -94,7 +94,7 @@ impl Default for EventConfig { fn default() -> Self { Self { errors_queue: 16, - problems_queue: 16, + notices_queue: 16, tcp_queue: 1024, udp_queue: 8192, logging_queue: 8192, @@ -106,23 +106,25 @@ impl Default for EventConfig { } } -/// Something the operator has to see. +/// Something the operator is told: an error, or just news ("recording +/// started"). Its [`NoticeKind`] says which, and what the backend does about +/// it. #[derive(Debug, Clone, PartialEq, Eq)] -pub struct Problem { - /// When it was detected. +pub struct Notice { + /// When it happened. pub at: SystemTime, - /// The board, if known. + /// The board, if it concerns one. pub board: Option, - /// What it means for the backend. - pub kind: ProblemKind, - /// The message with all its causes: "could not X: because Y: because Z" - /// (see [`full_message`]). + /// How it is shown, and what it means for the backend. + pub kind: NoticeKind, + /// The text. For an error, the message with all its causes: "could not + /// X: because Y: because Z" (see [`full_message`]). pub text: String, } -impl Problem { - /// A problem detected now. - pub fn now(kind: ProblemKind, board: Option, text: impl Into) -> Self { +impl Notice { + /// A notice of something that happened now. + pub fn now(kind: NoticeKind, board: Option, text: impl Into) -> Self { Self { at: SystemTime::now(), board, @@ -132,11 +134,14 @@ impl Problem { } } -/// What a [`Problem`] means for the backend. +/// How a [`Notice`] is shown, and what it means for the backend. #[derive(Debug, Clone, Copy, PartialEq, Eq)] -pub enum ProblemKind { - /// Shown on the front; the backend keeps running. - Shown, +pub enum NoticeKind { + /// News, not an error: shown on the front as information; the backend + /// keeps running. + Info, + /// Shown on the front as a warning; the backend keeps running. + Warning, /// The fault is sent, it is shown on the front and the backend stops. Fatal, /// Only written to the trace: not shown, the backend keeps running. @@ -167,8 +172,9 @@ pub enum ToPipeline { /// A notification, TCP or UDP, as soon as it arrives. `logging` gets the /// same copy. Received(Arc), - /// Something the operator has to see. - Problem(Problem), + /// Something the operator is told, shown on the front as a message from + /// the backend: as information, a warning or a fatal error, by its kind. + Notice(Notice), /// An order the front sent that went out: shown on the front as a message /// from the backend. OrderSent { @@ -195,8 +201,9 @@ pub enum ToPipeline { /// Why `event` ended. `main` reads it and shuts everything down in order. #[derive(Debug)] pub enum Stop { - /// A fatal error: shown on the front, fault sent (or attempted). - Fatal(Problem), + /// A fatal error, with the notice that told it: fault sent (or + /// attempted), shown on the front. + Fatal(Notice), /// `net`'s queues closed: UDP and TCP were stopped. NetGone, } @@ -220,8 +227,8 @@ pub struct Channels { pub event: EventEnds, /// ⑦, for websocket's order forwarder. pub orders: mpsc::Sender, - /// ②, cloned for every station module that reports problems. - pub problems: mpsc::Sender, + /// ②, cloned for every station module that reports notices. + pub notices: mpsc::Sender, /// ⑤, for `logging`. pub logging: mpsc::Receiver, /// ⑥, for `pipeline`. @@ -252,7 +259,7 @@ pub fn channels(config: &EventConfig) -> Channels { // Channel creation let (udp, udp_sinks) = Reporter::channels(udp_capacity, errors); let (tcp, tcp_sinks) = Reporter::channels(tcp_capacity, errors); - let (problems_tx, problems_rx) = mpsc::channel(config.problems_queue.max(1)); + let (notices_tx, notices_rx) = mpsc::channel(config.notices_queue.max(1)); let (orders_tx, orders_rx) = mpsc::channel(config.orders_queue.max(1)); let (logging_tx, logging_rx) = mpsc::channel(config.logging_queue.max(1)); let (pipeline_tx, pipeline_rx) = mpsc::channel(config.pipeline_queue.max(1)); @@ -264,7 +271,7 @@ pub fn channels(config: &EventConfig) -> Channels { router: RouterEnds { udp: udp_sinks, tcp: tcp_sinks, - problems: problems_rx, + notices: notices_rx, logging: logging_tx, pipeline: pipeline_tx, tcp_capacity, @@ -273,7 +280,7 @@ pub fn channels(config: &EventConfig) -> Channels { orders: orders_rx, }, orders: orders_tx, - problems: problems_tx, + notices: notices_tx, logging: logging_rx, pipeline: pipeline_rx, } diff --git a/backend/crates/station/src/event/README.md b/backend/crates/station/src/event/README.md index 2963c706a..c03d0e54d 100644 --- a/backend/crates/station/src/event/README.md +++ b/backend/crates/station/src/event/README.md @@ -41,7 +41,7 @@ the boards. ┌─ task ─────┐ ─① errors──────► │ reads in this order: │ │ net::tcp │ ─③ TCP notif.──► │ 1. ① ② errors │ ─⑥─► ┌─ task ───┐ └────────────┘ │ 2. ③ TCP notifications │ │ pipeline │ → websocket → front - any station ─② problems─────► │ 3. ④ UDP notifications │ └──────────┘ + any station ─② notices─────► │ 3. ④ UDP notifications │ └──────────┘ module └────────────┬─────────────┘ │ ⑧ (fatal error, board fault) ▼ @@ -127,7 +127,7 @@ event/ | # | Queue | From → to | Carries | |---|---|---|---| | ① | net errors (one queue per transport) | `net::udp`, `net::tcp` → routing loop | `ErrorReport` | -| ② | problems | any station module → routing loop | `Problem` | +| ② | notices | any station module → routing loop | `Notice` | | ③ | TCP notifications | `net::tcp` → routing loop | `Notification` (protections, messages, connected/disconnected) | | ④ | UDP notifications | `net::udp` → routing loop | `Notification` (data) | | ⑤ | to logging | routing loop, both workers → `logging` | `ToLogging` | @@ -162,7 +162,7 @@ let event = event::spawn(config, channels.event, pod_data, index, tcp); // Arc

, - /// ②, cloned for every station module that reports problems. - pub problems: mpsc::Sender, + /// ②, cloned for every station module that reports notices. + pub notices: mpsc::Sender, /// ⑤, for logging. pub logging: mpsc::Receiver, /// ⑥, for pipeline. @@ -396,28 +402,32 @@ pub enum ToLogging { pub enum ToPipeline { /// A notification, the same copy logging gets. Received(Arc), - Problem(Problem), + Notice(Notice), /// An order the front sent that went out, as in `ToLogging`. OrderSent { at: SystemTime, board: Option, order: OrderPacket }, /// An order the front sent that did not go out, and why. OrderFailed { at: SystemTime, order: OrderPacket, reason: String }, } -/// Something the operator has to see. `Problem::now(kind, board, text)` -/// builds one stamped with the current time. -pub struct Problem { +/// Something the operator is told: an error, or just news. Its kind says +/// which. `Notice::now(kind, board, text)` builds one stamped with the +/// current time. +pub struct Notice { pub at: SystemTime, - /// The board, if known. + /// The board, if it concerns one. pub board: Option, - pub kind: ProblemKind, - /// The message with all its causes: "could not X: because Y: because Z" - /// (`event::full_message` builds it from any error). + pub kind: NoticeKind, + /// The text. For an error, the message with all its causes: "could not + /// X: because Y: because Z" (`event::full_message` builds it from any + /// error). pub text: String, } -pub enum ProblemKind { - /// Procedure 2: shown, the backend keeps running. - Shown, +pub enum NoticeKind { + /// News, not an error: shown as information, the backend keeps running. + Info, + /// Procedure 2: shown as a warning, the backend keeps running. + Warning, /// Procedure 3: the fault is sent, it is shown and the backend stops. Fatal, /// Procedure 1: only traced, not shown; the backend keeps running. @@ -426,7 +436,7 @@ pub enum ProblemKind { /// Why event ended. `main` reads it and shuts down in order. pub enum Stop { - Fatal(Problem), + Fatal(Notice), /// `net`'s queues closed: UDP and TCP were stopped. NetGone, } @@ -435,7 +445,7 @@ pub enum Stop { /// clamped to at least 1. pub struct EventConfig { pub errors_queue: usize, // each of net's two error queues, ① (16) - pub problems_queue: usize, // ② (16) + pub notices_queue: usize, // ② (16) pub tcp_queue: usize, // ③ (1,024) pub udp_queue: usize, // ④ (8,192) pub logging_queue: usize, // ⑤ (8,192) @@ -454,11 +464,11 @@ these two calls only. `FaultRequest` (⑧) is private to `event`. ```text loop, select! in fixed order (closed queues are no longer watched): - 1. ① UDP errors, ① TCP errors, then ② problems -> policy: + 1. ① UDP errors, ① TCP errors, then ② notices -> policy: fatal -> stop (see "Stopping") board fault -> propagate_fault? request to ⑧ (every time) - first from that board? Problem to ⑥ - shown -> Problem to ⑥ + first from that board? Notice to ⑥ + shown -> Notice to ⑥ silent -> trace only 2. ③ TCP notifications.recv() -> fault protection or message? propagate_fault? request to ⑧ @@ -513,13 +523,15 @@ notifications a second through `event`, over 20 times the requirement. (`logger/enable`, variable selection) go straight to `logging`, not through `event`. - **`logging`** reads ⑤, picks which measurements to store following its own - selection, records the orders that went out, and reports its own failures - (e.g. the disk) on ②. + selection, records the orders that went out, and reports on ② its own + failures (e.g. the disk, as a `Fatal` notice) and its news (an `Info`, e.g. + recording started). - **`pipeline`** reads ⑥ and turns it into what the front shows: a notification into per-packet updates (counts, cycle time, averages) or protection and - message updates; a `Problem`, and an order that went out or failed + message updates; a `Notice`, and an order that went out or failed (`OrderSent`, `OrderFailed`), into a message from the backend - (`message/update`). It waits instead of dropping and does not decide anything + (`message/update`). A notice keeps its kind there: `Info` as info, `Warning` + as warning, `Fatal` as fault. It waits instead of dropping and does not decide anything about errors. ## Implementation notes diff --git a/backend/crates/station/src/event/fault.rs b/backend/crates/station/src/event/fault.rs index 8bd2ccc51..db948d41e 100644 --- a/backend/crates/station/src/event/fault.rs +++ b/backend/crates/station/src/event/fault.rs @@ -10,7 +10,7 @@ use tokio::sync::{mpsc, oneshot}; use tracing::{error, info, warn}; use super::orders::TCP_NOT_AVAILABLE; -use super::{Problem, ProblemKind, TcpLink, ToLogging, ToPipeline, board_name}; +use super::{Notice, NoticeKind, TcpLink, ToLogging, ToPipeline, board_name}; /// The fault's id on the wire: what a board sends when it detects an error, /// and what the backend sends to every board to put the pod in fault. @@ -82,8 +82,8 @@ pub(super) async fn run( error!(%text); // A fault that only half landed is exactly what the // operator has to know. - let problem = Problem::now(ProblemKind::Shown, None, text); - let _ = pipeline.send(ToPipeline::Problem(problem)).await; + let notice = Notice::now(NoticeKind::Warning, None, text); + let _ = pipeline.send(ToPipeline::Notice(notice)).await; } } if let Some(done) = done { diff --git a/backend/crates/station/src/event/manual_tests.rs b/backend/crates/station/src/event/manual_tests.rs index 3ca606239..9314ee5d1 100644 --- a/backend/crates/station/src/event/manual_tests.rs +++ b/backend/crates/station/src/event/manual_tests.rs @@ -28,11 +28,11 @@ async fn manual_event_throughput() -> Result<(), Box> { tcp, event, orders, - problems, + notices, mut logging, mut pipeline, } = channels(&config); - drop((tcp, orders, problems)); + drop((tcp, orders, notices)); let event = spawn(config, event, Arc::default(), Arc::default(), None); let logged = tokio::spawn(async move { diff --git a/backend/crates/station/src/event/policy.rs b/backend/crates/station/src/event/policy.rs index 074dd551d..69189d2b6 100644 --- a/backend/crates/station/src/event/policy.rs +++ b/backend/crates/station/src/event/policy.rs @@ -8,7 +8,7 @@ use software_core::model::{AdjId, BoardId, MessageLevel, Packet, PacketType, Sev use software_core::net::{self, Event, tcp, udp::UdpError}; use software_core::protocol::Index; -use super::ProblemKind; +use super::NoticeKind; /// What the routing loop does about an error. #[derive(Debug, Clone, Copy, PartialEq, Eq)] @@ -50,13 +50,13 @@ pub(super) fn classify(error: &net::Error) -> Action { } } -/// Decides what a [`super::Problem`] from a station module means: whatever +/// Decides what a [`super::Notice`] from a station module means: whatever /// the module that sent it says. -pub(super) fn for_problem(kind: ProblemKind) -> Action { +pub(super) fn for_notice(kind: NoticeKind) -> Action { match kind { - ProblemKind::Fatal => Action::Fatal, - ProblemKind::Shown => Action::Show, - ProblemKind::Silent => Action::Silent, + NoticeKind::Fatal => Action::Fatal, + NoticeKind::Info | NoticeKind::Warning => Action::Show, + NoticeKind::Silent => Action::Silent, } } @@ -353,10 +353,11 @@ mod tests { } #[test] - fn a_problem_means_what_its_module_says() { - assert_eq!(for_problem(ProblemKind::Fatal), Action::Fatal); - assert_eq!(for_problem(ProblemKind::Shown), Action::Show); - assert_eq!(for_problem(ProblemKind::Silent), Action::Silent); + fn a_notice_means_what_its_module_says() { + assert_eq!(for_notice(NoticeKind::Fatal), Action::Fatal); + assert_eq!(for_notice(NoticeKind::Info), Action::Show); + assert_eq!(for_notice(NoticeKind::Warning), Action::Show); + assert_eq!(for_notice(NoticeKind::Silent), Action::Silent); } #[test] diff --git a/backend/crates/station/src/event/router.rs b/backend/crates/station/src/event/router.rs index 8a5e817de..76028cbd6 100644 --- a/backend/crates/station/src/event/router.rs +++ b/backend/crates/station/src/event/router.rs @@ -1,6 +1,6 @@ //! The routing loop: everything towards the front. //! -//! Reads ① ② ③ ④ in fixed order (errors, problems, TCP, UDP), hands every +//! Reads ① ② ③ ④ in fixed order (errors, notices, TCP, UDP), hands every //! notification to `logging` and `pipeline` (⑤ ⑥), decides what each error //! and each board fault means with [`super::policy`], and asks the fault //! worker (⑧) for the fault. It never writes to a socket itself, so it never @@ -20,7 +20,7 @@ use tracing::{debug, error, warn}; use super::fault::FaultRequest; use super::policy::{self, Action}; use super::{ - EventConfig, Problem, ProblemKind, Stop, ToLogging, ToPipeline, board_name, full_message, + EventConfig, Notice, NoticeKind, Stop, ToLogging, ToPipeline, board_name, full_message, }; /// The routing loop's ends of the queues: the reading side of ① ② ③ ④ and @@ -31,8 +31,8 @@ pub(super) struct RouterEnds { pub(super) udp: Sinks, /// ① and ③: TCP's errors and notifications. pub(super) tcp: Sinks, - /// ②: problems from station modules. - pub(super) problems: mpsc::Receiver, + /// ②: notices from station modules. + pub(super) notices: mpsc::Receiver, /// ⑤: to `logging`. The workers get clones. pub(super) logging: mpsc::Sender, /// ⑥: to `pipeline`. The workers get clones. @@ -60,14 +60,14 @@ enum Consumer { /// Why the routing loop has to stop, before it does it. #[derive(Debug)] enum Halt { - Fatal(Problem), + Fatal(Notice), Gone(Consumer), } /// What one round of the `select!` got. enum Step { NetError(Transport, Option), - Problem(Option), + Notice(Option), Notification(Transport, Option), } @@ -78,7 +78,7 @@ enum Step { struct Open { udp_errors: bool, tcp_errors: bool, - problems: bool, + notices: bool, tcp_notifications: bool, udp_notifications: bool, } @@ -88,7 +88,7 @@ impl Default for Open { Self { udp_errors: true, tcp_errors: true, - problems: true, + notices: true, tcp_notifications: true, udp_notifications: true, } @@ -111,7 +111,7 @@ pub(super) struct Router { index: Arc, udp: Sinks, tcp: Sinks, - problems: mpsc::Receiver, + notices: mpsc::Receiver, logging: mpsc::Sender, pipeline: mpsc::Sender, fault: mpsc::Sender, @@ -139,7 +139,7 @@ impl Router { index, udp: ends.udp, tcp: ends.tcp, - problems: ends.problems, + notices: ends.notices, logging: ends.logging, pipeline: ends.pipeline, fault, @@ -172,7 +172,7 @@ impl Router { report = self.tcp.errors.recv(), if open.tcp_errors => { Step::NetError(Transport::Tcp, report) } - problem = self.problems.recv(), if open.problems => Step::Problem(problem), + notice = self.notices.recv(), if open.notices => Step::Notice(notice), // Then notifications after errrors notification = self.tcp.notifications.recv(), if open.tcp_notifications => { @@ -196,11 +196,11 @@ impl Router { Ok(()) } Step::NetError(_, Some(report)) => self.on_net_error(report).await, - Step::Problem(None) => { - self.open.problems = false; + Step::Notice(None) => { + self.open.notices = false; Ok(()) } - Step::Problem(Some(problem)) => self.on_problem(problem).await, + Step::Notice(Some(notice)) => self.on_notice(notice).await, // Notifications empty Step::Notification(Transport::Tcp, None) => { @@ -226,7 +226,7 @@ impl Router { match handled { Ok(()) => {} - Err(Halt::Fatal(problem)) => return self.stop_fatal(problem).await, + Err(Halt::Fatal(notice)) => return self.stop_fatal(notice).await, Err(Halt::Gone(consumer)) => return self.stop_consumer_gone(consumer).await, } } @@ -264,13 +264,13 @@ impl Router { } let kind = match action { - Action::Fatal => ProblemKind::Fatal, - Action::Silent => ProblemKind::Silent, - Action::Show | Action::BoardFault => ProblemKind::Shown, + Action::Fatal => NoticeKind::Fatal, + Action::Silent => NoticeKind::Silent, + Action::Show | Action::BoardFault => NoticeKind::Warning, }; - // Defines the problem to show, or to send with the fault if it is fatal. - let problem = Problem { + // Defines the notice to show, or to send with the fault if it is fatal. + let notice = Notice { at: report.at, board, kind, @@ -279,31 +279,31 @@ impl Router { // What to do with it: show it, send the fault, or just trace it. match action { - Action::Fatal => Err(Halt::Fatal(problem)), - Action::BoardFault => self.on_board_fault(problem, source.ip).await, - Action::Show => self.show(problem).await.map_err(Halt::Gone), + Action::Fatal => Err(Halt::Fatal(notice)), + Action::BoardFault => self.on_board_fault(notice, source.ip).await, + Action::Show => self.show(notice).await.map_err(Halt::Gone), Action::Silent => { - self.trace_silent(&problem); + self.trace_silent(¬ice); Ok(()) } } } - async fn on_problem(&mut self, problem: Problem) -> Result<(), Halt> { - match policy::for_problem(problem.kind) { - Action::Fatal => Err(Halt::Fatal(problem)), + async fn on_notice(&mut self, notice: Notice) -> Result<(), Halt> { + match policy::for_notice(notice.kind) { + Action::Fatal => Err(Halt::Fatal(notice)), Action::Silent => { - self.trace_silent(&problem); + self.trace_silent(¬ice); Ok(()) } - Action::Show | Action::BoardFault => self.show(problem).await.map_err(Halt::Gone), + Action::Show | Action::BoardFault => self.show(notice).await.map_err(Halt::Gone), } } /// Procedure 1: written to the trace, and nothing else. - fn trace_silent(&self, problem: &Problem) { - let board = problem.board.map(|board| board_name(&self.pod_data, board)); - warn!(board = ?board, problem = %problem.text, "problem not shown on the front"); + fn trace_silent(&self, notice: &Notice) { + let board = notice.board.map(|board| board_name(&self.pod_data, board)); + warn!(board = ?board, notice = %notice.text, "notice not shown on the front"); } /// A fault (packet id 0) a board sent: sent to every board each time. @@ -311,8 +311,8 @@ impl Router { /// It arrives as an error, not as a notification, so the front only sees /// it if it is shown here: the first one from each address is, repeats /// are not (`net` already traces them, rate-limited). - async fn on_board_fault(&mut self, problem: Problem, ip: Option) -> Result<(), Halt> { - let board = problem.board.map_or_else( + async fn on_board_fault(&mut self, notice: Notice, ip: Option) -> Result<(), Halt> { + let board = notice.board.map_or_else( || "an unknown board".to_string(), |board| board_name(&self.pod_data, board), ); @@ -320,8 +320,8 @@ impl Router { let first = ip.is_none_or(|ip| self.faults_shown.insert(ip)); if first { - warn!(fault = %problem.text, "first fault from this board"); - self.show(problem).await.map_err(Halt::Gone)?; + warn!(fault = %notice.text, "first fault from this board"); + self.show(notice).await.map_err(Halt::Gone)?; } Ok(()) } @@ -340,28 +340,28 @@ impl Router { } } - // sends to pipelne a Problem - async fn show(&self, problem: Problem) -> Result<(), Consumer> { + // sends to pipelne a Notice + async fn show(&self, notice: Notice) -> Result<(), Consumer> { self.pipeline - .send(ToPipeline::Problem(problem)) + .send(ToPipeline::Notice(notice)) .await .map_err(|_| Consumer::Pipeline) } - /// Procedure 3: send the fault, show the problem, pass on what was + /// Procedure 3: send the fault, show the notice, pass on what was /// already queued, stop. /// /// The fault is asked for first, since it has to reach the boards as soon /// as possible; the rest happens while the fault worker writes it, and the /// loop only stops once it has gone out. - async fn stop_fatal(mut self, problem: Problem) -> Stop { - error!(problem = %problem.text, "fatal error, stopping"); + async fn stop_fatal(mut self, notice: Notice) -> Stop { + error!(notice = %notice.text, "fatal error, stopping"); let deadline = Instant::now() + self.config.fault_timeout; let fault_sent = self.ask_for_fault(deadline).await; let pipeline_alive = self .pipeline - .send(ToPipeline::Problem(problem.clone())) + .send(ToPipeline::Notice(notice.clone())) .await .is_ok(); if pipeline_alive { @@ -372,7 +372,7 @@ impl Router { } self.wait_for_fault(fault_sent, deadline).await; - Stop::Fatal(problem) + Stop::Fatal(notice) } /// `logging` or `pipeline` stopped: nothing is recorded, or nothing is @@ -382,20 +382,17 @@ impl Router { Consumer::Logging => "logging stopped: nothing is being recorded", Consumer::Pipeline => "pipeline stopped: nothing reaches the front", }; - let problem = Problem::now(ProblemKind::Fatal, None, text); - error!(problem = %problem.text, "fatal error, stopping"); + let notice = Notice::now(NoticeKind::Fatal, None, text); + error!(notice = %notice.text, "fatal error, stopping"); let deadline = Instant::now() + self.config.fault_timeout; let fault_sent = self.ask_for_fault(deadline).await; if consumer == Consumer::Logging { - let _ = self - .pipeline - .send(ToPipeline::Problem(problem.clone())) - .await; + let _ = self.pipeline.send(ToPipeline::Notice(notice.clone())).await; } self.wait_for_fault(fault_sent, deadline).await; - Stop::Fatal(problem) + Stop::Fatal(notice) } /// Passes on what is already in ③ and ④, at most their capacity each, so diff --git a/backend/crates/station/src/event/tests.rs b/backend/crates/station/src/event/tests.rs index 0fbfda463..5cec5a0cf 100644 --- a/backend/crates/station/src/event/tests.rs +++ b/backend/crates/station/src/event/tests.rs @@ -203,14 +203,10 @@ async fn errors_come_first_then_tcp_then_udp() -> TestResult { channels.udp.report(fault_from(hvscu_addr(), HVSCU)).await?; let _event = spawn(config, channels.event, pod_data(), index(), None); - let ToPipeline::Problem(problem) = next(&mut channels.pipeline).await? else { + let ToPipeline::Notice(notice) = next(&mut channels.pipeline).await? else { unreachable!("the error comes first"); }; - assert!( - problem.text.contains("signalled a fault"), - "{}", - problem.text - ); + assert!(notice.text.contains("signalled a fault"), "{}", notice.text); let ToPipeline::Received(tcp) = next(&mut channels.pipeline).await? else { unreachable!("then the TCP notification"); @@ -233,12 +229,12 @@ async fn a_fatal_error_passes_on_what_was_queued_and_stops() -> TestResult { channels.udp.report(decode_error()).await?; let event = spawn(config, channels.event, pod_data(), index(), None); - let ToPipeline::Problem(problem) = next(&mut channels.pipeline).await? else { + let ToPipeline::Notice(notice) = next(&mut channels.pipeline).await? else { unreachable!("the fatal error is shown first"); }; - assert_eq!(problem.kind, ProblemKind::Fatal); - assert_eq!(problem.board, Some(HVSCU), "the board the error carries"); - assert!(problem.text.starts_with("HVSCU: "), "{}", problem.text); + assert_eq!(notice.kind, NoticeKind::Fatal); + assert_eq!(notice.board, Some(HVSCU), "the board the error carries"); + assert!(notice.text.starts_with("HVSCU: "), "{}", notice.text); // The data that arrived before the error still gets through, to both. shown(&mut channels.pipeline, 2).await?; @@ -247,7 +243,7 @@ async fn a_fatal_error_passes_on_what_was_queued_and_stops() -> TestResult { let Stop::Fatal(stopped_by) = stops(event).await? else { unreachable!("a decode error is fatal"); }; - assert_eq!(stopped_by, problem); + assert_eq!(stopped_by, notice); Ok(()) } @@ -265,10 +261,10 @@ async fn a_board_fault_is_shown_once_per_board_and_sent_to_every_board_each_time // A marker: whatever comes before it on pipeline is all there is. channels.udp.notify(HVSCU, data()).await?; - let ToPipeline::Problem(first) = next(&mut channels.pipeline).await? else { + let ToPipeline::Notice(first) = next(&mut channels.pipeline).await? else { unreachable!("HVSCU's first fault is shown"); }; - let ToPipeline::Problem(second) = next(&mut channels.pipeline).await? else { + let ToPipeline::Notice(second) = next(&mut channels.pipeline).await? else { unreachable!("VCU's first fault is shown"); }; let ToPipeline::Received(_) = next(&mut channels.pipeline).await? else { @@ -276,7 +272,7 @@ async fn a_board_fault_is_shown_once_per_board_and_sent_to_every_board_each_time }; assert_eq!(first.board, Some(HVSCU)); assert_eq!(second.board, Some(VCU)); - assert_eq!(first.kind, ProblemKind::Shown); + assert_eq!(first.kind, NoticeKind::Warning); // Four faults arrived, so the fault goes out four times. eventually(|| fake.faults.load(Ordering::SeqCst) == 4).await?; @@ -301,7 +297,7 @@ async fn a_fault_protection_or_message_is_forwarded_and_sent_to_every_board() -> channels.tcp.notify(HVSCU, policy::message_sent(2)).await?; channels.tcp.notify(HVSCU, policy::message_sent(3)).await?; - // They still reach the front as what they are, not as extra problems. + // They still reach the front as what they are, not as extra notices. shown(&mut channels.pipeline, 3).await?; logged(&mut channels.logging, 3).await?; eventually(|| fake.faults.load(Ordering::SeqCst) == 3).await?; @@ -357,7 +353,7 @@ async fn propagating_a_board_fault_can_be_turned_off() -> TestResult { let _event = spawn(config, channels.event, pod_data(), index(), as_link(&fake)); channels.udp.report(fault_from(hvscu_addr(), HVSCU)).await?; - let ToPipeline::Problem(_) = next(&mut channels.pipeline).await? else { + let ToPipeline::Notice(_) = next(&mut channels.pipeline).await? else { unreachable!("the fault is still shown"); }; channels @@ -378,11 +374,11 @@ async fn closed_queues_do_not_hide_the_others() -> TestResult { tcp, event, orders, - problems, + notices, mut logging, pipeline: _pipeline, } = channels(&config); - drop((tcp, orders, problems)); + drop((tcp, orders, notices)); let _event = spawn(config, event, pod_data(), index(), None); udp.notify(HVSCU, data()).await?; @@ -486,7 +482,7 @@ async fn a_fault_from_the_front_goes_out_even_if_one_was_sent_already() -> TestR eventually(|| fake.faults.load(Ordering::SeqCst) == 1).await?; channels.orders.send(order(0)).await?; - let ToPipeline::Problem(_) = next(&mut channels.pipeline).await? else { + let ToPipeline::Notice(_) = next(&mut channels.pipeline).await? else { unreachable!("the board's fault is shown first"); }; let ToPipeline::OrderSent { .. } = next(&mut channels.pipeline).await? else { @@ -540,38 +536,45 @@ async fn a_fault_that_misses_boards_is_shown() -> TestResult { let _event = spawn(config, channels.event, pod_data(), index(), as_link(&fake)); channels.udp.report(fault_from(hvscu_addr(), HVSCU)).await?; - let ToPipeline::Problem(fault) = next(&mut channels.pipeline).await? else { + let ToPipeline::Notice(fault) = next(&mut channels.pipeline).await? else { unreachable!("the board's fault is shown"); }; - let ToPipeline::Problem(missed) = next(&mut channels.pipeline).await? else { + let ToPipeline::Notice(missed) = next(&mut channels.pipeline).await? else { unreachable!("then the boards the fault did not reach"); }; assert!(fault.text.contains("signalled a fault"), "{}", fault.text); - assert_eq!(missed.kind, ProblemKind::Shown); + assert_eq!(missed.kind, NoticeKind::Warning); assert!(missed.text.contains("VCU"), "{}", missed.text); Ok(()) } #[tokio::test] -async fn a_station_problem_is_traced_shown_or_stops_as_its_module_says() -> TestResult { +async fn a_station_notice_is_traced_shown_or_stops_as_its_module_says() -> TestResult { let config = EventConfig::default(); let mut channels = channels(&config); let event = spawn(config, channels.event, pod_data(), index(), None); - let silent = Problem::now(ProblemKind::Silent, None, "only for the trace"); - let shown = Problem::now(ProblemKind::Shown, None, "something to show"); - channels.problems.send(silent).await?; - channels.problems.send(shown.clone()).await?; - let ToPipeline::Problem(problem) = next(&mut channels.pipeline).await? else { - unreachable!("a shown problem reaches pipeline"); - }; + let silent = Notice::now(NoticeKind::Silent, None, "only for the trace"); + let info = Notice::now(NoticeKind::Info, None, "recording started"); + let warning = Notice::now(NoticeKind::Warning, None, "something to show"); + channels.notices.send(silent).await?; + channels.notices.send(info.clone()).await?; + channels.notices.send(warning.clone()).await?; // The silent one went first, but only to the trace. - assert_eq!(problem, shown); + let ToPipeline::Notice(first) = next(&mut channels.pipeline).await? else { + unreachable!("an info notice reaches pipeline"); + }; + let ToPipeline::Notice(second) = next(&mut channels.pipeline).await? else { + unreachable!("a warning reaches pipeline"); + }; + assert_eq!(first, info); + assert_eq!(second, warning); + assert!(!event.is_finished(), "neither stops the backend"); - let fatal = Problem::now(ProblemKind::Fatal, None, "the disk is full"); - channels.problems.send(fatal.clone()).await?; + let fatal = Notice::now(NoticeKind::Fatal, None, "the disk is full"); + channels.notices.send(fatal.clone()).await?; let Stop::Fatal(stopped_by) = stops(event).await? else { - unreachable!("a fatal problem stops event"); + unreachable!("a fatal notice stops event"); }; assert_eq!(stopped_by, fatal); Ok(()) @@ -585,7 +588,7 @@ async fn when_logging_stops_event_stops_and_tells_pipeline() -> TestResult { tcp: _tcp, event, orders: _orders, - problems: _problems, + notices: _notices, logging, mut pipeline, } = channels(&config); @@ -593,11 +596,11 @@ async fn when_logging_stops_event_stops_and_tells_pipeline() -> TestResult { let event = spawn(config, event, pod_data(), index(), None); udp.notify(HVSCU, data()).await?; - let ToPipeline::Problem(problem) = next(&mut pipeline).await? else { + let ToPipeline::Notice(notice) = next(&mut pipeline).await? else { unreachable!("pipeline is told that logging stopped"); }; - assert_eq!(problem.kind, ProblemKind::Fatal); - assert!(problem.text.contains("logging"), "{}", problem.text); + assert_eq!(notice.kind, NoticeKind::Fatal); + assert!(notice.text.contains("logging"), "{}", notice.text); let Stop::Fatal(_) = stops(event).await? else { unreachable!("losing logging is fatal"); @@ -613,7 +616,7 @@ async fn when_net_closes_what_was_left_is_passed_on_and_event_stops() -> TestRes tcp, event, orders: _orders, - problems: _problems, + notices: _notices, mut logging, pipeline: _pipeline, } = channels(&config); diff --git a/backend/crates/station/src/main.rs b/backend/crates/station/src/main.rs index bf39e02bd..ab048ae59 100644 --- a/backend/crates/station/src/main.rs +++ b/backend/crates/station/src/main.rs @@ -6,7 +6,7 @@ //! - the **logging stand-in** counts the packets it would record and writes a //! summary every second (and every packet, with `RUST_LOG=station=debug`); //! - the **pipeline stand-in** writes to the log what the front would show: -//! problems and failed orders. +//! notices and failed orders. //! //! There is no TCP and no websocket yet: their queues are closed at start. //! @@ -45,7 +45,7 @@ use tokio::time::MissedTickBehavior; use tracing::{debug, error, info, warn}; use tracing_subscriber::EnvFilter; -use station::event::{self, ProblemKind, Stop, ToLogging, ToPipeline}; +use station::event::{self, NoticeKind, Stop, ToLogging, ToPipeline}; /// Branch of the ADJ repository that is downloaded. const ADJ_BRANCH: &str = "adjv3-software"; @@ -160,14 +160,14 @@ async fn serve( tcp, event: ends, orders, - problems, + notices, logging, pipeline, } = event::channels(&config); - // Not built yet: TCP, websocket, and modules that report problems. + // Not built yet: TCP, websocket, and modules that report notices. // Dropping their ends closes those queues, and event stops watching them. - drop((tcp, orders, problems)); + drop((tcp, orders, notices)); let udp_task = spawn_udp( UdpConfig { @@ -210,8 +210,8 @@ async fn serve( } match stop.map_err(StartError::Event)? { - Stop::Fatal(problem) => { - info!(reason = %problem.text, "stopped after a fatal error"); + Stop::Fatal(notice) => { + info!(reason = %notice.text, "stopped after a fatal error"); Ok(ExitCode::FAILURE) } Stop::NetGone if by_ctrl_c => { @@ -268,17 +268,20 @@ async fn stand_in_pipeline(mut queue: mpsc::Receiver, pod_data: Arc< Event::Received(_) => {} } } - ToPipeline::Problem(problem) => { - let board = problem.board.map(|board| name(&pod_data, board)); - match problem.kind { - ProblemKind::Fatal => { - error!(board = ?board, text = %problem.text, "front: fatal error"); + ToPipeline::Notice(notice) => { + let board = notice.board.map(|board| name(&pod_data, board)); + match notice.kind { + NoticeKind::Fatal => { + error!(board = ?board, text = %notice.text, "front: fatal error"); } - ProblemKind::Shown => { - warn!(board = ?board, text = %problem.text, "front: problem") + NoticeKind::Warning => { + warn!(board = ?board, text = %notice.text, "front: warning") + } + NoticeKind::Info => { + info!(board = ?board, text = %notice.text, "front: info") } // event only traces these: they never reach pipeline. - ProblemKind::Silent => {} + NoticeKind::Silent => {} } } // The front shows both as a message from the backend.