Skip to content

Commit

Permalink
refactor(tests): feature gate frame size histogram assertions
Browse files Browse the repository at this point in the history
see:

* prometheus/client_rust#242
* prometheus/client_rust#241

for now, refactor this test so that it gates all use of the (proposed)
`sum()` and `count()` accessors behind a temporary feature gate.

Signed-off-by: katelyn martin <[email protected]>
  • Loading branch information
cratelyn committed Nov 20, 2024
1 parent 225674b commit cc04760
Showing 1 changed file with 29 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,21 @@ async fn body_data_layer_records_frames() -> Result<(), Error> {
tracing::info!("acquiring response body metrics");
let labels = labels::RouteBackend(parent_ref.clone(), route_ref.clone(), backend_ref.clone());
let BodyDataMetrics {
frames_total,
frames_bytes,
// TODO(kate): currently, histograms do not expose their observation count or sum. so,
// we're left unable to exercise these metrics until prometheus/client_rust#242 lands.
// - https://github.com/prometheus/client_rust/pull/241
// - https://github.com/prometheus/client_rust/pull/242
#[cfg(feature = "prometheus-client-rust-242")]
frame_size,
..
} = metrics.get_response_body_metrics(&labels);

// Before we've sent a response, the counter should be zero.
assert_eq!(frames_total.get(), 0);
assert_eq!(frames_bytes.get(), 0);
#[cfg(feature = "prometheus-client-rust-242")]
{
assert_eq!(frame_size.count(), 0);
assert_eq!(frame_size.sum(), 0);
}

// Create a response whose body is backed by a channel that we can send chunks to, send it.
tracing::info!("sending response");
Expand All @@ -177,8 +185,11 @@ async fn body_data_layer_records_frames() -> Result<(), Error> {
};

// Before we've sent any bytes, the counter should be zero.
assert_eq!(frames_total.get(), 0);
assert_eq!(frames_bytes.get(), 0);
#[cfg(feature = "prometheus-client-rust-242")]
{
assert_eq!(frame_size.count(), 0);
assert_eq!(frame_size.sum(), 0);
}

// On the client end, poll our call future and await the response.
tracing::info!("polling service future");
Expand All @@ -205,8 +216,10 @@ async fn body_data_layer_records_frames() -> Result<(), Error> {
resp_tx.send_data("hello".into()).await?;
let chunk = read_chunk(&mut body).await?;
debug_assert_eq!("hello".as_bytes(), chunk, "should get same value back out");
assert_eq!(frames_total.get(), 1);
assert_eq!(frames_bytes.get(), 5);
#[cfg(feature = "prometheus-client-rust-242")]
assert_eq!(frame_size.count(), 1);
#[cfg(feature = "prometheus-client-rust-242")]
assert_eq!(frame_size.sum(), 5);
}

{
Expand All @@ -219,8 +232,10 @@ async fn body_data_layer_records_frames() -> Result<(), Error> {
chunk,
"should get same value back out"
);
assert_eq!(frames_total.get(), 2);
assert_eq!(frames_bytes.get(), 5 + 8);
#[cfg(feature = "prometheus-client-rust-242")]
assert_eq!(frame_size.count(), 2);
#[cfg(feature = "prometheus-client-rust-242")]
assert_eq!(frame_size.sum(), 5 + 8);
}

{
Expand All @@ -233,8 +248,10 @@ async fn body_data_layer_records_frames() -> Result<(), Error> {
Poll::Ready(None) => {}
_ => panic!("got unexpected poll result"),
};
assert_eq!(frames_total.get(), 2);
assert_eq!(frames_bytes.get(), 5 + 8);
#[cfg(feature = "prometheus-client-rust-242")]
assert_eq!(frame_size.count(), 2);
#[cfg(feature = "prometheus-client-rust-242")]
assert_eq!(frame_size.sum(), 5 + 8);
}

Ok(())
Expand Down

0 comments on commit cc04760

Please sign in to comment.