Skip to content

Commit

Permalink
Logging improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
cpg314 committed Jun 12, 2024
1 parent 7944073 commit 4a95cd0
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
[package]
name = "ch-grafana-cache"
version = "0.1.2"
version = "0.1.3"
edition = "2021"

[dependencies]
anyhow = "1.0.86"
bat = "0.24.0"
clap = { version = "4.5.4", features = ["derive", "env"] }
colored = "2.1.0"
indicatif = "0.17.8"
itertools = "0.13.0"
lazy_static = "1.4.0"
regex = "1.10.4"
Expand Down
13 changes: 13 additions & 0 deletions src/grafana.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,20 @@ impl Dashboard {
variables_config: VariablesConfig,
client: &ChClient,
) -> anyhow::Result<Vec<VariablesAssignment<'_>>> {
info!("Determining variables combinations");
let progress = indicatif::ProgressBar::with_draw_target(
Some(self.variables().count() as u64),
indicatif::ProgressDrawTarget::hidden(),
);
let mut combinations: Vec<VariablesAssignment> = vec![Default::default()];
for var in self.variables() {
info!(
var.name,
"Processing variable {}/{}, ETA {}",
progress.position(),
progress.length().unwrap(),
indicatif::HumanDuration(progress.eta())
);
let mut combinations2 = Vec::<VariablesAssignment>::default();
for assignment in &combinations {
// WARN: This heavily relies on the caching in the Clickhouse client to not rerun
Expand All @@ -81,6 +93,7 @@ impl Dashboard {
}
}
combinations = combinations2;
progress.inc(1);
}
Ok(combinations)
}
Expand Down
16 changes: 13 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,18 @@ async fn main_impl() -> anyhow::Result<()> {
"{} variables combinations found. Executing queries...",
n_combinations
);

for (i, combination) in combinations.into_iter().enumerate() {
info!(i, n_combinations, "Executing combination");
let progress = indicatif::ProgressBar::with_draw_target(
Some(n_combinations as u64),
indicatif::ProgressDrawTarget::hidden(),
);
for combination in combinations {
info!(
?combination,
"Executing combination {}/{}, ETA {}.",
progress.position(),
progress.length().unwrap(),
indicatif::HumanDuration(progress.eta())
);
let start = std::time::Instant::now();
debug!(?combination);

Expand All @@ -167,6 +176,7 @@ async fn main_impl() -> anyhow::Result<()> {
size += client.query_native(sql).await?;
}
info!(duration=?start.elapsed(), size_mb = size as f64/1e6, "Executed combination");
progress.inc(1);
}
info!(duration=?start.elapsed(), "Done");
}
Expand Down

0 comments on commit 4a95cd0

Please sign in to comment.