forked from Deuxfleurs/tricot
Compare commits
No commits in common. "in_flight_meter" and "main" have entirely different histories.
in_flight_
...
main
1 changed files with 3 additions and 28 deletions
31
src/https.rs
31
src/https.rs
|
@ -41,21 +41,9 @@ pub struct HttpsConfig {
|
||||||
struct HttpsMetrics {
|
struct HttpsMetrics {
|
||||||
requests_received: metrics::Counter<u64>,
|
requests_received: metrics::Counter<u64>,
|
||||||
requests_served: metrics::Counter<u64>,
|
requests_served: metrics::Counter<u64>,
|
||||||
requests_in_flight: metrics::UpDownCounter<i64>,
|
|
||||||
request_proxy_duration: metrics::Histogram<f64>,
|
request_proxy_duration: metrics::Histogram<f64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct InFlightGuard<'a, 'b> {
|
|
||||||
metrics: &'a HttpsMetrics,
|
|
||||||
tags: &'b [KeyValue],
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a, 'b> Drop for InFlightGuard<'a, 'b> {
|
|
||||||
fn drop(&mut self) {
|
|
||||||
self.metrics.requests_in_flight.add(-1, self.tags)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn serve_https(
|
pub async fn serve_https(
|
||||||
config: HttpsConfig,
|
config: HttpsConfig,
|
||||||
cert_store: Arc<CertStore>,
|
cert_store: Arc<CertStore>,
|
||||||
|
@ -74,10 +62,6 @@ pub async fn serve_https(
|
||||||
.u64_counter("https_requests_served")
|
.u64_counter("https_requests_served")
|
||||||
.with_description("Total number of requests served over HTTPS")
|
.with_description("Total number of requests served over HTTPS")
|
||||||
.init(),
|
.init(),
|
||||||
requests_in_flight: meter
|
|
||||||
.i64_up_down_counter("https_requests_in_flight")
|
|
||||||
.with_description("Current number of requests handled over HTTPS")
|
|
||||||
.init(),
|
|
||||||
request_proxy_duration: meter
|
request_proxy_duration: meter
|
||||||
.f64_histogram("https_request_proxy_duration")
|
.f64_histogram("https_request_proxy_duration")
|
||||||
.with_description("Duration between time when request was received, and time when backend returned status code and headers")
|
.with_description("Duration between time when request was received, and time when backend returned status code and headers")
|
||||||
|
@ -194,7 +178,9 @@ async fn handle_request(
|
||||||
.unwrap_or_default(),
|
.unwrap_or_default(),
|
||||||
);
|
);
|
||||||
|
|
||||||
metrics.requests_received.add(1, &[host_tag, method_tag.clone()]);
|
metrics
|
||||||
|
.requests_received
|
||||||
|
.add(1, &[host_tag, method_tag.clone()]);
|
||||||
|
|
||||||
let mut tags = vec![method_tag];
|
let mut tags = vec![method_tag];
|
||||||
let resp = select_target_and_proxy(
|
let resp = select_target_and_proxy(
|
||||||
|
@ -286,17 +272,6 @@ 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