Skip to content

Commit

Permalink
refactor(prom): Remove MkStreamLabel's associated types (#3234)
Browse files Browse the repository at this point in the history
`MkStreamLabel` is, in short, a generic
`(&Request) -> Option<StreamLabel>` function. we use it to inspect a
request, and potentially provide the caller with an object that can
provide relevant labels.

the `StreamLabel` interface includes associated types for the labels
used for metrics related to request/response duration, and counting
status codes.

we do not however, actually need to separately define these associated
types in the `MkStreamLabel` contract. instead, we can return a generic
`StreamLabel` of some sort, and leave the responsibility of the
(admittedly baroque) associated type access to our type aliases
like `RecordResponseDuration` and `RecordRequestDuration`.

this change has a pleasant knock-on effect of leaving a number of the
labels submodule's type aliases unused. this commit accordingly removes
aliases like `HttpRouteRsp`, `GrpcRouteRsp`, `HttpRouteBackendRsp`, and
`GrpcRouteBackendRsp`.

this is a small initial step towards simplifying code that must interact
with the `MkStreamLabel` interface.

Signed-off-by: katelyn martin <[email protected]>
  • Loading branch information
cratelyn committed Oct 1, 2024
1 parent bf4dc94 commit 6bc4fd1
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 43 deletions.
4 changes: 0 additions & 4 deletions linkerd/app/outbound/src/http/logical/policy/route.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,6 @@ impl<T> filters::Apply for Http<T> {
}

