tap: Support `tls` labeling (#1244)

The proxy's metrics are instrumented with a `tls` label that describes
the state of TLS for each connection and associated messges.

This same level of detail is useful to get in `tap` output as well.

This change updates Tap in the following ways:
* `TapEvent` protobuf updated:
  * Added `source_meta` field including source labels
  * `proxy_direction` enum indicates which proxy server was used.
* The proxy adds a `tls` label to both source and destination meta indicating the state of each peer's connection
* The CLI uses the `proxy_direction` field to determine which `tls` label should be rendered.
This commit is contained in:
Oliver Gould 2018-07-02 17:19:20 -07:00 committed by GitHub
parent 051a7639c5
commit 866167a955
1 changed files with 49 additions and 30 deletions

View File

@ -45,15 +45,12 @@ impl event::StreamResponseEnd {
eos,
};
let destination_meta = ctx.dst_labels()
.map(|ref d| tap_event::EndpointMeta {
labels: d.as_map().clone(),
});
common::TapEvent {
proxy_direction: ctx.server.direction().into(),
source: Some((&ctx.server.remote).into()),
source_meta: Some(ctx.server.src_meta()),
destination: Some((&ctx.client.remote).into()),
destination_meta,
destination_meta: Some(ctx.client.dst_meta()),
event: Some(tap_event::Event::Http(tap_event::Http {
event: Some(tap_event::http::Event::ResponseEnd(end)),
})),
@ -76,15 +73,12 @@ impl event::StreamResponseFail {
eos: Some(self.error.into()),
};
let destination_meta = ctx.dst_labels()
.map(|ref d| tap_event::EndpointMeta {
labels: d.as_map().clone(),
});
common::TapEvent {
proxy_direction: ctx.server.direction().into(),
source: Some((&ctx.server.remote).into()),
source_meta: Some(ctx.server.src_meta()),
destination: Some((&ctx.client.remote).into()),
destination_meta,
destination_meta: Some(ctx.client.dst_meta()),
event: Some(tap_event::Event::Http(tap_event::Http {
event: Some(tap_event::http::Event::ResponseEnd(end)),
})),
@ -107,15 +101,12 @@ impl event::StreamRequestFail {
eos: Some(self.error.into()),
};
let destination_meta = ctx.dst_labels()
.map(|ref d| tap_event::EndpointMeta {
labels: d.as_map().clone(),
});
common::TapEvent {
proxy_direction: ctx.server.direction().into(),
source: Some((&ctx.server.remote).into()),
source_meta: Some(ctx.server.src_meta()),
destination: Some((&ctx.client.remote).into()),
destination_meta,
destination_meta: Some(ctx.client.dst_meta()),
event: Some(tap_event::Event::Http(tap_event::Http {
event: Some(tap_event::http::Event::ResponseEnd(end)),
})),
@ -146,15 +137,12 @@ impl<'a> TryFrom<&'a Event> for common::TapEvent {
path: ctx.uri.path().into(),
};
let destination_meta = ctx.dst_labels()
.map(|ref d| tap_event::EndpointMeta {
labels: d.as_map().clone(),
});
common::TapEvent {
proxy_direction: ctx.server.direction().into(),
source: Some((&ctx.server.remote).into()),
source_meta: Some(ctx.server.src_meta()),
destination: Some((&ctx.client.remote).into()),
destination_meta,
destination_meta: Some(ctx.client.dst_meta()),
event: Some(tap_event::Event::Http(tap_event::Http {
event: Some(tap_event::http::Event::RequestInit(init)),
})),
@ -172,15 +160,12 @@ impl<'a> TryFrom<&'a Event> for common::TapEvent {
http_status: u32::from(ctx.status.as_u16()),
};
let destination_meta = ctx.dst_labels()
.map(|ref d| tap_event::EndpointMeta {
labels: d.as_map().clone(),
});
common::TapEvent {
proxy_direction: ctx.request.server.direction().into(),
source: Some((&ctx.request.server.remote).into()),
source_meta: Some(ctx.request.server.src_meta()),
destination: Some((&ctx.request.client.remote).into()),
destination_meta,
destination_meta: Some(ctx.request.client.dst_meta()),
event: Some(tap_event::Event::Http(tap_event::Http {
event: Some(tap_event::http::Event::ResponseInit(init)),
})),
@ -205,3 +190,37 @@ impl<'a> TryFrom<&'a Event> for common::TapEvent {
Ok(tap_ev)
}
}
impl ctx::transport::Server {
fn src_meta(&self) -> common::tap_event::EndpointMeta {
let mut meta = common::tap_event::EndpointMeta::default();
meta.labels.insert("tls".to_owned(), format!("{}", self.tls_status));
meta
}
fn direction(&self) -> common::tap_event::ProxyDirection {
if self.proxy.is_outbound() {
common::tap_event::ProxyDirection::Outbound
} else {
common::tap_event::ProxyDirection::Inbound
}
}
}
impl ctx::transport::Client {
fn dst_meta(&self) -> common::tap_event::EndpointMeta {
let mut meta = common::tap_event::EndpointMeta::default();
if let Some(ref d) = self.dst_labels() {
for (k, v) in d.as_map() {
meta.labels.insert(k.clone(), v.clone());
}
}
meta.labels.insert("tls".to_owned(), format!("{}", self.tls_status));
meta
}
}