@dads-framework/audit 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +21 -0
- package/README.md +69 -2
- package/dist/audit.tsbuildinfo +1 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +24 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/actor/compose-subject-to-audit-actor.d.ts +32 -0
- package/dist/lib/actor/compose-subject-to-audit-actor.d.ts.map +1 -0
- package/dist/lib/actor/compose-subject-to-audit-actor.js +66 -0
- package/dist/lib/actor/compose-subject-to-audit-actor.js.map +1 -0
- package/dist/lib/audit-plugin.d.ts +21 -0
- package/dist/lib/audit-plugin.d.ts.map +1 -0
- package/dist/lib/audit-plugin.js +61 -0
- package/dist/lib/audit-plugin.js.map +1 -0
- package/dist/lib/client-diagnostics/client-diagnostic-event.ids.d.ts +5 -0
- package/dist/lib/client-diagnostics/client-diagnostic-event.ids.d.ts.map +1 -0
- package/dist/lib/client-diagnostics/client-diagnostic-event.ids.js +4 -0
- package/dist/lib/client-diagnostics/client-diagnostic-event.ids.js.map +1 -0
- package/dist/lib/client-diagnostics/client-diagnostics.route-handlers.d.ts +23 -0
- package/dist/lib/client-diagnostics/client-diagnostics.route-handlers.d.ts.map +1 -0
- package/dist/lib/client-diagnostics/client-diagnostics.route-handlers.js +27 -0
- package/dist/lib/client-diagnostics/client-diagnostics.route-handlers.js.map +1 -0
- package/dist/lib/client-diagnostics/client-diagnostics.routes.d.ts +18 -0
- package/dist/lib/client-diagnostics/client-diagnostics.routes.d.ts.map +1 -0
- package/dist/lib/client-diagnostics/client-diagnostics.routes.js +41 -0
- package/dist/lib/client-diagnostics/client-diagnostics.routes.js.map +1 -0
- package/dist/lib/client-diagnostics/logic/client-diagnostic-row.d.ts +30 -0
- package/dist/lib/client-diagnostics/logic/client-diagnostic-row.d.ts.map +1 -0
- package/dist/lib/client-diagnostics/logic/client-diagnostic-row.js +39 -0
- package/dist/lib/client-diagnostics/logic/client-diagnostic-row.js.map +1 -0
- package/dist/lib/client-diagnostics/record-client-diagnostics.d.ts +29 -0
- package/dist/lib/client-diagnostics/record-client-diagnostics.d.ts.map +1 -0
- package/dist/lib/client-diagnostics/record-client-diagnostics.js +40 -0
- package/dist/lib/client-diagnostics/record-client-diagnostics.js.map +1 -0
- package/dist/lib/compose-audit.d.ts +27 -0
- package/dist/lib/compose-audit.d.ts.map +1 -0
- package/dist/lib/compose-audit.js +38 -0
- package/dist/lib/compose-audit.js.map +1 -0
- package/dist/lib/database/attach-audit-trigger.d.ts +34 -0
- package/dist/lib/database/attach-audit-trigger.d.ts.map +1 -0
- package/dist/lib/database/attach-audit-trigger.js +40 -0
- package/dist/lib/database/attach-audit-trigger.js.map +1 -0
- package/dist/lib/database/audit-log-position.ids.d.ts +13 -0
- package/dist/lib/database/audit-log-position.ids.d.ts.map +1 -0
- package/dist/lib/database/audit-log-position.ids.js +11 -0
- package/dist/lib/database/audit-log-position.ids.js.map +1 -0
- package/dist/lib/database/audit-row-json.d.ts +10 -0
- package/dist/lib/database/audit-row-json.d.ts.map +1 -0
- package/dist/lib/database/audit-row-json.js +2 -0
- package/dist/lib/database/audit-row-json.js.map +1 -0
- package/dist/lib/database/audit-trigger-allowlist.d.ts +4 -0
- package/dist/lib/database/audit-trigger-allowlist.d.ts.map +1 -0
- package/dist/lib/database/audit-trigger-allowlist.js +8 -0
- package/dist/lib/database/audit-trigger-allowlist.js.map +1 -0
- package/dist/lib/database/configure-audit-triggers.d.ts +8 -0
- package/dist/lib/database/configure-audit-triggers.d.ts.map +1 -0
- package/dist/lib/database/configure-audit-triggers.js +27 -0
- package/dist/lib/database/configure-audit-triggers.js.map +1 -0
- package/dist/lib/database/configure-plugin-audit-triggers.d.ts +11 -0
- package/dist/lib/database/configure-plugin-audit-triggers.d.ts.map +1 -0
- package/dist/lib/database/configure-plugin-audit-triggers.js +23 -0
- package/dist/lib/database/configure-plugin-audit-triggers.js.map +1 -0
- package/dist/lib/database/generated-tables/audit-log.tables.d.ts +363 -0
- package/dist/lib/database/generated-tables/audit-log.tables.d.ts.map +1 -0
- package/dist/lib/database/generated-tables/audit-log.tables.js +53 -0
- package/dist/lib/database/generated-tables/audit-log.tables.js.map +1 -0
- package/dist/lib/database/generated-tables/client-diagnostic-events.tables.d.ts +376 -0
- package/dist/lib/database/generated-tables/client-diagnostic-events.tables.d.ts.map +1 -0
- package/dist/lib/database/generated-tables/client-diagnostic-events.tables.js +45 -0
- package/dist/lib/database/generated-tables/client-diagnostic-events.tables.js.map +1 -0
- package/dist/lib/database/generated-tables/known-fault-fingerprints.tables.d.ts +76 -0
- package/dist/lib/database/generated-tables/known-fault-fingerprints.tables.d.ts.map +1 -0
- package/dist/lib/database/generated-tables/known-fault-fingerprints.tables.js +32 -0
- package/dist/lib/database/generated-tables/known-fault-fingerprints.tables.js.map +1 -0
- package/dist/lib/database/generated-tables/request-log.tables.d.ts +678 -0
- package/dist/lib/database/generated-tables/request-log.tables.d.ts.map +1 -0
- package/dist/lib/database/generated-tables/request-log.tables.js +59 -0
- package/dist/lib/database/generated-tables/request-log.tables.js.map +1 -0
- package/dist/lib/database/migrations/20260910233455_audit.migration.d.ts +5 -0
- package/dist/lib/database/migrations/20260910233455_audit.migration.d.ts.map +1 -0
- package/dist/lib/database/migrations/20260910233455_audit.migration.js +304 -0
- package/dist/lib/database/migrations/20260910233455_audit.migration.js.map +1 -0
- package/dist/lib/database/readers/audit-log-reader.interface.d.ts +82 -0
- package/dist/lib/database/readers/audit-log-reader.interface.d.ts.map +1 -0
- package/dist/lib/database/readers/audit-log-reader.interface.js +10 -0
- package/dist/lib/database/readers/audit-log-reader.interface.js.map +1 -0
- package/dist/lib/database/readers/drizzle-audit-log-reader.d.ts +16 -0
- package/dist/lib/database/readers/drizzle-audit-log-reader.d.ts.map +1 -0
- package/dist/lib/database/readers/drizzle-audit-log-reader.js +197 -0
- package/dist/lib/database/readers/drizzle-audit-log-reader.js.map +1 -0
- package/dist/lib/database/readers/drizzle-fault-alert-reader.d.ts +36 -0
- package/dist/lib/database/readers/drizzle-fault-alert-reader.d.ts.map +1 -0
- package/dist/lib/database/readers/drizzle-fault-alert-reader.js +113 -0
- package/dist/lib/database/readers/drizzle-fault-alert-reader.js.map +1 -0
- package/dist/lib/database/readers/drizzle-request-log-reader.d.ts +16 -0
- package/dist/lib/database/readers/drizzle-request-log-reader.d.ts.map +1 -0
- package/dist/lib/database/readers/drizzle-request-log-reader.js +88 -0
- package/dist/lib/database/readers/drizzle-request-log-reader.js.map +1 -0
- package/dist/lib/database/readers/fault-alert-reader.interface.d.ts +73 -0
- package/dist/lib/database/readers/fault-alert-reader.interface.d.ts.map +1 -0
- package/dist/lib/database/readers/fault-alert-reader.interface.js +13 -0
- package/dist/lib/database/readers/fault-alert-reader.interface.js.map +1 -0
- package/dist/lib/database/readers/request-log-reader.interface.d.ts +64 -0
- package/dist/lib/database/readers/request-log-reader.interface.d.ts.map +1 -0
- package/dist/lib/database/readers/request-log-reader.interface.js +9 -0
- package/dist/lib/database/readers/request-log-reader.interface.js.map +1 -0
- package/dist/lib/database/testing/audited-fixture-tables.d.ts +14 -0
- package/dist/lib/database/testing/audited-fixture-tables.d.ts.map +1 -0
- package/dist/lib/database/testing/audited-fixture-tables.js +46 -0
- package/dist/lib/database/testing/audited-fixture-tables.js.map +1 -0
- package/dist/lib/database/writers/client-diagnostic-writer.interface.d.ts +20 -0
- package/dist/lib/database/writers/client-diagnostic-writer.interface.d.ts.map +1 -0
- package/dist/lib/database/writers/client-diagnostic-writer.interface.js +3 -0
- package/dist/lib/database/writers/client-diagnostic-writer.interface.js.map +1 -0
- package/dist/lib/database/writers/drizzle-client-diagnostic-writer.d.ts +11 -0
- package/dist/lib/database/writers/drizzle-client-diagnostic-writer.d.ts.map +1 -0
- package/dist/lib/database/writers/drizzle-client-diagnostic-writer.js +46 -0
- package/dist/lib/database/writers/drizzle-client-diagnostic-writer.js.map +1 -0
- package/dist/lib/database/writers/drizzle-request-log-writer.d.ts +9 -0
- package/dist/lib/database/writers/drizzle-request-log-writer.d.ts.map +1 -0
- package/dist/lib/database/writers/drizzle-request-log-writer.js +17 -0
- package/dist/lib/database/writers/drizzle-request-log-writer.js.map +1 -0
- package/dist/lib/database/writers/request-log-writer.interface.d.ts +17 -0
- package/dist/lib/database/writers/request-log-writer.interface.d.ts.map +1 -0
- package/dist/lib/database/writers/request-log-writer.interface.js +10 -0
- package/dist/lib/database/writers/request-log-writer.interface.js.map +1 -0
- package/dist/lib/fault-alerts/alert-new-faults.job.d.ts +48 -0
- package/dist/lib/fault-alerts/alert-new-faults.job.d.ts.map +1 -0
- package/dist/lib/fault-alerts/alert-new-faults.job.js +105 -0
- package/dist/lib/fault-alerts/alert-new-faults.job.js.map +1 -0
- package/dist/lib/fault-alerts/logic/describe-fault-line.d.ts +16 -0
- package/dist/lib/fault-alerts/logic/describe-fault-line.d.ts.map +1 -0
- package/dist/lib/fault-alerts/logic/describe-fault-line.js +21 -0
- package/dist/lib/fault-alerts/logic/describe-fault-line.js.map +1 -0
- package/dist/lib/fault-alerts/logic/summarize-new-faults.d.ts +51 -0
- package/dist/lib/fault-alerts/logic/summarize-new-faults.d.ts.map +1 -0
- package/dist/lib/fault-alerts/logic/summarize-new-faults.js +56 -0
- package/dist/lib/fault-alerts/logic/summarize-new-faults.js.map +1 -0
- package/dist/lib/fault-alerts/new-faults.email-template.d.ts +8 -0
- package/dist/lib/fault-alerts/new-faults.email-template.d.ts.map +1 -0
- package/dist/lib/fault-alerts/new-faults.email-template.js +66 -0
- package/dist/lib/fault-alerts/new-faults.email-template.js.map +1 -0
- package/dist/lib/jobs/prune-client-diagnostics.job.d.ts +25 -0
- package/dist/lib/jobs/prune-client-diagnostics.job.d.ts.map +1 -0
- package/dist/lib/jobs/prune-client-diagnostics.job.js +38 -0
- package/dist/lib/jobs/prune-client-diagnostics.job.js.map +1 -0
- package/dist/lib/jobs/prune-request-log.job.d.ts +23 -0
- package/dist/lib/jobs/prune-request-log.job.d.ts.map +1 -0
- package/dist/lib/jobs/prune-request-log.job.js +36 -0
- package/dist/lib/jobs/prune-request-log.job.js.map +1 -0
- package/dist/lib/jobs/retention-window.d.ts +3 -0
- package/dist/lib/jobs/retention-window.d.ts.map +1 -0
- package/dist/lib/jobs/retention-window.js +10 -0
- package/dist/lib/jobs/retention-window.js.map +1 -0
- package/dist/lib/request-log/insert-foreign-rows.d.ts +21 -0
- package/dist/lib/request-log/insert-foreign-rows.d.ts.map +1 -0
- package/dist/lib/request-log/insert-foreign-rows.js +86 -0
- package/dist/lib/request-log/insert-foreign-rows.js.map +1 -0
- package/dist/lib/request-log/postgres-request-log-sink.d.ts +64 -0
- package/dist/lib/request-log/postgres-request-log-sink.d.ts.map +1 -0
- package/dist/lib/request-log/postgres-request-log-sink.js +168 -0
- package/dist/lib/request-log/postgres-request-log-sink.js.map +1 -0
- package/dist/schema.d.ts +6 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +5 -0
- package/dist/schema.js.map +1 -0
- package/dist/testing/audit-log-record.factory.d.ts +13 -0
- package/dist/testing/audit-log-record.factory.d.ts.map +1 -0
- package/dist/testing/audit-log-record.factory.js +46 -0
- package/dist/testing/audit-log-record.factory.js.map +1 -0
- package/dist/testing/audit-log.factory.d.ts +14 -0
- package/dist/testing/audit-log.factory.d.ts.map +1 -0
- package/dist/testing/audit-log.factory.js +30 -0
- package/dist/testing/audit-log.factory.js.map +1 -0
- package/dist/testing/index.d.ts +4 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +5 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/testing/request-log.factory.d.ts +13 -0
- package/dist/testing/request-log.factory.d.ts.map +1 -0
- package/dist/testing/request-log.factory.js +40 -0
- package/dist/testing/request-log.factory.js.map +1 -0
- package/package.json +67 -4
- package/src/lib/database/migrations/20260910233455_audit.migration.ts +345 -0
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { defineEmailTemplate, EmailBadge, EmailHeading, EmailText, } from "@dads-framework/email-templates";
|
|
5
|
+
/**
|
|
6
|
+
* The email that says something is newly broken.
|
|
7
|
+
*
|
|
8
|
+
* Deliberately dull and short. This arrives when someone is not looking for
|
|
9
|
+
* it, so it has to answer two questions before anyone decides whether to care:
|
|
10
|
+
* what is new, and how much of it is there. Everything else — the stack, the
|
|
11
|
+
* environment, the request it belonged to — is one fingerprint lookup away and
|
|
12
|
+
* does not belong in an email that might be read on a phone.
|
|
13
|
+
*
|
|
14
|
+
* No links, because there is no diagnostics page to link to yet and a dead
|
|
15
|
+
* link in an alert is worse than no link.
|
|
16
|
+
*/
|
|
17
|
+
const props = z.object({
|
|
18
|
+
faults: z.array(z.string()).meta({
|
|
19
|
+
description: "One line per newly-seen fault type, loudest first, already formatted by `describeFaultLine`. Never empty — an alert with nothing in it is not sent.",
|
|
20
|
+
}),
|
|
21
|
+
totalOccurrences: z.number().int().nonnegative().meta({
|
|
22
|
+
description: "Occurrences across every new fault found, including any trimmed from the list below.",
|
|
23
|
+
}),
|
|
24
|
+
truncated: z.boolean().meta({
|
|
25
|
+
description: "True when more new faults were found than one email should carry.",
|
|
26
|
+
}),
|
|
27
|
+
windowHours: z.number().int().positive().meta({
|
|
28
|
+
description: "How far back the sweep looked for first occurrences.",
|
|
29
|
+
}),
|
|
30
|
+
});
|
|
31
|
+
export const newFaultsEmailTemplate = defineEmailTemplate({
|
|
32
|
+
name: "audit.new-faults",
|
|
33
|
+
description: "Tells the operations address that fault types never seen before have started happening, with how often and roughly where.",
|
|
34
|
+
props,
|
|
35
|
+
subject: ({ faults }) => faults.length === 1
|
|
36
|
+
? "1 new application fault"
|
|
37
|
+
: `${faults.length} new application faults`,
|
|
38
|
+
preview: ({ totalOccurrences }) => `${totalOccurrences} occurrences since the last sweep`,
|
|
39
|
+
body: ({ faults, totalOccurrences, truncated, windowHours }) => (_jsxs(_Fragment, { children: [_jsx(EmailBadge, { tone: "danger", children: `${faults.length} new` }), _jsx(EmailHeading, { children: "Something new is failing" }), _jsxs(EmailText, { children: [faults.length === 1
|
|
40
|
+
? "One fault type"
|
|
41
|
+
: `${faults.length} fault types`, " ", "appeared for the first time in the last ", windowHours, " ", windowHours === 1 ? "hour" : "hours", ", accounting for", " ", totalOccurrences, " ", totalOccurrences === 1 ? "occurrence" : "occurrences", "."] }), faults.map((line) => (_jsx(EmailText, { children: line }, line))), truncated ? (_jsx(EmailText, { children: "More new faults were found than this email carries. Query request_log and client_diagnostic_events directly for the full set." })) : null] })),
|
|
42
|
+
samples: {
|
|
43
|
+
"one-fault": {
|
|
44
|
+
faults: ["TypeError (server) — 3 occurrences at /api/orders · a1b2c3d4"],
|
|
45
|
+
totalOccurrences: 3,
|
|
46
|
+
truncated: false,
|
|
47
|
+
windowHours: 1,
|
|
48
|
+
},
|
|
49
|
+
"both-origins": {
|
|
50
|
+
faults: [
|
|
51
|
+
"DomainError (server) — 204 occurrences at /api/orders/:orderId · 9f8e7d6c",
|
|
52
|
+
"render (client) — 12 occurrences at 0192f2a0 · 1a2b3c4d",
|
|
53
|
+
],
|
|
54
|
+
totalOccurrences: 216,
|
|
55
|
+
truncated: false,
|
|
56
|
+
windowHours: 1,
|
|
57
|
+
},
|
|
58
|
+
truncated: {
|
|
59
|
+
faults: ["ZodError (client) — 51 occurrences · deadbeef"],
|
|
60
|
+
totalOccurrences: 900,
|
|
61
|
+
truncated: true,
|
|
62
|
+
windowHours: 6,
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
//# sourceMappingURL=new-faults.email-template.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"new-faults.email-template.js","sourceRoot":"","sources":["../../../src/lib/fault-alerts/new-faults.email-template.tsx"],"names":[],"m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
import { type JobDefinition, type JobLog } from "@dads-framework/job-queue";
|
|
3
|
+
import type { ClientDiagnosticWriter } from "../database/writers/client-diagnostic-writer.interface.js";
|
|
4
|
+
export declare const PRUNE_CLIENT_DIAGNOSTICS_JOB = "audit.prune-client-diagnostics";
|
|
5
|
+
export type CreatePruneClientDiagnosticsJobDeps = {
|
|
6
|
+
readonly writer: Pick<ClientDiagnosticWriter, "deleteRecordedBefore">;
|
|
7
|
+
readonly clock: Pick<Clock, "now">;
|
|
8
|
+
/** Days a reported fault survives before this sweep deletes it. */
|
|
9
|
+
readonly retentionDays: number;
|
|
10
|
+
readonly log: JobLog;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Deletes every `client_diagnostic_events` row older than `retentionDays`.
|
|
14
|
+
*
|
|
15
|
+
* Its own clock, shorter than `request_log`'s by default, because an
|
|
16
|
+
* exception message is the one free-text column in either table and a page
|
|
17
|
+
* can compose one from whatever a user typed. A fault stops being worth
|
|
18
|
+
* keeping once the release that produced it is gone; an address stays useful
|
|
19
|
+
* for longer. Two questions, two windows.
|
|
20
|
+
*
|
|
21
|
+
* Runs an hour after the request-log sweep so the two never contend for the
|
|
22
|
+
* same connections, and under the job system actor like every other job.
|
|
23
|
+
*/
|
|
24
|
+
export declare function createPruneClientDiagnosticsJob(deps: CreatePruneClientDiagnosticsJobDeps): JobDefinition;
|
|
25
|
+
//# sourceMappingURL=prune-client-diagnostics.job.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prune-client-diagnostics.job.d.ts","sourceRoot":"","sources":["../../../src/lib/jobs/prune-client-diagnostics.job.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAGL,KAAK,aAAa,EAClB,KAAK,MAAM,EACZ,MAAM,2BAA2B,CAAC;AAEnC,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,2DAA2D,CAAC;AAOxG,eAAO,MAAM,4BAA4B,mCAAmC,CAAC;AAE7E,MAAM,MAAM,mCAAmC,GAAG;IAChD,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,sBAAsB,EAAE,sBAAsB,CAAC,CAAC;IACtE,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IACnC,mEAAmE;IACnE,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,wBAAgB,+BAA+B,CAC7C,IAAI,EAAE,mCAAmC,GACxC,aAAa,CAuBf"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { cronSchedule, defineJob, } from "@dads-framework/job-queue";
|
|
3
|
+
import { requirePositiveIntegerRetentionDays, retentionCutoff, } from "./retention-window.js";
|
|
4
|
+
export const PRUNE_CLIENT_DIAGNOSTICS_JOB = "audit.prune-client-diagnostics";
|
|
5
|
+
/**
|
|
6
|
+
* Deletes every `client_diagnostic_events` row older than `retentionDays`.
|
|
7
|
+
*
|
|
8
|
+
* Its own clock, shorter than `request_log`'s by default, because an
|
|
9
|
+
* exception message is the one free-text column in either table and a page
|
|
10
|
+
* can compose one from whatever a user typed. A fault stops being worth
|
|
11
|
+
* keeping once the release that produced it is gone; an address stays useful
|
|
12
|
+
* for longer. Two questions, two windows.
|
|
13
|
+
*
|
|
14
|
+
* Runs an hour after the request-log sweep so the two never contend for the
|
|
15
|
+
* same connections, and under the job system actor like every other job.
|
|
16
|
+
*/
|
|
17
|
+
export function createPruneClientDiagnosticsJob(deps) {
|
|
18
|
+
requirePositiveIntegerRetentionDays(deps.retentionDays);
|
|
19
|
+
return defineJob({
|
|
20
|
+
name: PRUNE_CLIENT_DIAGNOSTICS_JOB,
|
|
21
|
+
payload: z.strictObject({}),
|
|
22
|
+
retry: { attempts: 5, backoffMs: 1_000 },
|
|
23
|
+
schedules: [
|
|
24
|
+
cronSchedule({
|
|
25
|
+
id: "audit.prune-client-diagnostics.daily",
|
|
26
|
+
pattern: "0 0 4 * * *",
|
|
27
|
+
timeZone: "UTC",
|
|
28
|
+
payload: {},
|
|
29
|
+
}),
|
|
30
|
+
],
|
|
31
|
+
run: async () => {
|
|
32
|
+
const cutoff = retentionCutoff(deps.clock.now(), deps.retentionDays);
|
|
33
|
+
const deleted = await deps.writer.deleteRecordedBefore(cutoff);
|
|
34
|
+
deps.log.info({ event: "client-diagnostics.pruned", deleted, cutoff }, "client_diagnostic_events rows pruned");
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=prune-client-diagnostics.job.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prune-client-diagnostics.job.js","sourceRoot":"","sources":["../../../src/lib/jobs/prune-client-diagnostics.job.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,OAAO,EACL,YAAY,EACZ,SAAS,GAGV,MAAM,2BAA2B,CAAC;AAInC,OAAO,EACL,mCAAmC,EACnC,eAAe,GAChB,MAAM,uBAAuB,CAAC;AAE/B,MAAM,CAAC,MAAM,4BAA4B,GAAG,gCAAgC,CAAC;AAU7E;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,+BAA+B,CAC7C,IAAyC;IAEzC,mCAAmC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;IACxD,OAAO,SAAS,CAAC;QACf,IAAI,EAAE,4BAA4B;QAClC,OAAO,EAAE,CAAC,CAAC,YAAY,CAAC,EAAE,CAAC;QAC3B,KAAK,EAAE,EAAE,QAAQ,EAAE,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE;QACxC,SAAS,EAAE;YACT,YAAY,CAAC;gBACX,EAAE,EAAE,sCAAsC;gBAC1C,OAAO,EAAE,aAAa;gBACtB,QAAQ,EAAE,KAAK;gBACf,OAAO,EAAE,EAAE;aACZ,CAAC;SACH;QACD,GAAG,EAAE,KAAK,IAAI,EAAE;YACd,MAAM,MAAM,GAAG,eAAe,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;YACrE,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,oBAAoB,CAAC,MAAM,CAAC,CAAC;YAC/D,IAAI,CAAC,GAAG,CAAC,IAAI,CACX,EAAE,KAAK,EAAE,2BAA2B,EAAE,OAAO,EAAE,MAAM,EAAE,EACvD,sCAAsC,CACvC,CAAC;QACJ,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Clock } from "@dads-framework/clock";
|
|
2
|
+
import { type JobDefinition, type JobLog } from "@dads-framework/job-queue";
|
|
3
|
+
import type { RequestLogWriter } from "../database/writers/request-log-writer.interface.js";
|
|
4
|
+
export declare const PRUNE_REQUEST_LOG_JOB = "audit.prune-request-log";
|
|
5
|
+
export type CreatePruneRequestLogJobDeps = {
|
|
6
|
+
readonly writer: Pick<RequestLogWriter, "deleteRecordedBefore">;
|
|
7
|
+
readonly clock: Pick<Clock, "now">;
|
|
8
|
+
/** Days a `request_log` row survives before this sweep deletes it. */
|
|
9
|
+
readonly retentionDays: number;
|
|
10
|
+
readonly log: JobLog;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Deletes every `request_log` row older than `retentionDays` (ADR-0112 slice
|
|
14
|
+
* B). `request_log` is allowlisted out of the `audit_record` trigger — a
|
|
15
|
+
* per-request environment record, not business history — so this delete
|
|
16
|
+
* never produces an `audit_log` row. `audit_log` itself is never pruned.
|
|
17
|
+
*
|
|
18
|
+
* Runs under the job system actor (`job:audit.prune-request-log`), stamped by
|
|
19
|
+
* the job queue driver before `run` is called — this job never touches actor
|
|
20
|
+
* context itself.
|
|
21
|
+
*/
|
|
22
|
+
export declare function createPruneRequestLogJob(deps: CreatePruneRequestLogJobDeps): JobDefinition;
|
|
23
|
+
//# sourceMappingURL=prune-request-log.job.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prune-request-log.job.d.ts","sourceRoot":"","sources":["../../../src/lib/jobs/prune-request-log.job.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAGL,KAAK,aAAa,EAClB,KAAK,MAAM,EACZ,MAAM,2BAA2B,CAAC;AAEnC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qDAAqD,CAAC;AAO5F,eAAO,MAAM,qBAAqB,4BAA4B,CAAC;AAE/D,MAAM,MAAM,4BAA4B,GAAG;IACzC,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,gBAAgB,EAAE,sBAAsB,CAAC,CAAC;IAChE,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IACnC,sEAAsE;IACtE,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF;;;;;;;;;GASG;AACH,wBAAgB,wBAAwB,CACtC,IAAI,EAAE,4BAA4B,GACjC,aAAa,CAuBf"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { cronSchedule, defineJob, } from "@dads-framework/job-queue";
|
|
3
|
+
import { requirePositiveIntegerRetentionDays, retentionCutoff, } from "./retention-window.js";
|
|
4
|
+
export const PRUNE_REQUEST_LOG_JOB = "audit.prune-request-log";
|
|
5
|
+
/**
|
|
6
|
+
* Deletes every `request_log` row older than `retentionDays` (ADR-0112 slice
|
|
7
|
+
* B). `request_log` is allowlisted out of the `audit_record` trigger — a
|
|
8
|
+
* per-request environment record, not business history — so this delete
|
|
9
|
+
* never produces an `audit_log` row. `audit_log` itself is never pruned.
|
|
10
|
+
*
|
|
11
|
+
* Runs under the job system actor (`job:audit.prune-request-log`), stamped by
|
|
12
|
+
* the job queue driver before `run` is called — this job never touches actor
|
|
13
|
+
* context itself.
|
|
14
|
+
*/
|
|
15
|
+
export function createPruneRequestLogJob(deps) {
|
|
16
|
+
requirePositiveIntegerRetentionDays(deps.retentionDays);
|
|
17
|
+
return defineJob({
|
|
18
|
+
name: PRUNE_REQUEST_LOG_JOB,
|
|
19
|
+
payload: z.strictObject({}),
|
|
20
|
+
retry: { attempts: 5, backoffMs: 1_000 },
|
|
21
|
+
schedules: [
|
|
22
|
+
cronSchedule({
|
|
23
|
+
id: "audit.prune-request-log.daily",
|
|
24
|
+
pattern: "0 0 3 * * *",
|
|
25
|
+
timeZone: "UTC",
|
|
26
|
+
payload: {},
|
|
27
|
+
}),
|
|
28
|
+
],
|
|
29
|
+
run: async () => {
|
|
30
|
+
const cutoff = retentionCutoff(deps.clock.now(), deps.retentionDays);
|
|
31
|
+
const deleted = await deps.writer.deleteRecordedBefore(cutoff);
|
|
32
|
+
deps.log.info({ event: "request-log.pruned", deleted, cutoff }, "request_log rows pruned");
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=prune-request-log.job.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prune-request-log.job.js","sourceRoot":"","sources":["../../../src/lib/jobs/prune-request-log.job.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,OAAO,EACL,YAAY,EACZ,SAAS,GAGV,MAAM,2BAA2B,CAAC;AAInC,OAAO,EACL,mCAAmC,EACnC,eAAe,GAChB,MAAM,uBAAuB,CAAC;AAE/B,MAAM,CAAC,MAAM,qBAAqB,GAAG,yBAAyB,CAAC;AAU/D;;;;;;;;;GASG;AACH,MAAM,UAAU,wBAAwB,CACtC,IAAkC;IAElC,mCAAmC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;IACxD,OAAO,SAAS,CAAC;QACf,IAAI,EAAE,qBAAqB;QAC3B,OAAO,EAAE,CAAC,CAAC,YAAY,CAAC,EAAE,CAAC;QAC3B,KAAK,EAAE,EAAE,QAAQ,EAAE,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE;QACxC,SAAS,EAAE;YACT,YAAY,CAAC;gBACX,EAAE,EAAE,+BAA+B;gBACnC,OAAO,EAAE,aAAa;gBACtB,QAAQ,EAAE,KAAK;gBACf,OAAO,EAAE,EAAE;aACZ,CAAC;SACH;QACD,GAAG,EAAE,KAAK,IAAI,EAAE;YACd,MAAM,MAAM,GAAG,eAAe,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;YACrE,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,oBAAoB,CAAC,MAAM,CAAC,CAAC;YAC/D,IAAI,CAAC,GAAG,CAAC,IAAI,CACX,EAAE,KAAK,EAAE,oBAAoB,EAAE,OAAO,EAAE,MAAM,EAAE,EAChD,yBAAyB,CAC1B,CAAC;QACJ,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retention-window.d.ts","sourceRoot":"","sources":["../../../src/lib/jobs/retention-window.ts"],"names":[],"mappings":"AAEA,wBAAgB,mCAAmC,CACjD,aAAa,EAAE,MAAM,GACpB,IAAI,CAMN;AAED,wBAAgB,eAAe,CAAC,GAAG,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,GAAG,IAAI,CAEtE"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
const MILLISECONDS_PER_DAY = 24 * 60 * 60 * 1_000;
|
|
2
|
+
export function requirePositiveIntegerRetentionDays(retentionDays) {
|
|
3
|
+
if (!Number.isInteger(retentionDays) || retentionDays <= 0) {
|
|
4
|
+
throw new Error(`retentionDays must be a positive integer, got ${retentionDays}`);
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
export function retentionCutoff(now, retentionDays) {
|
|
8
|
+
return new Date(now.getTime() - retentionDays * MILLISECONDS_PER_DAY);
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=retention-window.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retention-window.js","sourceRoot":"","sources":["../../../src/lib/jobs/retention-window.ts"],"names":[],"mappings":"AAAA,MAAM,oBAAoB,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,KAAK,CAAC;AAElD,MAAM,UAAU,mCAAmC,CACjD,aAAqB;IAErB,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,aAAa,CAAC,IAAI,aAAa,IAAI,CAAC,EAAE,CAAC;QAC3D,MAAM,IAAI,KAAK,CACb,iDAAiD,aAAa,EAAE,CACjE,CAAC;IACJ,CAAC;AACH,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,GAAS,EAAE,aAAqB;IAC9D,OAAO,IAAI,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,GAAG,aAAa,GAAG,oBAAoB,CAAC,CAAC;AACxE,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { DrizzleHandle } from "@dads-framework/postgres";
|
|
2
|
+
import { clientDiagnosticEvents } from "../database/generated-tables/client-diagnostic-events.tables.js";
|
|
3
|
+
import { requestLog } from "../database/generated-tables/request-log.tables.js";
|
|
4
|
+
/**
|
|
5
|
+
* A database handle or an open transaction on it, so a caller can commit
|
|
6
|
+
* these rows together with its own bookkeeping row.
|
|
7
|
+
*/
|
|
8
|
+
export type ForeignRowsHandle = DrizzleHandle | Parameters<Parameters<DrizzleHandle["transaction"]>[0]>[0];
|
|
9
|
+
/**
|
|
10
|
+
* Inserts `request_log` rows recorded by another process of the same product
|
|
11
|
+
* (a remote instance), already tagged by the caller. Idempotent by primary key:
|
|
12
|
+
* a row whose `request_id` exists is skipped. Answers how many rows were new.
|
|
13
|
+
*/
|
|
14
|
+
export declare function insertForeignRequestRows(db: ForeignRowsHandle, rows: readonly (typeof requestLog.$inferInsert)[]): Promise<number>;
|
|
15
|
+
/**
|
|
16
|
+
* Inserts `client_diagnostic_events` rows recorded by another process of the
|
|
17
|
+
* same product (a remote instance), already tagged by the caller. Idempotent by
|
|
18
|
+
* primary key. Answers how many rows were new.
|
|
19
|
+
*/
|
|
20
|
+
export declare function insertForeignClientFaults(db: ForeignRowsHandle, rows: readonly (typeof clientDiagnosticEvents.$inferInsert)[]): Promise<number>;
|
|
21
|
+
//# sourceMappingURL=insert-foreign-rows.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"insert-foreign-rows.d.ts","sourceRoot":"","sources":["../../../src/lib/request-log/insert-foreign-rows.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAE9D,OAAO,EAAE,sBAAsB,EAAE,MAAM,iEAAiE,CAAC;AACzG,OAAO,EAAE,UAAU,EAAE,MAAM,oDAAoD,CAAC;AAEhF;;;GAGG;AACH,MAAM,MAAM,iBAAiB,GAC3B,aAAa,GAAG,UAAU,CAAC,UAAU,CAAC,aAAa,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAE7E;;;;GAIG;AACH,wBAAsB,wBAAwB,CAC5C,EAAE,EAAE,iBAAiB,EACrB,IAAI,EAAE,SAAS,CAAC,OAAO,UAAU,CAAC,YAAY,CAAC,EAAE,GAChD,OAAO,CAAC,MAAM,CAAC,CA8CjB;AAED;;;;GAIG;AACH,wBAAsB,yBAAyB,CAC7C,EAAE,EAAE,iBAAiB,EACrB,IAAI,EAAE,SAAS,CAAC,OAAO,sBAAsB,CAAC,YAAY,CAAC,EAAE,GAC5D,OAAO,CAAC,MAAM,CAAC,CA2BjB"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { clientDiagnosticEvents } from "../database/generated-tables/client-diagnostic-events.tables.js";
|
|
2
|
+
import { requestLog } from "../database/generated-tables/request-log.tables.js";
|
|
3
|
+
/**
|
|
4
|
+
* Inserts `request_log` rows recorded by another process of the same product
|
|
5
|
+
* (a remote instance), already tagged by the caller. Idempotent by primary key:
|
|
6
|
+
* a row whose `request_id` exists is skipped. Answers how many rows were new.
|
|
7
|
+
*/
|
|
8
|
+
export async function insertForeignRequestRows(db, rows) {
|
|
9
|
+
if (rows.length === 0)
|
|
10
|
+
return 0;
|
|
11
|
+
const inserted = await db
|
|
12
|
+
.insert(requestLog)
|
|
13
|
+
.values(rows.map((row) => ({
|
|
14
|
+
requestId: row.requestId,
|
|
15
|
+
imported: true,
|
|
16
|
+
recordedAt: row.recordedAt,
|
|
17
|
+
method: row.method,
|
|
18
|
+
routeId: row.routeId,
|
|
19
|
+
path: row.path,
|
|
20
|
+
status: row.status,
|
|
21
|
+
durationMs: row.durationMs,
|
|
22
|
+
actorKind: row.actorKind,
|
|
23
|
+
actorId: row.actorId,
|
|
24
|
+
authMethod: row.authMethod,
|
|
25
|
+
accessKind: row.accessKind,
|
|
26
|
+
permission: row.permission,
|
|
27
|
+
resourceType: row.resourceType,
|
|
28
|
+
resourceId: row.resourceId,
|
|
29
|
+
decision: row.decision,
|
|
30
|
+
errorCode: row.errorCode,
|
|
31
|
+
ip: row.ip,
|
|
32
|
+
forwardedFor: row.forwardedFor,
|
|
33
|
+
userAgent: row.userAgent,
|
|
34
|
+
clientHints: row.clientHints,
|
|
35
|
+
acceptLanguage: row.acceptLanguage,
|
|
36
|
+
clientContext: row.clientContext,
|
|
37
|
+
apiRelease: row.apiRelease,
|
|
38
|
+
dbQueryCount: row.dbQueryCount,
|
|
39
|
+
dbMs: row.dbMs,
|
|
40
|
+
authzCheckCount: row.authzCheckCount,
|
|
41
|
+
authzMs: row.authzMs,
|
|
42
|
+
instanceId: row.instanceId,
|
|
43
|
+
exceptionType: row.exceptionType,
|
|
44
|
+
exceptionFingerprint: row.exceptionFingerprint,
|
|
45
|
+
traceId: row.traceId,
|
|
46
|
+
authzCachedReadCount: row.authzCachedReadCount,
|
|
47
|
+
authzFullyConsistentReadCount: row.authzFullyConsistentReadCount,
|
|
48
|
+
authzLargestLookupCount: row.authzLargestLookupCount,
|
|
49
|
+
})))
|
|
50
|
+
.onConflictDoNothing({ target: requestLog.requestId })
|
|
51
|
+
.returning({ id: requestLog.requestId });
|
|
52
|
+
return inserted.length;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Inserts `client_diagnostic_events` rows recorded by another process of the
|
|
56
|
+
* same product (a remote instance), already tagged by the caller. Idempotent by
|
|
57
|
+
* primary key. Answers how many rows were new.
|
|
58
|
+
*/
|
|
59
|
+
export async function insertForeignClientFaults(db, rows) {
|
|
60
|
+
if (rows.length === 0)
|
|
61
|
+
return 0;
|
|
62
|
+
const inserted = await db
|
|
63
|
+
.insert(clientDiagnosticEvents)
|
|
64
|
+
.values(rows.map((row) => ({
|
|
65
|
+
id: row.id,
|
|
66
|
+
recordedAt: row.recordedAt,
|
|
67
|
+
occurredAt: row.occurredAt,
|
|
68
|
+
fingerprint: row.fingerprint,
|
|
69
|
+
kind: row.kind,
|
|
70
|
+
severity: row.severity,
|
|
71
|
+
name: row.name,
|
|
72
|
+
message: row.message,
|
|
73
|
+
frames: row.frames,
|
|
74
|
+
breadcrumbs: row.breadcrumbs,
|
|
75
|
+
release: row.release,
|
|
76
|
+
client: row.client,
|
|
77
|
+
requestId: row.requestId,
|
|
78
|
+
actorKind: row.actorKind,
|
|
79
|
+
actorId: row.actorId,
|
|
80
|
+
context: row.context,
|
|
81
|
+
})))
|
|
82
|
+
.onConflictDoNothing({ target: clientDiagnosticEvents.id })
|
|
83
|
+
.returning({ id: clientDiagnosticEvents.id });
|
|
84
|
+
return inserted.length;
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=insert-foreign-rows.js.map
|
|
@@ -0,0 +1 @@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CAAC,IAAI;QACd,QAAQ,EAAE,GAAG,CAAC,QAAQ;QACtB,IAAI,EAAE,GAAG,CAAC,IAAI;QACd,OAAO,EAAE,GAAG,CAAC,OAAO;QACpB,MAAM,EAAE,GAAG,CAAC,MAAM;QAClB,WAAW,EAAE,GAAG,CAAC,WAAW;QAC5B,OAAO,EAAE,GAAG,CAAC,OAAO;QACpB,MAAM,EAAE,GAAG,CAAC,MAAM;QAClB,SAAS,EAAE,GAAG,CAAC,SAAS;QACxB,SAAS,EAAE,GAAG,CAAC,SAAS;QACxB,OAAO,EAAE,GAAG,CAAC,OAAO;QACpB,OAAO,EAAE,GAAG,CAAC,OAAO;KACrB,CAAC,CAAC,CACJ;SACA,mBAAmB,CAAC,EAAE,MAAM,EAAE,sBAAsB,CAAC,EAAE,EAAE,CAAC;SAC1D,SAAS,CAAC,EAAE,EAAE,EAAE,sBAAsB,CAAC,EAAE,EAAE,CAAC,CAAC;IAChD,OAAO,QAAQ,CAAC,MAAM,CAAC;AACzB,CAAC"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `request_log` sink: buffers the rows the HTTP kit captures and writes
|
|
3
|
+
* them in batches, off the request path.
|
|
4
|
+
*
|
|
5
|
+
* Three properties matter more than throughput here, because this is
|
|
6
|
+
* diagnostic exhaust and the product does not depend on it:
|
|
7
|
+
*
|
|
8
|
+
* - **Bounded.** A database that stops answering cannot turn a request spike
|
|
9
|
+
* into an out-of-memory kill; past the ceiling the OLDEST row is dropped,
|
|
10
|
+
* because the newest rows are the ones describing the incident.
|
|
11
|
+
* - **Silent.** A failed insert is logged and the rows are gone. Nothing here
|
|
12
|
+
* is allowed to reject into a caller, least of all into shutdown.
|
|
13
|
+
* - **Drainable.** `close()` flushes, so a SIGTERM between two ticks does not
|
|
14
|
+
* lose the last second of traffic.
|
|
15
|
+
*/
|
|
16
|
+
import { RequestLogSink, type RequestRecord } from "@dads-framework/http";
|
|
17
|
+
import type { DrizzleHandle } from "@dads-framework/postgres";
|
|
18
|
+
/** What this sink says when a batch is lost, and when rows are dropped. */
|
|
19
|
+
export type RequestLogSinkLog = {
|
|
20
|
+
warn(obj: object, msg?: string): void;
|
|
21
|
+
error(obj: object, msg?: string): void;
|
|
22
|
+
};
|
|
23
|
+
export type PostgresRequestLogSinkOptions = {
|
|
24
|
+
/** Ceiling on unwritten rows; past it the oldest is dropped. Default 2000. */
|
|
25
|
+
readonly maxBufferedRows?: number;
|
|
26
|
+
/** Buffered rows that trigger a flush without waiting for the timer. Default 200. */
|
|
27
|
+
readonly flushAtRows?: number;
|
|
28
|
+
/** How often the buffer is written regardless of size. Default 1000ms. */
|
|
29
|
+
readonly flushIntervalMs?: number;
|
|
30
|
+
/** Whether successful reads are captured at all (the hook asks the sink). */
|
|
31
|
+
readonly includeSuccessfulReads?: boolean;
|
|
32
|
+
};
|
|
33
|
+
export declare class PostgresRequestLogSink extends RequestLogSink {
|
|
34
|
+
private readonly db;
|
|
35
|
+
private readonly log;
|
|
36
|
+
private readonly buffer;
|
|
37
|
+
private readonly maxBufferedRows;
|
|
38
|
+
private readonly flushAtRows;
|
|
39
|
+
private readonly flushIntervalMs;
|
|
40
|
+
/** Serializes writes, so `flush()` awaits the insert already in flight. */
|
|
41
|
+
private writing;
|
|
42
|
+
private timer;
|
|
43
|
+
private closed;
|
|
44
|
+
/** One warning per overflow episode, not one per dropped row. */
|
|
45
|
+
private overflowing;
|
|
46
|
+
constructor(db: DrizzleHandle, log: RequestLogSinkLog, options?: PostgresRequestLogSinkOptions);
|
|
47
|
+
record(row: RequestRecord): void;
|
|
48
|
+
flush(): Promise<void>;
|
|
49
|
+
close(): Promise<void>;
|
|
50
|
+
/** One insert per flush, and never a rejection — the rows are simply gone. */
|
|
51
|
+
private writeBufferedRows;
|
|
52
|
+
/**
|
|
53
|
+
* A chained `setTimeout` rather than `setInterval`: an interval can stack
|
|
54
|
+
* ticks on top of a slow write, and the only thing worse than losing
|
|
55
|
+
* diagnostic rows is a diagnostic subsystem queueing work behind itself.
|
|
56
|
+
* `unref()` so an idle process still exits — the flush loop must never be
|
|
57
|
+
* the reason a container refuses to stop
|
|
58
|
+
* (docs/architecture/http-edge.md#process-discipline--node-footguns).
|
|
59
|
+
*/
|
|
60
|
+
private scheduleNextFlush;
|
|
61
|
+
private cancelTimer;
|
|
62
|
+
private warnOnOverflow;
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=postgres-request-log-sink.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postgres-request-log-sink.d.ts","sourceRoot":"","sources":["../../../src/lib/request-log/postgres-request-log-sink.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,EACL,cAAc,EAEd,KAAK,aAAa,EACnB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAG9D,2EAA2E;AAC3E,MAAM,MAAM,iBAAiB,GAAG;IAC9B,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtC,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACxC,CAAC;AAEF,MAAM,MAAM,6BAA6B,GAAG;IAC1C,8EAA8E;IAC9E,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,CAAC;IAClC,qFAAqF;IACrF,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,0EAA0E;IAC1E,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,CAAC;IAClC,6EAA6E;IAC7E,QAAQ,CAAC,sBAAsB,CAAC,EAAE,OAAO,CAAC;CAC3C,CAAC;AAcF,qBAAa,sBAAuB,SAAQ,cAAc;IAatD,OAAO,CAAC,QAAQ,CAAC,EAAE;IACnB,OAAO,CAAC,QAAQ,CAAC,GAAG;IAbtB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAuB;IAC9C,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAS;IACzC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;IACrC,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAS;IACzC,2EAA2E;IAC3E,OAAO,CAAC,OAAO,CAAoC;IACnD,OAAO,CAAC,KAAK,CAA6B;IAC1C,OAAO,CAAC,MAAM,CAAS;IACvB,iEAAiE;IACjE,OAAO,CAAC,WAAW,CAAS;IAE5B,YACmB,EAAE,EAAE,aAAa,EACjB,GAAG,EAAE,iBAAiB,EACvC,OAAO,GAAE,6BAAkC,EAO5C;IAEQ,MAAM,CAAC,GAAG,EAAE,aAAa,GAAG,IAAI,CAQxC;IAEQ,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAM9B;IAEc,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAIpC;IAED,8EAA8E;YAChE,iBAAiB;IAqB/B;;;;;;;OAOG;IACH,OAAO,CAAC,iBAAiB;IAYzB,OAAO,CAAC,WAAW;IAMnB,OAAO,CAAC,cAAc;CAQvB"}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `request_log` sink: buffers the rows the HTTP kit captures and writes
|
|
3
|
+
* them in batches, off the request path.
|
|
4
|
+
*
|
|
5
|
+
* Three properties matter more than throughput here, because this is
|
|
6
|
+
* diagnostic exhaust and the product does not depend on it:
|
|
7
|
+
*
|
|
8
|
+
* - **Bounded.** A database that stops answering cannot turn a request spike
|
|
9
|
+
* into an out-of-memory kill; past the ceiling the OLDEST row is dropped,
|
|
10
|
+
* because the newest rows are the ones describing the incident.
|
|
11
|
+
* - **Silent.** A failed insert is logged and the rows are gone. Nothing here
|
|
12
|
+
* is allowed to reject into a caller, least of all into shutdown.
|
|
13
|
+
* - **Drainable.** `close()` flushes, so a SIGTERM between two ticks does not
|
|
14
|
+
* lose the last second of traffic.
|
|
15
|
+
*/
|
|
16
|
+
import { withSystemActor } from "@dads-framework/audit-actor";
|
|
17
|
+
import { RequestLogSink, requestIdSchema, } from "@dads-framework/http";
|
|
18
|
+
import { requestLog } from "../database/generated-tables/request-log.tables.js";
|
|
19
|
+
const DEFAULT_MAX_BUFFERED_ROWS = 2_000;
|
|
20
|
+
const DEFAULT_FLUSH_AT_ROWS = 200;
|
|
21
|
+
const DEFAULT_FLUSH_INTERVAL_MS = 1_000;
|
|
22
|
+
/**
|
|
23
|
+
* Writes run under a named system actor. `request_log` is on
|
|
24
|
+
* `AUDIT_TRIGGER_ALLOWLIST`, so no trigger demands one — but the attributed
|
|
25
|
+
* pool stamps every checkout, and a deterministic stamp beats whatever actor
|
|
26
|
+
* the async task that happened to trigger the flush was carrying.
|
|
27
|
+
*/
|
|
28
|
+
const REQUEST_LOG_ACTOR = "request-log";
|
|
29
|
+
export class PostgresRequestLogSink extends RequestLogSink {
|
|
30
|
+
db;
|
|
31
|
+
log;
|
|
32
|
+
buffer = [];
|
|
33
|
+
maxBufferedRows;
|
|
34
|
+
flushAtRows;
|
|
35
|
+
flushIntervalMs;
|
|
36
|
+
/** Serializes writes, so `flush()` awaits the insert already in flight. */
|
|
37
|
+
writing = Promise.resolve();
|
|
38
|
+
timer;
|
|
39
|
+
closed = false;
|
|
40
|
+
/** One warning per overflow episode, not one per dropped row. */
|
|
41
|
+
overflowing = false;
|
|
42
|
+
constructor(db, log, options = {}) {
|
|
43
|
+
super(options.includeSuccessfulReads ?? false);
|
|
44
|
+
this.db = db;
|
|
45
|
+
this.log = log;
|
|
46
|
+
this.maxBufferedRows = options.maxBufferedRows ?? DEFAULT_MAX_BUFFERED_ROWS;
|
|
47
|
+
this.flushAtRows = options.flushAtRows ?? DEFAULT_FLUSH_AT_ROWS;
|
|
48
|
+
this.flushIntervalMs = options.flushIntervalMs ?? DEFAULT_FLUSH_INTERVAL_MS;
|
|
49
|
+
this.scheduleNextFlush();
|
|
50
|
+
}
|
|
51
|
+
record(row) {
|
|
52
|
+
if (this.closed)
|
|
53
|
+
return;
|
|
54
|
+
if (this.buffer.length >= this.maxBufferedRows) {
|
|
55
|
+
this.buffer.shift();
|
|
56
|
+
this.warnOnOverflow();
|
|
57
|
+
}
|
|
58
|
+
this.buffer.push(row);
|
|
59
|
+
if (this.buffer.length >= this.flushAtRows)
|
|
60
|
+
void this.flush();
|
|
61
|
+
}
|
|
62
|
+
flush() {
|
|
63
|
+
this.writing = this.writing.then(() => this.writeBufferedRows(), () => this.writeBufferedRows());
|
|
64
|
+
return this.writing;
|
|
65
|
+
}
|
|
66
|
+
async close() {
|
|
67
|
+
this.closed = true;
|
|
68
|
+
this.cancelTimer();
|
|
69
|
+
await this.flush();
|
|
70
|
+
}
|
|
71
|
+
/** One insert per flush, and never a rejection — the rows are simply gone. */
|
|
72
|
+
async writeBufferedRows() {
|
|
73
|
+
const rows = this.buffer.splice(0, this.buffer.length);
|
|
74
|
+
if (rows.length === 0)
|
|
75
|
+
return;
|
|
76
|
+
try {
|
|
77
|
+
await withSystemActor(REQUEST_LOG_ACTOR, async () => {
|
|
78
|
+
await this.db
|
|
79
|
+
.insert(requestLog)
|
|
80
|
+
.values(rows.map(toRequestLogInsert))
|
|
81
|
+
// A retried request reuses its id, and the row already written is
|
|
82
|
+
// the one that described what actually happened first.
|
|
83
|
+
.onConflictDoNothing({ target: requestLog.requestId });
|
|
84
|
+
});
|
|
85
|
+
this.overflowing = false;
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
this.log.error({ event: "request-log.write-failed", err: error, rows: rows.length }, "request log rows were dropped");
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* A chained `setTimeout` rather than `setInterval`: an interval can stack
|
|
93
|
+
* ticks on top of a slow write, and the only thing worse than losing
|
|
94
|
+
* diagnostic rows is a diagnostic subsystem queueing work behind itself.
|
|
95
|
+
* `unref()` so an idle process still exits — the flush loop must never be
|
|
96
|
+
* the reason a container refuses to stop
|
|
97
|
+
* (docs/architecture/http-edge.md#process-discipline--node-footguns).
|
|
98
|
+
*/
|
|
99
|
+
scheduleNextFlush() {
|
|
100
|
+
if (this.closed)
|
|
101
|
+
return;
|
|
102
|
+
const timer = setTimeout(() => {
|
|
103
|
+
this.timer = undefined;
|
|
104
|
+
void this.flush().then(() => {
|
|
105
|
+
this.scheduleNextFlush();
|
|
106
|
+
});
|
|
107
|
+
}, this.flushIntervalMs);
|
|
108
|
+
timer.unref();
|
|
109
|
+
this.timer = timer;
|
|
110
|
+
}
|
|
111
|
+
cancelTimer() {
|
|
112
|
+
if (this.timer === undefined)
|
|
113
|
+
return;
|
|
114
|
+
clearTimeout(this.timer);
|
|
115
|
+
this.timer = undefined;
|
|
116
|
+
}
|
|
117
|
+
warnOnOverflow() {
|
|
118
|
+
if (this.overflowing)
|
|
119
|
+
return;
|
|
120
|
+
this.overflowing = true;
|
|
121
|
+
this.log.warn({ event: "request-log.buffer-overflow", limit: this.maxBufferedRows }, "request log buffer is full — dropping the oldest rows");
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* The record's fields are the table's columns, named one by one.
|
|
126
|
+
* `requestId` is the one boundary crossing: the pipeline carries it as a
|
|
127
|
+
* plain string end to end, and this insert is where it becomes the row's
|
|
128
|
+
* branded primary key.
|
|
129
|
+
*/
|
|
130
|
+
function toRequestLogInsert(row) {
|
|
131
|
+
return {
|
|
132
|
+
requestId: requestIdSchema.parse(row.requestId),
|
|
133
|
+
recordedAt: row.recordedAt,
|
|
134
|
+
method: row.method,
|
|
135
|
+
routeId: row.routeId,
|
|
136
|
+
path: row.path,
|
|
137
|
+
status: row.status,
|
|
138
|
+
durationMs: row.durationMs,
|
|
139
|
+
actorKind: row.actorKind,
|
|
140
|
+
actorId: row.actorId,
|
|
141
|
+
authMethod: row.authMethod,
|
|
142
|
+
accessKind: row.accessKind,
|
|
143
|
+
permission: row.permission,
|
|
144
|
+
resourceType: row.resourceType,
|
|
145
|
+
resourceId: row.resourceId,
|
|
146
|
+
decision: row.decision,
|
|
147
|
+
errorCode: row.errorCode,
|
|
148
|
+
ip: row.ip,
|
|
149
|
+
forwardedFor: row.forwardedFor,
|
|
150
|
+
userAgent: row.userAgent,
|
|
151
|
+
clientHints: row.clientHints,
|
|
152
|
+
acceptLanguage: row.acceptLanguage,
|
|
153
|
+
clientContext: row.clientContext,
|
|
154
|
+
apiRelease: row.apiRelease,
|
|
155
|
+
dbQueryCount: row.dbQueryCount,
|
|
156
|
+
dbMs: row.dbMs,
|
|
157
|
+
authzCheckCount: row.authzCheckCount,
|
|
158
|
+
authzMs: row.authzMs,
|
|
159
|
+
authzCachedReadCount: row.authzCachedReadCount,
|
|
160
|
+
authzFullyConsistentReadCount: row.authzFullyConsistentReadCount,
|
|
161
|
+
authzLargestLookupCount: row.authzLargestLookupCount,
|
|
162
|
+
instanceId: row.instanceId,
|
|
163
|
+
traceId: row.traceId,
|
|
164
|
+
exceptionType: row.exceptionType,
|
|
165
|
+
exceptionFingerprint: row.exceptionFingerprint,
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
//# sourceMappingURL=postgres-request-log-sink.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postgres-request-log-sink.js","sourceRoot":"","sources":["../../../src/lib/request-log/postgres-request-log-sink.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EACL,cAAc,EACd,eAAe,GAEhB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAAE,UAAU,EAAE,MAAM,oDAAoD,CAAC;AAmBhF,MAAM,yBAAyB,GAAG,KAAK,CAAC;AACxC,MAAM,qBAAqB,GAAG,GAAG,CAAC;AAClC,MAAM,yBAAyB,GAAG,KAAK,CAAC;AAExC;;;;;GAKG;AACH,MAAM,iBAAiB,GAAG,aAAa,CAAC;AAExC,MAAM,OAAO,sBAAuB,SAAQ,c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,YAAY,EAAE,GAAG,CAAC,YAAY;QAC9B,UAAU,EAAE,GAAG,CAAC,UAAU;QAC1B,QAAQ,EAAE,GAAG,CAAC,QAAQ;QACtB,SAAS,EAAE,GAAG,CAAC,SAAS;QACxB,EAAE,EAAE,GAAG,CAAC,EAAE;QACV,YAAY,EAAE,GAAG,CAAC,YAAY;QAC9B,SAAS,EAAE,GAAG,CAAC,SAAS;QACxB,WAAW,EAAE,GAAG,CAAC,WAAW;QAC5B,cAAc,EAAE,GAAG,CAAC,cAAc;QAClC,aAAa,EAAE,GAAG,CAAC,aAAa;QAChC,UAAU,EAAE,GAAG,CAAC,UAAU;QAC1B,YAAY,EAAE,GAAG,CAAC,YAAY;QAC9B,IAAI,EAAE,GAAG,CAAC,IAAI;QACd,eAAe,EAAE,GAAG,CAAC,eAAe;QACpC,OAAO,EAAE,GAAG,CAAC,OAAO;QACpB,oBAAoB,EAAE,GAAG,CAAC,oBAAoB;QAC9C,6BAA6B,EAAE,GAAG,CAAC,6BAA6B;QAChE,uBAAuB,EAAE,GAAG,CAAC,uBAAuB;QACpD,UAAU,EAAE,GAAG,CAAC,UAAU;QAC1B,OAAO,EAAE,GAAG,CAAC,OAAO;QACpB,aAAa,EAAE,GAAG,CAAC,aAAa;QAChC,oBAAoB,EAAE,GAAG,CAAC,oBAAoB;KAC/C,CAAC;AACJ,CAAC"}
|
package/dist/schema.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { attachAuditTrigger, detachAuditTrigger, } from "./lib/database/attach-audit-trigger.js";
|
|
2
|
+
export { up as installAuditSchemaV1 } from "./lib/database/migrations/20260910233455_audit.migration.js";
|
|
3
|
+
export { configureAuditTriggers, type AuditTriggerConfiguration, } from "./lib/database/configure-audit-triggers.js";
|
|
4
|
+
export type { AuditScopeValues } from "./lib/database/audit-row-json.js";
|
|
5
|
+
export { configurePluginAuditTriggers } from "./lib/database/configure-plugin-audit-triggers.js";
|
|
6
|
+
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,kBAAkB,GACnB,MAAM,wCAAwC,CAAC;AAChD,OAAO,EAAE,EAAE,IAAI,oBAAoB,EAAE,MAAM,6DAA6D,CAAC;AACzG,OAAO,EACL,sBAAsB,EACtB,KAAK,yBAAyB,GAC/B,MAAM,4CAA4C,CAAC;AACpD,YAAY,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AACzE,OAAO,EAAE,4BAA4B,EAAE,MAAM,mDAAmD,CAAC"}
|
package/dist/schema.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { attachAuditTrigger, detachAuditTrigger, } from "./lib/database/attach-audit-trigger.js";
|
|
2
|
+
export { up as installAuditSchemaV1 } from "./lib/database/migrations/20260910233455_audit.migration.js";
|
|
3
|
+
export { configureAuditTriggers, } from "./lib/database/configure-audit-triggers.js";
|
|
4
|
+
export { configurePluginAuditTriggers } from "./lib/database/configure-plugin-audit-triggers.js";
|
|
5
|
+
//# sourceMappingURL=schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,kBAAkB,GACnB,MAAM,wCAAwC,CAAC;AAChD,OAAO,EAAE,EAAE,IAAI,oBAAoB,EAAE,MAAM,6DAA6D,CAAC;AACzG,OAAO,EACL,sBAAsB,GAEvB,MAAM,4CAA4C,CAAC;AAEpD,OAAO,EAAE,4BAA4B,EAAE,MAAM,mDAAmD,CAAC"}
|