8000 tracing: Set contexts in new_service/make_service by olix0r · Pull Request #686 · linkerd/linkerd2-proxy · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

tracing: Set contexts in new_service/make_service #686

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
< 8000 /div>
4 changes: 1 addition & 3 deletions linkerd/app/inbound/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,9 +365,7 @@ impl Config {
.box_http_response(),
)
.push_map_target(|(_, accept): (http::Version, tls::accept::Meta)| accept)
.instrument(
|(version, _): &(http::Version, tls::accept::Meta)| info_span!("http", %version),
)
.instrument(|(v, _): &(http::Version, tls::accept::Meta)| info_span!("http", %v))
.check_new_service::<(http::Version, tls::accept::Meta), http::Request<_>>()
.into_inner();

Expand Down
4 changes: 2 additions & 2 deletions linkerd/app/outbound/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,14 +382,14 @@ impl Config {
.push(metrics.stack.layer(stack_labels("logical"))),
),
)
.instrument(|logical: &HttpLogical| info_span!("logical", dst = %logical.dst))
.into_make_service()
.spawn_buffer(buffer_capacity)
.check_make_service::<HttpLogical, http::Request<_>>()
.push(http::header_from_target::layer(CANONICAL_DST_HEADER))
// Strips headers that may be set by this proxy.
.push_on_response(http::strip_header::request::layer(DST_OVERRIDE_HEADER))
.check_make_service_clone::<HttpLogical, http::Request<B>>()
.instrument(|logical: &HttpLogical| info_span!("logical", dst = %logical.dst))
.into_inner()
}

Expand Down Expand Up @@ -487,7 +487,7 @@ impl Config {
.box_http_response(),
)
.push(svc::layer::mk(http::normalize_uri::MakeNormalizeUri::new))
.instrument(|a: &endpoint::HttpAccept| info_span!("http", version=%a.version))
.instrument(|a: &endpoint::HttpAccept| info_span!("http", v = %a.version))
.push_map_target(endpoint::HttpAccept::from)
.check_new_service::<(http::Version, endpoint::TcpLogical), http::Request<_>>()
.into_inner();
Expand Down
2 changes: 1 addition & 1 deletion linkerd/proxy/http/src/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ impl Version {
impl std::fmt::Display for Version {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Http1 => write!(f, "http/1.x"),
Self::Http1 => write!(f, "1.x"),
Self::H2 => write!(f, "h2"),
}
}
Expand Down
28 changes: 17 additions & 11 deletions linkerd/stack/tracing/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,23 +63,23 @@ impl<G: Clone, M> tower::layer::Layer<M> for InstrumentMakeLayer<G> {

impl<T, G, N> NewService<T> for InstrumentMake<G, N>
where
T: std::fmt::Debug,
G: GetSpan<T>,
N: NewService<T>,
{
type Service = Instrument<N::Service>;

fn new_service(&mut self, target: T) -> Self::Service {
trace!(?target, "new_service");
let span = self.get_span.get_span(&target);
let inner = span.in_scope(move || self.make.new_service(target));
let inner = span.in_scope(move || {
trace!("new");
self.make.new_service(target)
});
Instrument { inner, span }
}
}

impl<T, G, M> tower::Service<T> for InstrumentMake<G, M>
where
T: std::fmt::Debug,
G: GetSpan<T>,
M: tower::Service<T>,
{
Expand All @@ -88,16 +88,20 @@ where
type Future = Instrument<M::Future>;

fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
trace!("poll_ready");
let ready = self.make.poll_ready(cx);
trace!(ready = ready.is_ready());
match ready {
Poll::Pending => trace!(ready = false, "make"),
Poll::Ready(ref res) => trace!(ready = true, ok = res.is_ok(), "make"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIOLI: if res is an error, should we include the error in the event?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adding an error constraint means adding more type constraints in more places, so would prefer to avoid that for now. we tend to log errors otherwise.,

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fair, it's not a blocker

}
ready
}

fn call(&mut self, target: T) -> Self::Future {
trace!(?target, "make_service");
let span = self.get_span.get_span(&target);
let inner = span.in_scope(|| self.make.call(target));
let inner = span.in_scope(|| {
trace!("make");
self.make.call(target)
});
Instrument { inner, span }
}
}
Expand Down Expand Up @@ -162,16 +166,18 @@ where
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
let _enter = self.span.enter();

trace!("poll ready");
let ready = self.inner.poll_ready(cx);
trace!(ready = ready.is_ready());
match ready {
Poll::Pending => trace!(ready = false, "service"),
Poll::Ready(ref res) => trace!(ready = true, ok = res.is_ok(), "service"),
}
ready
}

fn call(&mut self, request: Req) -> Self::Future {
let _enter = self.span.enter();

trace!(?request, "call");
trace!(?request, "service");
self.inner.call(request).instrument(self.span.clone())
}
}
Expand Down
0