Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
ceb77c3
feat(backend, logging): logging module initial structure
pminmic Nov 27, 2026
667b660
docs(backend, logging): create README.md and explanation of module wo…
pminmic Nov 27, 2026
db6d981
feat(backend, logging): create directories when the backend is starte…
pminmic Nov 27, 2026
bd934c3
refactor(backend, logging): adapt event input
pminmic Dec 2, 2026
822606a
test(backend, logging): correct tests
pminmic Dec 3, 2026
0026070
fix(backent, logging): correct order logging to match OrderPacket
pminmic Dec 3, 2026
7e2ab8a
fix(backend, logging): log protection durations and simplify session …
pminmic Dec 3, 2026
ada1427
docs(backend, logging): document WebSocket integration plan
pminmic Dec 3, 2026
204e9b0
feat(backend, logging): add lifecycle and error tracing
pminmic Dec 3, 2026
3a3baeb
fix(backend, logging): orders payload enriched with Index metadata
pminmic Dec 3, 2026
b0c3126
fix(backend, logging): add order name field and rethink of payload (n…
pminmic Dec 3, 2026
e750a63
Merge branch 'new-backend' into backend/logging
JavierRibaldelRio Dec 6, 2026
aa0ab8f
fix(backend, logging): adapt tests to the merged event channels
JavierRibaldelRio Dec 6, 2026
45341f7
refactor(backend, logging): remove the saturation stop
JavierRibaldelRio Dec 6, 2026
7b4e407
refactor(backend, logging): take Arc<PodData> instead of Arc<Adj>
JavierRibaldelRio Dec 6, 2026
65ea1c3
feat(backend, logging): warn the front when a session stops on a writ…
JavierRibaldelRio Dec 6, 2026
fa3eefe
fix(backend, logging): discard orders with non-finite values instead …
JavierRibaldelRio Dec 6, 2026
d742e63
docs(backend, logging): data files are named after the measurement alias
JavierRibaldelRio Dec 6, 2026
7937189
feat(backend, websocket): make the command destinations public
JavierRibaldelRio Dec 6, 2026
6473141
feat(backend, logging): apply the frontend's logger commands
JavierRibaldelRio Dec 6, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions backend/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ repository = "https://github.com/Hyperloop-UPV/software"
software-core = { path = "crates/core" }

bytes = "1"
jiff = { version = "0.2", features = ["tzdb-bundle-always"] }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
thiserror = "2"
Expand Down
6 changes: 6 additions & 0 deletions backend/crates/core/src/logger/csv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,12 @@ impl<W: Write> Row<'_, W> {
self.number(format_args!("{value}"))
}

/// Appends the instant field. Cannot use `Self::int()`,
/// because an instant is an u128
pub fn instant(self, value: u128) -> Self {
self.number(format_args!("{value}"))
}

