Skip to content

Commit cc04760

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 225674b commit cc04760

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
@@ -155,13 +155,21 @@ async fn body_data_layer_records_frames() -> Result<(), Error> {
155155
tracing::info!("acquiring response body metrics");
156156
let labels = labels::RouteBackend(parent_ref.clone(), route_ref.clone(), backend_ref.clone());
157157
let BodyDataMetrics {
158-
frames_total,
159-
frames_bytes,
158+
// TODO(kate): currently, histograms do not expose their observation count or sum. so,
159+
// we're left unable to exercise these metrics until prometheus/client_rust#242 lands.
160+
// - https://github.com/prometheus/client_rust/pull/241
161+
// - https://github.com/prometheus/client_rust/pull/242
162+
#[cfg(feature = "prometheus-client-rust-242")]
163+
frame_size,
164+
..
160165
} = metrics.get_response_body_metrics(&labels);
161166

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

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

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

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

212225
{
@@ -219,8 +232,10 @@ async fn body_data_layer_records_frames() -> Result<(), Error> {
219232
chunk,
220233
"should get same value back out"
221234
);
222-
assert_eq!(frames_total.get(), 2);
223-
assert_eq!(frames_bytes.get(), 5 + 8);
235+
#[cfg(feature = "prometheus-client-rust-242")]
236+
assert_eq!(frame_size.count(), 2);
237+
#[cfg(feature = "prometheus-client-rust-242")]
238+
assert_eq!(frame_size.sum(), 5 + 8);
224239
}
225240

226241
{
@@ -233,8 +248,10 @@ async fn body_data_layer_records_frames() -> Result<(), Error> {
233248
Poll::Ready(None) => {}
234249
_ => panic!("got unexpected poll result"),
235250
};
236-
assert_eq!(frames_total.get(), 2);
237-
assert_eq!(frames_bytes.get(), 5 + 8);
251+
#[cfg(feature = "prometheus-client-rust-242")]
252+
assert_eq!(frame_size.count(), 2);
253+
#[cfg(feature = "prometheus-client-rust-242")]
254+
assert_eq!(frame_size.sum(), 5 + 8);
238255
}
239256

240257
Ok(())

0 commit comments

Comments
 (0)