mirror of
https://github.com/neondatabase/neon.git
synced 2026-01-05 20:42:54 +00:00
proxy: Report warm cold start if connection is from the local cache (#7104)
## Problem * quotes in serialized string * no status if connection is from local cache ## Summary of changes * remove quotes * report warm if connection if from local cache
This commit is contained in:
@@ -6,7 +6,9 @@ use super::{
|
||||
ApiCaches, ApiLocks, AuthInfo, AuthSecret, CachedAllowedIps, CachedNodeInfo, CachedRoleSecret,
|
||||
NodeInfo,
|
||||
};
|
||||
use crate::{auth::backend::ComputeUserInfo, compute, http, scram};
|
||||
use crate::{
|
||||
auth::backend::ComputeUserInfo, compute, console::messages::ColdStartInfo, http, scram,
|
||||
};
|
||||
use crate::{
|
||||
cache::Cached,
|
||||
context::RequestMonitoring,
|
||||
@@ -254,6 +256,7 @@ impl super::Api for Api {
|
||||
if permit.should_check_cache() {
|
||||
if let Some(cached) = self.caches.node_info.get(&key) {
|
||||
info!(key = &*key, "found cached compute node info");
|
||||
ctx.set_cold_start_info(ColdStartInfo::Warm);
|
||||
return Ok(cached);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,6 +111,10 @@ impl RequestMonitoring {
|
||||
)
|
||||
}
|
||||
|
||||
pub fn set_cold_start_info(&mut self, info: ColdStartInfo) {
|
||||
self.cold_start_info = Some(info);
|
||||
}
|
||||
|
||||
pub fn set_project(&mut self, x: MetricsAuxInfo) {
|
||||
self.set_endpoint_id(x.endpoint_id);
|
||||
self.branch = Some(x.branch_id);
|
||||
|
||||
@@ -93,7 +93,7 @@ struct RequestData {
|
||||
/// Or if we make it to proxy_pass
|
||||
success: bool,
|
||||
/// Indicates if the cplane started the new compute node for this request.
|
||||
cold_start_info: Option<String>,
|
||||
cold_start_info: Option<&'static str>,
|
||||
/// Tracks time from session start (HTTP request/libpq TCP handshake)
|
||||
/// Through to success/failure
|
||||
duration_us: u64,
|
||||
@@ -121,10 +121,12 @@ impl From<RequestMonitoring> for RequestData {
|
||||
region: value.region,
|
||||
error: value.error_kind.as_ref().map(|e| e.to_metric_label()),
|
||||
success: value.success,
|
||||
cold_start_info: value
|
||||
.cold_start_info
|
||||
.as_ref()
|
||||
.map(|x| serde_json::to_string(x).unwrap_or_default()),
|
||||
cold_start_info: value.cold_start_info.as_ref().map(|x| match x {
|
||||
crate::console::messages::ColdStartInfo::Unknown => "unknown",
|
||||
crate::console::messages::ColdStartInfo::Warm => "warm",
|
||||
crate::console::messages::ColdStartInfo::PoolHit => "pool_hit",
|
||||
crate::console::messages::ColdStartInfo::PoolMiss => "pool_miss",
|
||||
}),
|
||||
duration_us: SystemTime::from(value.first_packet)
|
||||
.elapsed()
|
||||
.unwrap_or_default()
|
||||
@@ -458,7 +460,7 @@ mod tests {
|
||||
region: "us-east-1",
|
||||
error: None,
|
||||
success: rng.gen(),
|
||||
cold_start_info: Some("no".into()),
|
||||
cold_start_info: Some("no"),
|
||||
duration_us: rng.gen_range(0..30_000_000),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ use crate::{
|
||||
config::ProxyConfig,
|
||||
console::{
|
||||
errors::{GetAuthInfoError, WakeComputeError},
|
||||
messages::ColdStartInfo,
|
||||
CachedNodeInfo,
|
||||
},
|
||||
context::RequestMonitoring,
|
||||
@@ -83,6 +84,7 @@ impl PoolingBackend {
|
||||
};
|
||||
|
||||
if let Some(client) = maybe_client {
|
||||
ctx.set_cold_start_info(ColdStartInfo::Warm);
|
||||
return Ok(client);
|
||||
}
|
||||
let conn_id = uuid::Uuid::new_v4();
|
||||
|
||||
Reference in New Issue
Block a user