Fixing up PR feedback.
This commit is contained in:
parent
caba3089f2
commit
1ebfc9cf49
|
@ -71,7 +71,7 @@ pub trait Snapshot {
|
|||
/// A value that can provide on-demand snapshots.
|
||||
pub trait SnapshotProvider {
|
||||
type Snapshot: Snapshot;
|
||||
type SnapshotError: Display;
|
||||
type SnapshotError;
|
||||
|
||||
/// Gets a snapshot.
|
||||
fn get_snapshot(&self) -> Result<Self::Snapshot, Self::SnapshotError>;
|
||||
|
@ -80,7 +80,7 @@ pub trait SnapshotProvider {
|
|||
/// A value that can provide on-demand snapshots asynchronously.
|
||||
pub trait AsyncSnapshotProvider {
|
||||
type Snapshot: Snapshot;
|
||||
type SnapshotError: Display;
|
||||
type SnapshotError;
|
||||
type SnapshotFuture: Future<Item = Self::Snapshot, Error = Self::SnapshotError>;
|
||||
|
||||
/// Gets a snapshot asynchronously.
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#[macro_use]
|
||||
extern crate log;
|
||||
|
||||
use std::error::Error;
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
use metrics_core::{Recorder, Snapshot, SnapshotProvider, AsyncSnapshotProvider};
|
||||
|
@ -28,7 +29,6 @@ pub struct LogExporter<C, R> {
|
|||
|
||||
impl<C, R> LogExporter<C, R>
|
||||
where
|
||||
C: SnapshotProvider + AsyncSnapshotProvider,
|
||||
R: Recorder + Clone + Into<String>,
|
||||
{
|
||||
/// Creates a new [`LogExporter`] that logs at the configurable level.
|
||||
|
@ -43,7 +43,11 @@ where
|
|||
}
|
||||
|
||||
/// Runs this exporter on the current thread, logging output on the given interval.
|
||||
pub fn run(&mut self, interval: Duration) {
|
||||
pub fn run(&mut self, interval: Duration)
|
||||
where
|
||||
C: SnapshotProvider,
|
||||
C::SnapshotError: Error,
|
||||
{
|
||||
loop {
|
||||
thread::sleep(interval);
|
||||
|
||||
|
@ -52,7 +56,11 @@ where
|
|||
}
|
||||
|
||||
/// Run this exporter, logging output only once.
|
||||
pub fn turn(&self) {
|
||||
pub fn turn(&self)
|
||||
where
|
||||
C: SnapshotProvider,
|
||||
C::SnapshotError: Error,
|
||||
{
|
||||
match self.controller.get_snapshot() {
|
||||
Ok(snapshot) => {
|
||||
let mut recorder = self.recorder.clone();
|
||||
|
@ -65,7 +73,11 @@ where
|
|||
}
|
||||
|
||||
/// Converts this exporter into a future which logs output on the given interval.
|
||||
pub fn into_future(self, interval: Duration) -> impl Future<Item = (), Error = ()> {
|
||||
pub fn into_future(self, interval: Duration) -> impl Future<Item = (), Error = ()>
|
||||
where
|
||||
C: AsyncSnapshotProvider,
|
||||
C::SnapshotError: Error,
|
||||
{
|
||||
let controller = self.controller;
|
||||
let recorder = self.recorder;
|
||||
let level = self.level;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
use super::data::snapshot::Snapshot;
|
||||
use crossbeam_channel::{bounded, Sender};
|
||||
use std::error::Error;
|
||||
use std::fmt;
|
||||
use metrics_core::{SnapshotProvider, AsyncSnapshotProvider};
|
||||
use futures::prelude::*;
|
||||
|
@ -15,6 +16,22 @@ pub enum SnapshotError {
|
|||
ReceiverShutdown,
|
||||
}
|
||||
|
||||
impl Error for SnapshotError {
|
||||
}
|
||||
|
||||
impl fmt::Display for SnapshotError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
SnapshotError::InternalError => {
|
||||
write!(f, "internal error while collecting snapshot")
|
||||
},
|
||||
SnapshotError::ReceiverShutdown => {
|
||||
write!(f, "receiver is shutdown")
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Various control actions performed by a controller.
|
||||
pub(crate) enum ControlFrame {
|
||||
/// Takes a snapshot of the current metric state.
|
||||
|
@ -72,6 +89,7 @@ impl AsyncSnapshotProvider for Controller {
|
|||
}
|
||||
}
|
||||
|
||||
/// A future representing collecting a snapshot.
|
||||
pub enum SnapshotFuture {
|
||||
Waiting(oneshot::Receiver<Snapshot>),
|
||||
Errored(SnapshotError),
|
||||
|
@ -88,12 +106,3 @@ impl Future for SnapshotFuture {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for SnapshotError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
SnapshotError::InternalError => write!(f, "internal error during snapshot generation"),
|
||||
SnapshotError::ReceiverShutdown => write!(f, "the receiver is not currently running"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue