mirror of
https://github.com/fawney19/Aether.git
synced 2026-10-07 18:07:47 +08:00
chore(proxy): guard metrics retention cleanup
This commit is contained in:
@@ -1031,22 +1031,38 @@ WHERE is_manual = 0
|
||||
&self,
|
||||
retain_1m_from_unix_secs: u64,
|
||||
retain_1h_from_unix_secs: u64,
|
||||
delete_limit: usize,
|
||||
) -> Result<ProxyNodeMetricsCleanupSummary, DataLayerError> {
|
||||
let deleted_1m =
|
||||
sqlx::query("DELETE FROM proxy_node_metrics_1m WHERE bucket_start_unix_secs < ?")
|
||||
.bind(i64::try_from(retain_1m_from_unix_secs).unwrap_or(i64::MAX))
|
||||
.execute(&self.pool)
|
||||
.await
|
||||
.map_sql_err()?
|
||||
.rows_affected() as usize;
|
||||
let delete_limit_i64 = i64::try_from(delete_limit.max(1)).unwrap_or(i64::MAX);
|
||||
let deleted_1m = sqlx::query(
|
||||
r#"
|
||||
DELETE FROM proxy_node_metrics_1m
|
||||
WHERE bucket_start_unix_secs < ?
|
||||
ORDER BY bucket_start_unix_secs ASC
|
||||
LIMIT ?
|
||||
"#,
|
||||
)
|
||||
.bind(i64::try_from(retain_1m_from_unix_secs).unwrap_or(i64::MAX))
|
||||
.bind(delete_limit_i64)
|
||||
.execute(&self.pool)
|
||||
.await
|
||||
.map_sql_err()?
|
||||
.rows_affected() as usize;
|
||||
|
||||
let deleted_1h =
|
||||
sqlx::query("DELETE FROM proxy_node_metrics_1h WHERE bucket_start_unix_secs < ?")
|
||||
.bind(i64::try_from(retain_1h_from_unix_secs).unwrap_or(i64::MAX))
|
||||
.execute(&self.pool)
|
||||
.await
|
||||
.map_sql_err()?
|
||||
.rows_affected() as usize;
|
||||
let deleted_1h = sqlx::query(
|
||||
r#"
|
||||
DELETE FROM proxy_node_metrics_1h
|
||||
WHERE bucket_start_unix_secs < ?
|
||||
ORDER BY bucket_start_unix_secs ASC
|
||||
LIMIT ?
|
||||
"#,
|
||||
)
|
||||
.bind(i64::try_from(retain_1h_from_unix_secs).unwrap_or(i64::MAX))
|
||||
.bind(delete_limit_i64)
|
||||
.execute(&self.pool)
|
||||
.await
|
||||
.map_sql_err()?
|
||||
.rows_affected() as usize;
|
||||
|
||||
Ok(ProxyNodeMetricsCleanupSummary {
|
||||
deleted_1m_rows: deleted_1m,
|
||||
|
||||
Reference in New Issue
Block a user