Skip to content

Commit

Permalink
refactor(app): Define layer type aliases
Browse files Browse the repository at this point in the history
this isn't a "simplification" so much as an outlining of the chunky
types in this function signature.

that said... it's subjectively nice to outline the definition of our
layers into a `MetricsLayer<T, N>` that we can use as shorthand in the
function signature of `layer(..)`.

Signed-off-by: katelyn martin <[email protected]>
  • Loading branch information
cratelyn committed Nov 20, 2024
1 parent 936ac9c commit 95e796f
Showing 1 changed file with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@ type ResponseMetrics<L> = record_response::ResponseMetrics<
<L as StreamLabel>::StatusLabels,
>;

type MetricsLayer<T, N> = BodyDataLayer<RequestLayer<ResponseLayer<T, N>>>;
type BodyDataLayer<N> = NewRecordBodyData<ExtractRecordBodyDataParams, N>;
type RequestLayer<N> = NewCountRequests<ExtractRequestCount, N>;
type ResponseLayer<T, N> = NewResponseDuration<
T,
ExtractRecordDurationParams<ResponseMetrics<<T as MkStreamLabel>::StreamLabel>>,
N,
>;

pub fn layer<T, N>(
metrics: &RouteBackendMetrics<T::StreamLabel>,
) -> impl svc::Layer<
N,
Service = NewRecordBodyData<
ExtractRecordBodyDataParams,
NewCountRequests<
ExtractRequestCount,
NewResponseDuration<T, ExtractRecordDurationParams<ResponseMetrics<T::StreamLabel>>, N>,
>,
>,
> + Clone
) -> impl svc::Layer<N, Service = MetricsLayer<T, N>> + Clone
where
T: MkStreamLabel,
{
Expand Down

0 comments on commit 95e796f

Please sign in to comment.