Skip to content

Commit

Permalink
feat(app): Outbount proxy uses route request frame metrics (wip)
Browse files Browse the repository at this point in the history
Signed-off-by: katelyn martin <[email protected]>
  • Loading branch information
cratelyn committed Nov 7, 2024
1 parent b408886 commit 82d97be
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 4 deletions.
2 changes: 1 addition & 1 deletion linkerd/app/outbound/src/http/logical/policy/route.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ where
// Set request extensions based on the route configuration
// AND/OR headers
.push(extensions::NewSetExtensions::layer())
.push(metrics::layer(&metrics.requests))
.push(metrics::layer(&metrics.requests, &metrics.body_data))
.check_new::<Self>()
.check_new_service::<Self, http::Request<http::BoxBody>>()
// Configure a classifier to use in the endpoint stack.
Expand Down
49 changes: 46 additions & 3 deletions linkerd/app/outbound/src/http/logical/policy/route/metrics.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
use super::{backend::metrics as backend, retry};
use crate::{ParentRef, RouteRef};
use linkerd_app_core::{
metrics::prom::{self, EncodeLabelSetMut},
svc,
};
use linkerd_http_prom::record_response::{self, StreamLabel};
use linkerd_http_prom::{
body_data::request::{BodyDataMetrics, NewRecordBodyData, RequestBodyFamilies},
record_response::{self, StreamLabel},
};

pub use linkerd_http_prom::record_response::MkStreamLabel;

Expand All @@ -23,6 +27,7 @@ pub struct RouteMetrics<R: StreamLabel, B: StreamLabel> {
pub(super) retry: retry::RouteRetryMetrics,
pub(super) requests: RequestMetrics<R>,
pub(super) backend: backend::RouteBackendMetrics<B>,
pub(super) body_data: RequestBodyFamilies<labels::Route>,
}

pub type HttpRouteMetrics = RouteMetrics<LabelHttpRouteRsp, LabelHttpRouteBackendRsp>;
Expand Down Expand Up @@ -56,13 +61,26 @@ pub type NewRecordDuration<T, M, N> =
#[derive(Clone, Debug)]
pub struct ExtractRecordDurationParams<M>(pub M);

#[derive(Clone, Debug)]
pub struct ExtractRecordBodyDataParams(RequestBodyFamilies<labels::Route>);

pub fn layer<T, N>(
metrics: &RequestMetrics<T::StreamLabel>,
) -> impl svc::Layer<N, Service = NewRecordDuration<T, RequestMetrics<T::StreamLabel>, N>> + Clone
body_data: &RequestBodyFamilies<labels::Route>,
) -> impl svc::Layer<
N,
Service = NewRecordBodyData<
ExtractRecordBodyDataParams,
NewRecordDuration<T, RequestMetrics<T::StreamLabel>, N>,
>,
>
where
T: Clone + MkStreamLabel,
{
NewRecordDuration::layer_via(ExtractRecordDurationParams(metrics.clone()))
let record = NewRecordDuration::layer_via(ExtractRecordDurationParams(metrics.clone()));
let body_data = NewRecordBodyData::layer_via(ExtractRecordBodyDataParams(body_data.clone()));

svc::layers().push(record).push(body_data)
}

// === impl RouteMetrics ===
Expand All @@ -89,6 +107,7 @@ impl<R: StreamLabel, B: StreamLabel> Default for RouteMetrics<R, B> {
requests: Default::default(),
backend: Default::default(),
retry: Default::default(),
body_data: Default::default(),
}
}
}
Expand All @@ -99,6 +118,7 @@ impl<R: StreamLabel, B: StreamLabel> Clone for RouteMetrics<R, B> {
requests: self.requests.clone(),
backend: self.backend.clone(),
retry: self.retry.clone(),
body_data: self.body_data.clone(),
}
}
}
Expand All @@ -113,11 +133,13 @@ impl<R: StreamLabel, B: StreamLabel> RouteMetrics<R, B> {
);

let retry = retry::RouteRetryMetrics::register(reg.sub_registry_with_prefix("retry"));
let body_data = RequestBodyFamilies::register(reg);

Self {
requests,
backend,
retry,
body_data,
}
}

Expand Down Expand Up @@ -147,6 +169,27 @@ where
}
}

// === impl ExtractRecordBodyDataParams ===

impl<T> svc::ExtractParam<BodyDataMetrics, T> for ExtractRecordBodyDataParams
where
T: svc::Param<ParentRef> + svc::Param<RouteRef>,
{
fn extract_param(&self, target: &T) -> BodyDataMetrics {
let Self(families) = self;

Check failure on line 179 in linkerd/app/outbound/src/http/logical/policy/route/metrics.rs

View workflow job for this annotation

GitHub Actions / rust

error: unused variable: `families` --> linkerd/app/outbound/src/http/logical/policy/route/metrics.rs:179:18 | 179 | let Self(families) = self; | ^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_families` | = note: `-D unused-variables` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(unused_variables)]`

#[allow(unreachable_code)] // XXX(kate); remove this once `todo!()` is addressed.
let labels = {

Check failure on line 182 in linkerd/app/outbound/src/http/logical/policy/route/metrics.rs

View workflow job for this annotation

GitHub Actions / rust

error: unused variable: `labels` --> linkerd/app/outbound/src/http/logical/policy/route/metrics.rs:182:13 | 182 | let labels = { | ^^^^^^ help: if this is intentional, prefix it with an underscore: `_labels`
let parent = target.param();

Check failure on line 183 in linkerd/app/outbound/src/http/logical/policy/route/metrics.rs

View workflow job for this annotation

GitHub Actions / rust

error: unused variable: `parent` --> linkerd/app/outbound/src/http/logical/policy/route/metrics.rs:183:17 | 183 | let parent = target.param(); | ^^^^^^ help: if this is intentional, prefix it with an underscore: `_parent`
let route = target.param();

Check failure on line 184 in linkerd/app/outbound/src/http/logical/policy/route/metrics.rs

View workflow job for this annotation

GitHub Actions / rust

error: unused variable: `route` --> linkerd/app/outbound/src/http/logical/policy/route/metrics.rs:184:17 | 184 | let route = target.param(); | ^^^^^ help: if this is intentional, prefix it with an underscore: `_route`
let uri = todo!();

Check failure on line 185 in linkerd/app/outbound/src/http/logical/policy/route/metrics.rs

View workflow job for this annotation

GitHub Actions / rust

error: unused variable: `uri` --> linkerd/app/outbound/src/http/logical/policy/route/metrics.rs:185:17 | 185 | let uri = todo!(); | ^^^ help: if this is intentional, prefix it with an underscore: `_uri`
labels::Route::new(parent, route, uri)
};

families.get(&labels)
}
}

// === impl LabelHttpRsp ===

impl<P> From<P> for LabelHttpRsp<P> {
Expand Down

0 comments on commit 82d97be

Please sign in to comment.