Skip to content

Commit 33f5f60

Browse files
committed
refactor(tests): feature gate frame size histogram assertions
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]>
1 parent da6e10c commit 33f5f60

File tree

1 file changed

+29
-12
lines changed
  • linkerd/app/outbound/src/http/logical/policy/route/backend/metrics

1 file changed

+29
-12
lines changed

linkerd/app/outbound/src/http/logical/policy/route/backend/metrics/tests.rs

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -153,13 +153,21 @@ async fn body_data_layer_records_frames() -> Result<(), Error> {
153153
tracing::info!("acquiring response body metrics");
154154
let labels = labels::RouteBackend(parent_ref.clone(), route_ref.clone(), backend_ref.clone());
155155
let BodyDataMetrics {
156-
frames_total,
157-
frames_bytes,
156+
// TODO(kate): currently, histograms do not expose their observation count or sum. so,
157+
// we're left unable to exercise these metrics until prometheus/client_rust#242 lands.
158+
// - https://github.com/prometheus/client_rust/pull/241
159+
// - https://github.com/prometheus/client_rust/pull/242
160+
#[cfg(feature = "prometheus-client-rust-242")]
161+
frame_size,
162+
..
158163
} = metrics.get_response_body_metrics(&labels);
159164

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

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

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

181192
// On the client end, poll our call future and await the response.
182193
tracing::info!("polling service future");
@@ -203,8 +214,10 @@ async fn body_data_layer_records_frames() -> Result<(), Error> {
203214
resp_tx.send_data("hello".into()).await?;
204215
let chunk = read_chunk(&mut body).await?;
205216
debug_assert_eq!("hello".as_bytes(), chunk, "should get same value back out");
206-
assert_eq!(frames_total.get(), 1);
207-
assert_eq!(frames_bytes.get(), 5);
217+
#[cfg(feature = "prometheus-client-rust-242")]
218+
assert_eq!(frame_size.count(), 1);
219+
#[cfg(feature = "prometheus-client-rust-242")]
220+
assert_eq!(frame_size.sum(), 5);
208221
}
209222

210223
{
@@ -217,8 +230,10 @@ async fn body_data_layer_records_frames() -> Result<(), Error> {
217230
chunk,
218231
"should get same value back out"
219232
);
220-
assert_eq!(frames_total.get(), 2);
221-
assert_eq!(frames_bytes.get(), 5 + 8);
233+
#[cfg(feature = "prometheus-client-rust-242")]
234+
assert_eq!(frame_size.count(), 2);
235+
#[cfg(feature = "prometheus-client-rust-242")]
236+
assert_eq!(frame_size.sum(), 5 + 8);
222237
}
223238

224239
{
@@ -231,8 +246,10 @@ async fn body_data_layer_records_frames() -> Result<(), Error> {
231246
Poll::Ready(None) => {}
232247
_ => panic!("got unexpected poll result"),
233248
};
234-
assert_eq!(frames_total.get(), 2);
235-
assert_eq!(frames_bytes.get(), 5 + 8);
249+
#[cfg(feature = "prometheus-client-rust-242")]
250+
assert_eq!(frame_size.count(), 2);
251+
#[cfg(feature = "prometheus-client-rust-242")]
252+
assert_eq!(frame_size.sum(), 5 + 8);
236253
}
237254

238255
Ok(())

0 commit comments

Comments
 (0)