Skip to content

Commit

Permalink
feat(app): Add hostname field to HTTP route labels
Browse files Browse the repository at this point in the history
  • Loading branch information
cratelyn committed Oct 4, 2024
1 parent ab68979 commit 471301d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
9 changes: 6 additions & 3 deletions linkerd/app/outbound/src/http/logical/policy/route.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ impl<T: Clone, M, F, P> svc::Param<HttpRouteLabels> for MatchedRoute<T, M, F, P>
HttpRouteLabels(
self.params.parent_ref.clone(),
self.params.route_ref.clone(),
// we do not know the hostname at instantiation time for the stack. this is found
// later when we are creating our labeler.
None,
)
}
}
Expand All @@ -183,14 +186,14 @@ impl<T> filters::Apply for Http<T> {

impl<T> metrics::MkStreamLabel for Http<T> {
type StatusLabels = metrics::labels::HttpRouteRsp;
type DurationLabels = metrics::labels::HttpRoute;
type DurationLabels = metrics::labels::HttpRoute; // TODO(kate): do we want hostname here?
type StreamLabel = metrics::LabelHttpRouteRsp;

fn mk_stream_labeler<B>(&self, _: &::http::Request<B>) -> Option<Self::StreamLabel> {
fn mk_stream_labeler<B>(&self, req: &::http::Request<B>) -> Option<Self::StreamLabel> {
let parent = self.params.parent_ref.clone();
let route = self.params.route_ref.clone();
Some(metrics::LabelHttpRsp::from(
metrics::labels::HttpRoute::from((parent, route)),
metrics::labels::HttpRoute::from((parent, route, req.uri().host().map(str::to_owned))),
))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use prometheus_client::encoding::*;
use crate::{BackendRef, ParentRef, RouteRef};

#[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct HttpRoute(pub ParentRef, pub RouteRef);
pub struct HttpRoute(pub ParentRef, pub RouteRef, pub Option<Host>);
type Host = String; // TODO(kate): use `url::Host` rather than bare strings.

#[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct GrpcRoute(pub ParentRef, pub RouteRef);
Expand Down Expand Up @@ -54,17 +55,18 @@ pub enum Error {

// === impl HttpRoute ===

impl From<(ParentRef, RouteRef)> for HttpRoute {
fn from((parent, route): (ParentRef, RouteRef)) -> Self {
Self(parent, route)
impl From<(ParentRef, RouteRef, Option<Host>)> for HttpRoute {
fn from((parent, route, host): (ParentRef, RouteRef, Option<Host>)) -> Self {
Self(parent, route, host)
}
}

impl EncodeLabelSetMut for HttpRoute {
fn encode_label_set(&self, enc: &mut LabelSetEncoder<'_>) -> std::fmt::Result {
let Self(parent, route) = self;
let Self(parent, route, host) = self;
parent.encode_label_set(enc)?;
route.encode_label_set(enc)?;
("hostname", host.as_deref().unwrap_or("unknown")).encode(enc.encode_label())?;
Ok(())
}
}
Expand Down

0 comments on commit 471301d

Please sign in to comment.