Skip to content

Commit

Permalink
port stack-metrics to std::future (#513)
Browse files Browse the repository at this point in the history
I had forgotten that `linkerd2-stack-metrics` is actually kind of load
bearing: the `TrackServiceLayer` is necessary for powering cache
eviction as well as being used for debugging. It turns out that we need
this to create stacks that work.

This branch ports `linkerd2-stack-metrics` to std::future. This change
was pretty trivial; I just updated to use the new `tower::Service`
trait. I also pruned a bunch of dependencies that this crate wasn't
actually using from the Cargo.toml.

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
  • Loading branch information
hawkw authored May 13, 2020
1 parent d72fe6f commit 47d207b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 21 deletions.
7 changes: 1 addition & 6 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1527,14 +1527,9 @@ dependencies = [
name = "linkerd2-stack-metrics"
version = "0.1.0"
dependencies = [
"futures 0.1.26",
"indexmap",
"linkerd2-metrics",
"tokio 0.1.22",
"tokio-timer",
"tower 0.1.1",
"tower-util",
"tracing",
"tower 0.3.1",
]

[[package]]
Expand Down
7 changes: 1 addition & 6 deletions linkerd/stack/metrics/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@ edition = "2018"
publish = false

[dependencies]
futures = "0.1"
indexmap = "1.0"
linkerd2-metrics = { path = "../../metrics" }
tokio = "0.1"
tokio-timer = "0.2" # for tokio_timer::clock
tower = "0.1"
tower-util = "0.1"
tracing = "0.1.9"
tower = { version = "0.3", default-features = false }
18 changes: 9 additions & 9 deletions linkerd/stack/metrics/src/service.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::Metrics;
use futures::{Async, Poll};
use std::sync::Arc;
use std::task::{Context, Poll};
use std::time::Instant;

#[derive(Clone, Debug)]
Expand Down Expand Up @@ -31,30 +31,30 @@ where
type Error = S::Error;
type Future = S::Future;

fn poll_ready(&mut self) -> Poll<(), Self::Error> {
match self.inner.poll_ready() {
Ok(Async::NotReady) => {
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
match self.inner.poll_ready(cx) {
Poll::Pending => {
self.metrics.not_ready_total.incr();
if self.blocked_since.is_none() {
self.blocked_since = Some(Instant::now());
}
Ok(Async::NotReady)
Poll::Pending
}
Ok(Async::Ready(())) => {
Poll::Ready(Ok(())) => {
self.metrics.ready_total.incr();
if let Some(t0) = self.blocked_since.take() {
let not_ready = Instant::now() - t0;
self.metrics.poll_millis.add(not_ready.as_millis() as u64);
}
Ok(Async::Ready(()))
Poll::Ready(Ok(()))
}
Err(e) => {
Poll::Ready(Err(e)) => {
self.metrics.error_total.incr();
if let Some(t0) = self.blocked_since.take() {
let not_ready = Instant::now() - t0;
self.metrics.poll_millis.add(not_ready.as_millis() as u64);
}
Err(e)
Poll::Ready(Err(e))
}
}
}
Expand Down

0 comments on commit 47d207b

Please sign in to comment.