Skip to content

Commit

Permalink
api key error reporting and null last_written_at fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jerbly committed Jan 12, 2024
1 parent ef9043b commit 912836a
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 13 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
/*.csv
/.vscode
.DS_Store
/*.sh
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "honey-health"
version = "0.3.1"
version = "0.3.2"
edition = "2021"
authors = ["Jeremy Blythe <[email protected]>"]

Expand Down
36 changes: 27 additions & 9 deletions src/honeycomb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const HONEYCOMB_API_KEY: &str = "HONEYCOMB_API_KEY";
#[derive(Debug, Deserialize)]
pub struct Dataset {
pub slug: String,
pub last_written_at: DateTime<Utc>,
pub last_written_at: Option<DateTime<Utc>>,
}

#[derive(Debug, Deserialize, Serialize)]
Expand All @@ -33,19 +33,37 @@ impl HoneyComb {
}
}
pub fn list_all_datasets(&self) -> anyhow::Result<Vec<Dataset>> {
let response = reqwest::blocking::Client::new()
let client = reqwest::blocking::Client::new();
let response = client
.get(format!("{}datasets", URL))
.header("X-Honeycomb-Team", &self.api_key)
.send()?
.json::<Vec<Dataset>>()?;
Ok(response)
.send()?;

let text = response.text()?;

match serde_json::from_str::<Vec<Dataset>>(&text) {
Ok(datasets) => Ok(datasets),
Err(_) => {
println!("Invalid JSON data: {}", text);
Err(anyhow::anyhow!("Invalid JSON data"))
}
}
}
pub fn list_all_columns(&self, dataset_slug: &str) -> anyhow::Result<Vec<Column>> {
let response = reqwest::blocking::Client::new()
let client = reqwest::blocking::Client::new();
let response = client
.get(format!("{}columns/{}", URL, dataset_slug))
.header("X-Honeycomb-Team", &self.api_key)
.send()?
.json::<Vec<Column>>()?;
Ok(response)
.send()?;

let text = response.text()?;

match serde_json::from_str::<Vec<Column>>(&text) {
Ok(columns) => Ok(columns),
Err(_) => {
println!("Invalid JSON data: {}", text);
Err(anyhow::anyhow!("Invalid JSON data"))
}
}
}
}
6 changes: 4 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ impl ColumnUsageMap {
.list_all_datasets()?
.iter()
.filter_map(|d| {
if (now - d.last_written_at).num_days() < max_last_written_days as i64 {
if (now - d.last_written_at.unwrap_or(Utc::now())).num_days()
< max_last_written_days as i64
{
if inc_datasets.is_empty() || inc_datasets.contains(&d.slug) {
Some(d.slug.clone())
} else {
Expand All @@ -117,7 +119,7 @@ impl ColumnUsageMap {
.collect::<Vec<_>>();
datasets.sort();
cm.datasets = datasets;
eprint!("Reading datasets ");
eprint!("Reading {} datasets ", cm.datasets.len());
for (dataset_num, dataset_slug) in cm.datasets.iter().enumerate() {
//println!("Reading dataset: {}", dataset_slug);
eprint!(".");
Expand Down

0 comments on commit 912836a

Please sign in to comment.