Skip to content

Commit

Permalink
ReadySet Status: Add database connection status
Browse files Browse the repository at this point in the history
Checks the connection to the upstream database and returns the status as
part of SHOW READYSET STATUS.

Release-Note-Core: Adds a status field for the connection between the
  ReadySet adapter and the upstream database to SHOW READYSET STATUS.
Change-Id: I989a0f7b49d01d130ab0586da90c0546f4a62b61
Reviewed-on: https://gerrit.readyset.name/c/readyset/+/5713
Tested-by: Buildkite CI
Reviewed-by: Fran Noriega <fran@readyset.io>
Reviewed-by: Alex Martin <Alex.m@readyset.io>
  • Loading branch information
Dan Wilbanks committed Aug 24, 2023
1 parent 9e63293 commit dafad7a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
16 changes: 15 additions & 1 deletion readyset-adapter/src/backend.rs
Expand Up @@ -1897,7 +1897,21 @@ where
self.show_caches(query_id).await
}
SqlQuery::Show(ShowStatement::ReadySetStatus) => {
self.noria.readyset_status(&self.authority).await
// Add upstream connectivity status
let additional_meta = if let Some(upstream) = &mut self.upstream {
let connection_status = upstream
.is_connected()
.await
.then(|| "Connected".to_string())
.unwrap_or_else(|| "Unreachable".to_string());
vec![("Database Connection".to_string(), connection_status)]
} else {
vec![]
};

self.noria
.readyset_status(&self.authority, additional_meta)
.await
}
SqlQuery::Show(ShowStatement::ReadySetMigrationStatus(id)) => {
self.noria.migration_status(*id).await
Expand Down
6 changes: 5 additions & 1 deletion readyset-adapter/src/backend/noria_connector.rs
Expand Up @@ -940,9 +940,12 @@ impl NoriaConnector {
Ok(QueryResult::Empty)
}

/// Returns status provided by the Controller and persisted in the Authority. Also appends
/// additional_meta provided by the caller to the status.
pub(crate) async fn readyset_status(
&mut self,
authority: &Authority,
mut additional_meta: Vec<(String, String)>,
) -> ReadySetResult<QueryResult<'static>> {
let mut status =
match noria_await!(self.inner.get_mut()?, self.inner.get_mut()?.noria.status()) {
Expand Down Expand Up @@ -977,7 +980,8 @@ impl NoriaConnector {
));
}

// Converts from ReadySetStatus -> Vec<(String, String)> -> QueryResult
status.append(&mut additional_meta);

Ok(QueryResult::MetaVariables(
status.into_iter().map(MetaVariable::from).collect(),
))
Expand Down

0 comments on commit dafad7a

Please sign in to comment.