impl<T> metrics::MkStreamLabel for Http<T> {
type StatusLabels = metrics::labels::HttpRouteRsp;
type DurationLabels = metrics::labels::Route;
type StreamLabel = metrics::LabelHttpRouteRsp;

fn mk_stream_labeler<B>(&self, _: &::http::Request<B>) -> Option<Self::StreamLabel> {
Expand Down Expand Up @@ -227,8 +225,6 @@ impl<T> filters::Apply for Grpc<T> {
}

impl<T> metrics::MkStreamLabel for Grpc<T> {
type StatusLabels = metrics::labels::GrpcRouteRsp;
type DurationLabels = metrics::labels::Route;
type StreamLabel = metrics::LabelGrpcRouteRsp;

fn mk_stream_labeler<B>(&self, _: &::http::Request<B>) -> Option<Self::StreamLabel> {
Expand Down
4 changes: 0 additions & 4 deletions linkerd/app/outbound/src/http/logical/policy/route/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,6 @@ impl<T> filters::Apply for Http<T> {
}

impl<T> metrics::MkStreamLabel for Http<T> {
type StatusLabels = metrics::labels::HttpRouteBackendRsp;
type DurationLabels = metrics::labels::RouteBackend;
type StreamLabel = metrics::LabelHttpRouteBackendRsp;

fn mk_stream_labeler<B>(&self, _: &::http::Request<B>) -> Option<Self::StreamLabel> {
Expand All @@ -176,8 +174,6 @@ impl<T> filters::Apply for Grpc<T> {
}

impl<T> metrics::MkStreamLabel for Grpc<T> {
type StatusLabels = metrics::labels::GrpcRouteBackendRsp;
type DurationLabels = metrics::labels::RouteBackend;
type StreamLabel = metrics::LabelGrpcRouteBackendRsp;

fn mk_stream_labeler<B>(&self, _: &::http::Request<B>) -> Option<Self::StreamLabel> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,6 @@ pub struct RouteBackend(pub ParentRef, pub RouteRef, pub BackendRef);
#[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct Rsp<P, L>(pub P, pub L);

pub type RouteRsp<L> = Rsp<Route, L>;
pub type HttpRouteRsp = RouteRsp<HttpRsp>;
pub type GrpcRouteRsp = RouteRsp<GrpcRsp>;

pub type RouteBackendRsp<L> = Rsp<RouteBackend, L>;
pub type HttpRouteBackendRsp = RouteBackendRsp<HttpRsp>;
pub type GrpcRouteBackendRsp = RouteBackendRsp<GrpcRsp>;

#[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct HttpRsp {
pub status: Option<http::StatusCode>,
Expand Down
22 changes: 1 addition & 21 deletions linkerd/http/prom/src/record_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,27 +32,7 @@ pub use self::{
/// This is specifically to support higher-cardinality status counters and
/// lower-cardinality stream duration histograms.
pub trait MkStreamLabel {
type DurationLabels: EncodeLabelSet
+ Clone
+ Eq
+ std::fmt::Debug
+ std::hash::Hash
+ Send
+ Sync
+ 'static;
type StatusLabels: EncodeLabelSet
+ Clone
+ Eq
+ std::fmt::Debug
+ std::hash::Hash
+ Send
+ Sync
+ 'static;

type StreamLabel: StreamLabel<
DurationLabels = Self::DurationLabels,
StatusLabels = Self::StatusLabels,
>;
type StreamLabel: StreamLabel;

/// Returns None when the request should not be recorded.
fn mk_stream_labeler<B>(&self, req: &http::Request<B>) -> Option<Self::StreamLabel>;
Expand Down
12 changes: 9 additions & 3 deletions linkerd/http/prom/src/record_response/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use std::{
};
use tokio::{sync::oneshot, time};

use super::{DurationFamily, MkDurationHistogram, MkStreamLabel};
use super::{DurationFamily, MkDurationHistogram, MkStreamLabel, StreamLabel};

/// Metrics type that tracks completed requests.
#[derive(Debug)]
Expand All @@ -25,13 +25,19 @@ pub struct RequestMetrics<DurL, StatL> {
pub type NewRequestDuration<L, X, N> = super::NewRecordResponse<
L,
X,
RequestMetrics<<L as MkStreamLabel>::DurationLabels, <L as MkStreamLabel>::StatusLabels>,
RequestMetrics<
<<L as MkStreamLabel>::StreamLabel as StreamLabel>::DurationLabels,
<<L as MkStreamLabel>::StreamLabel as StreamLabel>::StatusLabels,
>,
N,
>;

pub type RecordRequestDuration<L, S> = super::RecordResponse<
L,
RequestMetrics<<L as MkStreamLabel>::DurationLabels, <L as MkStreamLabel>::StatusLabels>,
RequestMetrics<
<<L as MkStreamLabel>::StreamLabel as StreamLabel>::DurationLabels,
<<L as MkStreamLabel>::StreamLabel as StreamLabel>::StatusLabels,
>,
S,
>;

Expand Down
12 changes: 9 additions & 3 deletions linkerd/http/prom/src/record_response/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use std::{
};
use tokio::{sync::oneshot, time};

use super::{DurationFamily, MkDurationHistogram, MkStreamLabel};
use super::{DurationFamily, MkDurationHistogram, MkStreamLabel, StreamLabel};

/// Metrics type that tracks completed responses.
#[derive(Debug)]
Expand All @@ -26,13 +26,19 @@ pub struct ResponseMetrics<DurL, StatL> {
pub type NewResponseDuration<L, X, N> = super::NewRecordResponse<
L,
X,
ResponseMetrics<<L as MkStreamLabel>::DurationLabels, <L as MkStreamLabel>::StatusLabels>,
ResponseMetrics<
<<L as MkStreamLabel>::StreamLabel as StreamLabel>::DurationLabels,
<<L as MkStreamLabel>::StreamLabel as StreamLabel>::StatusLabels,
>,
N,
>;

pub type RecordResponseDuration<L, S> = super::RecordResponse<
L,
ResponseMetrics<<L as MkStreamLabel>::DurationLabels, <L as MkStreamLabel>::StatusLabels>,
ResponseMetrics<
<<L as MkStreamLabel>::StreamLabel as StreamLabel>::DurationLabels,
<<L as MkStreamLabel>::StreamLabel as StreamLabel>::StatusLabels,
>,
S,
>;

Expand Down

0 comments on commit 6bc4fd1

Please sign in to comment.