From ebe5d9266bd062a0e2c681e750d85c28153da97e Mon Sep 17 00:00:00 2001 From: Toby Lawrence Date: Mon, 27 May 2019 15:33:58 -0400 Subject: [PATCH] Update exporters/recorders to use new metrics-util. --- metrics-exporter-http/Cargo.toml | 2 +- metrics-exporter-http/src/lib.rs | 20 ++++++++++++-------- metrics-recorder-prometheus/Cargo.toml | 4 ++-- metrics-recorder-text/Cargo.toml | 4 ++-- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/metrics-exporter-http/Cargo.toml b/metrics-exporter-http/Cargo.toml index 1b1a56c..09c97b7 100644 --- a/metrics-exporter-http/Cargo.toml +++ b/metrics-exporter-http/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "metrics-exporter-http" -version = "0.1.0" +version = "0.1.1" authors = ["Toby Lawrence "] edition = "2018" diff --git a/metrics-exporter-http/src/lib.rs b/metrics-exporter-http/src/lib.rs index 2f3b3fe..40f3f0a 100644 --- a/metrics-exporter-http/src/lib.rs +++ b/metrics-exporter-http/src/lib.rs @@ -11,13 +11,13 @@ #[macro_use] extern crate log; +use hyper::rt::run as hyper_run; +use hyper::rt::Future; +use hyper::service::service_fn; +use hyper::{Body, Response, Server}; use metrics_core::{AsyncSnapshotProvider, Recorder, Snapshot}; use std::error::Error; use std::net::SocketAddr; -use hyper::{Body, Response, Server}; -use hyper::service::service_fn; -use hyper::rt::run as hyper_run; -use hyper::rt::Future; /// Exports metrics over HTTP. pub struct HttpExporter { @@ -54,7 +54,6 @@ where } /// Converts this exporter into a future which can be driven externally. - /// logs output on the given interval. /// /// This starts an HTTP server on the `address` the exporter was originally configured with, /// responding to any request with the output of the configured recorder. @@ -67,7 +66,11 @@ where } } -fn build_hyper_server(controller: C, recorder: R, address: SocketAddr) -> impl Future +fn build_hyper_server( + controller: C, + recorder: R, + address: SocketAddr, +) -> impl Future where C: AsyncSnapshotProvider + Clone + Send + 'static, C::SnapshotFuture: Send + 'static, @@ -81,14 +84,15 @@ where service_fn(move |_| { let recorder3 = recorder2.clone(); - controller2.get_snapshot_async() + controller2 + .get_snapshot_async() .then(move |result| match result { Ok(snapshot) => { let mut r = recorder3.clone(); snapshot.record(&mut r); let output = r.into(); Ok(Response::new(Body::from(output))) - }, + } Err(e) => Err(e), }) }) diff --git a/metrics-recorder-prometheus/Cargo.toml b/metrics-recorder-prometheus/Cargo.toml index 21fd5e5..5881991 100644 --- a/metrics-recorder-prometheus/Cargo.toml +++ b/metrics-recorder-prometheus/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "metrics-recorder-prometheus" -version = "0.2.0" +version = "0.2.1" authors = ["Toby Lawrence "] edition = "2018" @@ -14,5 +14,5 @@ documentation = "https://docs.rs/metrics-recorder-prometheus" [dependencies] metrics-core = { path = "../metrics-core", version = "^0.3" } -metrics-util = { path = "../metrics-util", version = "^0.1" } +metrics-util = { path = "../metrics-util", version = "^0.2" } hdrhistogram = "^6.1" diff --git a/metrics-recorder-text/Cargo.toml b/metrics-recorder-text/Cargo.toml index 9e26d30..7aa60df 100644 --- a/metrics-recorder-text/Cargo.toml +++ b/metrics-recorder-text/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "metrics-recorder-text" -version = "0.2.0" +version = "0.2.1" authors = ["Toby Lawrence "] edition = "2018" @@ -14,5 +14,5 @@ documentation = "https://docs.rs/metrics-recorder-text" [dependencies] metrics-core = { path = "../metrics-core", version = "^0.3" } -metrics-util = { path = "../metrics-util", version = "^0.1" } +metrics-util = { path = "../metrics-util", version = "^0.2" } hdrhistogram = "^6.1"