Remove the labels::TlsStatus type (#73)
Following #67 and #68, the `labels::TlsStatus` type can be removed in favor of extending underlying `ctx::transport::TlsStatus` type to implement `FmtLabels`.
This commit is contained in:
parent
35b47fb3a0
commit
58ed628308
|
@ -23,7 +23,7 @@ pub struct RequestLabels {
|
||||||
authority: Authority,
|
authority: Authority,
|
||||||
|
|
||||||
/// Whether or not the request was made over TLS.
|
/// Whether or not the request was made over TLS.
|
||||||
tls_status: TlsStatus,
|
tls_status: ctx::transport::TlsStatus,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
|
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
|
||||||
|
@ -51,9 +51,6 @@ pub enum Classification {
|
||||||
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
|
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
|
||||||
struct DstLabels(String);
|
struct DstLabels(String);
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
|
|
||||||
pub struct TlsStatus(ctx::transport::TlsStatus);
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
|
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
|
||||||
struct Authority(Option<http::uri::Authority>);
|
struct Authority(Option<http::uri::Authority>);
|
||||||
|
|
||||||
|
@ -77,12 +74,12 @@ impl RequestLabels {
|
||||||
proxy: req.server.proxy,
|
proxy: req.server.proxy,
|
||||||
outbound_labels,
|
outbound_labels,
|
||||||
authority: Authority(authority),
|
authority: Authority(authority),
|
||||||
tls_status: TlsStatus(req.tls_status()),
|
tls_status: req.tls_status(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub fn tls_status(&self) -> TlsStatus {
|
pub fn tls_status(&self) -> ctx::transport::TlsStatus {
|
||||||
self.tls_status
|
self.tls_status
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -134,7 +131,7 @@ impl ResponseLabels {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub fn tls_status(&self) -> TlsStatus {
|
pub fn tls_status(&self) -> ctx::transport::TlsStatus {
|
||||||
self.request_labels.tls_status
|
self.request_labels.tls_status
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -240,43 +237,12 @@ impl FmtLabels for DstLabels {
|
||||||
|
|
||||||
// ===== impl TlsStatus =====
|
// ===== impl TlsStatus =====
|
||||||
|
|
||||||
impl FmtLabels for TlsStatus {
|
impl FmtLabels for ctx::transport::TlsStatus {
|
||||||
fn fmt_labels(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt_labels(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
match self.0 {
|
match self {
|
||||||
Conditional::None(tls::ReasonForNoTls::NoIdentity(why)) =>
|
Conditional::None(tls::ReasonForNoTls::NoIdentity(why)) =>
|
||||||
write!(f, "tls=\"no_identity\",no_tls_reason=\"{}\"", why),
|
write!(f, "tls=\"no_identity\",no_tls_reason=\"{}\"", why),
|
||||||
status => write!(f, "tls=\"{}\"", status),
|
status => write!(f, "tls=\"{}\"", status),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<ctx::transport::TlsStatus> for TlsStatus {
|
|
||||||
fn from(tls: ctx::transport::TlsStatus) -> Self {
|
|
||||||
TlsStatus(tls)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
impl Into<ctx::transport::TlsStatus> for TlsStatus {
|
|
||||||
fn into(self) -> ctx::transport::TlsStatus {
|
|
||||||
self.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl fmt::Display for tls::ReasonForNoIdentity {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
||||||
match self {
|
|
||||||
tls::ReasonForNoIdentity::NotHttp => f.pad("not_http"),
|
|
||||||
tls::ReasonForNoIdentity::NoAuthorityInHttpRequest =>
|
|
||||||
f.pad("no_authority_in_http_request"),
|
|
||||||
tls::ReasonForNoIdentity::NotProvidedByServiceDiscovery =>
|
|
||||||
f.pad("not_provided_by_service_discovery"),
|
|
||||||
tls::ReasonForNoIdentity::Loopback => f.pad("loopback"),
|
|
||||||
tls::ReasonForNoIdentity::NotConfigured => f.pad("not_configured"),
|
|
||||||
tls::ReasonForNoIdentity::NotImplementedForTap =>
|
|
||||||
f.pad("not_implemented_for_tap"),
|
|
||||||
tls::ReasonForNoIdentity::NotImplementedForMetrics =>
|
|
||||||
f.pad("not_implemented_for_metrics"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -135,7 +135,7 @@ mod test {
|
||||||
let ev = Event::StreamResponseEnd(rsp.clone(), end.clone());
|
let ev = Event::StreamResponseEnd(rsp.clone(), end.clone());
|
||||||
let labels = labels::ResponseLabels::new(&rsp, None);
|
let labels = labels::ResponseLabels::new(&rsp, None);
|
||||||
|
|
||||||
assert_eq!(labels.tls_status(), client_tls.into());
|
assert_eq!(labels.tls_status(), client_tls);
|
||||||
|
|
||||||
assert!(r.metrics.lock()
|
assert!(r.metrics.lock()
|
||||||
.expect("lock")
|
.expect("lock")
|
||||||
|
@ -231,8 +231,8 @@ mod test {
|
||||||
let req_labels = RequestLabels::new(&req);
|
let req_labels = RequestLabels::new(&req);
|
||||||
let rsp_labels = ResponseLabels::new(&rsp, None);
|
let rsp_labels = ResponseLabels::new(&rsp, None);
|
||||||
|
|
||||||
assert_eq!(client_tls, req_labels.tls_status().into());
|
assert_eq!(client_tls, req_labels.tls_status());
|
||||||
assert_eq!(client_tls, rsp_labels.tls_status().into());
|
assert_eq!(client_tls, rsp_labels.tls_status());
|
||||||
|
|
||||||
{
|
{
|
||||||
let mut lock = r.metrics.lock().expect("lock");
|
let mut lock = r.metrics.lock().expect("lock");
|
||||||
|
|
|
@ -4,7 +4,6 @@ use std::time::Duration;
|
||||||
|
|
||||||
use ctx;
|
use ctx;
|
||||||
use super::{
|
use super::{
|
||||||
labels::TlsStatus,
|
|
||||||
latency,
|
latency,
|
||||||
prom::{FmtLabels, FmtMetrics},
|
prom::{FmtLabels, FmtMetrics},
|
||||||
Counter,
|
Counter,
|
||||||
|
@ -38,7 +37,7 @@ pub struct Transports {
|
||||||
struct Key {
|
struct Key {
|
||||||
proxy: ctx::Proxy,
|
proxy: ctx::Proxy,
|
||||||
peer: Peer,
|
peer: Peer,
|
||||||
tls_status: TlsStatus,
|
tls_status: ctx::transport::TlsStatus,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Holds all of the metrics for a class of transport.
|
/// Holds all of the metrics for a class of transport.
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
use std::{
|
use std::{
|
||||||
self,
|
self,
|
||||||
|
fmt,
|
||||||
fs::File,
|
fs::File,
|
||||||
io::{self, Cursor, Read},
|
io::{self, Cursor, Read},
|
||||||
path::PathBuf,
|
path::PathBuf,
|
||||||
|
@ -154,6 +155,24 @@ impl From<ReasonForNoIdentity> for ReasonForNoTls {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for ReasonForNoIdentity {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
match self {
|
||||||
|
ReasonForNoIdentity::NotHttp => f.pad("not_http"),
|
||||||
|
ReasonForNoIdentity::NoAuthorityInHttpRequest =>
|
||||||
|
f.pad("no_authority_in_http_request"),
|
||||||
|
ReasonForNoIdentity::NotProvidedByServiceDiscovery =>
|
||||||
|
f.pad("not_provided_by_service_discovery"),
|
||||||
|
ReasonForNoIdentity::Loopback => f.pad("loopback"),
|
||||||
|
ReasonForNoIdentity::NotConfigured => f.pad("not_configured"),
|
||||||
|
ReasonForNoIdentity::NotImplementedForTap =>
|
||||||
|
f.pad("not_implemented_for_tap"),
|
||||||
|
ReasonForNoIdentity::NotImplementedForMetrics =>
|
||||||
|
f.pad("not_implemented_for_metrics"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub type ConditionalConnectionConfig<C> = Conditional<ConnectionConfig<C>, ReasonForNoTls>;
|
pub type ConditionalConnectionConfig<C> = Conditional<ConnectionConfig<C>, ReasonForNoTls>;
|
||||||
pub type ConditionalClientConfig = Conditional<ClientConfig, ReasonForNoTls>;
|
pub type ConditionalClientConfig = Conditional<ClientConfig, ReasonForNoTls>;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue