Skip to content

Commit

Permalink
metrics: remove Histogram from MetricsError
Browse files Browse the repository at this point in the history
Public MetricsError enum contains a reference to `Histogram`.

In fact, the `MetricsError::Poison` is never really constructed
since we always unwrap the PoisonError when trying to acquire
the mutex.

This is why we get rid of the `MetricsError::Poison` enum value and
convert the `MetricsError` enum to struct holding an error cause.
  • Loading branch information
muzarski committed Feb 15, 2024
1 parent 29f6744 commit caa559c
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions scylla/src/transport/metrics.rs
Original file line number Diff line number Diff line change
@@ -1,30 +1,23 @@
use histogram::Histogram;
use std::sync::atomic::{AtomicU64, Ordering};
use std::sync::{Arc, Mutex, MutexGuard, PoisonError};
use std::sync::{Arc, Mutex};

const ORDER_TYPE: Ordering = Ordering::Relaxed;

#[derive(Debug)]
pub enum MetricsError<'a> {
Poison(PoisonError<MutexGuard<'a, Histogram>>),
Histogram(&'static str),
pub struct MetricsError {
cause: &'static str,
}

impl<'a> From<PoisonError<MutexGuard<'a, Histogram>>> for MetricsError<'a> {
fn from(err: PoisonError<MutexGuard<'_, Histogram>>) -> MetricsError {
MetricsError::Poison(err)
}
}

impl From<&'static str> for MetricsError<'_> {
impl From<&'static str> for MetricsError {
fn from(err: &'static str) -> MetricsError {
MetricsError::Histogram(err)
MetricsError { cause: err }
}
}

impl std::fmt::Display for MetricsError<'_> {
impl std::fmt::Display for MetricsError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{:?}", self)
write!(f, "metrics error: {}", self.cause)
}
}

Expand Down

0 comments on commit caa559c

Please sign in to comment.