diff --git a/tools/restatectl/src/commands/cluster/config.rs b/tools/restatectl/src/commands/cluster/config.rs index 08533914e..9af0962b6 100644 --- a/tools/restatectl/src/commands/cluster/config.rs +++ b/tools/restatectl/src/commands/cluster/config.rs @@ -11,7 +11,7 @@ mod get; mod set; -use std::fmt::{self, Display, Write}; +use std::fmt::Write; use cling::prelude::*; @@ -19,6 +19,8 @@ use restate_types::{ logs::metadata::ProviderConfiguration, protobuf::cluster::ClusterConfiguration, }; +use crate::util::{write_default_provider, write_leaf}; + #[derive(Run, Subcommand, Clone)] pub enum Config { /// Print a brief overview of the cluster status (nodes, logs, partitions) @@ -32,7 +34,7 @@ pub fn cluster_config_string(config: &ClusterConfiguration) -> anyhow::Result anyhow::Result( - w: &mut W, - depth: usize, - provider: &ProviderConfiguration, -) -> Result<(), fmt::Error> { - let title = "Bifrost Provider"; - match provider { - #[cfg(any(test, feature = "memory-loglet"))] - ProviderConfiguration::InMemory => { - write_leaf(w, depth, true, title, "in-memory")?; - } - ProviderConfiguration::Local => { - write_leaf(w, depth, true, title, "local")?; - } - #[cfg(feature = "replicated-loglet")] - ProviderConfiguration::Replicated(config) => { - write_leaf(w, depth, true, title, "replicated")?; - let depth = depth + 1; - write_leaf( - w, - depth, - true, - "Replication property", - config.replication_property.to_string(), - )?; - write_leaf( - w, - depth, - true, - "Nodeset size", - config.target_nodeset_size.to_string(), - )?; - } - } - Ok(()) -} + write_default_provider(&mut w, 0, &provider)?; -fn write_leaf( - w: &mut W, - depth: usize, - last: bool, - title: impl Display, - value: impl Display, -) -> Result<(), fmt::Error> { - let depth = depth + 1; - let chr = if last { '└' } else { '├' }; - writeln!(w, "{chr:>depth$} {title}: {value}") + Ok(w) } diff --git a/tools/restatectl/src/commands/log/list_logs.rs b/tools/restatectl/src/commands/log/list_logs.rs index 547648c2a..53eae4640 100644 --- a/tools/restatectl/src/commands/log/list_logs.rs +++ b/tools/restatectl/src/commands/log/list_logs.rs @@ -15,12 +15,14 @@ use cling::prelude::*; use restate_cli_util::_comfy_table::{Cell, Table}; use restate_cli_util::c_println; use restate_cli_util::ui::console::StyledTable; +use restate_cli_util::ui::output::Console; use restate_types::logs::metadata::Chain; use restate_types::logs::LogId; use restate_types::Versioned; use crate::commands::log::{deserialize_replicated_log_params, render_loglet_params}; use crate::connection::ConnectionInfo; +use crate::util::write_default_provider; #[derive(Run, Parser, Collect, Clone, Debug)] #[clap(visible_alias = "ls")] @@ -32,12 +34,13 @@ pub async fn list_logs(connection: &ConnectionInfo, _opts: &ListLogsOpts) -> any let mut logs_table = Table::new_styled(); - c_println!("Log Configuration ({})", logs.version()); + c_println!("Log chain {}", logs.version()); - c_println!( - "Default Provider Config: {:?}", - logs.configuration().default_provider - ); + write_default_provider( + &mut Console::stdout(), + 0, + &logs.configuration().default_provider, + )?; // sort by log-id for display let logs: BTreeMap = logs.iter().map(|(id, chain)| (*id, chain)).collect(); diff --git a/tools/restatectl/src/util.rs b/tools/restatectl/src/util.rs index 270617fd8..f9120b01b 100644 --- a/tools/restatectl/src/util.rs +++ b/tools/restatectl/src/util.rs @@ -8,13 +8,64 @@ // the Business Source License, use of this software will be governed // by the Apache License, Version 2.0. +use std::fmt::{self, Display}; + use tonic::transport::Channel; use restate_cli_util::CliContext; use restate_core::network::net_util::create_tonic_channel; -use restate_types::net::AdvertisedAddress; +use restate_types::{logs::metadata::ProviderConfiguration, net::AdvertisedAddress}; pub fn grpc_channel(address: AdvertisedAddress) -> Channel { let ctx = CliContext::get(); create_tonic_channel(address, &ctx.network) } + +pub fn write_default_provider( + w: &mut W, + depth: usize, + provider: &ProviderConfiguration, +) -> Result<(), fmt::Error> { + let title = "Logs Provider"; + match provider { + #[cfg(any(test, feature = "memory-loglet"))] + ProviderConfiguration::InMemory => { + write_leaf(w, depth, true, title, "in-memory")?; + } + ProviderConfiguration::Local => { + write_leaf(w, depth, true, title, "local")?; + } + #[cfg(feature = "replicated-loglet")] + ProviderConfiguration::Replicated(config) => { + write_leaf(w, depth, true, title, "replicated")?; + let depth = depth + 1; + write_leaf( + w, + depth, + false, + "Log replication", + config.replication_property.to_string(), + )?; + write_leaf( + w, + depth, + true, + "Nodeset size", + config.target_nodeset_size.to_string(), + )?; + } + } + Ok(()) +} + +pub fn write_leaf( + w: &mut W, + depth: usize, + last: bool, + title: impl Display, + value: impl Display, +) -> Result<(), fmt::Error> { + let depth = depth + 1; + let chr = if last { '└' } else { '├' }; + writeln!(w, "{chr:>depth$} {title}: {value}") +}