mirror of
https://github.com/fawney19/Aether.git
synced 2026-10-06 17:37:47 +08:00
chore: update gateway pressure observability
This commit is contained in:
@@ -252,6 +252,12 @@ impl UsageRuntimeAccess for GatewayDataState {
|
||||
GatewayDataState::usage_worker_queue(self)
|
||||
}
|
||||
|
||||
fn usage_worker_should_defer_for_database_pressure(&self) -> bool {
|
||||
self.database_pool_summary()
|
||||
.as_ref()
|
||||
.is_some_and(GatewayDataState::database_pool_summary_under_usage_worker_pressure)
|
||||
}
|
||||
|
||||
async fn body_capture_policy(&self) -> Result<UsageBodyCapturePolicy, DataLayerError> {
|
||||
let value = match GatewayDataState::find_system_config_value(self, REQUEST_RECORD_LEVEL_KEY)
|
||||
.await?
|
||||
|
||||
@@ -170,6 +170,25 @@ impl GatewayDataState {
|
||||
.and_then(|backends| backends.database_pool_summary())
|
||||
}
|
||||
|
||||
pub(crate) async fn postgres_observability_snapshot(
|
||||
&self,
|
||||
) -> Result<Option<aether_data::DatabasePostgresObservabilitySnapshot>, DataLayerError> {
|
||||
match &self.backends {
|
||||
Some(backends) => backends.postgres_observability_snapshot().await,
|
||||
None => Ok(None),
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) async fn postgres_activity_groups(
|
||||
&self,
|
||||
limit: i64,
|
||||
) -> Result<Vec<aether_data::DatabasePostgresActivityGroup>, DataLayerError> {
|
||||
match &self.backends {
|
||||
Some(backends) => backends.postgres_activity_groups(limit).await,
|
||||
None => Ok(Vec::new()),
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn database_pool_under_maintenance_pressure(&self) -> bool {
|
||||
self.database_pool_summary()
|
||||
.as_ref()
|
||||
@@ -182,6 +201,14 @@ impl GatewayDataState {
|
||||
summary.checked_out > 0 && summary.idle <= Self::maintenance_pool_idle_reserve(summary)
|
||||
}
|
||||
|
||||
pub(crate) fn database_pool_summary_under_usage_worker_pressure(
|
||||
summary: &aether_data::DatabasePoolSummary,
|
||||
) -> bool {
|
||||
summary.checked_out > 0
|
||||
&& (summary.checked_out >= summary.max_connections as usize
|
||||
|| summary.idle <= Self::usage_worker_pool_idle_reserve(summary))
|
||||
}
|
||||
|
||||
pub(crate) fn maintenance_pool_idle_reserve(
|
||||
summary: &aether_data::DatabasePoolSummary,
|
||||
) -> usize {
|
||||
@@ -201,6 +228,13 @@ impl GatewayDataState {
|
||||
ten_percent_ceil.clamp(2, 10).min(max_connections)
|
||||
}
|
||||
|
||||
fn usage_worker_pool_idle_reserve(summary: &aether_data::DatabasePoolSummary) -> usize {
|
||||
if summary.max_connections <= 1 {
|
||||
return 0;
|
||||
}
|
||||
1
|
||||
}
|
||||
|
||||
pub(crate) fn should_defer_maintenance_for_database_pool_pressure(
|
||||
&self,
|
||||
deferred_since: &mut Option<Instant>,
|
||||
|
||||
Reference in New Issue
Block a user