From a83dbbf62bd5f14b9f6b2f309c41ae218212b7b5 Mon Sep 17 00:00:00 2001 From: jerbly Date: Fri, 5 Jan 2024 06:15:47 -0500 Subject: [PATCH] Last written days --- Cargo.lock | 2 +- Cargo.toml | 2 +- README.md | 13 +++++++------ src/main.rs | 20 +++++++++++--------- src/semconv.rs | 1 - 5 files changed, 20 insertions(+), 18 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d3d7c29..ec9acf7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -412,7 +412,7 @@ checksum = "d77f7ec81a6d05a3abb01ab6eb7590f6083d08449fe5a1c8b1e620283546ccb7" [[package]] name = "honey-health" -version = "0.2.0" +version = "0.3.0" dependencies = [ "anyhow", "chrono", diff --git a/Cargo.toml b/Cargo.toml index e85c7c6..a1940a0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "honey-health" -version = "0.2.0" +version = "0.3.0" edition = "2021" authors = ["Jeremy Blythe "] diff --git a/README.md b/README.md index a23dc52..37d918c 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,7 @@ $ git clone https://github.com/jerbly/honey-health.git $ cd honey-health $ cargo build --release $ ./target/release/honey-health --version -0.2.0 +0.3.0 ``` ## Usage @@ -59,11 +59,12 @@ Honey Health Usage: honey-health [OPTIONS] --model ... Options: - -m, --model ... Model paths - -d, --dataset [...] Datasets - -o, --output Output file path [default: hh_report.csv] - -h, --help Print help (see more with '--help') - -V, --version Print version + -m, --model ... Model paths + -d, --dataset [...] Datasets + -o, --output Output file path [default: hh_report.csv] + -l, --last-written-days Max last written days [default: 30] + -h, --help Print help (see more with '--help') + -V, --version Print version ``` You must provide `HONEYCOMB_API_KEY` as an environment variable or in a `.env` file. This api key must have access to read datasets and columns. diff --git a/src/main.rs b/src/main.rs index 3984760..5fdbfbe 100644 --- a/src/main.rs +++ b/src/main.rs @@ -84,6 +84,7 @@ impl ColumnUsageMap { fn new( root_dirs: &[String], include_datasets: Option>, + max_last_written_days: usize, ) -> anyhow::Result { let sc = SemanticConventions::new(root_dirs)?; @@ -103,7 +104,7 @@ impl ColumnUsageMap { .list_all_datasets()? .iter() .filter_map(|d| { - if (now - d.last_written_at).num_days() < 60 { + if (now - d.last_written_at).num_days() < max_last_written_days as i64 { if inc_datasets.is_empty() || inc_datasets.contains(&d.slug) { Some(d.slug.clone()) } else { @@ -124,7 +125,7 @@ impl ColumnUsageMap { let mut dataset_health = DatasetHealth::new(); for column in columns { let duration = now - column.last_written; - if duration.num_days() < 60 { + if duration.num_days() < max_last_written_days as i64 { let health: Suggestion; if let Some(cu) = cm.map.get_mut(&column.key_name) { cu.datasets[dataset_num] = true; @@ -290,6 +291,13 @@ struct Args { /// used when more than one dataset is included. #[arg(short, long, default_value_t = String::from("hh_report.csv"))] output: String, + + /// Max last written days + /// + /// The maximum number of days since a dataset was last written to. This + /// defaults to 30 days. + #[arg(short, long, default_value_t = 30)] + last_written_days: usize, } fn main() -> anyhow::Result<()> { @@ -309,7 +317,7 @@ fn main() -> anyhow::Result<()> { ); } let include_datasets = args.dataset.map(HashSet::from_iter); - let cm = ColumnUsageMap::new(&root_dirs, include_datasets)?; + let cm = ColumnUsageMap::new(&root_dirs, include_datasets, args.last_written_days)?; if cm.datasets.is_empty() { println!("No datasets found"); return Ok(()); @@ -321,9 +329,3 @@ fn main() -> anyhow::Result<()> { cm.print_dataset_report(); Ok(()) } - -// IDEAS -// Store the namespace as a trie for searching -// Provide command line to explore the trie to help find suitable namespaces and attribute names -// Search for attributes with natural language -// Generate a web page with a tree explorer across your semantic conventions diff --git a/src/semconv.rs b/src/semconv.rs index a983f21..e6e029b 100644 --- a/src/semconv.rs +++ b/src/semconv.rs @@ -158,7 +158,6 @@ impl SemanticConventions { } // Break up the namespace a.b.c into a, a.b, a.b.c and store them in the set - // TODO store this as a trie fn insert_prefixes(&mut self, input: &str) { let mut prefix = String::new(); for c in input.chars() {