Skip to content

Commit d1ab01b

Browse files
committed
cleanup progress reporting and add additional information
1 parent cc6bd56 commit d1ab01b

File tree

20 files changed

+125
-149
lines changed

20 files changed

+125
-149
lines changed

rust/stackable-cockpit/src/engine/docker/mod.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
use std::process::Stdio;
22

3-
use indicatif::ProgressStyle;
43
use snafu::{ResultExt, Snafu};
54
use tokio::process::Command;
6-
use tracing::{Span, debug, instrument};
7-
use tracing_indicatif::span_ext::IndicatifSpanExt;
5+
use tracing::{debug, instrument};
86

97
type Result<T, E = Error> = std::result::Result<T, E>;
108

@@ -24,7 +22,6 @@ pub enum Error {
2422
#[instrument(skip_all)]
2523
pub async fn check_if_docker_is_running() -> Result<()> {
2624
debug!("Checking if Docker is running");
27-
Span::current().pb_set_style(&ProgressStyle::with_template("").unwrap());
2825

2926
if Command::new("docker")
3027
.arg("info")

rust/stackable-cockpit/src/engine/kind/mod.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
use std::process::Stdio;
22

3-
use indicatif::ProgressStyle;
43
use snafu::{OptionExt, ResultExt, Snafu, ensure};
54
use tokio::{io::AsyncWriteExt, process::Command};
6-
use tracing::{Span, debug, info, instrument};
7-
use tracing_indicatif::span_ext::IndicatifSpanExt;
5+
use tracing::{debug, info, instrument};
86

97
use crate::{
108
engine::{
@@ -69,7 +67,6 @@ impl Cluster {
6967
#[instrument(skip_all)]
7068
pub async fn create(&self) -> Result<()> {
7169
info!("Creating local cluster using kind");
72-
Span::current().pb_set_style(&ProgressStyle::with_template("").unwrap());
7370

7471
// Check if required binaries are present
7572
if let Some(binary) = binaries_present_with_name(&["docker", "kind"]) {
@@ -115,7 +112,6 @@ impl Cluster {
115112
#[instrument(skip_all)]
116113
pub async fn create_if_not_exists(&self) -> Result<()> {
117114
info!("Creating cluster if it doesn't exist using kind");
118-
Span::current().pb_set_style(&ProgressStyle::with_template("").unwrap());
119115

120116
if Self::check_if_cluster_exists(&self.name).await? {
121117
return Ok(());
@@ -138,7 +134,6 @@ impl Cluster {
138134
#[instrument(skip_all)]
139135
async fn check_if_cluster_exists(cluster_name: &str) -> Result<bool> {
140136
debug!("Checking if kind cluster exists");
141-
Span::current().pb_set_style(&ProgressStyle::with_template("").unwrap());
142137

143138
let output = Command::new("kind")
144139
.args(["get", "clusters"])

rust/stackable-cockpit/src/engine/minikube/mod.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
use indicatif::ProgressStyle;
21
use snafu::{ResultExt, Snafu};
32
use tokio::process::Command;
4-
use tracing::{Span, debug, info, instrument};
5-
use tracing_indicatif::span_ext::IndicatifSpanExt;
3+
use tracing::{debug, info, instrument};
64

75
use crate::{
86
engine::docker::{self, check_if_docker_is_running},
@@ -46,7 +44,6 @@ impl Cluster {
4644
#[instrument(skip_all)]
4745
pub async fn create(&self) -> Result<(), Error> {
4846
info!("Creating local cluster using Minikube");
49-
Span::current().pb_set_style(&ProgressStyle::with_template("").unwrap());
5047

5148
// Check if required binaries are present
5249
if let Some(binary) = binaries_present_with_name(&["docker", "minikube"]) {
@@ -76,7 +73,6 @@ impl Cluster {
7673
#[instrument(skip_all)]
7774
pub async fn create_if_not_exists(&self) -> Result<(), Error> {
7875
info!("Creating cluster if it doesn't exist using Minikube");
79-
Span::current().pb_set_style(&ProgressStyle::with_template("").unwrap());
8076

8177
if Self::check_if_cluster_exists(&self.name).await? {
8278
return Ok(());
@@ -99,7 +95,6 @@ impl Cluster {
9995
#[instrument(skip_all)]
10096
async fn check_if_cluster_exists(cluster_name: &str) -> Result<bool, Error> {
10197
debug!("Checking if Minikube cluster exists");
102-
Span::current().pb_set_style(&ProgressStyle::with_template("").unwrap());
10398

10499
let output = Command::new("minikube")
105100
.arg("status")

rust/stackable-cockpit/src/helm.rs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
use std::fmt::Display;
22

3-
use indicatif::ProgressStyle;
43
use serde::{Deserialize, Serialize};
54
use snafu::{ResultExt, Snafu};
65
use tokio::task::block_in_place;
7-
use tracing::{Span, debug, error, info, instrument};
8-
use tracing_indicatif::span_ext::IndicatifSpanExt;
6+
use tracing::{debug, error, info, instrument};
97
use url::Url;
108

119
use crate::{
@@ -197,8 +195,6 @@ pub fn install_release_from_repo_or_registry(
197195
namespace: &str,
198196
suppress_output: bool,
199197
) -> Result<InstallReleaseStatus, Error> {
200-
Span::current().pb_set_style(&ProgressStyle::with_template("").unwrap());
201-
202198
// Ideally, each Helm invocation would spawn_blocking instead in/around helm_sys,
203199
// but that requires a larger refactoring
204200
block_in_place(|| {
@@ -274,8 +270,6 @@ fn install_release(
274270
namespace: &str,
275271
suppress_output: bool,
276272
) -> Result<(), Error> {
277-
Span::current().pb_set_style(&ProgressStyle::with_template("").unwrap());
278-
279273
let result = helm_sys::install_helm_release(
280274
release_name,
281275
chart_name,
@@ -310,7 +304,6 @@ pub fn uninstall_release(
310304
suppress_output: bool,
311305
) -> Result<UninstallReleaseStatus, Error> {
312306
debug!("Uninstall Helm release");
313-
Span::current().pb_set_style(&ProgressStyle::with_template("").unwrap());
314307

315308
if check_release_exists(release_name, namespace)? {
316309
let result = helm_sys::uninstall_helm_release(release_name, namespace, suppress_output);
@@ -343,7 +336,6 @@ pub fn uninstall_release(
343336
#[instrument]
344337
pub fn check_release_exists(release_name: &str, namespace: &str) -> Result<bool, Error> {
345338
debug!("Check if Helm release exists");
346-
Span::current().pb_set_style(&ProgressStyle::with_template("").unwrap());
347339

348340
// TODO (Techassi): Handle error
349341
Ok(helm_sys::check_helm_release_exists(release_name, namespace))
@@ -353,7 +345,6 @@ pub fn check_release_exists(release_name: &str, namespace: &str) -> Result<bool,
353345
#[instrument]
354346
pub fn list_releases(namespace: &str) -> Result<Vec<Release>, Error> {
355347
debug!("List Helm releases");
356-
Span::current().pb_set_style(&ProgressStyle::with_template("").unwrap());
357348

358349
let result = helm_sys::list_helm_releases(namespace);
359350

@@ -373,7 +364,6 @@ pub fn list_releases(namespace: &str) -> Result<Vec<Release>, Error> {
373364
#[instrument]
374365
pub fn get_release(release_name: &str, namespace: &str) -> Result<Option<Release>, Error> {
375366
debug!("Get Helm release");
376-
Span::current().pb_set_style(&ProgressStyle::with_template("").unwrap());
377367

378368
Ok(list_releases(namespace)?
379369
.into_iter()
@@ -384,7 +374,6 @@ pub fn get_release(release_name: &str, namespace: &str) -> Result<Option<Release
384374
#[instrument]
385375
pub fn add_repo(repository_name: &str, repository_url: &str) -> Result<(), Error> {
386376
debug!("Add Helm repo");
387-
Span::current().pb_set_style(&ProgressStyle::with_template("").unwrap());
388377

389378
let result = helm_sys::add_helm_repository(repository_name, repository_url);
390379

@@ -407,7 +396,6 @@ where
407396
T: AsRef<str> + std::fmt::Display + std::fmt::Debug,
408397
{
409398
debug!("Get Helm repo index file");
410-
Span::current().pb_set_style(&ProgressStyle::with_template("").unwrap());
411399

412400
let url = Url::parse(repo_url.as_ref()).context(UrlParseSnafu)?;
413401
let url = url.join(HELM_REPO_INDEX_FILE).context(UrlParseSnafu)?;

rust/stackable-cockpit/src/oci.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
use std::collections::HashMap;
22

3-
use indicatif::ProgressStyle;
43
use serde::Deserialize;
54
use snafu::{OptionExt, ResultExt, Snafu};
6-
use tracing::{Span, debug, instrument};
7-
use tracing_indicatif::span_ext::IndicatifSpanExt;
5+
use tracing::{debug, instrument};
86
use url::Url;
97
use urlencoding::encode;
108

@@ -122,8 +120,6 @@ impl OciUrlExt for Url {
122120
// TODO (@NickLarsenNZ): Look into why a HashMap is used here when the key is inside each entry in the value
123121
#[instrument]
124122
pub async fn get_oci_index<'a>() -> Result<HashMap<&'a str, ChartSourceMetadata>, Error> {
125-
Span::current().pb_set_style(&ProgressStyle::with_template("").unwrap());
126-
127123
let mut source_index_files: HashMap<&str, ChartSourceMetadata> = HashMap::new();
128124

129125
// initialize map

rust/stackable-cockpit/src/platform/demo/spec.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use indicatif::ProgressStyle;
22
use serde::{Deserialize, Serialize};
33
use snafu::{OptionExt, ResultExt, Snafu};
44
use tracing::{Span, debug, info, instrument, warn};
5-
use tracing_indicatif::span_ext::IndicatifSpanExt;
5+
use tracing_indicatif::span_ext::IndicatifSpanExt as _;
66
#[cfg(feature = "openapi")]
77
use utoipa::ToSchema;
88

@@ -100,7 +100,6 @@ impl DemoSpec {
100100
#[instrument(skip_all)]
101101
pub async fn check_prerequisites(&self, client: &Client, namespace: &str) -> Result<(), Error> {
102102
debug!("Checking prerequisites before installing demo");
103-
Span::current().pb_set_style(&ProgressStyle::with_template("").unwrap());
104103

105104
// Returns an error if the demo doesn't support to be installed in the
106105
// requested namespace
@@ -145,8 +144,6 @@ impl DemoSpec {
145144
client: &Client,
146145
transfer_client: &xfer::Client,
147146
) -> Result<(), Error> {
148-
Span::current().pb_set_style(&ProgressStyle::with_template("").unwrap());
149-
150147
// Get the stack spec based on the name defined in the demo spec
151148
let stack = stack_list.get(&self.stack).context(NoSuchStackSnafu {
152149
name: self.stack.clone(),
@@ -194,7 +191,7 @@ impl DemoSpec {
194191
transfer_client: &xfer::Client,
195192
) -> Result<(), Error> {
196193
info!("Installing demo manifests");
197-
Span::current().pb_set_style(&ProgressStyle::with_template("").unwrap());
194+
Span::current().pb_set_style(&ProgressStyle::with_template("{spinner} Installing manifests").unwrap());
198195

199196
let params = install_params
200197
.parameters

rust/stackable-cockpit/src/platform/manifests.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use indicatif::ProgressStyle;
44
use snafu::{ResultExt, Snafu};
55
use stackable_operator::kvp::Labels;
66
use tracing::{Span, debug, info, instrument};
7-
use tracing_indicatif::span_ext::IndicatifSpanExt;
7+
use tracing_indicatif::span_ext::IndicatifSpanExt as _;
88

99
use crate::{
1010
common::manifest::ManifestSpec,
@@ -75,7 +75,11 @@ pub trait InstallManifestsExt {
7575
transfer_client: &xfer::Client,
7676
) -> Result<(), Error> {
7777
debug!("Installing manifests");
78-
Span::current().pb_set_style(&ProgressStyle::with_template("").unwrap());
78+
79+
Span::current().pb_set_style(
80+
&ProgressStyle::with_template("Progress: {wide_bar} {pos}/{len}").unwrap(),
81+
);
82+
Span::current().pb_set_length(manifests.len() as u64);
7983

8084
let mut parameters = parameters.clone();
8185
// We add the NAMESPACE parameter, so that stacks/demos can use that to render e.g. the
@@ -148,6 +152,8 @@ pub trait InstallManifestsExt {
148152
.context(DeployManifestSnafu)?
149153
}
150154
}
155+
156+
Span::current().pb_inc(1);
151157
}
152158

153159
Ok(())

rust/stackable-cockpit/src/platform/operator/mod.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use indicatif::ProgressStyle;
44
use semver::Version;
55
use serde::Serialize;
66
use snafu::{ResultExt, Snafu, ensure};
7-
use tracing::{Span, instrument};
8-
use tracing_indicatif::span_ext::IndicatifSpanExt;
7+
use tracing::{info, instrument, Span};
8+
use tracing_indicatif::{indicatif_println, span_ext::IndicatifSpanExt};
99

1010
use crate::{
1111
constants::{
@@ -193,6 +193,7 @@ impl OperatorSpec {
193193
namespace: &str,
194194
chart_source: &ChartSourceType,
195195
) -> Result<(), helm::Error> {
196+
info!(operator = %self, "Installing operator");
196197
Span::current().pb_set_message(format!("Installing {}-operator", self.name).as_str());
197198
Span::current().pb_set_style(&ProgressStyle::with_template("{spinner} {msg}").unwrap());
198199

@@ -219,9 +220,6 @@ impl OperatorSpec {
219220
true,
220221
)?;
221222

222-
Span::current().pb_set_message(format!("{}-operator installed", self.name).as_str());
223-
Span::current().pb_set_style(&ProgressStyle::with_template("{msg}").unwrap());
224-
225223
Ok(())
226224
}
227225

@@ -231,11 +229,9 @@ impl OperatorSpec {
231229
where
232230
T: AsRef<str> + std::fmt::Display + std::fmt::Debug,
233231
{
234-
Span::current().pb_set_style(&ProgressStyle::with_template("").unwrap());
235-
236232
match helm::uninstall_release(&self.helm_name(), namespace.as_ref(), true) {
237233
Ok(status) => {
238-
println!("{status}");
234+
indicatif_println!("{}", status);
239235
Ok(())
240236
}
241237
Err(err) => Err(err),

rust/stackable-cockpit/src/platform/release/spec.rs

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use indicatif::ProgressStyle;
44
use serde::{Deserialize, Serialize};
55
use snafu::{ResultExt, Snafu};
66
use tokio::task::JoinError;
7-
use tracing::{Instrument, Span, debug, instrument};
8-
use tracing_indicatif::span_ext::IndicatifSpanExt;
7+
use tracing::{info, instrument, Instrument, Span};
8+
use tracing_indicatif::{span_ext::IndicatifSpanExt as _};
99
#[cfg(feature = "openapi")]
1010
use utoipa::ToSchema;
1111

@@ -63,6 +63,11 @@ impl ReleaseSpec {
6363
namespace: &str,
6464
chart_source: &ChartSourceType,
6565
) -> Result<()> {
66+
info!("Installing release");
67+
Span::current().pb_set_style(
68+
&ProgressStyle::with_template("Progress: {wide_bar} {pos}/{len}").unwrap(),
69+
);
70+
6671
include_products.iter().for_each(|product| {
6772
Span::current().record("product.included", product);
6873
});
@@ -72,9 +77,6 @@ impl ReleaseSpec {
7277

7378
let operators = self.filter_products(include_products, exclude_products);
7479

75-
Span::current().pb_set_style(
76-
&ProgressStyle::with_template("Installing Release {wide_bar} {pos}/{len}").unwrap(),
77-
);
7880
Span::current().pb_set_length(operators.len() as u64);
7981

8082
let namespace = namespace.to_string();
@@ -90,12 +92,6 @@ impl ReleaseSpec {
9092
tokio::spawn(
9193
async move {
9294
Span::current().record("product_name", &product_name);
93-
Span::current().pb_set_message(
94-
format!("Installing {}-operator", product_name).as_str(),
95-
);
96-
Span::current().pb_set_style(
97-
&ProgressStyle::with_template("{spinner} {msg}").unwrap(),
98-
);
9995

10096
// Create operator spec
10197
let operator =
@@ -107,12 +103,6 @@ impl ReleaseSpec {
107103
.install(&namespace, &chart_source)
108104
.context(HelmInstallSnafu)?;
109105

110-
Span::current().pb_set_message(
111-
format!("{}-operator installed", product_name).as_str(),
112-
);
113-
Span::current()
114-
.pb_set_style(&ProgressStyle::with_template("{msg}").unwrap());
115-
116106
Ok(())
117107
}
118108
.instrument(task_span),
@@ -129,15 +119,15 @@ impl ReleaseSpec {
129119

130120
#[instrument(skip_all)]
131121
pub fn uninstall(&self, namespace: &str) -> Result<()> {
132-
debug!("Uninstalling release");
122+
info!("Uninstalling release");
133123

134124
Span::current().pb_set_style(
135-
&ProgressStyle::with_template("Uninstalling Release {wide_bar} {pos}/{len}").unwrap(),
125+
&ProgressStyle::with_template("Progress: {wide_bar} {pos}/{len}").unwrap(),
136126
);
137127
Span::current().pb_set_length(self.products.len() as u64);
138128

139129
for (product_name, product_spec) in &self.products {
140-
debug!("Uninstalling {product_name}-operator");
130+
info!("Uninstalling {product_name}-operator");
141131

142132
// Create operator spec
143133
let operator = OperatorSpec::new(product_name, Some(product_spec.version.clone()))

0 commit comments

Comments
 (0)