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

Minor restatectl improvements #2668

Merged
merged 1 commit into from
Feb 10, 2025
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
60 changes: 7 additions & 53 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 All @@ -32,7 +34,7 @@ pub fn cluster_config_string(config: &ClusterConfiguration) -> anyhow::Result<St
writeln!(w, "⚙️ Cluster Configuration")?;
write_leaf(
&mut w,
1,
0,
false,
"Number of partitions",
config.num_partitions,
Expand All @@ -43,63 +45,15 @@ pub fn cluster_config_string(config: &ClusterConfiguration) -> anyhow::Result<St
.map(|p| p.replication_property.as_str())
.unwrap_or("*");

write_leaf(&mut w, 1, false, "Partition replication", strategy)?;
write_leaf(&mut w, 0, false, "Partition replication", strategy)?;

let provider: ProviderConfiguration = config
.bifrost_provider
.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(())
}
write_default_provider(&mut w, 0, &provider)?;

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}")
Ok(w)
}
13 changes: 8 additions & 5 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 @@ -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<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> {
Comment on lines +24 to +28
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm okay to merge this of course, it'd also be nice if we use kv-styled tables.

Copy link
Contributor Author

@muhamadazmy muhamadazmy Feb 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The table definitely looks nice. This was done originally to print cluster configuration which is kinda nested and hence I thought tree view would look better to show it (specially with diff and such). We can move to table view in a follow up imho to unify the UI across entire restatectl

for example

⚙️ Cluster Configuration
├ Number of partitions: 24
├ Partition replication: *
└ Logs Provider: replicated
 ├ Log replication: {node: 2}
 └ Nodeset size: 0

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: 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}")
}
Loading