Skip to content

Commit

Permalink
Merge pull request #2193 from RolandSherwin/max_logs
Browse files Browse the repository at this point in the history
feat(manager): limit the max number of safenode log files
  • Loading branch information
jacderida authored Oct 4, 2024
2 parents 5c2302e + 1e4cef6 commit 90dfd39
Show file tree
Hide file tree
Showing 12 changed files with 814 additions and 24 deletions.
4 changes: 4 additions & 0 deletions node-launchpad/src/node_mgmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,8 @@ async fn scale_down_nodes(config: &NodeConfig, count: u16) {
None,
None,
None,
None,
None,
None, // We don't care about the port, as we are scaling down
config.owner.clone(),
config.peers_args.clone(),
Expand Down Expand Up @@ -368,6 +370,8 @@ async fn add_nodes(
None,
None,
None,
None,
None,
port_range,
config.owner.clone(),
config.peers_args.clone(),
Expand Down
20 changes: 10 additions & 10 deletions sn_logging/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ pub struct LogBuilder {
default_logging_targets: Vec<(String, Level)>,
output_dest: LogOutputDest,
format: LogFormat,
max_uncompressed_log_files: Option<usize>,
max_compressed_log_files: Option<usize>,
max_log_files: Option<usize>,
max_archived_log_files: Option<usize>,
/// Setting this would print the sn_logging related updates to stdout.
print_updates_to_stdout: bool,
}
Expand All @@ -140,8 +140,8 @@ impl LogBuilder {
default_logging_targets,
output_dest: LogOutputDest::Stderr,
format: LogFormat::Default,
max_uncompressed_log_files: None,
max_compressed_log_files: None,
max_log_files: None,
max_archived_log_files: None,
print_updates_to_stdout: true,
}
}
Expand All @@ -157,13 +157,13 @@ impl LogBuilder {
}

/// The max number of uncompressed log files to store
pub fn max_uncompressed_log_files(&mut self, files: usize) {
self.max_uncompressed_log_files = Some(files);
pub fn max_log_files(&mut self, files: usize) {
self.max_log_files = Some(files);
}

/// The max number of compressed files to store
pub fn max_compressed_log_files(&mut self, files: usize) {
self.max_compressed_log_files = Some(files);
pub fn max_archived_log_files(&mut self, files: usize) {
self.max_archived_log_files = Some(files);
}

/// Setting this to false would prevent sn_logging from printing things to stdout.
Expand All @@ -182,8 +182,8 @@ impl LogBuilder {
self.default_logging_targets.clone(),
&self.output_dest,
self.format,
self.max_uncompressed_log_files,
self.max_compressed_log_files,
self.max_log_files,
self.max_archived_log_files,
self.print_updates_to_stdout,
)?;

Expand Down
24 changes: 12 additions & 12 deletions sn_node/src/bin/safenode/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,16 +107,16 @@ struct Opt {
///
/// After reaching this limit, the older files are archived to save space.
/// You can also specify the maximum number of archived log files to keep.
#[clap(long = "max_log_files", verbatim_doc_comment)]
max_uncompressed_log_files: Option<usize>,
#[clap(long, verbatim_doc_comment)]
max_log_files: Option<usize>,

/// Specify the maximum number of archived log files to store.
///
/// This argument is ignored if `log_output_dest` is set to "stdout"
///
/// After reaching this limit, the older archived files are deleted.
#[clap(long = "max_archived_log_files", verbatim_doc_comment)]
max_compressed_log_files: Option<usize>,
#[clap(long, verbatim_doc_comment)]
max_archived_log_files: Option<usize>,

/// Specify the node's data directory.
///
Expand Down Expand Up @@ -433,11 +433,11 @@ fn init_logging(opt: &Opt, peer_id: PeerId) -> Result<(String, ReloadHandle, Opt
let mut log_builder = sn_logging::LogBuilder::new(logging_targets);
log_builder.output_dest(output_dest.clone());
log_builder.format(opt.log_format.unwrap_or(LogFormat::Default));
if let Some(files) = opt.max_uncompressed_log_files {
log_builder.max_uncompressed_log_files(files);
if let Some(files) = opt.max_log_files {
log_builder.max_log_files(files);
}
if let Some(files) = opt.max_compressed_log_files {
log_builder.max_compressed_log_files(files);
if let Some(files) = opt.max_archived_log_files {
log_builder.max_archived_log_files(files);
}

log_builder.initialize()?
Expand All @@ -451,11 +451,11 @@ fn init_logging(opt: &Opt, peer_id: PeerId) -> Result<(String, ReloadHandle, Opt
let mut log_builder = sn_logging::LogBuilder::new(logging_targets);
log_builder.output_dest(output_dest.clone());
log_builder.format(opt.log_format.unwrap_or(LogFormat::Default));
if let Some(files) = opt.max_uncompressed_log_files {
log_builder.max_uncompressed_log_files(files);
if let Some(files) = opt.max_log_files {
log_builder.max_log_files(files);
}
if let Some(files) = opt.max_compressed_log_files {
log_builder.max_compressed_log_files(files);
if let Some(files) = opt.max_archived_log_files {
log_builder.max_archived_log_files(files);
}
log_builder.initialize()
})?;
Expand Down
14 changes: 13 additions & 1 deletion sn_node_manager/src/add_services/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ pub struct InstallNodeServiceCtxBuilder {
pub log_dir_path: PathBuf,
pub log_format: Option<LogFormat>,
pub name: String,
pub max_archived_log_files: Option<usize>,
pub max_log_files: Option<usize>,
pub metrics_port: Option<u16>,
pub node_ip: Option<Ipv4Addr>,
pub node_port: Option<u16>,
Expand Down Expand Up @@ -132,6 +134,14 @@ impl InstallNodeServiceCtxBuilder {
args.push(OsString::from("--owner"));
args.push(OsString::from(owner));
}
if let Some(log_files) = self.max_archived_log_files {
args.push(OsString::from("--max-archived-log-files"));
args.push(OsString::from(log_files.to_string()));
}
if let Some(log_files) = self.max_log_files {
args.push(OsString::from("--max-log-files"));
args.push(OsString::from(log_files.to_string()));
}

if !self.bootstrap_peers.is_empty() {
let peers_str = self
Expand Down Expand Up @@ -169,10 +179,12 @@ pub struct AddNodeServiceOptions {
pub home_network: bool,
pub local: bool,
pub log_format: Option<LogFormat>,
pub max_archived_log_files: Option<usize>,
pub max_log_files: Option<usize>,
pub metrics_port: Option<PortRange>,
pub owner: Option<String>,
pub node_ip: Option<Ipv4Addr>,
pub node_port: Option<PortRange>,
pub owner: Option<String>,
pub rpc_address: Option<Ipv4Addr>,
pub rpc_port: Option<PortRange>,
pub safenode_src_path: PathBuf,
Expand Down
4 changes: 4 additions & 0 deletions sn_node_manager/src/add_services/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,8 @@ pub async fn add_node(
local: options.local,
log_dir_path: service_log_dir_path.clone(),
log_format: options.log_format,
max_archived_log_files: options.max_archived_log_files,
max_log_files: options.max_log_files,
metrics_port: metrics_free_port,
name: service_name.clone(),
node_ip: options.node_ip,
Expand Down Expand Up @@ -260,6 +262,8 @@ pub async fn add_node(
local: options.local,
log_dir_path: service_log_dir_path.clone(),
log_format: options.log_format,
max_archived_log_files: options.max_archived_log_files,
max_log_files: options.max_log_files,
metrics_port: metrics_free_port,
node_ip: options.node_ip,
node_port,
Expand Down
Loading

0 comments on commit 90dfd39

Please sign in to comment.