Skip to content

Commit

Permalink
consolidate metrics snapshot types
Browse files Browse the repository at this point in the history
  • Loading branch information
brayniac committed Oct 13, 2023
1 parent 0cabee4 commit 9455b70
Show file tree
Hide file tree
Showing 5 changed files with 246 additions and 260 deletions.
16 changes: 8 additions & 8 deletions src/admin/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,10 @@ mod handlers {
pub async fn prometheus_stats() -> Result<impl warp::Reply, Infallible> {
let mut data = Vec::new();

let metrics_state = METRICS_STATE.read().await;
let metrics_snapshot = METRICS_SNAPSHOT.read().await;

let timestamp = metrics_state
.timestamp
let timestamp = metrics_snapshot
.current
.duration_since(UNIX_EPOCH)
.unwrap()
.as_millis();
Expand Down Expand Up @@ -162,7 +162,7 @@ mod handlers {
data.push(format!("# TYPE {name} gauge\n{name} {value}"));
}
} else if any.downcast_ref::<AtomicHistogram>().is_some() {
let percentiles = metrics_state.percentiles(metric.name());
let percentiles = metrics_snapshot.percentiles(metric.name());

for (_label, percentile, value) in percentiles {
if let Some(description) = metric.description() {
Expand Down Expand Up @@ -198,7 +198,7 @@ mod handlers {
pub async fn json_stats() -> Result<impl warp::Reply, Infallible> {
let mut data = Vec::new();

let metrics_state = METRICS_STATE.read().await;
let metrics_snapshot = METRICS_SNAPSHOT.read().await;

for metric in &metriken::metrics() {
if metric.name().starts_with("log_") {
Expand All @@ -223,7 +223,7 @@ mod handlers {

data.push(format!("\"{name}\": {value}"));
} else if any.downcast_ref::<AtomicHistogram>().is_some() {
let percentiles = metrics_state.percentiles(metric.name());
let percentiles = metrics_snapshot.percentiles(metric.name());

for (label, _percentile, value) in percentiles {
data.push(format!("\"{name}/{label}\": {value}",));
Expand All @@ -250,7 +250,7 @@ mod handlers {
pub async fn human_stats() -> Result<impl warp::Reply, Infallible> {
let mut data = Vec::new();

let metrics_state = METRICS_STATE.read().await;
let metrics_snapshot = METRICS_SNAPSHOT.read().await;

for metric in &metriken::metrics() {
if metric.name().starts_with("log_") {
Expand All @@ -275,7 +275,7 @@ mod handlers {

data.push(format!("\"{name}\": {value}"));
} else if any.downcast_ref::<AtomicHistogram>().is_some() {
let percentiles = metrics_state.percentiles(metric.name());
let percentiles = metrics_snapshot.percentiles(metric.name());

for (label, _percentile, value) in percentiles {
data.push(format!("\"{name}/{label}\": {value}",));
Expand Down
4 changes: 2 additions & 2 deletions src/clients/momento/commands/get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ pub async fn get(
.await
{
Ok(Ok(r)) => match r {
Get::Hit { .. } => {
::momento::response::Get::Hit { .. } => {
GET_OK.increment();
RESPONSE_HIT.increment();
GET_KEY_HIT.increment();
Ok(())
}
Get::Miss => {
::momento::response::Get::Miss => {
GET_OK.increment();
RESPONSE_MISS.increment();
GET_KEY_MISS.increment();
Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type UnixInstant = clocksource::UnixInstant<clocksource::Nanoseconds<u64>>;

static RUNNING: AtomicBool = AtomicBool::new(true);

static METRICS_STATE: Lazy<Arc<RwLock<HistogramMetricsSnapshot>>> =
static METRICS_SNAPSHOT: Lazy<Arc<RwLock<MetricsSnapshot>>> =
Lazy::new(|| Arc::new(RwLock::new(Default::default())));

fn main() {
Expand Down Expand Up @@ -124,7 +124,7 @@ fn main() {
while RUNNING.load(Ordering::Relaxed) {
// acquire a lock and update the snapshots
{
let mut snapshots = METRICS_STATE.write().await;
let mut snapshots = METRICS_SNAPSHOT.write().await;
snapshots.update();
}

Expand Down
Loading

0 comments on commit 9455b70

Please sign in to comment.