Skip to content

Commit

Permalink
move parse_prometheus_error
Browse files Browse the repository at this point in the history
  • Loading branch information
koushiro committed Sep 3, 2024
1 parent 9b5c096 commit 6c49506
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
17 changes: 11 additions & 6 deletions core/src/layers/prometheus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ impl PrometheusLayerBuilder {
),
&labels,
)
.map_err(Error::parse_prometheus_error)?;
.map_err(parse_prometheus_error)?;
let operation_bytes = HistogramVec::new(
histogram_opts!(
observe::METRIC_OPERATION_BYTES.name(),
Expand All @@ -335,7 +335,7 @@ impl PrometheusLayerBuilder {
),
&labels,
)
.map_err(Error::parse_prometheus_error)?;
.map_err(parse_prometheus_error)?;

let labels = OperationLabels::names(true, self.path_label_level);
let operation_errors_total = GenericCounterVec::new(
Expand All @@ -345,17 +345,17 @@ impl PrometheusLayerBuilder {
),
&labels,
)
.map_err(Error::parse_prometheus_error)?;
.map_err(parse_prometheus_error)?;

registry
.register(Box::new(operation_duration_seconds.clone()))
.map_err(Error::parse_prometheus_error)?;
.map_err(parse_prometheus_error)?;
registry
.register(Box::new(operation_bytes.clone()))
.map_err(Error::parse_prometheus_error)?;
.map_err(parse_prometheus_error)?;
registry
.register(Box::new(operation_errors_total.clone()))
.map_err(Error::parse_prometheus_error)?;
.map_err(parse_prometheus_error)?;

Ok(PrometheusLayer {
interceptor: PrometheusInterceptor {
Expand All @@ -368,6 +368,11 @@ impl PrometheusLayerBuilder {
}
}

/// Convert the [`prometheus::Error`] to [`Error`].
fn parse_prometheus_error(err: prometheus::Error) -> Error {
Error::new(ErrorKind::Unexpected, err.to_string()).set_source(err)
}

#[derive(Clone, Debug)]
pub struct PrometheusInterceptor {
operation_duration_seconds: HistogramVec,
Expand Down
6 changes: 0 additions & 6 deletions core/src/types/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,12 +400,6 @@ impl Error {
pub fn is_temporary(&self) -> bool {
self.status == ErrorStatus::Temporary
}

/// Convert the [`prometheus::Error`] to [`Self`].
#[cfg(feature = "layers-prometheus")]
pub fn parse_prometheus_error(err: prometheus::Error) -> Self {
Self::new(ErrorKind::Unexpected, err.to_string()).set_source(err)
}
}

impl From<Error> for io::Error {
Expand Down

0 comments on commit 6c49506

Please sign in to comment.