mirror of
https://github.com/fawney19/Aether.git
synced 2026-10-07 01:47:47 +08:00
chore(proxy): guard metrics retention cleanup
This commit is contained in:
@@ -1448,22 +1448,52 @@ WHERE id = $1
|
||||
&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 < $1")
|
||||
.bind(i64::try_from(retain_1m_from_unix_secs).unwrap_or(i64::MAX))
|
||||
.execute(&self.pool)
|
||||
.await
|
||||
.map_postgres_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#"
|
||||
WITH expired AS (
|
||||
SELECT node_id, bucket_start_unix_secs
|
||||
FROM proxy_node_metrics_1m
|
||||
WHERE bucket_start_unix_secs < $1
|
||||
ORDER BY bucket_start_unix_secs ASC
|
||||
LIMIT $2
|
||||
)
|
||||
DELETE FROM proxy_node_metrics_1m metrics
|
||||
USING expired
|
||||
WHERE metrics.node_id = expired.node_id
|
||||
AND metrics.bucket_start_unix_secs = expired.bucket_start_unix_secs
|
||||
"#,
|
||||
)
|
||||
.bind(i64::try_from(retain_1m_from_unix_secs).unwrap_or(i64::MAX))
|
||||
.bind(delete_limit_i64)
|
||||
.execute(&self.pool)
|
||||
.await
|
||||
.map_postgres_err()?
|
||||
.rows_affected() as usize;
|
||||
|
||||
let deleted_1h =
|
||||
sqlx::query("DELETE FROM proxy_node_metrics_1h WHERE bucket_start_unix_secs < $1")
|
||||
.bind(i64::try_from(retain_1h_from_unix_secs).unwrap_or(i64::MAX))
|
||||
.execute(&self.pool)
|
||||
.await
|
||||
.map_postgres_err()?
|
||||
.rows_affected() as usize;
|
||||
let deleted_1h = sqlx::query(
|
||||
r#"
|
||||
WITH expired AS (
|
||||
SELECT node_id, bucket_start_unix_secs
|
||||
FROM proxy_node_metrics_1h
|
||||
WHERE bucket_start_unix_secs < $1
|
||||
ORDER BY bucket_start_unix_secs ASC
|
||||
LIMIT $2
|
||||
)
|
||||
DELETE FROM proxy_node_metrics_1h metrics
|
||||
USING expired
|
||||
WHERE metrics.node_id = expired.node_id
|
||||
AND metrics.bucket_start_unix_secs = expired.bucket_start_unix_secs
|
||||
"#,
|
||||
)
|
||||
.bind(i64::try_from(retain_1h_from_unix_secs).unwrap_or(i64::MAX))
|
||||
.bind(delete_limit_i64)
|
||||
.execute(&self.pool)
|
||||
.await
|
||||
.map_postgres_err()?
|
||||
.rows_affected() as usize;
|
||||
|
||||
Ok(ProxyNodeMetricsCleanupSummary {
|
||||
deleted_1m_rows: deleted_1m,
|
||||
|
||||
Reference in New Issue
Block a user