-
Notifications
You must be signed in to change notification settings - Fork 270
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(app): add backend response frame count metric
Signed-off-by: katelyn martin <[email protected]>
- Loading branch information
Showing
11 changed files
with
539 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
pub mod request; | ||
pub mod response; | ||
|
||
mod body; | ||
mod metrics; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
use super::metrics::BodyDataMetrics; | ||
use http::HeaderMap; | ||
use http_body::SizeHint; | ||
use pin_project::pin_project; | ||
use std::{ | ||
pin::Pin, | ||
task::{Context, Poll}, | ||
}; | ||
|
||
/// An instrumented body. | ||
#[pin_project] | ||
pub struct Body<B> { | ||
/// The inner body. | ||
#[pin] | ||
inner: B, | ||
/// Metrics with which the inner body will be instrumented. | ||
metrics: BodyDataMetrics, | ||
} | ||
|
||
impl<B> Body<B> { | ||
/// Returns a new, instrumented body. | ||
pub(crate) fn new(body: B, metrics: BodyDataMetrics) -> Self { | ||
Self { | ||
inner: body, | ||
metrics, | ||
} | ||
} | ||
} | ||
|
||
impl<B> http_body::Body for Body<B> | ||
where | ||
B: http_body::Body, | ||
{ | ||
type Data = B::Data; | ||
type Error = B::Error; | ||
|
||
/// Attempt to pull out the next data buffer of this stream. | ||
fn poll_data( | ||
self: Pin<&mut Self>, | ||
cx: &mut Context<'_>, | ||
) -> Poll<Option<Result<Self::Data, Self::Error>>> { | ||
let this = self.project(); | ||
let inner = this.inner; | ||
let BodyDataMetrics { | ||
frames_total, | ||
frames_bytes: _, // DEV(kate); count bytes in body chunks. | ||
} = this.metrics; | ||
|
||
let data = std::task::ready!(inner.poll_data(cx)); | ||
|
||
if let Some(Ok(_)) = data.as_ref() { | ||
frames_total.inc(); | ||
} | ||
|
||
Poll::Ready(data) | ||
} | ||
|
||
fn poll_trailers( | ||
self: Pin<&mut Self>, | ||
cx: &mut Context<'_>, | ||
) -> Poll<Result<Option<HeaderMap>, Self::Error>> { | ||
self.project().inner.poll_trailers(cx) | ||
} | ||
|
||
fn is_end_stream(&self) -> bool { | ||
self.inner.is_end_stream() | ||
} | ||
|
||
fn size_hint(&self) -> SizeHint { | ||
self.inner.size_hint() | ||
} | ||
} |
Oops, something went wrong.