Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

refactor(audit-log): move audit log counter increment to after queue push for consistency

Victor Hugo dos Santosfdf7ae5681c4
diff --git a/backend/src/ee/services/audit-log/audit-log-queue.ts b/backend/src/ee/services/audit-log/audit-log-queue.ts
index d0b8ad3f1c..5454dd412a 100644
--- a/backend/src/ee/services/audit-log/audit-log-queue.ts
+++ b/backend/src/ee/services/audit-log/audit-log-queue.ts
@@ -74,11 +74,6 @@ export const auditLogQueueServiceFactory = async ({
const isClickHouseBatchEnabled = Boolean(clickhouseClient && CLICKHOUSE_AUDIT_LOG_ENABLED);
const pushToLog = async (data: TCreateAuditLogDTO) => {
- auditLogEnqueuedCounter.add(1, {
- "audit_log.event_type": data.event?.type ?? "unknown",
- "audit_log.actor_type": data.actor?.type ?? "unknown",
- ...(data.orgId ? { "infisical.organization.id": data.orgId } : {})
- });
await queueService.queue<QueueName.AuditLog>(QueueName.AuditLog, QueueJobs.AuditLog, data, {
removeOnFail: {
count: 3
@@ -86,6 +81,11 @@ export const auditLogQueueServiceFactory = async ({
removeOnComplete: true,
jobId: randomUUID()
});
+ auditLogEnqueuedCounter.add(1, {
+ "audit_log.event_type": data.event?.type ?? "unknown",
+ "audit_log.actor_type": data.actor?.type ?? "unknown",
+ ...(data.orgId ? { "infisical.organization.id": data.orgId } : {})
+ });
};
queueService.start(QueueName.AuditLog, async (job) => {
diff --git a/backend/src/lib/cache/with-cache.ts b/backend/src/lib/cache/with-cache.ts
index b34726f20a..6aab904929 100644
--- a/backend/src/lib/cache/with-cache.ts
+++ b/backend/src/lib/cache/with-cache.ts
@@ -125,8 +125,9 @@ export const withCacheFingerprint = async <T>({
if (markerValue !== null && cachedDataStr !== null) {
try {
const { payload } = JSON.parse(cachedDataStr) as TCachedData<T>;
+ const revived = applyReviver(payload, reviver);
permissionCacheLookupCounter.add(1, { "cache.result": "marker_hit" });
- return applyReviver(payload, reviver);
+ return revived;
} catch (err) {
logger.warn(
{ key: dataKey, err },
@@ -154,8 +155,9 @@ export const withCacheFingerprint = async <T>({
const cachedData = JSON.parse(cachedDataStr) as TCachedData<T>;
if (cachedData.fingerprint === currentFingerprint) {
await cacheSet(keyStore, markerKey, markerTtlSeconds, "1", "withCacheFingerprint: marker reset failed");
+ const revived = applyReviver(cachedData.payload, reviver);
permissionCacheLookupCounter.add(1, { "cache.result": "fingerprint_match" });
- return applyReviver(cachedData.payload, reviver);
+ return revived;
}
} catch (err) {
logger.error(
diff --git a/backend/src/server/plugins/error-handler.ts b/backend/src/server/plugins/error-handler.ts
index 4c2f997f12..11f457e5c0 100644
--- a/backend/src/server/plugins/error-handler.ts
+++ b/backend/src/server/plugins/error-handler.ts
@@ -215,7 +215,7 @@ export const fastifyErrHandler = fastifyPlugin(async (server: FastifyZodProvider
});
} else if (error instanceof RateLimitError) {
rateLimitExceededCounter.add(1, {
- "http.route": req.routerPath ?? "unknown",
+ "http.route": req.routeOptions.url ?? "unknown",
"http.request.method": req.method
});
void res.status(HttpStatusCodes.TooManyRequests).send({