Make `metrics!` visible within `telemetry` (#50)
The `telemetry::metrics` module has a mix of core metrics types and application-specific code. I'd like to change this module to only contain core types. All app-specific module will be moved into `telemetry`. In order to make these changes, the `metrics!` macro (and related types) must be visible to to `telemetry`. This change moves the macro definition into the parent mod.rs, and makes the `Metric`, `FmtMetric`, and `Scopes` types public. In subsequent PRs, app-specific logic will be moved from `telemetry::metrics` to `telemetry`, and the `telemetry::metrics` module's public API will be minimized.
This commit is contained in:
parent
0394df0cca
commit
009b5bc32e
|
@ -5,7 +5,6 @@ use super::{
|
||||||
latency,
|
latency,
|
||||||
Counter,
|
Counter,
|
||||||
Histogram,
|
Histogram,
|
||||||
Metric,
|
|
||||||
RequestLabels,
|
RequestLabels,
|
||||||
ResponseLabels,
|
ResponseLabels,
|
||||||
Scopes,
|
Scopes,
|
||||||
|
|
|
@ -37,19 +37,6 @@ use indexmap::IndexMap;
|
||||||
|
|
||||||
use ctx;
|
use ctx;
|
||||||
|
|
||||||
macro_rules! metrics {
|
|
||||||
{ $( $name:ident : $kind:ty { $help:expr } ),+ } => {
|
|
||||||
$(
|
|
||||||
#[allow(non_upper_case_globals)]
|
|
||||||
const $name: Metric<'static, $kind> = Metric {
|
|
||||||
name: stringify!($name),
|
|
||||||
help: $help,
|
|
||||||
_p: ::std::marker::PhantomData,
|
|
||||||
};
|
|
||||||
)+
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mod counter;
|
mod counter;
|
||||||
mod gauge;
|
mod gauge;
|
||||||
mod histogram;
|
mod histogram;
|
||||||
|
@ -80,7 +67,7 @@ pub use self::serve::Serve;
|
||||||
/// This trait is implemented by `Counter`, `Gauge`, and `Histogram` to account for the
|
/// This trait is implemented by `Counter`, `Gauge`, and `Histogram` to account for the
|
||||||
/// differences in formatting each type of metric. Specifically, `Histogram` formats a
|
/// differences in formatting each type of metric. Specifically, `Histogram` formats a
|
||||||
/// counter for each bucket, as well as a count and total sum.
|
/// counter for each bucket, as well as a count and total sum.
|
||||||
trait FmtMetric {
|
pub trait FmtMetric {
|
||||||
/// The metric's `TYPE` in help messages.
|
/// The metric's `TYPE` in help messages.
|
||||||
const KIND: &'static str;
|
const KIND: &'static str;
|
||||||
|
|
||||||
|
@ -97,10 +84,10 @@ trait FmtMetric {
|
||||||
/// Describes a metric statically.
|
/// Describes a metric statically.
|
||||||
///
|
///
|
||||||
/// Formats help messages and metric values for prometheus output.
|
/// Formats help messages and metric values for prometheus output.
|
||||||
struct Metric<'a, M: FmtMetric> {
|
pub struct Metric<'a, M: FmtMetric> {
|
||||||
name: &'a str,
|
pub name: &'a str,
|
||||||
help: &'a str,
|
pub help: &'a str,
|
||||||
_p: PhantomData<M>,
|
pub _p: PhantomData<M>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The root scope for all runtime metrics.
|
/// The root scope for all runtime metrics.
|
||||||
|
@ -119,7 +106,7 @@ struct Root {
|
||||||
///
|
///
|
||||||
/// An `S` type typically holds one or more metrics.
|
/// An `S` type typically holds one or more metrics.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct Scopes<L: Display + Hash + Eq, S> {
|
pub struct Scopes<L: Display + Hash + Eq, S> {
|
||||||
scopes: IndexMap<L, S>,
|
scopes: IndexMap<L, S>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ use std::fmt;
|
||||||
use std::time::UNIX_EPOCH;
|
use std::time::UNIX_EPOCH;
|
||||||
|
|
||||||
use ctx;
|
use ctx;
|
||||||
use super::{Gauge, Metric};
|
use super::Gauge;
|
||||||
|
|
||||||
use self::system::System;
|
use self::system::System;
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ use std::{
|
||||||
time::{SystemTime, UNIX_EPOCH},
|
time::{SystemTime, UNIX_EPOCH},
|
||||||
};
|
};
|
||||||
|
|
||||||
use telemetry::metrics::{labels::Errno, Counter, Gauge, Metric, Scopes};
|
use telemetry::metrics::{labels::Errno, Counter, Gauge, Scopes};
|
||||||
use transport::tls;
|
use transport::tls;
|
||||||
|
|
||||||
metrics! {
|
metrics! {
|
||||||
|
|
|
@ -6,7 +6,6 @@ use super::{
|
||||||
Counter,
|
Counter,
|
||||||
Gauge,
|
Gauge,
|
||||||
Histogram,
|
Histogram,
|
||||||
Metric,
|
|
||||||
TransportLabels,
|
TransportLabels,
|
||||||
TransportCloseLabels,
|
TransportCloseLabels,
|
||||||
Scopes,
|
Scopes,
|
||||||
|
|
|
@ -3,7 +3,22 @@ use std::time::Duration;
|
||||||
|
|
||||||
use ctx;
|
use ctx;
|
||||||
|
|
||||||
|
macro_rules! metrics {
|
||||||
|
{ $( $name:ident : $kind:ty { $help:expr } ),+ } => {
|
||||||
|
$(
|
||||||
|
#[allow(non_upper_case_globals)]
|
||||||
|
const $name: ::telemetry::metrics::Metric<'static, $kind> =
|
||||||
|
::telemetry::metrics::Metric {
|
||||||
|
name: stringify!($name),
|
||||||
|
help: $help,
|
||||||
|
_p: ::std::marker::PhantomData,
|
||||||
|
};
|
||||||
|
)+
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub mod event;
|
pub mod event;
|
||||||
|
// TODO this shouldn't need to be public.
|
||||||
pub mod metrics;
|
pub mod metrics;
|
||||||
pub mod sensor;
|
pub mod sensor;
|
||||||
pub mod tap;
|
pub mod tap;
|
||||||
|
|
Loading…
Reference in New Issue