Compare commits

...

1 Commits

Author SHA1 Message Date
Conrad Ludgate
264ea1cc49 proxy: make latency metrics additive, fix latency calculation for link flow 2024-04-30 10:43:52 +01:00
2 changed files with 34 additions and 23 deletions

View File

@@ -79,15 +79,19 @@ pub(super) async fn authenticate(
// Give user a URL to spawn a new database. // Give user a URL to spawn a new database.
info!(parent: &span, "sending the auth URL to the user"); info!(parent: &span, "sending the auth URL to the user");
let pause = ctx.latency_timer.pause(crate::metrics::Waiting::Client);
client client
.write_message_noflush(&Be::AuthenticationOk)? .write_message_noflush(&Be::AuthenticationOk)?
.write_message_noflush(&Be::CLIENT_ENCODING)? .write_message_noflush(&Be::CLIENT_ENCODING)?
.write_message(&Be::NoticeResponse(&greeting)) .write_message(&Be::NoticeResponse(&greeting))
.await?; .await?;
drop(pause);
// Wait for web console response (see `mgmt`). // Wait for web console response (see `mgmt`).
info!(parent: &span, "waiting for console's reply..."); info!(parent: &span, "waiting for console's reply...");
let pause = ctx.latency_timer.pause(crate::metrics::Waiting::Cplane);
let db_info = waiter.await.map_err(LinkAuthError::from)?; let db_info = waiter.await.map_err(LinkAuthError::from)?;
drop(pause);
client.write_message_noflush(&Be::NoticeResponse("Connecting to database."))?; client.write_message_noflush(&Be::NoticeResponse("Connecting to database."))?;

View File

@@ -277,15 +277,16 @@ pub struct ComputeConnectionLatencyGroup {
protocol: Protocol, protocol: Protocol,
cold_start_info: ColdStartInfo, cold_start_info: ColdStartInfo,
outcome: ConnectOutcome, outcome: ConnectOutcome,
excluded: LatencyExclusions, component: LatencyComponents,
} }
#[derive(FixedCardinalityLabel, Copy, Clone)] #[derive(FixedCardinalityLabel, Copy, Clone)]
pub enum LatencyExclusions { pub enum LatencyComponents {
Client, Client,
ClientAndCplane, Cplane,
ClientCplaneCompute, Compute,
ClientCplaneComputeRetry, ComputeRetry,
Proxy,
} }
#[derive(FixedCardinalityLabel, Copy, Clone)] #[derive(FixedCardinalityLabel, Copy, Clone)]
@@ -445,46 +446,52 @@ impl Drop for LatencyTimer {
let metric = &Metrics::get().proxy.compute_connection_latency_seconds; let metric = &Metrics::get().proxy.compute_connection_latency_seconds;
// Excluding client communication from the accumulated time. // client only latency
metric.observe( metric.observe(
ComputeConnectionLatencyGroup { ComputeConnectionLatencyGroup {
protocol: self.protocol, protocol: self.protocol,
cold_start_info: self.cold_start_info, cold_start_info: self.cold_start_info,
outcome: self.outcome, outcome: self.outcome,
excluded: LatencyExclusions::Client, component: LatencyComponents::Client,
}, },
duration self.accumulated.client.as_secs_f64(),
.saturating_sub(self.accumulated.client)
.as_secs_f64(),
); );
// Exclude client and cplane communication from the accumulated time. // cplane only latency
let accumulated_total = self.accumulated.client + self.accumulated.cplane;
metric.observe( metric.observe(
ComputeConnectionLatencyGroup { ComputeConnectionLatencyGroup {
protocol: self.protocol, protocol: self.protocol,
cold_start_info: self.cold_start_info, cold_start_info: self.cold_start_info,
outcome: self.outcome, outcome: self.outcome,
excluded: LatencyExclusions::ClientAndCplane, component: LatencyComponents::Cplane,
}, },
duration.saturating_sub(accumulated_total).as_secs_f64(), self.accumulated.cplane.as_secs_f64(),
); );
// Exclude client cplane, compue communication from the accumulated time. // compute connect only latency
let accumulated_total =
self.accumulated.client + self.accumulated.cplane + self.accumulated.compute;
metric.observe( metric.observe(
ComputeConnectionLatencyGroup { ComputeConnectionLatencyGroup {
protocol: self.protocol, protocol: self.protocol,
cold_start_info: self.cold_start_info, cold_start_info: self.cold_start_info,
outcome: self.outcome, outcome: self.outcome,
excluded: LatencyExclusions::ClientCplaneCompute, component: LatencyComponents::Compute,
}, },
duration.saturating_sub(accumulated_total).as_secs_f64(), self.accumulated.compute.as_secs_f64(),
); );
// Exclude client cplane, compue, retry communication from the accumulated time. // compute failure retry latency
let accumulated_total = self.accumulated.client metric.observe(
ComputeConnectionLatencyGroup {
protocol: self.protocol,
cold_start_info: self.cold_start_info,
outcome: self.outcome,
component: LatencyComponents::ComputeRetry,
},
self.accumulated.retry.as_secs_f64(),
);
// proxy only latency, removing client+cplane+compute+retry from the total
let accumulated = self.accumulated.client
+ self.accumulated.cplane + self.accumulated.cplane
+ self.accumulated.compute + self.accumulated.compute
+ self.accumulated.retry; + self.accumulated.retry;
@@ -493,9 +500,9 @@ impl Drop for LatencyTimer {
protocol: self.protocol, protocol: self.protocol,
cold_start_info: self.cold_start_info, cold_start_info: self.cold_start_info,
outcome: self.outcome, outcome: self.outcome,
excluded: LatencyExclusions::ClientCplaneComputeRetry, component: LatencyComponents::Proxy,
}, },
duration.saturating_sub(accumulated_total).as_secs_f64(), duration.saturating_sub(accumulated).as_secs_f64(),
); );
} }
} }