Skip to content

Commit

Permalink
adapter: Add 'start time' to SHOW READYSET STATUS
Browse files Browse the repository at this point in the history
Add the start time of the adapter to the output of
SHOW READYSET STATUS.

Fixes: REA-3321
Release-Note-Core: ReadySet will display the process start time in
  SHOW READYSET SATAUS if `--prometheus-metrics` is enabled.

Change-Id: I5e9810a73551ff7ecc3b0a554de4e493a09fef8e
Reviewed-on: https://gerrit.readyset.name/c/readyset/+/6076
Tested-by: Buildkite CI
Reviewed-by: Tamas Juhasz <tamas@readyset.io>
  • Loading branch information
jasobrown-rs authored and lukoktonos committed Sep 21, 2023
1 parent 8526b46 commit e6afd5f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
7 changes: 6 additions & 1 deletion readyset-adapter/src/backend.rs
Expand Up @@ -1969,7 +1969,7 @@ where
}
SqlQuery::Show(ShowStatement::ReadySetStatus) => {
// Add upstream connectivity status
let additional_meta = if let Some(upstream) = &mut self.upstream {
let mut additional_meta = if let Some(upstream) = &mut self.upstream {
let connection_status = upstream
.is_connected()
.await
Expand All @@ -1980,6 +1980,11 @@ where
vec![]
};

if let Some(handle) = self.metrics_handle.as_ref() {
let mut statuses = handle.readyset_status();
additional_meta.append(&mut statuses);
}

self.noria
.readyset_status(&self.authority, additional_meta)
.await
Expand Down
27 changes: 27 additions & 0 deletions readyset-adapter/src/metrics_handle.rs
Expand Up @@ -5,6 +5,8 @@ use metrics_exporter_prometheus::formatting::{sanitize_label_key, sanitize_label
use metrics_exporter_prometheus::{Distribution, PrometheusHandle};
use metrics_util::Summary;
use quanta::Instant;
// adding an alias to disambiguate vs readyset_client_metrics::recorded
use readyset_client::metrics::recorded as client_recorded;
use readyset_client_metrics::recorded::QUERY_LOG_EXECUTION_TIME;

#[derive(Debug, Default, Clone)]
Expand Down Expand Up @@ -106,4 +108,29 @@ impl MetricsHandle {
p99_us: summary.quantile(0.99).unwrap_or_default(),
})
}

fn sum_counter(&self, name: &str) -> u64 {
let results = self.counters(Some(|x: &str| x.eq(name)));
match results.get(name) {
Some(res) => {
let mut f = 0;
for (_, v) in res.iter() {
f += v;
}
f
}
None => 0,
}
}

/// Gather all the metrics that are relevant to be printed with
/// `SHOW READYSET STATUS`
pub fn readyset_status(&self) -> Vec<(String, String)> {
let mut statuses = Vec::new();

let val = self.sum_counter(client_recorded::NORIA_STARTUP_TIMESTAMP);
statuses.push(("Process start time".to_string(), val.to_string()));

statuses
}
}

0 comments on commit e6afd5f

Please sign in to comment.