Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Config overhaul: improve admin experience #941

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions 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 packages/configuration/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ camino = { version = "1.1.6", features = ["serde", "serde1"] }
derive_more = "0"
figment = { version = "0.10.18", features = ["env", "test", "toml"] }
serde = { version = "1", features = ["derive"] }
serde_json = { version = "1", features = ["preserve_order"] }
serde_with = "3"
thiserror = "1"
toml = "0"
Expand Down
6 changes: 3 additions & 3 deletions packages/configuration/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,17 @@
let env_var_config_toml_path = ENV_VAR_CONFIG_TOML_PATH.to_string();

let config_toml = if let Ok(config_toml) = env::var(env_var_config_toml) {
println!("Loading configuration from environment variable:\n {config_toml}");
println!("Loading extra configuration from environment variable:\n {config_toml}");

Check warning on line 114 in packages/configuration/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

packages/configuration/src/lib.rs#L114

Added line #L114 was not covered by tests
Some(config_toml)
} else {
None
};

let config_toml_path = if let Ok(config_toml_path) = env::var(env_var_config_toml_path) {
println!("Loading configuration from file: `{config_toml_path}` ...");
println!("Loading extra configuration from file: `{config_toml_path}` ...");

Check warning on line 121 in packages/configuration/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

packages/configuration/src/lib.rs#L121

Added line #L121 was not covered by tests
config_toml_path
} else {
println!("Loading configuration from default configuration file: `{default_config_toml_path}` ...");
println!("Loading extra configuration from default configuration file: `{default_config_toml_path}` ...");
default_config_toml_path
};

Expand Down
16 changes: 16 additions & 0 deletions packages/configuration/src/v2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,10 +346,26 @@
}

/// Encodes the configuration to TOML.
///
/// # Panics
///
/// Will panic if it can't be converted to TOML.
#[must_use]
fn to_toml(&self) -> String {
// code-review: do we need to use Figment also to serialize into toml?
toml::to_string(self).expect("Could not encode TOML value")
}

/// Encodes the configuration to JSON.
///
/// # Panics
///
/// Will panic if it can't be converted to JSON.
#[must_use]
pub fn to_json(&self) -> String {

Check warning on line 365 in packages/configuration/src/v2/mod.rs

View check run for this annotation

Codecov / codecov/patch

packages/configuration/src/v2/mod.rs#L365

Added line #L365 was not covered by tests
// code-review: do we need to use Figment also to serialize into json?
serde_json::to_string_pretty(self).expect("Could not encode JSON value")
}

Check warning on line 368 in packages/configuration/src/v2/mod.rs

View check run for this annotation

Codecov / codecov/patch

packages/configuration/src/v2/mod.rs#L367-L368

Added lines #L367 - L368 were not covered by tests
}

#[cfg(test)]
Expand Down
7 changes: 7 additions & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@
/// - Can't retrieve tracker keys from database.
/// - Can't load whitelist from database.
pub async fn start(config: &Configuration, tracker: Arc<core::Tracker>) -> Vec<JoinHandle<()>> {
if config.http_api.is_none()
&& (config.udp_trackers.is_none() || config.udp_trackers.as_ref().map_or(true, std::vec::Vec::is_empty))
&& (config.http_trackers.is_none() || config.http_trackers.as_ref().map_or(true, std::vec::Vec::is_empty))

Check warning on line 43 in src/app.rs

View check run for this annotation

Codecov / codecov/patch

src/app.rs#L41-L43

Added lines #L41 - L43 were not covered by tests
{
warn!("No services enabled in configuration");

Check warning on line 45 in src/app.rs

View check run for this annotation

Codecov / codecov/patch

src/app.rs#L45

Added line #L45 was not covered by tests
}

let mut jobs: Vec<JoinHandle<()>> = Vec::new();

let registar = Registar::default();
Expand Down
4 changes: 4 additions & 0 deletions src/bootstrap/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

use torrust_tracker_clock::static_time;
use torrust_tracker_configuration::Configuration;
use tracing::info;

use super::config::initialize_configuration;
use crate::bootstrap;
Expand All @@ -26,8 +27,11 @@
#[must_use]
pub fn setup() -> (Configuration, Arc<Tracker>) {
let configuration = initialize_configuration();

let tracker = initialize_with_configuration(&configuration);

info!("Configuration:\n{}", configuration.to_json());

Check warning on line 33 in src/bootstrap/app.rs

View check run for this annotation

Codecov / codecov/patch

src/bootstrap/app.rs#L33

Added line #L33 was not covered by tests

(configuration, tracker)
}

Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
TraceStyle::Json => builder.json().init(),
};

info!("logging initialized.");
info!("Logging initialized");

Check warning on line 55 in src/bootstrap/logging.rs

View check run for this annotation

Codecov / codecov/patch

