Remove the labels::Direction type (#72)

Following #67 and #68, the `labels::Direction` type can be replaced with
an `impl FmtLabels for ctx::Proxy`.
This commit is contained in:
Oliver Gould 2018-08-17 14:50:52 -07:00 committed by GitHub
parent e3df08678d
commit 35b47fb3a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 24 deletions

View File

@ -8,6 +8,8 @@ pub mod transport;
/// local instance.
/// - The _outbound_ proxy receives traffic from the local instance and forwards it to a
/// remote service.
///
/// This type is used for the purposes of caching and telemetry.
#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq)]
pub enum Proxy {
Inbound,

View File

@ -12,9 +12,7 @@ use transport::tls;
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
pub struct RequestLabels {
/// Was the request in the inbound or outbound direction?
direction: Direction,
proxy: ctx::Proxy,
// Additional labels identifying the destination service of an outbound
// request, provided by service discovery.
@ -50,9 +48,6 @@ pub enum Classification {
Failure,
}
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
pub struct Direction(ctx::Proxy);
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
struct DstLabels(String);
@ -72,8 +67,6 @@ struct GrpcStatus(u32);
impl RequestLabels {
pub fn new(req: &ctx::http::Request) -> Self {
let direction = Direction::new(req.server.proxy);
let outbound_labels = DstLabels::new(req.labels());
let authority = req.uri
@ -81,7 +74,7 @@ impl RequestLabels {
.cloned();
RequestLabels {
direction,
proxy: req.server.proxy,
outbound_labels,
authority: Authority(authority),
tls_status: TlsStatus(req.tls_status()),
@ -98,7 +91,7 @@ impl FmtLabels for RequestLabels {
fn fmt_labels(&self, f: &mut fmt::Formatter) -> fmt::Result {
let dst = (self.outbound_labels.as_ref(), &self.tls_status);
((&self.authority, &self.direction), dst).fmt_labels(f)
((&self.authority, &self.proxy), dst).fmt_labels(f)
}
}
@ -203,17 +196,10 @@ impl FmtLabels for Classification {
}
}
// ===== impl Direction =====
impl Direction {
pub fn new(ctx: ctx::Proxy) -> Self {
Direction(ctx)
}
}
impl FmtLabels for Direction {
// TODO https://github.com/linkerd/linkerd2/issues/1486
impl FmtLabels for ctx::Proxy {
fn fmt_labels(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self.0 {
match *self {
ctx::Proxy::Inbound => f.pad("direction=\"inbound\""),
ctx::Proxy::Outbound => f.pad("direction=\"outbound\""),
}

View File

@ -4,7 +4,7 @@ use std::time::Duration;
use ctx;
use super::{
labels::{Direction, TlsStatus},
labels::TlsStatus,
latency,
prom::{FmtLabels, FmtMetrics},
Counter,
@ -36,7 +36,7 @@ pub struct Transports {
/// Implements `fmt::Display` to render a comma-separated list of key-value pairs.
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
struct Key {
direction: Direction,
proxy: ctx::Proxy,
peer: Peer,
tls_status: TlsStatus,
}
@ -181,14 +181,14 @@ impl FmtMetrics for Transports {
impl FmtLabels for Key {
fn fmt_labels(&self, f: &mut fmt::Formatter) -> fmt::Result {
((self.direction, self.peer), self.tls_status).fmt_labels(f)
((self.proxy, self.peer), self.tls_status).fmt_labels(f)
}
}
impl Key {
fn new(ctx: &ctx::transport::Ctx) -> Self {
Self {
direction: Direction::new(ctx.proxy()),
proxy: ctx.proxy(),
peer: match *ctx {
ctx::transport::Ctx::Server(_) => Peer::Src,
ctx::transport::Ctx::Client(_) => Peer::Dst,