Skip to content

Commit

Permalink
extract error map logic to helper for reasons of cuteness
Browse files Browse the repository at this point in the history
  • Loading branch information
david-crespo committed Dec 3, 2024
1 parent b4468d5 commit 683df3e
Showing 1 changed file with 22 additions and 36 deletions.
58 changes: 22 additions & 36 deletions nexus/src/app/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,29 +140,15 @@ impl super::Nexus {
self.timeseries_client
.oxql_query(query)
.await
.map(|result| {
// TODO-observability: The query method returns information
// about the duration of the OxQL query and the database
// resource usage for each contained SQL query. We should
// publish this as a timeseries itself, so that we can track
// improvements to query processing.
//
// For now, simply return the tables alone.
result.tables
})
.map_err(|e| match e {
oximeter_db::Error::DatabaseUnavailable(_)
| oximeter_db::Error::Connection(_) => {
Error::ServiceUnavailable {
internal_message: e.to_string(),
}
}
oximeter_db::Error::Oxql(_)
| oximeter_db::Error::TimeseriesNotFound(_) => {
Error::invalid_request(e.to_string())
}
_ => Error::InternalError { internal_message: e.to_string() },
})
// TODO-observability: The query method returns information
// about the duration of the OxQL query and the database
// resource usage for each contained SQL query. We should
// publish this as a timeseries itself, so that we can track
// improvements to query processing.
//
// For now, simply return the tables alone.
.map(|result| result.tables)
.map_err(map_timeseries_err)
}

/// Run an OxQL query against the timeseries database, scoped to a specific project.
Expand All @@ -188,18 +174,18 @@ impl super::Nexus {
.oxql_query(filtered_query)
.await
.map(|result| result.tables)
.map_err(|e| match e {
oximeter_db::Error::DatabaseUnavailable(_)
| oximeter_db::Error::Connection(_) => {
Error::ServiceUnavailable {
internal_message: e.to_string(),
}
}
oximeter_db::Error::Oxql(_)
| oximeter_db::Error::TimeseriesNotFound(_) => {
Error::invalid_request(e.to_string())
}
_ => Error::InternalError { internal_message: e.to_string() },
})
.map_err(map_timeseries_err)
}
}

fn map_timeseries_err(e: oximeter_db::Error) -> Error {
match e {
oximeter_db::Error::DatabaseUnavailable(_)
| oximeter_db::Error::Connection(_) => Error::unavail(&e.to_string()),
oximeter_db::Error::Oxql(_)
| oximeter_db::Error::TimeseriesNotFound(_) => {
Error::invalid_request(e.to_string())
}
_ => Error::internal_error(&e.to_string()),
}
}

0 comments on commit 683df3e

Please sign in to comment.