Skip to content

Commit

Permalink
Add 2 weeks to all alerts
Browse files Browse the repository at this point in the history
  • Loading branch information
prevostc committed Dec 22, 2023
1 parent 9976245 commit 71a6b42
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
4 changes: 2 additions & 2 deletions analytics/provisioning/alerting/alerts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ groups:
panelId: 1
noDataState: OK
execErrState: Error
for: 6h
for: 14d
annotations:
__dashboardUid__: dad68cbc-f965-4400-9db3-66a3bb4c447e
__panelId__: "1"
Expand Down Expand Up @@ -278,7 +278,7 @@ groups:
panelId: 1
noDataState: OK
execErrState: Error
for: 6h
for: 14d
annotations:
__dashboardUid__: dad68cbc-f965-4400-9db3-66a3bb4c447e
__panelId__: "1"
Expand Down
7 changes: 6 additions & 1 deletion src/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@ export const DISCORD_NOTIFY_UNEVENTFUL_HARVEST = process.env.DISCORD_NOTIFY_UNEV
export const DISCORD_PING_ROLE_IDS_ON_ERROR = process.env.DISCORD_PING_ROLE_IDS_ON_ERROR
? process.env.DISCORD_PING_ROLE_IDS_ON_ERROR.split(',')
: [];
export const DB_REPORTS_RETENTION_IN_DAYS = parseInt(process.env.DB_REPORTS_RETENTION_IN_DAYS || '10', 10);

// retain all reports for 7 days and daily reports for 30 days
// we need to cleanup reports to avoid breaking heroku's 10k rows limit
export const DB_REPORTS_FULL_RETENTION_IN_DAYS = parseInt(process.env.DB_REPORTS_RETENTION_IN_DAYS || '7', 10);
export const DB_REPORTS_DAILY_RETENTION_IN_DAYS = parseInt(process.env.DB_REPORTS_DAILY_RETENTION_IN_DAYS || '30', 10);

export const REPORT_URL_TEMPLATE = process.env.REPORT_URL_TEMPLATE || 'https://localhost/report/{{reportId}}';
export const CENSOR_SECRETS_FROM_REPORTS = process.env.CENSOR_SECRETS_FROM_REPORTS
? process.env.CENSOR_SECRETS_FROM_REPORTS.split(',')
Expand Down
20 changes: 15 additions & 5 deletions src/lib/db/db-report.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { rootLogger } from '../../util/logger';
import { DB_REPORTS_RETENTION_IN_DAYS } from '../config';
import { DB_REPORTS_FULL_RETENTION_IN_DAYS, DB_REPORTS_DAILY_RETENTION_IN_DAYS } from '../config';
import { HarvestReport } from '../harvest-report';
import { serializeReport } from '../reports';
import { RevenueBridgeHarvestReport } from '../revenue-bridge-harvest-report';
Expand All @@ -10,15 +10,25 @@ import { db_query, db_query_one } from './utils';
const logger = rootLogger.child({ module: 'db-report' });

export async function applyRetention() {
logger.debug({ msg: 'Applying retention', data: { DB_REPORTS_RETENTION_IN_DAYS } });
logger.debug({
msg: 'Applying retention',
data: { DB_REPORTS_FULL_RETENTION_IN_DAYS, DB_REPORTS_DAILY_RETENTION_IN_DAYS },
});
await db_query(
`
DELETE FROM raw_report
WHERE datetime < (NOW() - (%L || ' day')::interval)
WHERE
(datetime < (NOW() - (%L || ' day')::interval) and extract(hour from datetime) != 0)
OR
(datetime < (NOW() - (%L || ' day')::interval))
`,
[DB_REPORTS_RETENTION_IN_DAYS.toFixed()]
[DB_REPORTS_FULL_RETENTION_IN_DAYS.toFixed(), DB_REPORTS_DAILY_RETENTION_IN_DAYS.toFixed()]
);
logger.info({ msg: 'Retention applied', data: { DB_REPORTS_RETENTION_IN_DAYS } });
logger.info({
msg: 'Retention applied',
data: { DB_REPORTS_FULL_RETENTION_IN_DAYS, DB_REPORTS_DAILY_RETENTION_IN_DAYS },
});
}

export function insertHarvestReport(report: HarvestReport) {
Expand Down

0 comments on commit 71a6b42

Please sign in to comment.