Skip to content

Commit

Permalink
Minor restatectl improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
muhamadazmy committed Feb 7, 2025
1 parent 673c2dc commit 878e4fc
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 55 deletions.
54 changes: 4 additions & 50 deletions tools/restatectl/src/commands/cluster/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@
mod get;
mod set;

use std::fmt::{self, Display, Write};
use std::fmt::Write;

use cling::prelude::*;

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)
Expand Down Expand Up @@ -50,56 +52,8 @@ pub fn cluster_config_string(config: &ClusterConfiguration) -> anyhow::Result<St
.clone()
.unwrap_or_default()
.try_into()?;

write_default_provider(&mut w, 1, &provider)?;

Ok(w)
}

fn write_default_provider<W: fmt::Write>(
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(())
}

fn write_leaf<W: fmt::Write>(
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}")
}
12 changes: 8 additions & 4 deletions tools/restatectl/src/commands/log/list_logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand All @@ -34,10 +36,12 @@ pub async fn list_logs(connection: &ConnectionInfo, _opts: &ListLogsOpts) -> any

c_println!("Log Configuration ({})", logs.version());

c_println!(
"Default Provider Config: {:?}",
logs.configuration().default_provider
);
c_println!("Default Provider Config: ");
write_default_provider(
&mut Console::stdout(),
1,
&logs.configuration().default_provider,
)?;

// sort by log-id for display
let logs: BTreeMap<LogId, &Chain> = logs.iter().map(|(id, chain)| (*id, chain)).collect();
Expand Down
53 changes: 52 additions & 1 deletion tools/restatectl/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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: fmt::Write>(
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 + 2;
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: fmt::Write>(
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}")
}

0 comments on commit 878e4fc

Please sign in to comment.