Skip to content

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

refactor(audit-log-stream): inline the delivery error bound in flagStreamFailing

Calvin045e6705cfcc
diff --git a/backend/src/ee/services/audit-log-stream-outbox/audit-log-stream-outbox-service.ts b/backend/src/ee/services/audit-log-stream-outbox/audit-log-stream-outbox-service.ts
index d47d29ca9b..5f36203022 100644
--- a/backend/src/ee/services/audit-log-stream-outbox/audit-log-stream-outbox-service.ts
+++ b/backend/src/ee/services/audit-log-stream-outbox/audit-log-stream-outbox-service.ts
@@ -16,7 +16,7 @@ import { TProjectDALFactory } from "@app/services/project/project-dal";
import { chunkAuditLogsByBatchLimit } from "../audit-log-stream/audit-log-stream-batching";
import { TAuditLogStreamDALFactory } from "../audit-log-stream/audit-log-stream-dal";
import { LogProvider, StreamMode } from "../audit-log-stream/audit-log-stream-enums";
-import { emitAuditLogStreamDeliveryFailed, truncateDeliveryError } from "../audit-log-stream/audit-log-stream-events";
+import { emitAuditLogStreamDeliveryFailed } from "../audit-log-stream/audit-log-stream-events";
import { LOG_STREAM_FACTORY_MAP } from "../audit-log-stream/audit-log-stream-factory";
import {
auditLogMatchesStreamFilter,
@@ -216,16 +216,16 @@ export const auditLogStreamOutboxServiceFactory = ({
}: { streamId: string; orgId: string; provider: string | null; errorMessage: string; droppedCount: number },
tx: Knex
) => {
- const truncatedError = truncateDeliveryError(errorMessage);
- const failingSince = await auditLogStreamOutboxDAL.markStreamFailing(
- { streamId, errorMessage: truncatedError },
- tx
- );
+ // Delivery errors are short axios or network messages, so this is only a guard: the event outbox
+ // rejects payloads over 16KB, and a throw from emit here would roll back the drop and leave the
+ // stream unflagged with no alert.
+ const boundedError = errorMessage.slice(0, 500);
+ const failingSince = await auditLogStreamOutboxDAL.markStreamFailing({ streamId, errorMessage: boundedError }, tx);
if (!failingSince) return;
await emitAuditLogStreamDeliveryFailed(
eventEmitter,
- { orgId, streamId, provider, errorMessage: truncatedError, droppedCount, failingSince },
+ { orgId, streamId, provider, errorMessage: boundedError, droppedCount, failingSince },
tx
);
};
diff --git a/backend/src/ee/services/audit-log-stream/audit-log-stream-events.ts b/backend/src/ee/services/audit-log-stream/audit-log-stream-events.ts
index 475a924709..82a2bc8162 100644
--- a/backend/src/ee/services/audit-log-stream/audit-log-stream-events.ts
+++ b/backend/src/ee/services/audit-log-stream/audit-log-stream-events.ts
@@ -6,8 +6,6 @@ import { TEventEmitter } from "@app/services/event-outbox/event-outbox-types";
export const AUDIT_LOG_STREAM_RESOURCE_TYPE = "audit-log.stream";
export const AUDIT_LOG_STREAM_DELIVERY_FAILED_EVENT = "audit-log.stream.delivery-failed";
-export const AUDIT_LOG_STREAM_ERROR_MAX_LENGTH = 500;
-
export const AuditLogStreamDeliveryFailedPayloadSchema = z.object({
provider: z.string(),
errorMessage: z.string(),
@@ -24,11 +22,6 @@ export type TAuditLogStreamDeliveryFailedInput = {
failingSince: Date;
};
-export const truncateDeliveryError = (message: string): string =>
- message.length > AUDIT_LOG_STREAM_ERROR_MAX_LENGTH
- ? `${message.slice(0, AUDIT_LOG_STREAM_ERROR_MAX_LENGTH)}...`
- : message;
-
export const emitAuditLogStreamDeliveryFailed = (
eventEmitter: TEventEmitter,
{ orgId, streamId, provider, errorMessage, droppedCount, failingSince }: TAuditLogStreamDeliveryFailedInput,