forked from Deuxfleurs/tricot
Compare commits
2 commits
68980642e1
...
2999e366d8
Author | SHA1 | Date | |
---|---|---|---|
|
2999e366d8 | ||
|
1f621cd2a5 |
1 changed files with 18 additions and 13 deletions
31
src/https.rs
31
src/https.rs
|
@ -45,12 +45,12 @@ struct HttpsMetrics {
|
||||||
request_proxy_duration: metrics::Histogram<f64>,
|
request_proxy_duration: metrics::Histogram<f64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct InFlightGuard<'a> {
|
struct InFlightGuard<'a, 'b> {
|
||||||
metrics: Arc<HttpsMetrics>,
|
metrics: &'a HttpsMetrics,
|
||||||
tags: &'a [KeyValue],
|
tags: &'b [KeyValue],
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Drop for InFlightGuard<'a> {
|
impl<'a, 'b> Drop for InFlightGuard<'a, 'b> {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
self.metrics.requests_in_flight.add(-1, self.tags)
|
self.metrics.requests_in_flight.add(-1, self.tags)
|
||||||
}
|
}
|
||||||
|
@ -179,8 +179,8 @@ async fn handle_request(
|
||||||
) -> Result<Response<Body>, Infallible> {
|
) -> Result<Response<Body>, Infallible> {
|
||||||
let method_tag = KeyValue::new("method", req.method().to_string());
|
let method_tag = KeyValue::new("method", req.method().to_string());
|
||||||
|
|
||||||
// The host tag is only included in the requests_received and requests_in_flight
|
// The host tag is only included in the requests_received metric,
|
||||||
// metrics, as for other metrics it can easily lead to cardinality explosions.
|
// as for other metrics it can easily lead to cardinality explosions.
|
||||||
let host_tag = KeyValue::new(
|
let host_tag = KeyValue::new(
|
||||||
"host",
|
"host",
|
||||||
req.uri()
|
req.uri()
|
||||||
|
@ -194,13 +194,7 @@ async fn handle_request(
|
||||||
.unwrap_or_default(),
|
.unwrap_or_default(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let tags = [host_tag, method_tag.clone()];
|
metrics.requests_received.add(1, &[host_tag, method_tag.clone()]);
|
||||||
metrics.requests_received.add(1, &tags);
|
|
||||||
metrics.requests_in_flight.add(1, &tags);
|
|
||||||
let _guard = InFlightGuard {
|
|
||||||
metrics: Arc::clone(&metrics),
|
|
||||||
tags: &tags,
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut tags = vec![method_tag];
|
let mut tags = vec![method_tag];
|
||||||
let resp = select_target_and_proxy(
|
let resp = select_target_and_proxy(
|
||||||
|
@ -292,6 +286,17 @@ async fn select_target_and_proxy(
|
||||||
);
|
);
|
||||||
proxy_to.calls_in_progress.fetch_add(1, Ordering::SeqCst);
|
proxy_to.calls_in_progress.fetch_add(1, Ordering::SeqCst);
|
||||||
|
|
||||||
|
let tags_in_flight = &tags.clone();
|
||||||
|
metrics.requests_in_flight.add(1, &tags_in_flight);
|
||||||
|
// The guard ensures that we decrement requests_in_flight in all cases where
|
||||||
|
// the current tasks ends, including the case where it gets canceled and
|
||||||
|
// doesn't run to completion (which may happen e.g. if it timeouts).
|
||||||
|
// (Crucially we create the guard before the first .await in this function.)
|
||||||
|
let _guard = InFlightGuard {
|
||||||
|
metrics: &metrics,
|
||||||
|
tags: &tags_in_flight,
|
||||||
|
};
|
||||||
|
|
||||||
// Forward to backend
|
// Forward to backend
|
||||||
debug!("{}{} -> {}", host, path, proxy_to);
|
debug!("{}{} -> {}", host, path, proxy_to);
|
||||||
trace!("Request: {:?}", req);
|
trace!("Request: {:?}", req);
|
||||||
|
|
Loading…
Reference in a new issue