@bli-cockpit/telemetry-core 0.1.59 → 0.1.64
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/dist/log-digest/classify.d.ts +7 -0
- package/dist/log-digest/classify.js +14 -0
- package/dist/log-digest/digest-source.d.ts +3 -1
- package/dist/log-digest/digest-source.js +3 -2
- package/dist/log-digest/digest.d.ts +8 -0
- package/dist/log-digest/digest.js +14 -2
- package/dist/log-digest/index.d.ts +6 -2
- package/dist/log-digest/index.js +6 -2
- package/dist/log-digest/log-projects.d.ts +92 -0
- package/dist/log-digest/log-projects.js +173 -0
- package/dist/log-digest/project-classes.d.ts +16 -0
- package/dist/log-digest/project-classes.js +107 -0
- package/dist/log-digest/scrub.d.ts +11 -0
- package/dist/log-digest/scrub.js +73 -0
- package/dist/log-digest/sources/vercel.d.ts +31 -1
- package/dist/log-digest/sources/vercel.js +35 -26
- package/dist/log-digest/stored.d.ts +131 -0
- package/dist/log-digest/stored.js +198 -0
- package/dist/log-digest/tower-classes.js +18 -0
- package/package.json +1 -1
|
@@ -17,6 +17,11 @@ export interface TablePattern {
|
|
|
17
17
|
note: string;
|
|
18
18
|
/** Where the verdict came from: a ticket, a commit, a measured window. */
|
|
19
19
|
basis: string;
|
|
20
|
+
/**
|
|
21
|
+
* Judge a matching line even when it carries no trouble word (BLI-12870: `[SMS Pull] Skipped … no_extension=[…]`
|
|
22
|
+
* names users who need a person, in words the important-line filter does not know). Off by default.
|
|
23
|
+
*/
|
|
24
|
+
watch?: boolean;
|
|
20
25
|
}
|
|
21
26
|
export interface ClassTableData {
|
|
22
27
|
version: number;
|
|
@@ -38,6 +43,8 @@ export declare class ClassTable {
|
|
|
38
43
|
private readonly patterns;
|
|
39
44
|
private readonly cache;
|
|
40
45
|
constructor(data: ClassTableData);
|
|
46
|
+
/** True when a `watch` pattern matches this masked line: the digest judges it instead of counting it as routine. */
|
|
47
|
+
watches(unit: string, template: string, source: string): boolean;
|
|
41
48
|
/** A table read from its JSON text (the `--table` file a person writes to try a pattern). */
|
|
42
49
|
static fromJson(text: string): ClassTable;
|
|
43
50
|
classify: Classify;
|
|
@@ -35,6 +35,20 @@ export class ClassTable {
|
|
|
35
35
|
};
|
|
36
36
|
});
|
|
37
37
|
}
|
|
38
|
+
/** True when a `watch` pattern matches this masked line: the digest judges it instead of counting it as routine. */
|
|
39
|
+
watches(unit, template, source) {
|
|
40
|
+
for (const pattern of this.patterns) {
|
|
41
|
+
if (!pattern.spec.watch)
|
|
42
|
+
continue;
|
|
43
|
+
if (pattern.unit && !pattern.unit.test(unit))
|
|
44
|
+
continue;
|
|
45
|
+
if (pattern.source && !pattern.source.test(source))
|
|
46
|
+
continue;
|
|
47
|
+
if (pattern.match.test(template))
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
38
52
|
/** A table read from its JSON text (the `--table` file a person writes to try a pattern). */
|
|
39
53
|
static fromJson(text) {
|
|
40
54
|
return new ClassTable(JSON.parse(text));
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* both thin callers of `digestSource`, so they print the same thing.
|
|
5
5
|
*/
|
|
6
6
|
import { ClassTable } from "./classify.js";
|
|
7
|
-
import { type RoutineEvents } from "./digest.js";
|
|
7
|
+
import { type DigestResult, type RoutineEvents } from "./digest.js";
|
|
8
8
|
import { type LogFn, type RunCli, type SourceContext } from "./sources/types.js";
|
|
9
9
|
export declare const SOURCE_NAMES: readonly ["collector", "dashboard", "railway", "railway:<service>", "-"];
|
|
10
10
|
/** A Railway service name: validated before anything is spawned, because a Windows run goes through cmd.exe. */
|
|
@@ -95,5 +95,7 @@ export interface Refusal {
|
|
|
95
95
|
export type DigestOutcome = DigestAnswer | RawAnswer | Refusal;
|
|
96
96
|
/** `railway:ladder` becomes `railway`: the source family a table pattern's `source` regex is matched against. */
|
|
97
97
|
export declare function sourceFamily(source: string): string;
|
|
98
|
+
/** Every group of a digest result, classified and ordered: what needs a person first, then by count. */
|
|
99
|
+
export declare function classifyTemplates(result: DigestResult, table: ClassTable, family: string): DigestTemplate[];
|
|
98
100
|
/** Reads, digests, classifies and renders one source. Never throws for a refusal: it is returned, named. */
|
|
99
101
|
export declare function digestSource(request: DigestRequest, env?: DigestEnvironment): Promise<DigestOutcome>;
|
|
@@ -44,7 +44,8 @@ const iso = (epoch) => new Date(epoch * 1000).toISOString();
|
|
|
44
44
|
function windowFacts(window) {
|
|
45
45
|
return { from: iso(window.fromEpoch), to: iso(window.toEpoch), label: window.label };
|
|
46
46
|
}
|
|
47
|
-
|
|
47
|
+
/** Every group of a digest result, classified and ordered: what needs a person first, then by count. */
|
|
48
|
+
export function classifyTemplates(result, table, family) {
|
|
48
49
|
const rows = result.groups.map((record) => {
|
|
49
50
|
const verdict = table.classify(record.unit, record.template, family);
|
|
50
51
|
return {
|
|
@@ -122,7 +123,7 @@ export async function digestSource(request, env = {}) {
|
|
|
122
123
|
return { ok: true, kind: "raw", source: request.source, tid: wanted, window: facts, matched, lines, notes: source.notes, text: [head, ...lines].join("\n") };
|
|
123
124
|
}
|
|
124
125
|
const text = renderCapped(result, { source: request.source, window: window.label, classify: (unit, template) => table.classify(unit, template, family), maxBytes: request.maxBytes ?? DEFAULT_MAX_BYTES, notes: source.notes });
|
|
125
|
-
const all =
|
|
126
|
+
const all = classifyTemplates(result, table, family);
|
|
126
127
|
const rawChars = source.rawChars ?? source.lines.reduce((sum, line) => sum + line.message.length + 1, 0);
|
|
127
128
|
const errors = all.filter((entry) => entry.severity === "ERROR").length;
|
|
128
129
|
log("[logs digest] digested", { source: family, window: window.label, lines: result.lines, noise: result.noise, templates: all.length, error_templates: errors, printed_bytes: Buffer.byteLength(text, "utf8"), raw_chars: rawChars });
|
|
@@ -45,6 +45,11 @@ export interface DigestOptions {
|
|
|
45
45
|
* Off by default so Kaiben's journals digest exactly as the Python does.
|
|
46
46
|
*/
|
|
47
47
|
taggedLines?: boolean;
|
|
48
|
+
/**
|
|
49
|
+
* A class table's say on a line that carries no trouble word (BLI-12870): true judges it anyway. Only patterns marked
|
|
50
|
+
* `watch` answer true, so Kaiben's journals and every unmarked table digest exactly as before.
|
|
51
|
+
*/
|
|
52
|
+
watch?: (group: string, template: string) => boolean;
|
|
48
53
|
}
|
|
49
54
|
export interface LineFacts {
|
|
50
55
|
/** systemd's own words about a unit rather than the unit's output. */
|
|
@@ -65,6 +70,7 @@ export declare class Digest {
|
|
|
65
70
|
private readonly quiet;
|
|
66
71
|
private readonly routineUnits;
|
|
67
72
|
private readonly taggedLines;
|
|
73
|
+
private readonly watch;
|
|
68
74
|
private readonly openTracebacks;
|
|
69
75
|
constructor(options?: DigestOptions);
|
|
70
76
|
isNoise(unit: string | undefined, identifier: string | undefined): boolean;
|
|
@@ -72,6 +78,8 @@ export declare class Digest {
|
|
|
72
78
|
addEntry(entry: JournalEntry): void;
|
|
73
79
|
/** One log line from any source. `ts` is epoch seconds (0 when the source has none). */
|
|
74
80
|
addLine(unit: string, message: string, ts: number, facts?: LineFacts): void;
|
|
81
|
+
/** A line the class table asked to see even without a trouble word (a `watch` pattern matches its masked text). */
|
|
82
|
+
private watched;
|
|
75
83
|
private routineCount;
|
|
76
84
|
private addGroup;
|
|
77
85
|
/** Python tracebacks span many lines: fold each into one group named by its exception and last frame. */
|
|
@@ -30,6 +30,9 @@ export const DEFAULT_NOISE = [
|
|
|
30
30
|
// systemd's own routine words about a unit; the rest of such a line is the unit's description, which can say anything
|
|
31
31
|
const SYSTEMD_ROUTINE = /^(Starting|Started|Finished|Stopping|Stopped|Reloading|Reloaded|Created slice|Removed slice|Listening|Reached target|Closed|Queued|Activating|Deactivated|Consumed|\S+: (Deactivated|Consumed|Succeeded|Main process exited, code=exited, status=0\/SUCCESS))/;
|
|
32
32
|
const EXCEPTION_LINE = /^([A-Za-z_][\w.]*(?:Error|Exception|Interrupt|Exit|Warning|Failure))(?::\s?(.*))?$/;
|
|
33
|
+
// A thrown JavaScript error (`TypeError: ...`, `PostgresError: ...`): the word `error` is glued to its name, so the
|
|
34
|
+
// Python-ported word list (`\berror\b`) never sees it. Only consulted for Tower-shaped sources (`taggedLines`).
|
|
35
|
+
const JS_EXCEPTION = /\b[A-Z][A-Za-z]*(?:Error|Exception)\b/;
|
|
33
36
|
const FRAME_LINE = /^\s+File "([^"]+)", line \d+, in (\S+)/;
|
|
34
37
|
function compileAll(patterns) {
|
|
35
38
|
return patterns.map((pattern) => new RegExp(pattern));
|
|
@@ -50,9 +53,11 @@ export class Digest {
|
|
|
50
53
|
quiet;
|
|
51
54
|
routineUnits;
|
|
52
55
|
taggedLines;
|
|
56
|
+
watch;
|
|
53
57
|
openTracebacks = new Map();
|
|
54
58
|
constructor(options = {}) {
|
|
55
59
|
this.taggedLines = options.taggedLines ?? false;
|
|
60
|
+
this.watch = options.watch ?? null;
|
|
56
61
|
this.noise = compileAll(options.noise ?? DEFAULT_NOISE);
|
|
57
62
|
this.quiet = compileAll(options.quietUnits ?? []);
|
|
58
63
|
this.routineUnits = new Set(options.routineUnits ?? []);
|
|
@@ -138,7 +143,10 @@ export class Digest {
|
|
|
138
143
|
const parsed = parseTagged(message);
|
|
139
144
|
if (parsed) {
|
|
140
145
|
const judged = judgeTagged(parsed, facts.level);
|
|
141
|
-
if (!judged.important) {
|
|
146
|
+
if (!judged.important && this.watched(group, message)) {
|
|
147
|
+
this.addGroup(group, instance, "tagged", mask(message), ts, message);
|
|
148
|
+
}
|
|
149
|
+
else if (!judged.important) {
|
|
142
150
|
this.routineCount(group, judged.template, null);
|
|
143
151
|
}
|
|
144
152
|
else {
|
|
@@ -152,7 +160,7 @@ export class Digest {
|
|
|
152
160
|
// The source's own level is NOT a verdict on a plain line: Tower writes ordinary output to stderr, which Vercel
|
|
153
161
|
// and Railway both mark "error" (measured 2026-10-07). Words and fields decide; see tagged.ts.
|
|
154
162
|
const judgedText = this.taggedLines ? withoutZeroCounters(message) : message;
|
|
155
|
-
if (looksImportant(judgedText) && !(manager && SYSTEMD_ROUTINE.test(message))) {
|
|
163
|
+
if ((looksImportant(judgedText) || (this.taggedLines && JS_EXCEPTION.test(judgedText)) || this.watched(group, message)) && !(manager && SYSTEMD_ROUTINE.test(message))) {
|
|
156
164
|
this.addGroup(group, instance, event, mask(message), ts, message);
|
|
157
165
|
return;
|
|
158
166
|
}
|
|
@@ -163,6 +171,10 @@ export class Digest {
|
|
|
163
171
|
this.routineCount(group, routineEvent, null);
|
|
164
172
|
}
|
|
165
173
|
// -- internals
|
|
174
|
+
/** A line the class table asked to see even without a trouble word (a `watch` pattern matches its masked text). */
|
|
175
|
+
watched(group, message) {
|
|
176
|
+
return this.watch !== null && this.watch(group, mask(message));
|
|
177
|
+
}
|
|
166
178
|
routineCount(group, event, subject) {
|
|
167
179
|
let events = this.routine.get(group);
|
|
168
180
|
if (!events)
|
|
@@ -6,10 +6,14 @@ export { CLASS_ORDER, ClassTable, type Classify, type ClassInfo, type ClassTable
|
|
|
6
6
|
export { clock, fleetView, numberText, renderCapped, renderFleet, renderLocal, routineText, subjectsText, timeRange, type CappedOptions, type FleetView, } from "./render.js";
|
|
7
7
|
export { TOWER_CLASSES, TOWER_PATTERNS, TOWER_TABLE, towerClassTable } from "./tower-classes.js";
|
|
8
8
|
export { WindowError, isoOf, parseWindow, relativeSeconds, type LogWindow } from "./window.js";
|
|
9
|
-
export { DEFAULT_MAX_BYTES, SOURCE_NAMES, digestSource, sourceFamily, type DigestAnswer, type DigestEnvironment, type DigestOutcome, type DigestRequest, type DigestTemplate, type RawAnswer, type Refusal, } from "./digest-source.js";
|
|
9
|
+
export { DEFAULT_MAX_BYTES, SOURCE_NAMES, classifyTemplates, digestSource, sourceFamily, type DigestAnswer, type DigestEnvironment, type DigestOutcome, type DigestRequest, type DigestTemplate, type RawAnswer, type Refusal, } from "./digest-source.js";
|
|
10
10
|
export { SourceRefusal, type CliRun, type LogFn, type RunCli, type SourceContext, type SourceLine, type SourceRead } from "./sources/types.js";
|
|
11
11
|
export { nodeRunCli } from "./sources/process.js";
|
|
12
12
|
export { readCollector, receiptLine, streamLines, windowShare } from "./sources/collector.js";
|
|
13
13
|
export { RAILWAY_ENVIRONMENT, RAILWAY_PROJECT_ID, railwayRefusal, readRailway } from "./sources/railway.js";
|
|
14
|
-
export { VERCEL_PROJECT, VERCEL_SCOPE, readDashboard, routeTemplate, vercelRefusal } from "./sources/vercel.js";
|
|
14
|
+
export { VERCEL_PROJECT, VERCEL_SCOPE, readDashboard, routeTemplate, vercelRecordLines, vercelRefusal, type VercelClasses, type VercelRecord } from "./sources/vercel.js";
|
|
15
15
|
export { readStdin } from "./sources/stdin.js";
|
|
16
|
+
export { LOCAL_ACCESS_REFUSALS, STORED_MAX_TEMPLATES_PER_WINDOW, digestLines, mergeStored, notReadLines, scrubRow, storedRowBytes, toStoredRows, type DigestedLines, type StillRefusing, type StoredMerge, type StoredRow, type StoredWindow, type UnreadableSource, } from "./stored.js";
|
|
17
|
+
export { PROJECT_TABLES, projectClassTable } from "./project-classes.js";
|
|
18
|
+
export { LOG_EXCLUDED, LOG_EXCLUDED_SUPABASE_REFS, LOG_PROJECTS, LOG_PROJECT_IDS, LOG_PROJECT_PATTERN, TOWER_RAILWAY, VERCEL_TEAM_ID, findLogProject, type GcpSource, type LogProject, type LogSource, type NotWiredSource, type RailwaySource, type SupabaseSource, type SupabaseStream, type VercelSource, } from "./log-projects.js";
|
|
19
|
+
export { STORED_EXAMPLE_CHARS, STORED_TEMPLATE_CHARS, scrubForStorage, scrubLine, scrubUnit } from "./scrub.js";
|
package/dist/log-digest/index.js
CHANGED
|
@@ -6,10 +6,14 @@ export { CLASS_ORDER, ClassTable, } from "./classify.js";
|
|
|
6
6
|
export { clock, fleetView, numberText, renderCapped, renderFleet, renderLocal, routineText, subjectsText, timeRange, } from "./render.js";
|
|
7
7
|
export { TOWER_CLASSES, TOWER_PATTERNS, TOWER_TABLE, towerClassTable } from "./tower-classes.js";
|
|
8
8
|
export { WindowError, isoOf, parseWindow, relativeSeconds } from "./window.js";
|
|
9
|
-
export { DEFAULT_MAX_BYTES, SOURCE_NAMES, digestSource, sourceFamily, } from "./digest-source.js";
|
|
9
|
+
export { DEFAULT_MAX_BYTES, SOURCE_NAMES, classifyTemplates, digestSource, sourceFamily, } from "./digest-source.js";
|
|
10
10
|
export { SourceRefusal } from "./sources/types.js";
|
|
11
11
|
export { nodeRunCli } from "./sources/process.js";
|
|
12
12
|
export { readCollector, receiptLine, streamLines, windowShare } from "./sources/collector.js";
|
|
13
13
|
export { RAILWAY_ENVIRONMENT, RAILWAY_PROJECT_ID, railwayRefusal, readRailway } from "./sources/railway.js";
|
|
14
|
-
export { VERCEL_PROJECT, VERCEL_SCOPE, readDashboard, routeTemplate, vercelRefusal } from "./sources/vercel.js";
|
|
14
|
+
export { VERCEL_PROJECT, VERCEL_SCOPE, readDashboard, routeTemplate, vercelRecordLines, vercelRefusal } from "./sources/vercel.js";
|
|
15
15
|
export { readStdin } from "./sources/stdin.js";
|
|
16
|
+
export { LOCAL_ACCESS_REFUSALS, STORED_MAX_TEMPLATES_PER_WINDOW, digestLines, mergeStored, notReadLines, scrubRow, storedRowBytes, toStoredRows, } from "./stored.js";
|
|
17
|
+
export { PROJECT_TABLES, projectClassTable } from "./project-classes.js";
|
|
18
|
+
export { LOG_EXCLUDED, LOG_EXCLUDED_SUPABASE_REFS, LOG_PROJECTS, LOG_PROJECT_IDS, LOG_PROJECT_PATTERN, TOWER_RAILWAY, VERCEL_TEAM_ID, findLogProject, } from "./log-projects.js";
|
|
19
|
+
export { STORED_EXAMPLE_CHARS, STORED_TEMPLATE_CHARS, scrubForStorage, scrubLine, scrubUnit } from "./scrub.js";
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The project registry (BLI-12855): which Vercel project, Railway project and
|
|
3
|
+
* Supabase project each BLI product runs on, so the server-side cron knows what
|
|
4
|
+
* to read and `cockpit logs <project>` knows what to answer for.
|
|
5
|
+
*
|
|
6
|
+
* Ids and names only: no URL with a secret, no token, no env value. Every id
|
|
7
|
+
* below was discovered from the platforms' own CLIs on 2026-10-07
|
|
8
|
+
* (`vercel project ls --scope bli-inc`, `vercel api /v9/projects`,
|
|
9
|
+
* `railway list` and the Railway GraphQL API, `supabase projects list`), and the
|
|
10
|
+
* Vercel-to-Supabase pairing was read from each repo's own code
|
|
11
|
+
* (`gh search code supabase.co --repo BLI-INC/<repo>`), never guessed. A source
|
|
12
|
+
* that cannot be read is `not_wired` with the reason, so a gap is a line in this
|
|
13
|
+
* file and in `docs/runbooks/tower-logs.md`, not a silence.
|
|
14
|
+
*
|
|
15
|
+
* Adding a project: `docs/runbooks/tower-logs.md`, "Add a project".
|
|
16
|
+
*/
|
|
17
|
+
/** The Vercel team every BLI project lives in (slug `bli-inc`). */
|
|
18
|
+
export declare const VERCEL_TEAM_ID = "team_JPu5D09vtC8U3J7FyVxintpK";
|
|
19
|
+
/** Railway project `bli-cockpit-inference` (workspace "canakobli's Projects"), environment `production`. */
|
|
20
|
+
export declare const TOWER_RAILWAY: {
|
|
21
|
+
readonly project_id: "868238ce-d8fe-4629-8e05-fb7492baff1f";
|
|
22
|
+
readonly environment_id: "ec008563-7123-4f26-b425-fb6bb498a404";
|
|
23
|
+
readonly environment: "production";
|
|
24
|
+
};
|
|
25
|
+
export type SupabaseStream = "postgres" | "api" | "auth";
|
|
26
|
+
interface SourceBase {
|
|
27
|
+
/** A stable label stored with every row: `vercel:<name>`, `railway:<project>`, `supabase:<name>`. */
|
|
28
|
+
source: string;
|
|
29
|
+
/** What the class table's `source` regex sees: `dashboard`, `railway`, `vercel`, `supabase`. */
|
|
30
|
+
family: string;
|
|
31
|
+
}
|
|
32
|
+
export interface VercelSource extends SourceBase {
|
|
33
|
+
kind: "vercel";
|
|
34
|
+
/** `prj_...` */
|
|
35
|
+
project_id: string;
|
|
36
|
+
name: string;
|
|
37
|
+
/** The unit prefix of every line: `dashboard` keeps Tower's own class table matching. */
|
|
38
|
+
unit_prefix: string;
|
|
39
|
+
}
|
|
40
|
+
export interface RailwaySource extends SourceBase {
|
|
41
|
+
kind: "railway";
|
|
42
|
+
project_id: string;
|
|
43
|
+
environment_id: string;
|
|
44
|
+
environment: string;
|
|
45
|
+
}
|
|
46
|
+
export interface SupabaseSource extends SourceBase {
|
|
47
|
+
kind: "supabase";
|
|
48
|
+
ref: string;
|
|
49
|
+
name: string;
|
|
50
|
+
streams: readonly SupabaseStream[];
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Google Cloud Logging, one Cloud Run service (BLI-12855). Read with a read-only service account
|
|
54
|
+
* (`roles/logging.viewer`) whose JSON key is `LOGS_GCP_SA_KEY_B64` on the `logs-digest` service; the registry holds
|
|
55
|
+
* the project and service names only, never the key.
|
|
56
|
+
*/
|
|
57
|
+
export interface GcpSource extends SourceBase {
|
|
58
|
+
kind: "gcp";
|
|
59
|
+
/** The GCP project id that holds the logs (`resourceNames: ["projects/<id>"]`). */
|
|
60
|
+
gcp_project: string;
|
|
61
|
+
/** The Cloud Run service name (`resource.labels.service_name`). */
|
|
62
|
+
service: string;
|
|
63
|
+
/** The unit prefix of every line. */
|
|
64
|
+
unit_prefix: string;
|
|
65
|
+
}
|
|
66
|
+
export interface NotWiredSource extends SourceBase {
|
|
67
|
+
kind: "not_wired";
|
|
68
|
+
/** The platform it would be read from. */
|
|
69
|
+
platform: string;
|
|
70
|
+
/** Plain words: why nothing reads it, and what would. */
|
|
71
|
+
reason: string;
|
|
72
|
+
}
|
|
73
|
+
export type LogSource = VercelSource | RailwaySource | SupabaseSource | GcpSource | NotWiredSource;
|
|
74
|
+
export interface LogProject {
|
|
75
|
+
/** What `cockpit logs <project>` takes. */
|
|
76
|
+
id: string;
|
|
77
|
+
name: string;
|
|
78
|
+
sources: readonly LogSource[];
|
|
79
|
+
}
|
|
80
|
+
export declare const LOG_PROJECTS: readonly LogProject[];
|
|
81
|
+
/** Not Tower, so not here: Veetesh's own Vercel project. */
|
|
82
|
+
export declare const LOG_EXCLUDED: readonly ["bli-cockpit-oversight"];
|
|
83
|
+
/**
|
|
84
|
+
* Supabase refs that must NEVER be read, from the project sessions' handoffs on ticket 12860: Kolm's frozen v14 and its
|
|
85
|
+
* empty project, and Pearl Portal's unused staging. `stored.test.ts` pins that none is in the registry.
|
|
86
|
+
*/
|
|
87
|
+
export declare const LOG_EXCLUDED_SUPABASE_REFS: Readonly<Record<string, string>>;
|
|
88
|
+
export declare function findLogProject(id: string): LogProject | null;
|
|
89
|
+
export declare const LOG_PROJECT_IDS: readonly string[];
|
|
90
|
+
/** A project id as `cockpit logs <project>` spells it: lowercase letters, digits and dashes. */
|
|
91
|
+
export declare const LOG_PROJECT_PATTERN: RegExp;
|
|
92
|
+
export {};
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The project registry (BLI-12855): which Vercel project, Railway project and
|
|
3
|
+
* Supabase project each BLI product runs on, so the server-side cron knows what
|
|
4
|
+
* to read and `cockpit logs <project>` knows what to answer for.
|
|
5
|
+
*
|
|
6
|
+
* Ids and names only: no URL with a secret, no token, no env value. Every id
|
|
7
|
+
* below was discovered from the platforms' own CLIs on 2026-10-07
|
|
8
|
+
* (`vercel project ls --scope bli-inc`, `vercel api /v9/projects`,
|
|
9
|
+
* `railway list` and the Railway GraphQL API, `supabase projects list`), and the
|
|
10
|
+
* Vercel-to-Supabase pairing was read from each repo's own code
|
|
11
|
+
* (`gh search code supabase.co --repo BLI-INC/<repo>`), never guessed. A source
|
|
12
|
+
* that cannot be read is `not_wired` with the reason, so a gap is a line in this
|
|
13
|
+
* file and in `docs/runbooks/tower-logs.md`, not a silence.
|
|
14
|
+
*
|
|
15
|
+
* Adding a project: `docs/runbooks/tower-logs.md`, "Add a project".
|
|
16
|
+
*/
|
|
17
|
+
/** The Vercel team every BLI project lives in (slug `bli-inc`). */
|
|
18
|
+
export const VERCEL_TEAM_ID = "team_JPu5D09vtC8U3J7FyVxintpK";
|
|
19
|
+
/** Railway project `bli-cockpit-inference` (workspace "canakobli's Projects"), environment `production`. */
|
|
20
|
+
export const TOWER_RAILWAY = {
|
|
21
|
+
project_id: "868238ce-d8fe-4629-8e05-fb7492baff1f",
|
|
22
|
+
environment_id: "ec008563-7123-4f26-b425-fb6bb498a404",
|
|
23
|
+
environment: "production",
|
|
24
|
+
};
|
|
25
|
+
const vercel = (name, project_id, options = {}) => ({
|
|
26
|
+
kind: "vercel",
|
|
27
|
+
source: `vercel:${name}`,
|
|
28
|
+
family: options.family ?? "vercel",
|
|
29
|
+
project_id,
|
|
30
|
+
name,
|
|
31
|
+
unit_prefix: options.unit_prefix ?? name,
|
|
32
|
+
});
|
|
33
|
+
const supabase = (name, ref, streams = ["postgres", "api", "auth"]) => ({
|
|
34
|
+
kind: "supabase",
|
|
35
|
+
source: `supabase:${name.toLowerCase().replace(/[^a-z0-9]+/g, "-")}`,
|
|
36
|
+
family: "supabase",
|
|
37
|
+
ref,
|
|
38
|
+
name,
|
|
39
|
+
streams,
|
|
40
|
+
});
|
|
41
|
+
const gcpCloudRun = (gcp_project, service) => ({
|
|
42
|
+
kind: "gcp",
|
|
43
|
+
source: `gcp:${service}`,
|
|
44
|
+
family: "gcp",
|
|
45
|
+
gcp_project,
|
|
46
|
+
service,
|
|
47
|
+
unit_prefix: service,
|
|
48
|
+
});
|
|
49
|
+
const notWired = (source, platform, reason) => ({ kind: "not_wired", source, family: platform, platform, reason });
|
|
50
|
+
export const LOG_PROJECTS = [
|
|
51
|
+
{
|
|
52
|
+
id: "tower",
|
|
53
|
+
name: "Tower",
|
|
54
|
+
sources: [
|
|
55
|
+
vercel("bli-cockpit-dashboard", "prj_tKAQTQFCCBIXfnEJWvAbMGAqJjuN", { unit_prefix: "dashboard", family: "dashboard" }),
|
|
56
|
+
{ kind: "railway", source: "railway:bli-cockpit-inference", family: "railway", ...TOWER_RAILWAY },
|
|
57
|
+
supabase("BLI-Cockpit", "bnwolptxyrjalnppqyaf"),
|
|
58
|
+
],
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
id: "portpal",
|
|
62
|
+
name: "PortPal",
|
|
63
|
+
sources: [
|
|
64
|
+
vercel("portpal-2", "prj_QfzQ7rmAAlIdYphezkFXY4JebM3W"),
|
|
65
|
+
supabase("PortPal", "qcnozghkxbnlofahaqig"),
|
|
66
|
+
],
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
id: "blue-pearl-website",
|
|
70
|
+
name: "Blue Pearl website",
|
|
71
|
+
sources: [
|
|
72
|
+
vercel("blue-pearl-landing-page", "prj_qNlZmob3hynJcGfSY6EQRgriDENe"),
|
|
73
|
+
vercel("azure-pearl-insurance", "prj_AYGiGlrYR6Oc6QPA4YxTCL9MTvYp"),
|
|
74
|
+
// The website's own Supabase project, not Pearl Portal's (named in the Pearl Portal session's handoff on ticket 12860).
|
|
75
|
+
supabase("blue-pearl-website", "wcdvrwqwnhbsqtyoqrot"),
|
|
76
|
+
],
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
id: "pearl-portal",
|
|
80
|
+
name: "Pearl Portal",
|
|
81
|
+
sources: [
|
|
82
|
+
vercel("bluepearl-frontend", "prj_cnvD5OppdZqyc8NjlfELlJlChkWf"),
|
|
83
|
+
supabase("BluePearl", "cfznyqwbdjlyvmfhvfuo"),
|
|
84
|
+
// Pearl's mortgage backend on Cloud Run, named by the Pearl Portal session (ticket 12860's comment). Read with the
|
|
85
|
+
// read-only service account tower-logs-reader@buildlaunchiterate (roles/logging.viewer). Its staging service,
|
|
86
|
+
// staging-bluepearlmortgage, exists but is unused: never registered.
|
|
87
|
+
gcpCloudRun("buildlaunchiterate", "blue-pearl-mortgage"),
|
|
88
|
+
notWired("sentry:build-launch-iterate/javascript-nextjs", "sentry", "sentry_token_not_mintable: the Pearl frontend also reports to Sentry (org build-launch-iterate, project javascript-nextjs); a read-only internal-integration token (event:read, project:read, org:read) needs org-level write that the existing Sentry login lacks (creating the integration answered 403), so no token was minted and Edward's broader personal token was not copied; create the integration in Sentry settings, then register the source"),
|
|
89
|
+
],
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
id: "triage-ocr",
|
|
93
|
+
name: "Triage OCR",
|
|
94
|
+
sources: [
|
|
95
|
+
vercel("triage-ocr", "prj_649ktBEpFEkkd46MFAbIFRml55N3"),
|
|
96
|
+
notWired("supabase:triage-ocr", "supabase", "the repo's Supabase ref (xdcheixvpvanblntpisx) is in no Supabase organization the Tower login can read, so its logs cannot be queried; add the ref once a token with access exists"),
|
|
97
|
+
],
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
id: "triage-crm",
|
|
101
|
+
name: "Triage CRM",
|
|
102
|
+
sources: [
|
|
103
|
+
vercel("triage-engine", "prj_PYzJea8t6bgMeUlHGZnwNFklH7GU"),
|
|
104
|
+
supabase("Triage-CRM", "qpzgytjwjgyvevtmrjai"),
|
|
105
|
+
],
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
id: "kolm",
|
|
109
|
+
name: "Kolm",
|
|
110
|
+
sources: [
|
|
111
|
+
vercel("kolm-dashboard-v15", "prj_suQSpiNRR0qi6DEeaYUtYIdL6pia"),
|
|
112
|
+
// Kolm PRODUCTION (the Kolm session's handoff on ticket 12860). The CLI lists this ref under the name "kolm-v15-staging".
|
|
113
|
+
supabase("Kolm", "hvhoyqalnkvbnpteggpi"),
|
|
114
|
+
],
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
id: "kaiben",
|
|
118
|
+
name: "Kaiben",
|
|
119
|
+
sources: [
|
|
120
|
+
supabase("kaiben-core", "ozwovnqtzdwptaeslrep"),
|
|
121
|
+
notWired("droplet:kaiben-ridestyler", "droplet", "Kaiben's operator already writes a 15-minute fleet digest, but only as files on the droplet (/var/log/kaiben-operator/digest-latest.txt and digests/); there is no HTTP or API read, only ssh, which a Railway cron does not hold; the fix is for the operator to POST its digest to a Tower door"),
|
|
122
|
+
],
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
id: "black-knight-tire",
|
|
126
|
+
name: "Black Knight Tire",
|
|
127
|
+
sources: [
|
|
128
|
+
vercel("black-knight-marketplace", "prj_u02otChICpzmg01INncuB2agKDL0"),
|
|
129
|
+
vercel("bkt-reply-copilot", "prj_zvDt2gD4N69hMpU7zfzgNBFlDhgR"),
|
|
130
|
+
supabase("Black Knight Tire", "lvfxhppyzfnvooerblrz"),
|
|
131
|
+
],
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
id: "sublimation-squad",
|
|
135
|
+
name: "Sublimation Squad",
|
|
136
|
+
sources: [
|
|
137
|
+
vercel("sublimation", "prj_CK3YtimGeLZoEbk66Tzr9SVbayWH"),
|
|
138
|
+
supabase("Sublimation-Website", "jlfrjgqvevdnyilkpoue"),
|
|
139
|
+
],
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
id: "bli-website",
|
|
143
|
+
name: "BLI website",
|
|
144
|
+
sources: [
|
|
145
|
+
vercel("bli-website", "prj_7CvxylNLGAFeUeWzEXY7lYjHllIs"),
|
|
146
|
+
vercel("buildlaunchiterate", "prj_Tk79luzslERUZyA8xuGvciVBdPhX"),
|
|
147
|
+
],
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
id: "keep-downloader",
|
|
151
|
+
name: "keep-downloader",
|
|
152
|
+
sources: [
|
|
153
|
+
notWired("railway:keep-downloader", "railway", "a second Railway project (id 84fb1eba-5a8e-4071-a392-22bea076ceee, service keep) with no owner named in any ticket; not wired until someone says it is a BLI product, then it needs its own Railway project token"),
|
|
154
|
+
],
|
|
155
|
+
},
|
|
156
|
+
];
|
|
157
|
+
/** Not Tower, so not here: Veetesh's own Vercel project. */
|
|
158
|
+
export const LOG_EXCLUDED = ["bli-cockpit-oversight"];
|
|
159
|
+
/**
|
|
160
|
+
* Supabase refs that must NEVER be read, from the project sessions' handoffs on ticket 12860: Kolm's frozen v14 and its
|
|
161
|
+
* empty project, and Pearl Portal's unused staging. `stored.test.ts` pins that none is in the registry.
|
|
162
|
+
*/
|
|
163
|
+
export const LOG_EXCLUDED_SUPABASE_REFS = {
|
|
164
|
+
bgrbctwnlnccilpejgth: "Kolm v14, frozen",
|
|
165
|
+
imzkkjrhincdbiejfmlp: "Kolm, an empty project",
|
|
166
|
+
wsqxucgzdqomoyrfnazw: "Pearl Portal staging, unused",
|
|
167
|
+
};
|
|
168
|
+
export function findLogProject(id) {
|
|
169
|
+
return LOG_PROJECTS.find((project) => project.id === id) ?? null;
|
|
170
|
+
}
|
|
171
|
+
export const LOG_PROJECT_IDS = LOG_PROJECTS.map((project) => project.id);
|
|
172
|
+
/** A project id as `cockpit logs <project>` spells it: lowercase letters, digits and dashes. */
|
|
173
|
+
export const LOG_PROJECT_PATTERN = /^[a-z][a-z0-9-]{1,40}$/;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One class table per project (BLI-12855): which masked log templates are bugs,
|
|
3
|
+
* hiccups or harmless, for each BLI product the cron digests.
|
|
4
|
+
*
|
|
5
|
+
* Every table starts from Tower's classes and the `any-*` patterns of Tower's own
|
|
6
|
+
* table (a warning every AI SDK app prints, an npm notice every Railway service
|
|
7
|
+
* prints), then adds that project's own patterns. A project's patterns are seeded
|
|
8
|
+
* from its FIRST REAL DAY of logs, each naming the window and count it came from;
|
|
9
|
+
* a template no pattern matches stays `unknown` and alerts, so a table only ever
|
|
10
|
+
* grows by explaining something, never by silencing it (the rule of
|
|
11
|
+
* `tower-classes.ts`, "Teach it a new pattern" in `docs/runbooks/tower-logs.md`).
|
|
12
|
+
*/
|
|
13
|
+
import { ClassTable, type ClassTableData } from "./classify.js";
|
|
14
|
+
export declare const PROJECT_TABLES: Record<string, ClassTableData>;
|
|
15
|
+
/** The compiled table of one project (built once per process); an unknown project gets the shared one. */
|
|
16
|
+
export declare function projectClassTable(project: string): ClassTable;
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One class table per project (BLI-12855): which masked log templates are bugs,
|
|
3
|
+
* hiccups or harmless, for each BLI product the cron digests.
|
|
4
|
+
*
|
|
5
|
+
* Every table starts from Tower's classes and the `any-*` patterns of Tower's own
|
|
6
|
+
* table (a warning every AI SDK app prints, an npm notice every Railway service
|
|
7
|
+
* prints), then adds that project's own patterns. A project's patterns are seeded
|
|
8
|
+
* from its FIRST REAL DAY of logs, each naming the window and count it came from;
|
|
9
|
+
* a template no pattern matches stays `unknown` and alerts, so a table only ever
|
|
10
|
+
* grows by explaining something, never by silencing it (the rule of
|
|
11
|
+
* `tower-classes.ts`, "Teach it a new pattern" in `docs/runbooks/tower-logs.md`).
|
|
12
|
+
*/
|
|
13
|
+
import { ClassTable } from "./classify.js";
|
|
14
|
+
import { LOG_PROJECT_IDS } from "./log-projects.js";
|
|
15
|
+
import { TOWER_CLASSES, TOWER_PATTERNS } from "./tower-classes.js";
|
|
16
|
+
const SHARED = TOWER_PATTERNS.filter((pattern) => pattern.id.startsWith("any-"));
|
|
17
|
+
const raw = String.raw;
|
|
18
|
+
/**
|
|
19
|
+
* Pearl Portal's backend (Cloud Run `blue-pearl-mortgage`, source family `gcp`), seeded from `gcloud logging read` over
|
|
20
|
+
* 2026-10-06 08:00Z onward. Masking turns every counter into `#`, so a pattern can tell a line's SHAPE, never its values.
|
|
21
|
+
*/
|
|
22
|
+
const PEARL_PORTAL = [
|
|
23
|
+
{
|
|
24
|
+
id: "pearl-sms-optout-sweep-done",
|
|
25
|
+
class: "benign",
|
|
26
|
+
source: "^gcp$",
|
|
27
|
+
unit: "^blue-pearl-mortgage",
|
|
28
|
+
// Only the `done mode=` summary that says `complete=true`: any other OptOut line, or a sweep that did not complete, still alerts.
|
|
29
|
+
match: raw `^\[SMS OptOut Sweep\] done mode=\w+ swept=# .*\bcomplete=true ms=#$`,
|
|
30
|
+
note: "the SMS opt-out sweep's end-of-run summary, one line per run; masking hides the counters, and every run read had refused=0 deferred=0 unfinished=0",
|
|
31
|
+
basis: "pearl-portal gcp:blue-pearl-mortgage via gcloud logging read, 2026-10-06 08:00Z onward: 6 runs, all refused=0 deferred=0 unfinished=0 complete=true",
|
|
32
|
+
},
|
|
33
|
+
// BLI-12870 (revision blue-pearl-mortgage-00682-csz, live 2026-10-07 09:19Z) gave the SMS pull one line per failed user and
|
|
34
|
+
// one skipped line per run, so the summary no longer has to carry the failures. Shapes from BLI-12870 comment d699a863.
|
|
35
|
+
{
|
|
36
|
+
id: "pearl-sms-pull-user-failed-reconnect",
|
|
37
|
+
class: "config_drift",
|
|
38
|
+
source: "^gcp$",
|
|
39
|
+
unit: "^blue-pearl-mortgage",
|
|
40
|
+
match: raw `^\[SMS Pull\] User # failed: reason=(token_refresh_failed|no_token_for_extension|token_unavailable)\b`,
|
|
41
|
+
note: "an ACTIVE user's RingCentral login is dead or missing (deactivated users are skipped before any token call), so their texts are not pulled; a person must reconnect that user's RingCentral (BLI-12871, Ian)",
|
|
42
|
+
basis: "BLI-12870 comment d699a863: the failure line's reason labels; 291 and 297 were failing token refresh every cycle before the fix",
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
id: "pearl-sms-pull-user-failed-code",
|
|
46
|
+
class: "our_bug",
|
|
47
|
+
source: "^gcp$",
|
|
48
|
+
unit: "^blue-pearl-mortgage",
|
|
49
|
+
match: raw `^\[SMS Pull\] User # failed: reason=(message_store_refused|upsert_failed|unexpected_error)\b`,
|
|
50
|
+
note: "the pull reached RingCentral but storing or reading the messages failed: our code or our database, not a login",
|
|
51
|
+
basis: "BLI-12870 comment d699a863: the failure line's reason labels",
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
id: "pearl-sms-pull-skipped-needs-setup",
|
|
55
|
+
class: "config_drift",
|
|
56
|
+
watch: true, // the line has no trouble word, so without this the digest would count it as routine and never alert
|
|
57
|
+
source: "^gcp$",
|
|
58
|
+
unit: "^blue-pearl-mortgage",
|
|
59
|
+
match: raw `^\[SMS Pull\] Skipped # user\(s\):.*\b(no_extension|empty_jwt)=\[`,
|
|
60
|
+
note: "active users with no RingCentral extension or no RingCentral login, so their texts never reach Pearl; Edward 2026-10-07: a gap, not expected. A person sets them up (BLI-12871, Ian)",
|
|
61
|
+
basis: "BLI-12870 comment d699a863: no_extension was 7 users in production (179, 192, 194, 274, 286, 291, 297)",
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
id: "pearl-sms-pull-skipped-inactive",
|
|
65
|
+
class: "benign",
|
|
66
|
+
source: "^gcp$",
|
|
67
|
+
unit: "^blue-pearl-mortgage",
|
|
68
|
+
// Only reached when the line names no no_extension or empty_jwt list (the pattern above wins first).
|
|
69
|
+
match: raw `^\[SMS Pull\] Skipped # user\(s\): inactive_user=\[[#, ]*\]$`,
|
|
70
|
+
note: "deactivated users skipped before any token call, by design since BLI-12870",
|
|
71
|
+
basis: "BLI-12870 comment d699a863",
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
id: "pearl-sms-pull-done",
|
|
75
|
+
class: "benign",
|
|
76
|
+
source: "^gcp$",
|
|
77
|
+
unit: "^blue-pearl-mortgage",
|
|
78
|
+
match: raw `^\[SMS Pull\] Done\. Users: #, Fetched: #, Upserted: #, Skipped: #, Errors: #$`,
|
|
79
|
+
note: "the SMS pull's end-of-run summary; every failure now has its own `User # failed` line, which carries the alert, so the counters here are information",
|
|
80
|
+
basis: "BLI-12870 comment d699a863; first run after the fix (09:34Z) said Errors: 0",
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
id: "pearl-rc-token-pool-refresh-failed",
|
|
84
|
+
class: "config_drift",
|
|
85
|
+
source: "^gcp$",
|
|
86
|
+
unit: "^blue-pearl-mortgage",
|
|
87
|
+
match: raw `^Failed to refresh token for user #: `,
|
|
88
|
+
note: "the RingCentral token pool cannot refresh a user's login (OAU-222 account gone, OAU-331). It fires for active users who need reconnecting AND for deactivated users whose rc_jwt offboarding never cleared; either way a person acts (reconnect, or clear the deactivated user's RingCentral login)",
|
|
89
|
+
basis: "BLI-12870 comment d699a863: about 96 lines a day each for 221, 247 (deactivated) and 291, 297 (active)",
|
|
90
|
+
},
|
|
91
|
+
];
|
|
92
|
+
/** Patterns seeded from each project's first real day. Specific patterns first; first match wins. */
|
|
93
|
+
const SEEDED = {
|
|
94
|
+
tower: TOWER_PATTERNS,
|
|
95
|
+
"pearl-portal": [...PEARL_PORTAL, ...SHARED],
|
|
96
|
+
};
|
|
97
|
+
export const PROJECT_TABLES = Object.fromEntries(LOG_PROJECT_IDS.map((id) => [id, { version: 1, classes: TOWER_CLASSES, patterns: SEEDED[id] ?? SHARED, noiseUnits: [] }]));
|
|
98
|
+
const compiled = new Map();
|
|
99
|
+
/** The compiled table of one project (built once per process); an unknown project gets the shared one. */
|
|
100
|
+
export function projectClassTable(project) {
|
|
101
|
+
let table = compiled.get(project);
|
|
102
|
+
if (!table) {
|
|
103
|
+
table = new ClassTable(PROJECT_TABLES[project] ?? { version: 1, classes: TOWER_CLASSES, patterns: SHARED, noiseUnits: [] });
|
|
104
|
+
compiled.set(project, table);
|
|
105
|
+
}
|
|
106
|
+
return table;
|
|
107
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare const STORED_TEMPLATE_CHARS = 160;
|
|
2
|
+
export declare const STORED_EXAMPLE_CHARS = 160;
|
|
3
|
+
/** Email and phone only: the light pass applied to every line before it is digested. */
|
|
4
|
+
export declare function scrubLine(message: string): string;
|
|
5
|
+
/** A unit (a route family or service name) is never a path to mask; only a person's email or phone in it goes. */
|
|
6
|
+
export declare function scrubUnit(unit: string): string;
|
|
7
|
+
/**
|
|
8
|
+
* The full scrub of a template or an example. Idempotent: scrubbing a scrubbed
|
|
9
|
+
* text returns it unchanged, so the read path can apply it again for free.
|
|
10
|
+
*/
|
|
11
|
+
export declare function scrubForStorage(text: string, limit?: number): string;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The storage scrubber (BLI-12855): what may be written to `project_log_digests`.
|
|
3
|
+
*
|
|
4
|
+
* Plain words: a stored digest row is readable by every `member` and later feeds
|
|
5
|
+
* the brain, and a log line can carry a borrower's email, name, phone or amount
|
|
6
|
+
* (Pearl Portal is a mortgage CRM). The digest's own `redact()` removes secrets
|
|
7
|
+
* only. This removes the people: emails become `<email>`, phone-shaped runs
|
|
8
|
+
* `<phone>`, every number, id, url and path a placeholder (the digest's `mask()`),
|
|
9
|
+
* and every quoted VALUE `"<q>"` (a JSON key stays so the line still reads).
|
|
10
|
+
* What is stored is therefore a masked line, never a raw one.
|
|
11
|
+
*
|
|
12
|
+
* It runs on the STORAGE path only, so the Python-parity digest and the local
|
|
13
|
+
* `cockpit logs` are untouched. Two entry points:
|
|
14
|
+
* - `scrubLine`: email and phone only, applied to each line BEFORE it is
|
|
15
|
+
* digested, so the template id is stable across borrowers and a 200-character
|
|
16
|
+
* cut can never land in the middle of an email.
|
|
17
|
+
* - `scrubForStorage`: the full scrub of a template or example, applied before
|
|
18
|
+
* insert and again on the way out of the table (idempotent, so a row written
|
|
19
|
+
* by anything else is still scrubbed when it is read).
|
|
20
|
+
*
|
|
21
|
+
* What it cannot see, stated plainly: a name that is not quoted and not a
|
|
22
|
+
* `name=...` field ("Borrower Jane Doe applied") is plain prose. That is why the
|
|
23
|
+
* example is cut to 160 characters and why the runbook lists it.
|
|
24
|
+
*/
|
|
25
|
+
import { cut, mask, squash } from "./mask.js";
|
|
26
|
+
const EMAIL = /[A-Za-z0-9._%+-]+@[A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)*\.[A-Za-z]{2,}/g;
|
|
27
|
+
// +1 604 555 0199, (604) 555-0199, 604-555-0199, 604.555.0199. A bare digit run is left to mask()'s number rule.
|
|
28
|
+
const PHONE = /(?<![\w.:-])(?:\+\d{1,3}[\s.-]?)?(?:\(\d{3}\)|\d{3})[\s.-]\d{3}[\s.-]\d{4}(?![\w:])|(?<![\w.:-])\+\d[\d\s().-]{7,}\d(?![\w:])/g;
|
|
29
|
+
// `name=Jane`, `applicant=Jane`: a person's field written as key=value outside JSON.
|
|
30
|
+
const PERSON_FIELD = /\b((?:first_?name|last_?name|full_?name|given_?name|surname|name|borrower|applicant|customer|client|contact|owner|address|dob|birth_?date|sin|ssn)\s*=\s*)[^\s,;&}"'<]+/gi;
|
|
31
|
+
const DOUBLE_QUOTED = /"([^"\n]{0,300})"(\s*:)?/g;
|
|
32
|
+
const SINGLE_QUOTED = /(?<![\w])'([^'\n]{0,300}?)'(?![\w])/g;
|
|
33
|
+
const UNTERMINATED_DOUBLE = /"[^"\n\u0001\u0002\u0003]*$/;
|
|
34
|
+
const UNTERMINATED_SINGLE = /(?<![\w\u0001\u0003])'[^'\n\u0001\u0003]*$/;
|
|
35
|
+
// Control characters stand in for finished quotes while the text is worked on, so a leftover quote mark is an open one.
|
|
36
|
+
const VALUE = "\u0001";
|
|
37
|
+
const KEY = "\u0002";
|
|
38
|
+
const SINGLE_VALUE = "\u0003";
|
|
39
|
+
export const STORED_TEMPLATE_CHARS = 160;
|
|
40
|
+
export const STORED_EXAMPLE_CHARS = 160;
|
|
41
|
+
const CUT_MARK = "…";
|
|
42
|
+
/** Email and phone only: the light pass applied to every line before it is digested. */
|
|
43
|
+
export function scrubLine(message) {
|
|
44
|
+
return message.replace(EMAIL, "<email>").replace(PHONE, "<phone>");
|
|
45
|
+
}
|
|
46
|
+
/** A unit (a route family or service name) is never a path to mask; only a person's email or phone in it goes. */
|
|
47
|
+
export function scrubUnit(unit) {
|
|
48
|
+
return cut(scrubLine(unit), 200);
|
|
49
|
+
}
|
|
50
|
+
function maskQuotedValues(text) {
|
|
51
|
+
let out = text.replace(DOUBLE_QUOTED, (_match, inner, colon) => (colon ? `${KEY}${inner}${KEY}${colon}` : VALUE));
|
|
52
|
+
out = out.replace(SINGLE_QUOTED, SINGLE_VALUE);
|
|
53
|
+
// A cut can land inside a quote: what is left open at the end is a value too.
|
|
54
|
+
out = out.replace(UNTERMINATED_DOUBLE, '"<q>').replace(UNTERMINATED_SINGLE, "'<q>");
|
|
55
|
+
return out.replaceAll(VALUE, '"<q>"').replaceAll(SINGLE_VALUE, "'<q>'").replaceAll(KEY, '"');
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* The full scrub of a template or an example. Idempotent: scrubbing a scrubbed
|
|
59
|
+
* text returns it unchanged, so the read path can apply it again for free.
|
|
60
|
+
*/
|
|
61
|
+
export function scrubForStorage(text, limit = STORED_EXAMPLE_CHARS) {
|
|
62
|
+
if (text === "")
|
|
63
|
+
return text;
|
|
64
|
+
const alreadyCut = text.endsWith(CUT_MARK);
|
|
65
|
+
const body = alreadyCut ? text.slice(0, -CUT_MARK.length) : text;
|
|
66
|
+
let out = scrubLine(body).replace(PERSON_FIELD, "$1<redacted>");
|
|
67
|
+
out = mask(out); // numbers, ids, urls, paths, secrets; cuts to 160
|
|
68
|
+
out = maskQuotedValues(out);
|
|
69
|
+
out = squash(out);
|
|
70
|
+
if (Array.from(out).length > limit)
|
|
71
|
+
return `${cut(out, limit - 1)}${CUT_MARK}`;
|
|
72
|
+
return alreadyCut ? `${out}${CUT_MARK}` : out;
|
|
73
|
+
}
|
|
@@ -1,10 +1,40 @@
|
|
|
1
|
-
import { SourceRefusal, type CliRun, type SourceContext, type SourceRead } from "./types.js";
|
|
1
|
+
import { SourceRefusal, type CliRun, type SourceContext, type SourceLine, type SourceRead } from "./types.js";
|
|
2
2
|
export declare const VERCEL_PROJECT = "bli-cockpit-dashboard";
|
|
3
3
|
export declare const VERCEL_SCOPE = "bli-inc";
|
|
4
|
+
export interface VercelRecord {
|
|
5
|
+
id?: string;
|
|
6
|
+
timestamp?: number;
|
|
7
|
+
level?: string;
|
|
8
|
+
message?: string;
|
|
9
|
+
source?: string;
|
|
10
|
+
requestMethod?: string;
|
|
11
|
+
requestPath?: string;
|
|
12
|
+
responseStatusCode?: number;
|
|
13
|
+
logs?: Array<{
|
|
14
|
+
level?: string;
|
|
15
|
+
message?: string;
|
|
16
|
+
}>;
|
|
17
|
+
}
|
|
4
18
|
/** `/api/docs/3f2a…` becomes `/api/docs/:id`; digits, uuids, long hex and long slugs are one placeholder. */
|
|
5
19
|
export declare function routeTemplate(path: string | undefined): string;
|
|
6
20
|
/** Which named refusal a failed `vercel` run is, or null when the run is not a refusal. */
|
|
7
21
|
export declare function vercelRefusal(run: CliRun): SourceRefusal | null;
|
|
8
22
|
/** The refusal-pattern the runner stops on, so an interactive login is never left waiting. */
|
|
9
23
|
export declare const VERCEL_ABORT_PATTERN: RegExp;
|
|
24
|
+
/** Request classes counted while a Vercel read is turned into lines. */
|
|
25
|
+
export interface VercelClasses {
|
|
26
|
+
ok: number;
|
|
27
|
+
redirect: number;
|
|
28
|
+
client: number;
|
|
29
|
+
server: number;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Turns Vercel request records into digest lines: each nested console line is one line, and a request that ended
|
|
33
|
+
* 5xx / 429 / 403 adds a synthetic line even when the code logged nothing. Shared by the CLI reader above and the
|
|
34
|
+
* server-side HTTP reader (`apps/dashboard/src/lib/project-logs`), so both digest the same text.
|
|
35
|
+
*/
|
|
36
|
+
export declare function vercelRecordLines(records: readonly VercelRecord[], fromEpoch: number, unitPrefix: string): {
|
|
37
|
+
lines: SourceLine[];
|
|
38
|
+
classes: VercelClasses;
|
|
39
|
+
};
|
|
10
40
|
export declare function readDashboard(context: SourceContext): Promise<SourceRead>;
|
|
@@ -77,6 +77,40 @@ function parseRecords(stdout) {
|
|
|
77
77
|
}
|
|
78
78
|
return records;
|
|
79
79
|
}
|
|
80
|
+
/**
|
|
81
|
+
* Turns Vercel request records into digest lines: each nested console line is one line, and a request that ended
|
|
82
|
+
* 5xx / 429 / 403 adds a synthetic line even when the code logged nothing. Shared by the CLI reader above and the
|
|
83
|
+
* server-side HTTP reader (`apps/dashboard/src/lib/project-logs`), so both digest the same text.
|
|
84
|
+
*/
|
|
85
|
+
export function vercelRecordLines(records, fromEpoch, unitPrefix) {
|
|
86
|
+
const lines = [];
|
|
87
|
+
const classes = { ok: 0, redirect: 0, client: 0, server: 0 };
|
|
88
|
+
for (const record of records) {
|
|
89
|
+
const ts = (record.timestamp ?? 0) / 1000;
|
|
90
|
+
if (ts && ts < fromEpoch)
|
|
91
|
+
continue;
|
|
92
|
+
const route = routeTemplate(record.requestPath);
|
|
93
|
+
const unit = route ? `${unitPrefix}:${route}` : unitPrefix;
|
|
94
|
+
const nested = record.logs && record.logs.length > 0 ? record.logs : record.message ? [{ level: record.level, message: record.message }] : [];
|
|
95
|
+
for (const entry of nested) {
|
|
96
|
+
if (typeof entry.message === "string" && entry.message)
|
|
97
|
+
lines.push({ unit, message: entry.message, ts, level: entry.level });
|
|
98
|
+
}
|
|
99
|
+
const status = record.responseStatusCode ?? 0;
|
|
100
|
+
if (status >= 200 && status < 300)
|
|
101
|
+
classes.ok += 1;
|
|
102
|
+
else if (status >= 300 && status < 400)
|
|
103
|
+
classes.redirect += 1;
|
|
104
|
+
else if (status >= 400 && status < 500)
|
|
105
|
+
classes.client += 1;
|
|
106
|
+
else if (status >= 500)
|
|
107
|
+
classes.server += 1;
|
|
108
|
+
if (status >= 500 || status === 429 || status === 403) {
|
|
109
|
+
lines.push({ unit, message: `HTTP ${status} ${record.requestMethod ?? "?"} ${route || "?"}`, ts, level: "error" });
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return { lines, classes };
|
|
113
|
+
}
|
|
80
114
|
export async function readDashboard(context) {
|
|
81
115
|
const { window, run, log } = context;
|
|
82
116
|
const allLevels = context.allLevels ?? false;
|
|
@@ -147,32 +181,7 @@ export async function readDashboard(context) {
|
|
|
147
181
|
await Promise.all(Array.from({ length: CONCURRENCY }, () => worker()));
|
|
148
182
|
if (failure)
|
|
149
183
|
throw failure;
|
|
150
|
-
const lines = [];
|
|
151
|
-
const classes = { ok: 0, redirect: 0, client: 0, server: 0 };
|
|
152
|
-
for (const record of seen.values()) {
|
|
153
|
-
const ts = (record.timestamp ?? 0) / 1000;
|
|
154
|
-
if (ts && ts < window.fromEpoch)
|
|
155
|
-
continue;
|
|
156
|
-
const route = routeTemplate(record.requestPath);
|
|
157
|
-
const unit = route ? `dashboard:${route}` : "dashboard";
|
|
158
|
-
const nested = record.logs && record.logs.length > 0 ? record.logs : record.message ? [{ level: record.level, message: record.message }] : [];
|
|
159
|
-
for (const entry of nested) {
|
|
160
|
-
if (typeof entry.message === "string" && entry.message)
|
|
161
|
-
lines.push({ unit, message: entry.message, ts, level: entry.level });
|
|
162
|
-
}
|
|
163
|
-
const status = record.responseStatusCode ?? 0;
|
|
164
|
-
if (status >= 200 && status < 300)
|
|
165
|
-
classes.ok += 1;
|
|
166
|
-
else if (status >= 300 && status < 400)
|
|
167
|
-
classes.redirect += 1;
|
|
168
|
-
else if (status >= 400 && status < 500)
|
|
169
|
-
classes.client += 1;
|
|
170
|
-
else if (status >= 500)
|
|
171
|
-
classes.server += 1;
|
|
172
|
-
if (status >= 500 || status === 429 || status === 403) {
|
|
173
|
-
lines.push({ unit, message: `HTTP ${status} ${record.requestMethod ?? "?"} ${route || "?"}`, ts, level: "error" });
|
|
174
|
-
}
|
|
175
|
-
}
|
|
184
|
+
const { lines, classes } = vercelRecordLines([...seen.values()], window.fromEpoch, "dashboard");
|
|
176
185
|
const notes = [];
|
|
177
186
|
const requests = classes.ok + classes.redirect + classes.client + classes.server;
|
|
178
187
|
notes.push(allLevels
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stored digests (BLI-12855): the server-side half of `cockpit logs`.
|
|
3
|
+
*
|
|
4
|
+
* Plain words: Tower's cron reads each project's platform logs every 15 minutes,
|
|
5
|
+
* digests them (the same masking, counting and classifying as a local
|
|
6
|
+
* `cockpit logs`) and keeps ONLY the digest: one row per template per window,
|
|
7
|
+
* never a raw line. `digestLines` is the write half (lines to rows);
|
|
8
|
+
* `mergeStored` is the read half (many windows of rows back into one capped
|
|
9
|
+
* digest, real bugs first), which is what `cockpit logs <project>` and the MCP
|
|
10
|
+
* `logs_digest` print when no local log is in reach.
|
|
11
|
+
*
|
|
12
|
+
* Pure functions: no I/O, no clock. The cron and the dashboard door own both.
|
|
13
|
+
*/
|
|
14
|
+
import { type ClassTable } from "./classify.js";
|
|
15
|
+
import { type DigestTemplate } from "./digest-source.js";
|
|
16
|
+
import type { SourceLine } from "./sources/types.js";
|
|
17
|
+
/**
|
|
18
|
+
* The refusals of a LOCAL read that mean "this machine cannot reach the platform": the stored digest is the answer
|
|
19
|
+
* for them, in `cockpit logs` and in the MCP `logs_digest` alike.
|
|
20
|
+
*/
|
|
21
|
+
export declare const LOCAL_ACCESS_REFUSALS: ReadonlySet<string>;
|
|
22
|
+
/** A window keeps at most this many templates; the rest are counted, never silently lost. */
|
|
23
|
+
export declare const STORED_MAX_TEMPLATES_PER_WINDOW = 200;
|
|
24
|
+
/** One template in one window of one source of one project. Metadata only: the example is redacted and cut. */
|
|
25
|
+
export interface StoredRow {
|
|
26
|
+
project: string;
|
|
27
|
+
source: string;
|
|
28
|
+
window_start: string;
|
|
29
|
+
window_end: string;
|
|
30
|
+
tid: string;
|
|
31
|
+
unit: string;
|
|
32
|
+
class: string;
|
|
33
|
+
severity: string;
|
|
34
|
+
template: string;
|
|
35
|
+
example: string;
|
|
36
|
+
count: number;
|
|
37
|
+
first_at: string | null;
|
|
38
|
+
last_at: string | null;
|
|
39
|
+
}
|
|
40
|
+
/** One finished (or refused) window of one source: the commit marker the cursor reads. */
|
|
41
|
+
export interface StoredWindow {
|
|
42
|
+
project: string;
|
|
43
|
+
source: string;
|
|
44
|
+
window_start: string;
|
|
45
|
+
window_end: string;
|
|
46
|
+
/** `ok`, or the named reason this window could not be read (`vercel_token_missing`...). */
|
|
47
|
+
status: string;
|
|
48
|
+
lines_read: number;
|
|
49
|
+
noise: number;
|
|
50
|
+
raw_chars: number;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* A source whose NEWEST row on record is a refusal: blind right now, however old the refusal is. The cron writes an
|
|
54
|
+
* unchanged refusal about every six hours, not every pass, so a read that only looks inside the asked window loses an
|
|
55
|
+
* ongoing outage the moment the window starts after the last refusal row (BLI-12855, the `--since 1h` that read as all clear).
|
|
56
|
+
*/
|
|
57
|
+
export interface StillRefusing {
|
|
58
|
+
source: string;
|
|
59
|
+
/** The named reason of the newest row (`vercel_token_missing`). */
|
|
60
|
+
reason: string;
|
|
61
|
+
/** When the first refusal after this source's last good window was written: how long it has been blind. */
|
|
62
|
+
since: string;
|
|
63
|
+
/** When the newest refusal row was written. */
|
|
64
|
+
last_seen: string;
|
|
65
|
+
}
|
|
66
|
+
/** A registered source nothing reads, with the reason the registry gives. */
|
|
67
|
+
export interface UnreadableSource {
|
|
68
|
+
source: string;
|
|
69
|
+
reason: string;
|
|
70
|
+
}
|
|
71
|
+
export interface DigestedLines {
|
|
72
|
+
lines: number;
|
|
73
|
+
noise: number;
|
|
74
|
+
/** Characters of the log lines read: what the digest saved. */
|
|
75
|
+
rawChars: number;
|
|
76
|
+
/** The kept templates, what needs a person first. */
|
|
77
|
+
templates: DigestTemplate[];
|
|
78
|
+
/** Templates beyond the per-window cap, counted so the loss is said. */
|
|
79
|
+
dropped: number;
|
|
80
|
+
}
|
|
81
|
+
/** Digests one window's lines and classifies every template with the project's table. */
|
|
82
|
+
export declare function digestLines(lines: readonly SourceLine[], options: {
|
|
83
|
+
family: string;
|
|
84
|
+
table: ClassTable;
|
|
85
|
+
maxTemplates?: number;
|
|
86
|
+
}): DigestedLines;
|
|
87
|
+
/** Template rows ready to store: the redacted example and the masked template, never a raw line. */
|
|
88
|
+
export declare function toStoredRows(templates: readonly DigestTemplate[], window: {
|
|
89
|
+
project: string;
|
|
90
|
+
source: string;
|
|
91
|
+
window_start: string;
|
|
92
|
+
window_end: string;
|
|
93
|
+
}): StoredRow[];
|
|
94
|
+
/** A stored row as it may leave the table. */
|
|
95
|
+
export declare function scrubRow(row: StoredRow): StoredRow;
|
|
96
|
+
/** The size of one stored row as JSON: what "bytes stored" counts. */
|
|
97
|
+
export declare function storedRowBytes(row: StoredRow): number;
|
|
98
|
+
export interface StoredMerge {
|
|
99
|
+
text: string;
|
|
100
|
+
/** Merged templates, what needs a person first. */
|
|
101
|
+
templates: Array<DigestTemplate & {
|
|
102
|
+
sources: string[];
|
|
103
|
+
}>;
|
|
104
|
+
windows: number;
|
|
105
|
+
windows_ok: number;
|
|
106
|
+
lines: number;
|
|
107
|
+
noise: number;
|
|
108
|
+
/** `source: reason` for every distinct refusal inside the span, so a blind spot is named. */
|
|
109
|
+
refusals: string[];
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* The verdict lines that sit right under the header: `NOT READ: 5 sources refusing since ...: reason xN, ...` and one
|
|
113
|
+
* line per source. Empty only when every registered source is wired and its newest row is a good window, which is the
|
|
114
|
+
* one state that may read as clear. The counts of ERROR templates stay in the header, apart from this.
|
|
115
|
+
*/
|
|
116
|
+
export declare function notReadLines(stillRefusing: readonly StillRefusing[], notWired: readonly UnreadableSource[]): string[];
|
|
117
|
+
/** Many windows of stored rows merged by template id into one capped digest (about 2 KB, real bugs first). */
|
|
118
|
+
export declare function mergeStored(storedRows: readonly StoredRow[], windows: readonly StoredWindow[], options: {
|
|
119
|
+
project: string;
|
|
120
|
+
label: string;
|
|
121
|
+
maxBytes?: number;
|
|
122
|
+
extraNotes?: readonly string[];
|
|
123
|
+
/** Sources whose newest row is a refusal, whatever the asked window: the answer is NOT clear while any exists. */
|
|
124
|
+
stillRefusing?: readonly StillRefusing[];
|
|
125
|
+
/** Registered sources nothing reads: also NOT clear. */
|
|
126
|
+
notWired?: readonly UnreadableSource[];
|
|
127
|
+
/** True when the project has no window row at all (the cron has never written one for it). */
|
|
128
|
+
neverRan?: boolean;
|
|
129
|
+
/** When the newest row of the project was written, said when the span holds no window. */
|
|
130
|
+
lastRowAt?: string | null;
|
|
131
|
+
}): StoredMerge;
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stored digests (BLI-12855): the server-side half of `cockpit logs`.
|
|
3
|
+
*
|
|
4
|
+
* Plain words: Tower's cron reads each project's platform logs every 15 minutes,
|
|
5
|
+
* digests them (the same masking, counting and classifying as a local
|
|
6
|
+
* `cockpit logs`) and keeps ONLY the digest: one row per template per window,
|
|
7
|
+
* never a raw line. `digestLines` is the write half (lines to rows);
|
|
8
|
+
* `mergeStored` is the read half (many windows of rows back into one capped
|
|
9
|
+
* digest, real bugs first), which is what `cockpit logs <project>` and the MCP
|
|
10
|
+
* `logs_digest` print when no local log is in reach.
|
|
11
|
+
*
|
|
12
|
+
* Pure functions: no I/O, no clock. The cron and the dashboard door own both.
|
|
13
|
+
*/
|
|
14
|
+
import { CLASS_ORDER } from "./classify.js";
|
|
15
|
+
import { Digest } from "./digest.js";
|
|
16
|
+
import { classifyTemplates } from "./digest-source.js";
|
|
17
|
+
import { mergeResults } from "./merge.js";
|
|
18
|
+
import { renderCapped } from "./render.js";
|
|
19
|
+
import { STORED_EXAMPLE_CHARS, STORED_TEMPLATE_CHARS, scrubForStorage, scrubLine, scrubUnit } from "./scrub.js";
|
|
20
|
+
/**
|
|
21
|
+
* The refusals of a LOCAL read that mean "this machine cannot reach the platform": the stored digest is the answer
|
|
22
|
+
* for them, in `cockpit logs` and in the MCP `logs_digest` alike.
|
|
23
|
+
*/
|
|
24
|
+
export const LOCAL_ACCESS_REFUSALS = new Set([
|
|
25
|
+
"vercel_cli_missing", "vercel_not_logged_in", "vercel_scope_denied", "railway_cli_missing", "railway_not_logged_in", "railway_project_unreachable",
|
|
26
|
+
]);
|
|
27
|
+
/** A window keeps at most this many templates; the rest are counted, never silently lost. */
|
|
28
|
+
export const STORED_MAX_TEMPLATES_PER_WINDOW = 200;
|
|
29
|
+
const iso = (epoch) => (epoch ? new Date(epoch * 1000).toISOString() : null);
|
|
30
|
+
/** Digests one window's lines and classifies every template with the project's table. */
|
|
31
|
+
export function digestLines(lines, options) {
|
|
32
|
+
const digest = new Digest({
|
|
33
|
+
noise: options.table.noiseUnits,
|
|
34
|
+
taggedLines: true,
|
|
35
|
+
watch: (group, template) => options.table.watches(group, template, options.family),
|
|
36
|
+
});
|
|
37
|
+
let rawChars = 0;
|
|
38
|
+
for (const line of lines) {
|
|
39
|
+
rawChars += line.message.length + 1;
|
|
40
|
+
// Storage path only: people are removed from each line BEFORE it is digested, so the template id is stable across
|
|
41
|
+
// borrowers and a cut can never land inside an email. The local `cockpit logs` digest does not do this.
|
|
42
|
+
digest.addLine(scrubUnit(line.unit), scrubLine(line.message), line.ts, { level: line.level });
|
|
43
|
+
}
|
|
44
|
+
const result = digest.result();
|
|
45
|
+
const all = classifyTemplates(result, options.table, options.family);
|
|
46
|
+
const cap = options.maxTemplates ?? STORED_MAX_TEMPLATES_PER_WINDOW;
|
|
47
|
+
return { lines: result.lines, noise: result.noise, rawChars, templates: all.slice(0, cap), dropped: Math.max(0, all.length - cap) };
|
|
48
|
+
}
|
|
49
|
+
/** Template rows ready to store: the redacted example and the masked template, never a raw line. */
|
|
50
|
+
export function toStoredRows(templates, window) {
|
|
51
|
+
return templates.map((template) => ({
|
|
52
|
+
...window,
|
|
53
|
+
tid: template.tid,
|
|
54
|
+
unit: scrubUnit(template.unit),
|
|
55
|
+
class: template.class,
|
|
56
|
+
severity: template.severity,
|
|
57
|
+
// What is stored is a masked line, never a raw one (see scrub.ts).
|
|
58
|
+
template: scrubForStorage(template.template, STORED_TEMPLATE_CHARS),
|
|
59
|
+
example: scrubForStorage(template.example, STORED_EXAMPLE_CHARS),
|
|
60
|
+
count: template.count,
|
|
61
|
+
first_at: iso(template.first),
|
|
62
|
+
last_at: iso(template.last),
|
|
63
|
+
}));
|
|
64
|
+
}
|
|
65
|
+
/** A stored row as it may leave the table. */
|
|
66
|
+
export function scrubRow(row) {
|
|
67
|
+
return {
|
|
68
|
+
...row,
|
|
69
|
+
unit: scrubUnit(row.unit),
|
|
70
|
+
template: scrubForStorage(row.template, STORED_TEMPLATE_CHARS),
|
|
71
|
+
example: scrubForStorage(row.example, STORED_EXAMPLE_CHARS),
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
/** The size of one stored row as JSON: what "bytes stored" counts. */
|
|
75
|
+
export function storedRowBytes(row) {
|
|
76
|
+
return Buffer.byteLength(JSON.stringify(row), "utf8");
|
|
77
|
+
}
|
|
78
|
+
const MAX_REFUSALS_NOTED = 4;
|
|
79
|
+
const MAX_STILL_REFUSING_LINES = 6;
|
|
80
|
+
/** `2026-10-07T06:47Z` from any ISO-ish time, the form the other notes use. */
|
|
81
|
+
function minuteOf(time) {
|
|
82
|
+
const parsed = Date.parse(time);
|
|
83
|
+
return Number.isNaN(parsed) ? time.slice(0, 16) : `${new Date(parsed).toISOString().slice(0, 16)}Z`;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* The verdict lines that sit right under the header: `NOT READ: 5 sources refusing since ...: reason xN, ...` and one
|
|
87
|
+
* line per source. Empty only when every registered source is wired and its newest row is a good window, which is the
|
|
88
|
+
* one state that may read as clear. The counts of ERROR templates stay in the header, apart from this.
|
|
89
|
+
*/
|
|
90
|
+
export function notReadLines(stillRefusing, notWired) {
|
|
91
|
+
if (stillRefusing.length === 0 && notWired.length === 0)
|
|
92
|
+
return [];
|
|
93
|
+
const ordered = [...stillRefusing].sort((a, b) => Date.parse(a.since) - Date.parse(b.since) || (a.source < b.source ? -1 : a.source > b.source ? 1 : 0));
|
|
94
|
+
const parts = [];
|
|
95
|
+
if (ordered.length > 0) {
|
|
96
|
+
const reasons = new Map();
|
|
97
|
+
for (const entry of ordered)
|
|
98
|
+
reasons.set(entry.reason, (reasons.get(entry.reason) ?? 0) + 1);
|
|
99
|
+
const earliest = minuteOf(ordered[0].since);
|
|
100
|
+
const together = ordered.every((entry) => minuteOf(entry.since) === earliest);
|
|
101
|
+
const when = together ? ` since ${earliest}` : `, oldest since ${earliest}`;
|
|
102
|
+
parts.push(`${ordered.length} source${ordered.length === 1 ? "" : "s"} refusing${when}: ${[...reasons].map(([reason, count]) => `${reason} x${count}`).join(", ")}`);
|
|
103
|
+
}
|
|
104
|
+
if (notWired.length > 0)
|
|
105
|
+
parts.push(`not wired: ${notWired.map((entry) => entry.source).join(", ")}`);
|
|
106
|
+
const lines = [`NOT READ: ${parts.join("; ")}`];
|
|
107
|
+
for (const entry of ordered.slice(0, MAX_STILL_REFUSING_LINES))
|
|
108
|
+
lines.push(` ${entry.source}: ${entry.reason} (since ${minuteOf(entry.since)}, still refusing)`);
|
|
109
|
+
if (ordered.length > MAX_STILL_REFUSING_LINES)
|
|
110
|
+
lines.push(` +${ordered.length - MAX_STILL_REFUSING_LINES} more still refusing (--json lists all)`);
|
|
111
|
+
return lines;
|
|
112
|
+
}
|
|
113
|
+
/** Many windows of stored rows merged by template id into one capped digest (about 2 KB, real bugs first). */
|
|
114
|
+
export function mergeStored(storedRows, windows, options) {
|
|
115
|
+
// Defence in depth: whatever wrote the rows, what leaves the table is scrubbed again (the scrub is idempotent).
|
|
116
|
+
const rows = storedRows.map(scrubRow);
|
|
117
|
+
const newestFirst = [...rows].sort((a, b) => (a.window_end < b.window_end ? 1 : a.window_end > b.window_end ? -1 : 0));
|
|
118
|
+
// The exact verdict of a template id (newest window wins), and a verdict by printed text for the renderer, which only
|
|
119
|
+
// sees unit and template: two ids whose scrubbed text is identical share it, and the WORSE class wins, so a
|
|
120
|
+
// collision can only make a line louder, never hide a bug.
|
|
121
|
+
const verdictOfTid = new Map();
|
|
122
|
+
const verdicts = new Map();
|
|
123
|
+
const sources = new Map();
|
|
124
|
+
for (const row of newestFirst) {
|
|
125
|
+
const key = `${row.unit}\x1f${row.template}`;
|
|
126
|
+
if (!verdictOfTid.has(row.tid))
|
|
127
|
+
verdictOfTid.set(row.tid, { class: row.class, severity: row.severity });
|
|
128
|
+
const known = verdicts.get(key);
|
|
129
|
+
if (!known || (CLASS_ORDER[row.class] ?? 0) < (CLASS_ORDER[known.class] ?? 0))
|
|
130
|
+
verdicts.set(key, { class: row.class, severity: row.severity });
|
|
131
|
+
const names = sources.get(row.tid) ?? new Set();
|
|
132
|
+
names.add(row.source);
|
|
133
|
+
sources.set(row.tid, names);
|
|
134
|
+
}
|
|
135
|
+
const groups = rows.map((row) => ({
|
|
136
|
+
tid: row.tid,
|
|
137
|
+
unit: row.unit,
|
|
138
|
+
event: "stored",
|
|
139
|
+
template: row.template,
|
|
140
|
+
count: row.count,
|
|
141
|
+
first: row.first_at ? Date.parse(row.first_at) / 1000 : null,
|
|
142
|
+
last: row.last_at ? Date.parse(row.last_at) / 1000 : null,
|
|
143
|
+
example: row.example,
|
|
144
|
+
instances: [],
|
|
145
|
+
}));
|
|
146
|
+
const okWindows = windows.filter((window) => window.status === "ok");
|
|
147
|
+
const lines = okWindows.reduce((sum, window) => sum + window.lines_read, 0);
|
|
148
|
+
const noise = okWindows.reduce((sum, window) => sum + window.noise, 0);
|
|
149
|
+
const merged = mergeResults([{ lines, noise, groups, span: [null, null] }]);
|
|
150
|
+
const refusals = [...new Set(windows.filter((window) => window.status !== "ok").map((window) => `${window.source}: ${window.status}`))];
|
|
151
|
+
const stillRefusing = options.stillRefusing ?? [];
|
|
152
|
+
const stillBlind = new Set(stillRefusing.map((entry) => entry.source));
|
|
153
|
+
// The verdict first, right under the header: a source that is blind or unwired means the counts below are not the whole story.
|
|
154
|
+
const notes = notReadLines(stillRefusing, options.notWired ?? []);
|
|
155
|
+
const spans = okWindows.map((window) => [Date.parse(window.window_start), Date.parse(window.window_end)]);
|
|
156
|
+
if (spans.length > 0) {
|
|
157
|
+
const from = new Date(Math.min(...spans.map((span) => span[0]))).toISOString().slice(0, 16);
|
|
158
|
+
const to = new Date(Math.max(...spans.map((span) => span[1]))).toISOString().slice(0, 16);
|
|
159
|
+
const names = new Set(okWindows.map((window) => window.source));
|
|
160
|
+
notes.push(`stored digests: ${okWindows.length} window${okWindows.length === 1 ? "" : "s"} of ${names.size} source${names.size === 1 ? "" : "s"}, ${from}Z to ${to}Z`);
|
|
161
|
+
}
|
|
162
|
+
else if (options.neverRan) {
|
|
163
|
+
// The ONLY case that says "not run yet": the project has no window row at all, a good one or a refusal.
|
|
164
|
+
notes.push("stored digests: the cron has not run for this project yet (it has written no window row for it)");
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
// The cron has run. A refusal is named above; with none, say how old the newest row is instead of guessing why.
|
|
168
|
+
const newest = stillRefusing.length === 0 && options.lastRowAt ? `; the newest row Tower has for this project was written ${minuteOf(options.lastRowAt)}` : "";
|
|
169
|
+
notes.push(`stored digests: no window was read in this span${newest}`);
|
|
170
|
+
}
|
|
171
|
+
// A refusal inside the span from a source that is still refusing is already in the NOT READ block; this lists the gaps that closed.
|
|
172
|
+
const gaps = [...new Set(windows.filter((window) => window.status !== "ok" && !stillBlind.has(window.source)).map((window) => `${window.source}: ${window.status}`))];
|
|
173
|
+
if (gaps.length > 0) {
|
|
174
|
+
notes.push(`unread: ${gaps.slice(0, MAX_REFUSALS_NOTED).join("; ")}${gaps.length > MAX_REFUSALS_NOTED ? ` +${gaps.length - MAX_REFUSALS_NOTED}` : ""}`);
|
|
175
|
+
}
|
|
176
|
+
notes.push(...(options.extraNotes ?? []));
|
|
177
|
+
const text = renderCapped(merged, {
|
|
178
|
+
source: options.project,
|
|
179
|
+
window: options.label,
|
|
180
|
+
maxBytes: options.maxBytes,
|
|
181
|
+
notes,
|
|
182
|
+
classify: (unit, template) => {
|
|
183
|
+
const verdict = verdicts.get(`${unit}\x1f${template}`);
|
|
184
|
+
return { class: verdict?.class ?? "unknown", severity: (verdict?.severity ?? "ERROR"), pattern: null, note: "" };
|
|
185
|
+
},
|
|
186
|
+
});
|
|
187
|
+
const templates = merged.groups
|
|
188
|
+
.map((group) => {
|
|
189
|
+
const verdict = verdictOfTid.get(group.tid);
|
|
190
|
+
return {
|
|
191
|
+
tid: group.tid, unit: group.unit, class: verdict?.class ?? "unknown", severity: verdict?.severity ?? "ERROR", pattern: null,
|
|
192
|
+
count: group.count, first: group.first, last: group.last, template: group.template, example: group.example, instances: [],
|
|
193
|
+
sources: [...(sources.get(group.tid) ?? [])].sort(),
|
|
194
|
+
};
|
|
195
|
+
})
|
|
196
|
+
.sort((a, b) => (CLASS_ORDER[a.class] ?? 0) - (CLASS_ORDER[b.class] ?? 0) || b.count - a.count || (a.tid < b.tid ? -1 : 1));
|
|
197
|
+
return { text, templates, windows: windows.length, windows_ok: okWindows.length, lines, noise, refusals };
|
|
198
|
+
}
|
|
@@ -243,6 +243,24 @@ export const TOWER_PATTERNS = [
|
|
|
243
243
|
basis: "dashboard 1 h: 1 line",
|
|
244
244
|
},
|
|
245
245
|
// ------------------------------------------------------------------ railway cron services
|
|
246
|
+
{
|
|
247
|
+
id: "railway-logs-digest-repeat-refusal",
|
|
248
|
+
class: "benign",
|
|
249
|
+
source: "^railway$",
|
|
250
|
+
unit: "^logs-digest$",
|
|
251
|
+
match: raw `^\[project-logs unit\] (not asked, platform refused earlier in this firing|refusal unchanged, not written again) reason=`,
|
|
252
|
+
note: "the digest cron restating a refusal it already reported (the platform refused once this firing, or the stored refusal is unchanged); the first refusal is its own line and stays an alert",
|
|
253
|
+
basis: "Edward's QA of `cockpit logs railway --since 1h`, 2026-10-07: 272 such lines filled 6 of the 9 ERROR rows while three tokens were missing",
|
|
254
|
+
},
|
|
255
|
+
{
|
|
256
|
+
id: "railway-logs-digest-token-missing",
|
|
257
|
+
class: "config_drift",
|
|
258
|
+
source: "^railway$",
|
|
259
|
+
unit: "^logs-digest$",
|
|
260
|
+
match: raw `^\[project-logs unit\] refused reason=[a-z]+_token_missing`,
|
|
261
|
+
note: "a platform token is not set on the logs-digest service, so that platform's sources wait (BLI-12855); setting the variable is the fix",
|
|
262
|
+
basis: "Edward's QA, 2026-10-07: LOGS_VERCEL_TOKEN, LOGS_RAILWAY_TOKEN, LOGS_SUPABASE_TOKEN unset on the first live firing",
|
|
263
|
+
},
|
|
246
264
|
{
|
|
247
265
|
id: "railway-cal-sync-token-expired",
|
|
248
266
|
class: "hiccup",
|