feat(http/prom): loosen bounds for StreamLabel's associated labels#4250
feat(http/prom): loosen bounds for StreamLabel's associated labels#4250
StreamLabel's associated labels#4250Conversation
## overview this commit makes a change, loosening the prerequisite trait bounds for implementations of `StreamLabel` and `MkStreamLabel`'s associated `StatusLabels` and `DurationLabels` types. this commit introduces a trait alias, `linkerd_http_prom::stream_label::LabelSet`, which is implemented on behalf of types that satisfy the bounds.. `T: EncodeLabelSet + Clone + Eq + std::fmt::Debug + std::hash::Hash + Send + Sync + 'static` ..previously expected of these traits' associated types. this provides dependent code with a shorthand mechanism to express these bounds on `linkerd-app-outbound`'s route- and backend-level stream labeling facilities. ## motivation the implicit purpose of this change is that loosening these bounds allows for us to _compose_ discrete, reusable, `StreamLabel` implementations. this will permit us to decompose the outbound proxy's `LabelGrpcRsp` and `LabelHttpRsp` types into discrete components for obtaining HTTP status codes, gRPC status codes, error labels, and route labels that we will be able to share with the inbound proxy. Signed-off-by: katelyn martin <kate@buoyant.io>
|
see #4251, which is based upon this branch. that pull request proposes |
olix0r
left a comment
There was a problem hiding this comment.
Not hard-blocked, but in general I'm wary of having to express additional type assertions everywhere. It would help to understand what flexibility we get for the verbosity trade-off.
| L::DurationLabels: LabelSet, | ||
| L::StatusLabels: LabelSet, |
There was a problem hiding this comment.
are these load bearing on the struct definition? we try to minimize type requirements on type definitions (since it bleeds out quickly, requiring assertions even when decoupled from an impl)
| type DurationLabels; | ||
| type StatusLabels; |
There was a problem hiding this comment.
I know this is the main point of this PR but I'm missing how it all ties together. It seems like we incur a ton of boilerplate by not having these enforce a : LabelSet bound here.
Where aren't these bounds actually required? Is there a way for us to special-case that?
Signed-off-by: katelyn martin <kate@buoyant.io>
certainly. let me try and outline where i believe we are headed with this we have a pair of today, this pair of traits is used only within the today, the so, our high-level goal is to decompose so, how does this change help us get there? by loosening this constraint, we may define some reusable stream labeling for what it's worth, an alias like the now, note that after we introduce a standalone status counting layer, we can remove these in this world, we end up with a pub trait StreamLabel: Send + 'static {
type Labels;
fn init_response<B>(&mut self, rsp: &http::Response<B>);
fn end_response(&mut self, trailers: Result<Option<&http::HeaderMap>, &Error>);
fn labels(&self) -> Self::Labels;
}there is, as you point out, a tradeoff here: we incur some complexity in i've also noticed that after we extricate status code metrics from so, i feel some conviction that in the long-term, this is worth the cost. i'm |
see #4250 (59f90ac) for previous related work. * feat(http/prom): add http and grpc status labelers this commit introduces a collection of `MkStreamLabel` and `StreamLabel` implementations that can be used to inspect status codes for HTTP and gRPC traffic. these do not emit duration labels, but can be used by other implementors of these traits to perform the common logic of checking HTTP status codes in response front matter, and for inspecting body trailers in gRPC traffic. Signed-off-by: katelyn martin <kate@buoyant.io> * feat(http/prom): add an error labeler this commit introduces a `LabelError<E>` type, which provides a `StreamLabel` implementation that maps boxed errors to labels. this is generic across `E`-typed labels that can be constructed `From` a reference to a boxed `linkerd_error::Error`. Signed-off-by: katelyn martin <kate@buoyant.io> * feat(http/prom): add an identity labeler this commit introduces a simple "identity" implementation of `MkStreamLabel` and `StreamLabel`. this is useful for metrics such as our duration recording histogram, that do not inspect the request, response, or outcome for further labels. Signed-off-by: katelyn martin <kate@buoyant.io> --------- Signed-off-by: katelyn martin <kate@buoyant.io>
**nb:** this branch is based upon #4250 and #4251. this branch re-frames the outbound proxy's stream labeling facilities in terms of the constituent status and error labeling facilities introduced to the `linkerd-http-prom` library in #4251. * feat(app/outbound): convenience constructors for `HttpRsp`, `GrpcRsp` Signed-off-by: katelyn martin <kate@buoyant.io> * feat(app/outbound): `GrpcRsp`, `HttpRsp` are `From<&Error>` Signed-off-by: katelyn martin <kate@buoyant.io> * feat(app/outbound): `GrpcRsp` and `HttpRsp` can be merged this commit introduces `apply()` methods to `HttpRsp` and `GrpcRsp`. this allows us to collect both the response status and response error when a body encounters an error whilst polling. Signed-off-by: katelyn martin <kate@buoyant.io> * refactor(app/outbound): `LabelHttpRsp` uses `LabelHttpStatus` Signed-off-by: katelyn martin <kate@buoyant.io> * refactor(app/outbound): `LabelGrpcRsp` uses `LabelGrpcStatus` Signed-off-by: katelyn martin <kate@buoyant.io> --------- Signed-off-by: katelyn martin <kate@buoyant.io>
overview
this commit makes a change, loosening the prerequisite trait bounds for
implementations of
StreamLabelandMkStreamLabel's associatedStatusLabelsandDurationLabelstypes.this commit introduces a trait alias,
linkerd_http_prom::stream_label::LabelSet, which is implemented onbehalf of types that satisfy the bounds..
T: EncodeLabelSet + Clone + Eq + std::fmt::Debug + std::hash::Hash + Send + Sync + 'static..previously expected of these traits' associated types. this provides
dependent code with a shorthand mechanism to express these bounds on
linkerd-app-outbound's route- and backend-level stream labelingfacilities.
motivation
the implicit purpose of this change is that loosening these bounds
allows for us to compose discrete, reusable,
StreamLabelimplementations.
this will permit us to decompose the outbound proxy's
LabelGrpcRspand
LabelHttpRsptypes into discrete components for obtaining HTTPstatus codes, gRPC status codes, error labels, and route labels that we
will be able to share with the inbound proxy.
Signed-off-by: katelyn martin kate@buoyant.io