Repository navigation
[Event] Backend/event - #683
Merged
Merged
Conversation
… for logging and pipeline
pminmic
approved these changes
Dec 1, 2026
pminmic
left a comment
There was a problem hiding this comment.
Just minor changes, but it's very well done.
GaziH
approved these changes
Dec 1, 2026
GaziH
left a comment
There was a problem hiding this comment.
Really good stuff, just do what was commented on and should be good!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
(Includes UDP from NET)
What
eventisstation::eventis how station's modules talk to each other. It is the single consumer ofcore::net's queues:logging(disk) andpipeline(front).The full design (queues, error table, shutdown, contract) is in
backend/crates/station/src/event/README.md. This description is the short version, plus what each module has to do to plug into it.How it works
eventis three tasks:net::udp,net::tcp→ routing loopErrorReportProblemnet::tcp→ routing loopNotificationnet::udp→ routing loopNotificationloggingToLoggingpipelineToPipelinewebsocket→ orders workerOrderPacketFaultRequestrouter.rs). Oneselect!with a fixed order: errors, problems, TCP, UDP.loggingandpipelineas one shared copy (Arc<Notification>).policy.rs.orders.rs). Takes the front's orders one at a time, writes each one to TCP and waits for the result.OrderSentgoes tologgingandpipeline.OrderFailedgoes topipeline, with the reason.fault.rs). Sends the fault (order id 0) to every board, once per request, and reports which boards it did not reach.Principles
event::channels()creates every queue in one call. There are circles (event→logging→event,event→ TCP →event), and creating everything first removes the "who exists first" problem.eventowns the types of every queue, sologgingandpipelinedepend onevent, never the other way round.eventnever looks inside the data.loggingpicks the measurements it stores andpipelinecomputes what the front shows.eventonly routes.eventapplies one of three procedures:Fault, or a message of levelFault/Panic. Ifpropagate_faultis on (the default), the fault is sent to every board each time one arrives.How each module plugs in
mainmainkeeps no copy of aReporter: aReporterleft alive keeps its queues open, and the routing loop never ends.channels.tcp.event's task ends with aStop:Fatal(problem)exits with code 1;NetGoneexits with 0 after Ctrl+C and with 1 otherwise.net(udpandtcp): theReporter, not theSinksnetonly ever sees the sending side: oneReporterper transport (channels.udp,channels.tcp), cloned once per task (the UDP loop, each TCP connection). The receiving side (Sinks, withnotificationsanderrors) belongs toevent: it travels insidechannels.eventand only the routing loop reads it.netnever touches aSinks.reporter.notify(board, event).awaitfor everything that happens:Event::Connected,Event::Disconnected,Event::Received(packet). It stamps the time (at) itself; nothing else may stamp it by hand.reporter.report(error).awaitfor everything that goes wrong. The identity goes inside the error variant (board, address).notifywaits: never drop, nevertry_send.Err(Closed)meanseventis gone: stop the task.How
eventreads each error:UdpError::Decode,UdpError::RecvUdpError::Fault { from, board }(packet id 0, recognised before decoding)tcp::Error::Decodetcp::Error::ConnectDisconnectednotification already tells the front)tcp::Error::WriteSpecifics:
net::udpresolves the board of an error from the sender's IP:UdpConfig::boards, built withPodData::boards_by_ip()(included in this PR).net::tcpadditionally:tcp::Error::Faultvariant, whichpolicy::classifywill map to board fault);eventas aTcpLink, directly or through a thin adapter:send(order)returns the board once the order is written, and fails right away if the board is not connected;send_fault()returns the boards it did not reach.loggingIt receives
channels.logging, anmpsc::Receiver<ToLogging>(⑤):Notificationcarriesboard,at(the full date, taken when the bytes came off the socket) andevent. Protections and messages also carry the board's own clock (ShortTimestamp, a time of day with no date).loggingfalls behind,eventwaits, and so doesnetbehind it.logging's job.eventsends everything.channels.problemsas aProblem. UseProblemKind::Fatalfor anything that stops recording (for instance the disk), andevent::full_message(&err)for the text with all its causes.recv()returnsNone,eventhas stopped: write what is left, flush and end. That is the shutdown signal.event("logging stopped: nothing is being recorded").pipelineIt receives
channels.pipeline, anmpsc::Receiver<ToPipeline>(⑥):Received(Arc<Notification>)Problem(Problem)message/update).kindsays whether it isShownorFatalOrderSent { at, board, order }message/update: the order went out (board = Nonefor the fault)OrderFailed { at, order, reason }message/update: the order did not go out, and whylogging: keep reading, never drop, and end whenrecv()returnsNone.pipelinedoes not decide anything about errors: that has already been decided.event.websocket(orders)It receives
channels.orders, anmpsc::Sender<OrderPacket>(⑦):orders.send(order).await.websocket: it reaches the front throughpipeline(OrderSent/OrderFailedturned intomessage/update).logger/enable, variable selection) go tologgingdirectly, not throughevent.sendfails,eventis gone.Any other station module
Clone
channels.problems(②) and send aProblem, for exampleProblem::now(ProblemKind::Shown, board, text).Also in this PR
core::model:PodData::board_nameandPodData::boards_by_ip.core::net::udp:UdpError::DecodeandUdpError::Faultcarry the board (Option<BoardId>), resolved throughUdpConfig::boards.station/src/main.rs: downloads the ADJ, listens on UDP and runs everything throughevent, with stand-ins forloggingandpipeline.station/src/lib.rs: station's modules are declared there, so each one compiles and is tested on its own while it is being built, whether or notmainwires it in yet.main.rsonly starts and connects them.http(feat(backend, http): add HTTP API for ADJ catalogs and WebSocket upgrade support #676) was not declared anywhere, so it was not compiled: it is now, with its tests (clippy has threeneedless_borrows_for_generic_argswarnings inhttp/server.rstests).Not wired yet
send(order) -> Result<(), SendError>does not return the board, andeventneeds "sent" to mean "written". An adapter toTcpLinkis needed once both are in.websocket([Backend] feat(backend): payload an websocket modules #680), the realloggingandpipeline:mainuses stand-ins.loggingdisk failure always fatal?Testing
cargo test -p software-core --all-featuresandcargo test -p station, the same as CI. 31 tests ineventcover:Faultprotections andFault/Panicmessages sent to every board each time; warnings only forwarded;netclosing, and a fault that never finishes sending.cargo test -p station --release manual_event -- --ignored --nocapture: about 1,000,000 notifications a second throughevent, 24 times the 41,000/s required.