src/bootstrap/logging.rs#L55

Added line #L55 was not covered by tests
}

#[derive(Debug)]
Expand Down
4 changes: 2 additions & 2 deletions src/console/ci/e2e/logs_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ impl RunningServices {
///
/// ```text
/// Loading configuration from default configuration file: `./share/default/config/tracker.development.sqlite3.toml` ...
/// 2024-06-10T16:07:39.989540Z INFO torrust_tracker::bootstrap::logging: logging initialized.
/// 2024-06-10T16:07:39.989540Z INFO torrust_tracker::bootstrap::logging: Logging initialized
/// 2024-06-10T16:07:39.990205Z INFO UDP TRACKER: Starting on: udp://0.0.0.0:6868
/// 2024-06-10T16:07:39.990215Z INFO UDP TRACKER: Started on: udp://0.0.0.0:6868
/// 2024-06-10T16:07:39.990244Z INFO UDP TRACKER: Starting on: udp://0.0.0.0:6969
Expand Down Expand Up @@ -116,7 +116,7 @@ mod tests {
fn it_should_parse_from_logs_with_valid_logs() {
let logs = r"
Loading configuration from default configuration file: `./share/default/config/tracker.development.sqlite3.toml` ...
2024-06-10T16:07:39.989540Z INFO torrust_tracker::bootstrap::logging: logging initialized.
2024-06-10T16:07:39.989540Z INFO torrust_tracker::bootstrap::logging: Logging initialized
2024-06-10T16:07:39.990244Z INFO UDP TRACKER: Starting on: udp://0.0.0.0:6969
2024-06-10T16:07:39.990255Z INFO UDP TRACKER: Started on: udp://0.0.0.0:6969
2024-06-10T16:07:39.990261Z INFO torrust_tracker::bootstrap::jobs: TLS not enabled
Expand Down
2 changes: 1 addition & 1 deletion src/console/ci/e2e/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@

fn tracing_stdout_init(filter: LevelFilter) {
tracing_subscriber::fmt().with_max_level(filter).init();
info!("Logging initialized.");
info!("Logging initialized");

Check warning on line 120 in src/console/ci/e2e/runner.rs

View check run for this annotation

Codecov / codecov/patch

src/console/ci/e2e/runner.rs#L120

Added line #L120 was not covered by tests
}

fn load_tracker_configuration(args: &Args) -> anyhow::Result<String> {
Expand Down
2 changes: 1 addition & 1 deletion src/console/clients/checker/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@

fn tracing_stdout_init(filter: LevelFilter) {
tracing_subscriber::fmt().with_max_level(filter).init();
debug!("logging initialized.");
debug!("Logging initialized");

Check warning on line 106 in src/console/clients/checker/app.rs

View check run for this annotation

Codecov / codecov/patch

src/console/clients/checker/app.rs#L106

Added line #L106 was not covered by tests
}

fn setup_config(args: Args) -> Result<Configuration> {
Expand Down
2 changes: 1 addition & 1 deletion src/console/clients/udp/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@

fn tracing_stdout_init(filter: LevelFilter) {
tracing_subscriber::fmt().with_max_level(filter).init();
debug!("logging initialized.");
debug!("Logging initialized");

Check warning on line 132 in src/console/clients/udp/app.rs

View check run for this annotation

Codecov / codecov/patch

src/console/clients/udp/app.rs#L132

Added line #L132 was not covered by tests
}

async fn handle_announce(remote_addr: SocketAddr, info_hash: &TorrustInfoHash) -> Result<Response, Error> {
Expand Down
2 changes: 1 addition & 1 deletion src/console/profiling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ pub async fn run() {
info!("Torrust timed shutdown..");
},
_ = tokio::signal::ctrl_c() => {
info!("Torrust shutting down via Ctrl+C..");
info!("Torrust shutting down via Ctrl+C ...");
// Await for all jobs to shutdown
futures::future::join_all(jobs).await;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ async fn main() {
// handle the signals
tokio::select! {
_ = tokio::signal::ctrl_c() => {
info!("Torrust shutting down..");
info!("Torrust shutting down ...");

// Await for all jobs to shutdown
futures::future::join_all(jobs).await;
Expand Down
2 changes: 1 addition & 1 deletion src/servers/apis/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
//!
//! ```text
//! Loading configuration from config file ./tracker.toml
//! 023-03-28T12:19:24.963054069+01:00 [torrust_tracker::bootstrap::logging][INFO] logging initialized.
//! 023-03-28T12:19:24.963054069+01:00 [torrust_tracker::bootstrap::logging][INFO] Logging initialized
//! ...
//! 023-03-28T12:19:24.964138723+01:00 [torrust_tracker::bootstrap::jobs::tracker_apis][INFO] Starting Torrust APIs server on: http://0.0.0.0:1212
//! ```
Expand Down
Loading