Add support for custom report database path in statistics collector

This commit is contained in:
Simon Wicky
2025-01-28 11:32:33 +01:00
parent 3a770a5af9
commit c31f449afd
4 changed files with 18 additions and 0 deletions
@@ -42,6 +42,10 @@ pub(crate) struct Init {
#[clap(short, long, default_value_t = OutputFormat::default())]
output: OutputFormat,
/// Custom path to the report storage database
#[clap(long)]
report_database_path: Option<PathBuf>,
}
impl From<Init> for OverrideConfig {
@@ -50,6 +54,7 @@ impl From<Init> for OverrideConfig {
nym_apis: init_config.common_args.nym_apis,
nyxd_urls: init_config.common_args.nyxd_urls,
enabled_credentials_mode: init_config.common_args.enabled_credentials_mode,
report_database_path: init_config.report_database_path,
}
}
}
@@ -7,10 +7,12 @@ use log::error;
use nym_bin_common::bin_info;
use nym_bin_common::completions::{fig_generate, ArgShell};
use nym_client_core::cli_helpers::CliClient;
use nym_config::OptionalSet;
use nym_statistics_collector::{
config::{helpers::try_upgrade_config, BaseClientConfig, Config},
error::StatsCollectorError,
};
use std::path::PathBuf;
use std::sync::OnceLock;
mod add_gateway;
@@ -98,6 +100,7 @@ pub(crate) struct OverrideConfig {
nym_apis: Option<Vec<url::Url>>,
nyxd_urls: Option<Vec<url::Url>>,
enabled_credentials_mode: Option<bool>,
report_database_path: Option<PathBuf>,
}
pub(crate) fn override_config(config: Config, args: OverrideConfig) -> Config {
@@ -118,6 +121,7 @@ pub(crate) fn override_config(config: Config, args: OverrideConfig) -> Config {
BaseClientConfig::with_disabled_credentials,
args.enabled_credentials_mode.map(|b| !b),
)
.with_optional(Config::with_report_database_path, args.report_database_path)
}
pub(crate) async fn execute(args: Cli) -> Result<(), StatsCollectorError> {
@@ -20,6 +20,7 @@ impl From<Run> for OverrideConfig {
nym_apis: None,
nyxd_urls: run_config.common_args.nyxd_urls,
enabled_credentials_mode: run_config.common_args.enabled_credentials_mode,
report_database_path: None,
}
}
}
@@ -101,6 +101,14 @@ impl Config {
self.storage_paths = StatsCollectorPaths::new_base(data_directory);
self
}
#[allow(unused)]
pub fn with_report_database_path<P: Into<std::path::PathBuf>>(
mut self,
database_path: P,
) -> Self {
self.storage_paths.client_reports_database = database_path.into();
self
}
pub fn read_from_toml_file<P: AsRef<Path>>(path: P) -> io::Result<Self> {
nym_config::read_config_from_toml_file(path)