/// Appends a boolean field, as `true` or `false`.
pub fn bool(self, value: bool) -> Self {
self.number(format_args!("{value}"))
Expand Down
4 changes: 3 additions & 1 deletion backend/crates/station/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ authors.workspace = true
repository.workspace = true

[dependencies]
software-core = { workspace = true, features = ["net", "git", "http"] }
software-core = { workspace = true, features = ["net", "git", "http", "logger"] }
jiff.workspace = true
serde.workspace = true
thiserror.workspace = true
tokio.workspace = true
Expand All @@ -23,6 +24,7 @@ axum = { version = "0.8.9", features = ["ws", "http1", "http2"] }
tower-http = { version = "0.6.11", features = ["cors", "set-header"] }

[dev-dependencies]
tempfile = "3.27"
tokio = { workspace = true, features = ["test-util"] }

[lints]
Expand Down
4 changes: 3 additions & 1 deletion backend/crates/station/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@
//! - [`event`]: the communication between the modules (see
//! `src/event/README.md`).
//! - [`http`]: the HTTP API (ADJ catalogs and the WebSocket upgrade).
//! - [`logging`]: recording configuration, sessions, and event consumption.
//! - [`payload`]: the messages that travel over the WebSocket.
//! - [`pipeline`]: turns what `event` routes into what the front shows (see
//! `src/pipeline/README.md`).
//! - [`websocket`]: the broker and the connections with the frontends.

pub mod event;
pub mod http;
pub mod logging;
pub mod payload;
pub mod pipeline;
mod vehicle;
pub mod websocket;
pub mod websocket;
93 changes: 93 additions & 0 deletions backend/crates/station/src/logging.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
//! Backend recording policy, built on `software_core::logger`.
//!
//! Configuration, session metadata, CSV recording, event consumption and the
//! dedicated writer are implemented. Frontend and startup integration remain
//! the application's responsibility.
//! File writing stays in `software_core::logger`; this module decides what
//! to record, where it belongs and when to flush it.
//! The full specification and pending decisions are in `logging/README.md`.
//!
//! Lifecycle:
//! - At backend startup, create a `YYYY-MM-DDTHH-MM-SS` directory and its
//! `others/` directory for the ADJ validator output, settings and JSONL trace.
//! - `play` prepares a new recording session after discarding inactive backlog.
//! - `stop` drains the ready input prefix up to its reception-time cutoff,
//! flushes buffers and closes session files.
//! - `emergency_stop` performs the same drain on frontend disconnection or
//! backend shutdown. Backend shutdown also finishes the writer and flushes
//! the backend trace; frontend disconnection must allow a later session.
//!
//! The writer owns session state and consumes event's existing bounded channel
//! directly. Independent lifecycle controls remain usable when data is full.
//! Async controls return after their transition completes; observers receive
//! status snapshots through a watch channel. Input stays open between sessions.

mod catalog;
mod commands;
mod control;
mod data;
mod error;
mod messages;
mod order;
mod output;
mod protections;
mod service;
mod session;
mod settings;
mod status;
mod writer;

#[cfg(test)]
mod test_support;

pub use crate::event::ToLogging;
pub use commands::serve_commands;
pub use error::Error;
pub use service::Logging;
pub use session::{BackendRun, MeasurementKey, Session, SessionId, SessionSelection};
pub use settings::{Config, Settings, TimeUnit};
pub use status::{Phase, SessionInfo, Status, StatusReceiver, StopReason, StopReport};
pub use writer::WriterOptions;

#[cfg(test)]
mod tests {

use super::{Config, TimeUnit};
use serde_json::json;
use std::time::Duration;

type TestResult = Result<(), Box<dyn std::error::Error + Send + Sync>>;

#[test]
fn config_matches_frontend_units_and_rejects_unknown_units() -> TestResult {
let units = [
("ns", TimeUnit::Nanoseconds),
("us", TimeUnit::Microseconds),
("ms", TimeUnit::Milliseconds),
("s", TimeUnit::Seconds),
];
for (name, unit) in units {
let config: Config = toml::from_str(&format!(
"time_unit = {name:?}\nlogging_path = \"recordings\""
))?;
assert_eq!(config.time_unit, unit);
assert_eq!(serde_json::to_value(unit)?, json!(name));
}
assert!(toml::from_str::<Config>("time_unit = \"minutes\"").is_err());
assert_eq!(toml::from_str::<Config>("")?, Config::default());
Ok(())
}

#[test]
fn integer_conversion_truncates_fractions_without_overflow() {
let elapsed = Duration::new(2, 35_123_456);
assert_eq!(TimeUnit::Seconds.convert(elapsed), 2);
assert_eq!(TimeUnit::Milliseconds.convert(elapsed), 2035);
assert_eq!(TimeUnit::Microseconds.convert(elapsed), 2_035_123);
assert_eq!(TimeUnit::Nanoseconds.convert(elapsed), 2_035_123_456);
assert_eq!(
TimeUnit::Nanoseconds.convert(Duration::MAX),
Duration::MAX.as_nanos()
);
}
}
Loading
Loading