Move telemetry::metrics into dedicated crate (#84)
The `metrics!` macro is currently local to the telemetry module. Furthermore, the `telemetry::metrics` module no longer has proxy-specific logic. This change moves the `telemetry::metrics` module into a new crate, `linkerd2_metrics`. This will enable unifying `telemetry::http` and `telemetry::transport` into `http` and `transport`, respectively.
This commit is contained in:
parent
d38f686c5e
commit
8a9a9bf26b
14
Cargo.lock
14
Cargo.lock
|
@ -469,12 +469,23 @@ name = "linked-hash-map"
|
|||
version = "0.4.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "linkerd2-metrics"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"deflate 0.7.18 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"futures 0.1.23 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"http 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"hyper 0.12.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"indexmap 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "linkerd2-proxy"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"bytes 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"deflate 0.7.18 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"env_logger 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"flate2 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"futures 0.1.23 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -488,6 +499,7 @@ dependencies = [
|
|||
"inotify 0.5.2-dev (git+https://github.com/inotify-rs/inotify)",
|
||||
"ipnet 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"linkerd2-metrics 0.1.0",
|
||||
"linkerd2-proxy-api 0.1.1 (git+https://github.com/linkerd/linkerd2-proxy-api?tag=v0.1.1)",
|
||||
"linkerd2-proxy-router 0.1.0",
|
||||
"log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
members = [
|
||||
".",
|
||||
"futures-mpsc-lossy",
|
||||
"metrics",
|
||||
"router",
|
||||
]
|
||||
|
||||
|
@ -18,12 +19,12 @@ flaky_tests = []
|
|||
|
||||
[dependencies]
|
||||
futures-mpsc-lossy = { path = "./futures-mpsc-lossy" }
|
||||
linkerd2-metrics = { path = "./metrics" }
|
||||
linkerd2-proxy-router = { path = "./router" }
|
||||
|
||||
linkerd2-proxy-api = { git = "https://github.com/linkerd/linkerd2-proxy-api", tag = "v0.1.1", version = "0.1.1" }
|
||||
|
||||
bytes = "0.4"
|
||||
deflate = {version = "0.7.18", features = ["gzip"] }
|
||||
env_logger = { version = "0.5", default-features = false }
|
||||
futures = "0.1"
|
||||
futures-watch = { git = "https://github.com/carllerche/better-future" }
|
||||
|
@ -77,6 +78,7 @@ procinfo = "0.4.2"
|
|||
[dev-dependencies]
|
||||
net2 = "0.2"
|
||||
quickcheck = { version = "0.6", default-features = false }
|
||||
linkerd2-metrics = { path = "./metrics", features = ["test_util"] }
|
||||
linkerd2-proxy-api = { git = "https://github.com/linkerd/linkerd2-proxy-api", tag = "v0.1.1", version = "0.1.1", features = ["arbitrary"] }
|
||||
flate2 = { version = "1.0.1", default-features = false, features = ["rust_backend"] }
|
||||
# `tokio-io` is needed for TCP tests, because `tokio::io` doesn't re-export
|
||||
|
|
|
@ -19,17 +19,19 @@ WORKDIR /usr/src/linkerd2-proxy
|
|||
#
|
||||
# Mock out all local code and fetch external dependencies to ensure that
|
||||
# external sources are primarily cached on Cargo.lock.
|
||||
RUN for d in . futures-mpsc-lossy router ; \
|
||||
RUN for d in . futures-mpsc-lossy router metrics ; \
|
||||
do mkdir -p "${d}/src" && touch "${d}/src/lib.rs" ; \
|
||||
done
|
||||
COPY Cargo.toml Cargo.lock ./
|
||||
COPY futures-mpsc-lossy/Cargo.toml futures-mpsc-lossy/Cargo.toml
|
||||
COPY router/Cargo.toml router/Cargo.toml
|
||||
COPY metrics/Cargo.toml metrics/Cargo.toml
|
||||
RUN cargo fetch --locked
|
||||
|
||||
# Build libraries, leaving the proxy mocked out.
|
||||
COPY futures-mpsc-lossy futures-mpsc-lossy
|
||||
COPY router router
|
||||
COPY metrics metrics
|
||||
ARG PROXY_UNOPTIMIZED
|
||||
RUN if [ -n "$PROXY_UNOPTIMIZED" ]; \
|
||||
then cargo build --frozen ; \
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
[package]
|
||||
name = "linkerd2-metrics"
|
||||
version = "0.1.0"
|
||||
authors = ["Oliver Gould <ver@buoyant.io>"]
|
||||
publish = false
|
||||
|
||||
[features]
|
||||
default = []
|
||||
test_util = []
|
||||
|
||||
[dependencies]
|
||||
deflate = { version = "0.7.18", features = ["gzip"] }
|
||||
futures = "0.1"
|
||||
http = "0.1"
|
||||
hyper = "0.12.3"
|
||||
indexmap = "1.0"
|
||||
log = "0.4"
|
|
@ -85,11 +85,11 @@ impl<V: Into<u64>> Histogram<V> {
|
|||
self.buckets[idx].incr();
|
||||
self.sum += value;
|
||||
}
|
||||
}
|
||||
|
||||
// ===== Test-only methods to help with assertions about histograms. =====
|
||||
|
||||
#[cfg(any(test, feature = "test_util"))]
|
||||
impl<V: Into<u64>> Histogram<V> {
|
||||
/// Assert the bucket containing `le` has a count of at least `at_least`.
|
||||
#[cfg(test)]
|
||||
pub fn assert_bucket_at_least(&self, le: u64, at_least: u64) {
|
||||
for (&bucket, &count) in self {
|
||||
if bucket >= le {
|
||||
|
@ -104,7 +104,6 @@ impl<V: Into<u64>> Histogram<V> {
|
|||
}
|
||||
|
||||
/// Assert the bucket containing `le` has a count of exactly `exactly`.
|
||||
#[cfg(test)]
|
||||
pub fn assert_bucket_exactly(&self, le: u64, exactly: u64) -> &Self {
|
||||
for (&bucket, &count) in self {
|
||||
if bucket >= le {
|
||||
|
@ -122,7 +121,6 @@ impl<V: Into<u64>> Histogram<V> {
|
|||
|
||||
/// Assert all buckets less than the one containing `value` have
|
||||
/// counts of exactly `exactly`.
|
||||
#[cfg(test)]
|
||||
pub fn assert_lt_exactly(&self, value: u64, exactly: u64) -> &Self {
|
||||
for (i, &bucket) in self.bounds.0.iter().enumerate() {
|
||||
let ceiling = match bucket {
|
||||
|
@ -148,7 +146,6 @@ impl<V: Into<u64>> Histogram<V> {
|
|||
|
||||
/// Assert all buckets greater than the one containing `value` have
|
||||
/// counts of exactly `exactly`.
|
||||
#[cfg(test)]
|
||||
pub fn assert_gt_exactly(&self, value: u64, exactly: u64) -> &Self {
|
||||
// We set this to true after we've iterated past the first bucket
|
||||
// whose upper bound is >= `value`.
|
|
@ -0,0 +1,39 @@
|
|||
//! Utilties for exposing metrics to Prometheus.
|
||||
|
||||
extern crate deflate;
|
||||
extern crate indexmap;
|
||||
extern crate futures;
|
||||
extern crate http;
|
||||
extern crate hyper;
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
|
||||
mod counter;
|
||||
mod gauge;
|
||||
mod histogram;
|
||||
pub mod latency;
|
||||
mod prom;
|
||||
mod scopes;
|
||||
mod serve;
|
||||
|
||||
pub use self::counter::Counter;
|
||||
pub use self::gauge::Gauge;
|
||||
pub use self::histogram::Histogram;
|
||||
pub use self::prom::{FmtMetrics, FmtLabels, FmtMetric, Metric};
|
||||
pub use self::scopes::Scopes;
|
||||
pub use self::serve::Serve;
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! metrics {
|
||||
{ $( $name:ident : $kind:ty { $help:expr } ),+ } => {
|
||||
$(
|
||||
#[allow(non_upper_case_globals)]
|
||||
const $name: ::linkerd2_metrics::Metric<'static, $kind> =
|
||||
::linkerd2_metrics::Metric {
|
||||
name: stringify!($name),
|
||||
help: $help,
|
||||
_p: ::std::marker::PhantomData,
|
||||
};
|
||||
)+
|
||||
}
|
||||
}
|
|
@ -3,9 +3,7 @@
|
|||
#![deny(warnings)]
|
||||
|
||||
extern crate bytes;
|
||||
extern crate linkerd2_proxy_api;
|
||||
extern crate env_logger;
|
||||
extern crate deflate;
|
||||
#[macro_use]
|
||||
extern crate futures;
|
||||
extern crate futures_mpsc_lossy;
|
||||
|
@ -47,12 +45,16 @@ extern crate tower_h2;
|
|||
extern crate tower_h2_balance;
|
||||
extern crate tower_reconnect;
|
||||
extern crate tower_service;
|
||||
extern crate linkerd2_proxy_router;
|
||||
extern crate tower_util;
|
||||
extern crate tower_in_flight_limit;
|
||||
extern crate trust_dns_resolver;
|
||||
extern crate try_lock;
|
||||
|
||||
#[macro_use]
|
||||
extern crate linkerd2_metrics;
|
||||
extern crate linkerd2_proxy_api;
|
||||
extern crate linkerd2_proxy_router;
|
||||
|
||||
use futures::*;
|
||||
|
||||
use std::error::Error;
|
||||
|
|
|
@ -1,16 +0,0 @@
|
|||
//! Utilties for exposing metrics to Prometheus.
|
||||
|
||||
mod counter;
|
||||
mod gauge;
|
||||
mod histogram;
|
||||
pub mod latency;
|
||||
mod prom;
|
||||
mod scopes;
|
||||
mod serve;
|
||||
|
||||
pub use self::counter::Counter;
|
||||
pub use self::gauge::Gauge;
|
||||
pub use self::histogram::Histogram;
|
||||
pub use self::prom::{FmtMetrics, FmtLabels, FmtMetric, Metric};
|
||||
pub use self::scopes::Scopes;
|
||||
pub use self::serve::Serve;
|
|
@ -1,23 +1,10 @@
|
|||
use std::sync::{Arc, Mutex};
|
||||
use std::time::{Duration, SystemTime};
|
||||
|
||||
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,
|
||||
};
|
||||
)+
|
||||
}
|
||||
}
|
||||
use linkerd2_metrics as metrics;
|
||||
|
||||
mod errno;
|
||||
pub mod http;
|
||||
mod metrics;
|
||||
mod process;
|
||||
mod report;
|
||||
pub mod tap;
|
||||
|
|
Loading…
Reference in New Issue