1
0
Fork 0
mirror of synced 2024-06-18 18:54:55 +12:00

update maintenance to delete only hourly metrics older than 3 months

This commit is contained in:
Damodar Lohani 2022-10-23 07:29:13 +00:00
parent 8c3cfa877b
commit c8b5301267
3 changed files with 7 additions and 28 deletions

View file

@ -78,11 +78,10 @@ $cli
->trigger();
}
function notifyDeleteUsageStats(int $interval1h, int $interval1d)
function notifyDeleteUsageStats(int $interval1h)
{
(new Delete())
->setType(DELETE_TYPE_USAGE)
->setDateTime1d(DateTime::addSeconds(new \DateTime(), -1 * $interval1d))
->setDateTime1h(DateTime::addSeconds(new \DateTime(), -1 * $interval1h))
->trigger();
}
@ -144,11 +143,11 @@ $cli
$executionLogsRetention = (int) App::getEnv('_APP_MAINTENANCE_RETENTION_EXECUTION', '1209600');
$auditLogRetention = (int) App::getEnv('_APP_MAINTENANCE_RETENTION_AUDIT', '1209600');
$abuseLogsRetention = (int) App::getEnv('_APP_MAINTENANCE_RETENTION_ABUSE', '86400');
$usageStatsRetention1h = (int) App::getEnv('_APP_MAINTENANCE_RETENTION_USAGE_30M', '129600'); //36 hours
$usageStatsRetention1d = (int) App::getEnv('_APP_MAINTENANCE_RETENTION_USAGE_1D', '8640000'); // 100 days
$usageStatsRetention1h = (int) App::getEnv('_APP_MAINTENANCE_RETENTION_USAGE_1H', '8640000'); //100 days
$cacheRetention = (int) App::getEnv('_APP_MAINTENANCE_RETENTION_CACHE', '2592000'); // 30 days
Console::loop(function () use ($interval, $executionLogsRetention, $abuseLogsRetention, $auditLogRetention, $usageStatsRetention1h, $usageStatsRetention1d, $cacheRetention) {
Console::loop(function () use ($interval, $executionLogsRetention, $abuseLogsRetention, $auditLogRetention, $usageStatsRetention1h, $cacheRetention) {
$database = getConsoleDB();
$time = DateTime::now();
@ -157,7 +156,7 @@ $cli
notifyDeleteExecutionLogs($executionLogsRetention);
notifyDeleteAbuseLogs($abuseLogsRetention);
notifyDeleteAuditLogs($auditLogRetention);
notifyDeleteUsageStats($usageStatsRetention1h, $usageStatsRetention1d);
notifyDeleteUsageStats($usageStatsRetention1h);
notifyDeleteConnections();
notifyDeleteExpiredSessions();
renewCertificates($database);

View file

@ -217,16 +217,10 @@ class DeletesV1 extends Worker
* @param string $datetime1d
* @param string $datetime1h
*/
protected function deleteUsageStats(string $datetime1d, string $datetime1h)
protected function deleteUsageStats(string $datetime1h)
{
$this->deleteForProjectIds(function (string $projectId) use ($datetime1d, $datetime1h) {
$this->deleteForProjectIds(function (string $projectId) use ($datetime1h) {
$dbForProject = $this->getProjectDB($projectId);
// Delete Usage stats
$this->deleteByGroup('stats', [
Query::lessThan('time', $datetime1d),
Query::equal('period', ['1d']),
], $dbForProject);
$this->deleteByGroup('stats', [
Query::lessThan('time', $datetime1h),
Query::equal('period', ['1h']),

View file

@ -12,7 +12,6 @@ class Delete extends Event
protected ?string $resource = null;
protected ?string $datetime = null;
protected ?string $dateTime1h = null;
protected ?string $dateTime1d = null;
public function __construct()
@ -55,18 +54,6 @@ class Delete extends Event
return $this;
}
/**
* Set datetime for 1 day interval.
*
* @param string $datetime
* @return self
*/
public function setDateTime1d(string $datetime): self
{
$this->dateTime1d = $datetime;
return $this;
}
/**
* Sets datetime for 1h interval.
*
@ -140,7 +127,6 @@ class Delete extends Event
'document' => $this->document,
'resource' => $this->resource,
'datetime' => $this->datetime,
'dateTime1d' => $this->dateTime1d,
'dateTime1h' => $this->dateTime1h,
]);
}