-
Notifications
You must be signed in to change notification settings - Fork 230
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add cron jobs to delete incident and alert metrics older than 180 days
- Loading branch information
Showing
4 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import OneUptimeDate from "Common/Types/Date"; | ||
import RunCron from "../../Utils/Cron"; | ||
import { EVERY_DAY } from "Common/Utils/CronTime"; | ||
import logger from "Common/Server/Utils/Logger"; | ||
import MetricService from "Common/Server/Services/MetricService"; | ||
import QueryHelper from "Common/Server/Types/Database/QueryHelper"; | ||
import { ServiceType } from "Common/Models/AnalyticsModels/Metric"; | ||
|
||
RunCron( | ||
"Metric:DeleteAlertMetricsOlderThanXDays", | ||
{ schedule: EVERY_DAY, runOnStartup: true }, | ||
async () => { | ||
const olderThanDays: number = 180; // store for 6 months. | ||
|
||
logger.debug("Checking Metric:DeleteAlertMetricsOlderThanXDays"); | ||
|
||
logger.debug(`Deleting Alert Metrics older than ${olderThanDays} days`); | ||
|
||
await MetricService.deleteBy({ | ||
query: { | ||
createdAt: QueryHelper.lessThan( | ||
OneUptimeDate.getSomeDaysAgo(olderThanDays), | ||
), | ||
serviceType: ServiceType.Alert, | ||
}, | ||
props: { | ||
isRoot: true, | ||
}, | ||
}); | ||
}, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import OneUptimeDate from "Common/Types/Date"; | ||
import RunCron from "../../Utils/Cron"; | ||
import { EVERY_DAY } from "Common/Utils/CronTime"; | ||
import logger from "Common/Server/Utils/Logger"; | ||
import MetricService from "Common/Server/Services/MetricService"; | ||
import QueryHelper from "Common/Server/Types/Database/QueryHelper"; | ||
import { ServiceType } from "Common/Models/AnalyticsModels/Metric"; | ||
|
||
RunCron( | ||
"Metric:DeleteIncidentMetricsOlderThanXDays", | ||
{ schedule: EVERY_DAY, runOnStartup: true }, | ||
async () => { | ||
const olderThanDays: number = 180; // store for 6 months. | ||
|
||
logger.debug("Checking Metric:DeleteIncidentMetricsOlderThanXDays"); | ||
|
||
logger.debug(`Deleting Incident Metrics older than ${olderThanDays} days`); | ||
|
||
await MetricService.deleteBy({ | ||
query: { | ||
createdAt: QueryHelper.lessThan( | ||
OneUptimeDate.getSomeDaysAgo(olderThanDays), | ||
), | ||
serviceType: ServiceType.Incident, | ||
}, | ||
props: { | ||
isRoot: true, | ||
}, | ||
}); | ||
}, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters