Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(server): auditlog won't push if retention period is zero #1510

Merged
merged 2 commits into from
Mar 1, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 22 additions & 12 deletions backend/src/ee/services/audit-log/audit-log-queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,40 @@ export const auditLogQueueServiceFactory = ({
licenseService
}: TAuditLogQueueServiceFactoryDep) => {
const pushToLog = async (data: TCreateAuditLogDTO) => {
await queueService.queue(QueueName.AuditLog, QueueJobs.AuditLog, data, {
removeOnFail: {
count: 5
},
removeOnComplete: true
});
};

queueService.start(QueueName.AuditLog, async (job) => {
const { actor, event, ipAddress, projectId, userAgent, userAgentType } = job.data;
let { orgId } = job.data;
let { orgId } = data;
const MS_IN_DAY = 24 * 60 * 60 * 1000;

if (!orgId) {
// it will never be undefined for both org and project id
// TODO(akhilmhdh): use caching here in dal to avoid db calls
const project = await projectDAL.findById(projectId as string);
const project = await projectDAL.findById(data.projectId as string);
orgId = project.orgId;
}

const plan = await licenseService.getPlan(orgId);
const ttl = plan.auditLogsRetentionDays * MS_IN_DAY;
// skip inserting if audit log retention is 0 meaning its not supported
if (ttl === 0) return;

await queueService.queue(
QueueName.AuditLog,
QueueJobs.AuditLog,
{ ...data, orgId },
{
removeOnFail: {
count: 3
},
removeOnComplete: true
}
);
};

queueService.start(QueueName.AuditLog, async (job) => {
const { actor, event, ipAddress, projectId, userAgent, userAgentType, orgId } = job.data;
const MS_IN_DAY = 24 * 60 * 60 * 1000;

const plan = await licenseService.getPlan(orgId as string);
const ttl = plan.auditLogsRetentionDays * MS_IN_DAY;
await auditLogDAL.create({
actor: actor.type,
actorMetadata: actor.metadata,
Expand Down
Loading