@bli-cockpit/telemetry-core 0.1.58 → 0.1.60
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 +48 -0
- package/dist/log-digest/classify.js +81 -0
- package/dist/log-digest/digest-source.d.ts +101 -0
- package/dist/log-digest/digest-source.js +131 -0
- package/dist/log-digest/digest.d.ts +81 -0
- package/dist/log-digest/digest.js +262 -0
- package/dist/log-digest/index.d.ts +19 -0
- package/dist/log-digest/index.js +19 -0
- package/dist/log-digest/judge.d.ts +33 -0
- package/dist/log-digest/judge.js +198 -0
- package/dist/log-digest/log-projects.d.ts +78 -0
- package/dist/log-digest/log-projects.js +163 -0
- package/dist/log-digest/mask.d.ts +12 -0
- package/dist/log-digest/mask.js +106 -0
- package/dist/log-digest/merge.d.ts +12 -0
- package/dist/log-digest/merge.js +65 -0
- package/dist/log-digest/project-classes.d.ts +16 -0
- package/dist/log-digest/project-classes.js +31 -0
- package/dist/log-digest/render.d.ts +51 -0
- package/dist/log-digest/render.js +214 -0
- package/dist/log-digest/scrub.d.ts +11 -0
- package/dist/log-digest/scrub.js +73 -0
- package/dist/log-digest/sources/collector.d.ts +15 -0
- package/dist/log-digest/sources/collector.js +166 -0
- package/dist/log-digest/sources/process.d.ts +2 -0
- package/dist/log-digest/sources/process.js +78 -0
- package/dist/log-digest/sources/railway.d.ts +6 -0
- package/dist/log-digest/sources/railway.js +156 -0
- package/dist/log-digest/sources/stdin.d.ts +9 -0
- package/dist/log-digest/sources/stdin.js +56 -0
- package/dist/log-digest/sources/types.d.ts +67 -0
- package/dist/log-digest/sources/types.js +13 -0
- package/dist/log-digest/sources/vercel.d.ts +40 -0
- package/dist/log-digest/sources/vercel.js +194 -0
- package/dist/log-digest/stored.d.ts +98 -0
- package/dist/log-digest/stored.js +149 -0
- package/dist/log-digest/tagged.d.ts +37 -0
- package/dist/log-digest/tagged.js +114 -0
- package/dist/log-digest/tower-classes.d.ts +28 -0
- package/dist/log-digest/tower-classes.js +301 -0
- package/dist/log-digest/window.d.ts +21 -0
- package/dist/log-digest/window.js +39 -0
- package/package.json +6 -1
|
@@ -0,0 +1,163 @@
|
|
|
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 notWired = (source, platform, reason) => ({ kind: "not_wired", source, family: platform, platform, reason });
|
|
42
|
+
export const LOG_PROJECTS = [
|
|
43
|
+
{
|
|
44
|
+
id: "tower",
|
|
45
|
+
name: "Tower",
|
|
46
|
+
sources: [
|
|
47
|
+
vercel("bli-cockpit-dashboard", "prj_tKAQTQFCCBIXfnEJWvAbMGAqJjuN", { unit_prefix: "dashboard", family: "dashboard" }),
|
|
48
|
+
{ kind: "railway", source: "railway:bli-cockpit-inference", family: "railway", ...TOWER_RAILWAY },
|
|
49
|
+
supabase("BLI-Cockpit", "bnwolptxyrjalnppqyaf"),
|
|
50
|
+
],
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
id: "portpal",
|
|
54
|
+
name: "PortPal",
|
|
55
|
+
sources: [
|
|
56
|
+
vercel("portpal-2", "prj_QfzQ7rmAAlIdYphezkFXY4JebM3W"),
|
|
57
|
+
supabase("PortPal", "qcnozghkxbnlofahaqig"),
|
|
58
|
+
],
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
id: "blue-pearl-website",
|
|
62
|
+
name: "Blue Pearl website",
|
|
63
|
+
sources: [
|
|
64
|
+
vercel("blue-pearl-landing-page", "prj_qNlZmob3hynJcGfSY6EQRgriDENe"),
|
|
65
|
+
vercel("azure-pearl-insurance", "prj_AYGiGlrYR6Oc6QPA4YxTCL9MTvYp"),
|
|
66
|
+
// The website's own Supabase project, not Pearl Portal's (named in the Pearl Portal session's handoff on ticket 12860).
|
|
67
|
+
supabase("blue-pearl-website", "wcdvrwqwnhbsqtyoqrot"),
|
|
68
|
+
],
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
id: "pearl-portal",
|
|
72
|
+
name: "Pearl Portal",
|
|
73
|
+
sources: [
|
|
74
|
+
vercel("bluepearl-frontend", "prj_cnvD5OppdZqyc8NjlfELlJlChkWf"),
|
|
75
|
+
supabase("BluePearl", "cfznyqwbdjlyvmfhvfuo"),
|
|
76
|
+
// From the Pearl Portal session (ticket 12860's comment), not re-verified live from here.
|
|
77
|
+
notWired("gcp:blue-pearl-mortgage", "gcp", "gcloud_not_authenticated: Pearl's mortgage backend runs on Google Cloud Run (service blue-pearl-mortgage, GCP project buildlaunchiterate, region northamerica-northeast2), read through Cloud Logging; this machine's gcloud login (edward@buildlaunchiterate.ca) needs a fresh `gcloud auth login` before a read-only service account (roles/logging.viewer) can be minted, and the cron holds no Google credential yet"),
|
|
78
|
+
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"),
|
|
79
|
+
],
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
id: "triage-ocr",
|
|
83
|
+
name: "Triage OCR",
|
|
84
|
+
sources: [
|
|
85
|
+
vercel("triage-ocr", "prj_649ktBEpFEkkd46MFAbIFRml55N3"),
|
|
86
|
+
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"),
|
|
87
|
+
],
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
id: "triage-crm",
|
|
91
|
+
name: "Triage CRM",
|
|
92
|
+
sources: [
|
|
93
|
+
vercel("triage-engine", "prj_PYzJea8t6bgMeUlHGZnwNFklH7GU"),
|
|
94
|
+
supabase("Triage-CRM", "qpzgytjwjgyvevtmrjai"),
|
|
95
|
+
],
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
id: "kolm",
|
|
99
|
+
name: "Kolm",
|
|
100
|
+
sources: [
|
|
101
|
+
vercel("kolm-dashboard-v15", "prj_suQSpiNRR0qi6DEeaYUtYIdL6pia"),
|
|
102
|
+
// Kolm PRODUCTION (the Kolm session's handoff on ticket 12860). The CLI lists this ref under the name "kolm-v15-staging".
|
|
103
|
+
supabase("Kolm", "hvhoyqalnkvbnpteggpi"),
|
|
104
|
+
],
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
id: "kaiben",
|
|
108
|
+
name: "Kaiben",
|
|
109
|
+
sources: [
|
|
110
|
+
supabase("kaiben-core", "ozwovnqtzdwptaeslrep"),
|
|
111
|
+
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"),
|
|
112
|
+
],
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
id: "black-knight-tire",
|
|
116
|
+
name: "Black Knight Tire",
|
|
117
|
+
sources: [
|
|
118
|
+
vercel("black-knight-marketplace", "prj_u02otChICpzmg01INncuB2agKDL0"),
|
|
119
|
+
vercel("bkt-reply-copilot", "prj_zvDt2gD4N69hMpU7zfzgNBFlDhgR"),
|
|
120
|
+
supabase("Black Knight Tire", "lvfxhppyzfnvooerblrz"),
|
|
121
|
+
],
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
id: "sublimation-squad",
|
|
125
|
+
name: "Sublimation Squad",
|
|
126
|
+
sources: [
|
|
127
|
+
vercel("sublimation", "prj_CK3YtimGeLZoEbk66Tzr9SVbayWH"),
|
|
128
|
+
supabase("Sublimation-Website", "jlfrjgqvevdnyilkpoue"),
|
|
129
|
+
],
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
id: "bli-website",
|
|
133
|
+
name: "BLI website",
|
|
134
|
+
sources: [
|
|
135
|
+
vercel("bli-website", "prj_7CvxylNLGAFeUeWzEXY7lYjHllIs"),
|
|
136
|
+
vercel("buildlaunchiterate", "prj_Tk79luzslERUZyA8xuGvciVBdPhX"),
|
|
137
|
+
],
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
id: "keep-downloader",
|
|
141
|
+
name: "keep-downloader",
|
|
142
|
+
sources: [
|
|
143
|
+
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"),
|
|
144
|
+
],
|
|
145
|
+
},
|
|
146
|
+
];
|
|
147
|
+
/** Not Tower, so not here: Veetesh's own Vercel project. */
|
|
148
|
+
export const LOG_EXCLUDED = ["bli-cockpit-oversight"];
|
|
149
|
+
/**
|
|
150
|
+
* Supabase refs that must NEVER be read, from the project sessions' handoffs on ticket 12860: Kolm's frozen v14 and its
|
|
151
|
+
* empty project, and Pearl Portal's unused staging. `stored.test.ts` pins that none is in the registry.
|
|
152
|
+
*/
|
|
153
|
+
export const LOG_EXCLUDED_SUPABASE_REFS = {
|
|
154
|
+
bgrbctwnlnccilpejgth: "Kolm v14, frozen",
|
|
155
|
+
imzkkjrhincdbiejfmlp: "Kolm, an empty project",
|
|
156
|
+
wsqxucgzdqomoyrfnazw: "Pearl Portal staging, unused",
|
|
157
|
+
};
|
|
158
|
+
export function findLogProject(id) {
|
|
159
|
+
return LOG_PROJECTS.find((project) => project.id === id) ?? null;
|
|
160
|
+
}
|
|
161
|
+
export const LOG_PROJECT_IDS = LOG_PROJECTS.map((project) => project.id);
|
|
162
|
+
/** A project id as `cockpit logs <project>` spells it: lowercase letters, digits and dashes. */
|
|
163
|
+
export const LOG_PROJECT_PATTERN = /^[a-z][a-z0-9-]{1,40}$/;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare const TEMPLATE_CHARS = 160;
|
|
2
|
+
export declare const EXAMPLE_CHARS = 200;
|
|
3
|
+
/** First `limit` code points, like Python's `text[:limit]`. */
|
|
4
|
+
export declare function cut(text: string, limit: number): string;
|
|
5
|
+
/** Python's `" ".join(text.split())`: whitespace runs become one space. */
|
|
6
|
+
export declare function squash(text: string): string;
|
|
7
|
+
/** Tokens and keys masked; the rest untouched. Applied to every example before it is stored or printed. */
|
|
8
|
+
export declare function redact(text: string): string;
|
|
9
|
+
/** The template of one message: every variable part replaced by a placeholder, then cut to 160 characters. */
|
|
10
|
+
export declare function mask(input: unknown): string;
|
|
11
|
+
/** Eight hex characters of sha1(unit group, event, template). Equal problems on two machines share a tid. */
|
|
12
|
+
export declare function templateId(unitGroup: string, event: string, template: string): string;
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Masking: the template of one log message (port of Kaiben's `log_digest.mask`).
|
|
3
|
+
*
|
|
4
|
+
* Plain words: every part of a line that changes from one occurrence to the next
|
|
5
|
+
* (an address, an id, a time, a number) becomes a placeholder, so two lines that
|
|
6
|
+
* say the same thing become the same template and can be counted instead of read.
|
|
7
|
+
*
|
|
8
|
+
* Fixed masking order, so a memory address can never fake a status code
|
|
9
|
+
* (`0x7f...403...`): memory addresses, URLs, UUIDs, timestamps, IPs, long hex,
|
|
10
|
+
* long ids, absolute paths, long or numeric quoted strings, then every other
|
|
11
|
+
* number except a status code in a status position (`HTTP 403`, `status=500`,
|
|
12
|
+
* `[Errno 28]`).
|
|
13
|
+
*
|
|
14
|
+
* Known difference from the Python original: `\b`, `\w` and `\d` here are ASCII
|
|
15
|
+
* only, Python's are Unicode. A template next to a non-ASCII letter can differ.
|
|
16
|
+
*/
|
|
17
|
+
import { createHash } from "node:crypto";
|
|
18
|
+
export const TEMPLATE_CHARS = 160;
|
|
19
|
+
export const EXAMPLE_CHARS = 200;
|
|
20
|
+
const ANSI = /\x1b\[[0-9;]*[A-Za-z]/g;
|
|
21
|
+
const SECRET_PARAMETER = /\b(token|key|apikey|api_key|secret|signature|password|sig|x-amz-[a-z-]+)=([^&\s"']+)/gi;
|
|
22
|
+
const BEARER = /(bearer\s+)\S+/gi;
|
|
23
|
+
// A secret written as a JSON field, which the `name=value` rule cannot see.
|
|
24
|
+
const SECRET_JSON_FIELD = /("(?:token|secret|password|passwd|api_key|apikey|authorization|access_token|refresh_token|client_secret)"\s*:\s*")[^"]*/gi;
|
|
25
|
+
// Token-shaped strings by their well-known prefixes, wherever they appear.
|
|
26
|
+
const TOKEN_SHAPES = [
|
|
27
|
+
/\beyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{4,}/g, // JWT
|
|
28
|
+
/\b(?:sk|pk|rk)-[A-Za-z0-9_-]{16,}/g, // OpenAI-style keys
|
|
29
|
+
/\bgh[pousr]_[A-Za-z0-9]{20,}/g, // GitHub tokens
|
|
30
|
+
/\bgithub_pat_[A-Za-z0-9_]{20,}/g,
|
|
31
|
+
/\bsb_(?:secret|publishable)_[A-Za-z0-9_-]{8,}/g, // Supabase keys
|
|
32
|
+
/\bxox[abprs]-[A-Za-z0-9-]{10,}/g, // Slack tokens
|
|
33
|
+
/\bAKIA[0-9A-Z]{16}\b/g, // AWS access key id
|
|
34
|
+
/\bnpm_[A-Za-z0-9]{30,}/g,
|
|
35
|
+
];
|
|
36
|
+
const MEMORY_ADDRESS = /\b0x[0-9a-fA-F]+\b/g;
|
|
37
|
+
const URL_PATTERN = /\b[a-zA-Z][a-zA-Z0-9+.-]*:\/\/([^/\s"'<>?#:]+)[^\s"'<>]*/g;
|
|
38
|
+
const UUID = /\b[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}\b/g;
|
|
39
|
+
const TIMESTAMP = /\b\d{4}-\d{2}-\d{2}(?:[T ]\d{2}:\d{2}(?::\d{2}(?:[.,]\d+)?)?(?:Z|[+-]\d{2}:?\d{2})?)?\b|\b\d{2}:\d{2}:\d{2}(?:[.,]\d+)?\b/g;
|
|
40
|
+
const IP_ADDRESS = /\b\d{1,3}(?:\.\d{1,3}){3}(?::\d+)?\b/g;
|
|
41
|
+
const LONG_HEX = /\b(?=[0-9a-fA-F]*[0-9])(?=[0-9a-fA-F]*[a-fA-F])[0-9a-fA-F]{8,}\b/g;
|
|
42
|
+
// 4+ digits: an id, not a unit name.
|
|
43
|
+
const LONG_ID = /\b(?=(?:[A-Za-z_-]*\d){4})(?=[A-Za-z0-9_-]*[A-Za-z])[A-Za-z0-9_-]{20,}={0,2}/g;
|
|
44
|
+
// A ':' or ',' inside a segment, never a trailing one.
|
|
45
|
+
const PATH = /(?<![\w.<>/])(?:\/(?:[\w.@%+~-]|[:,](?=\w))+){2,}\/?/g;
|
|
46
|
+
const QUOTED = /'([^'\n]{0,300})'|"([^"\n]{0,300})"/g;
|
|
47
|
+
const NUMBER = /(?<![A-Za-z_\d#])\d+(?:[.,]\d+)*/g;
|
|
48
|
+
// A number right after one of these is a status, not a quantity: kept so
|
|
49
|
+
// "HTTP 403" and "HTTP 404" stay different templates.
|
|
50
|
+
const STATUS_BEFORE = /(?:\bHTTP(?: Error)?[ /:]|\bHTTP\/\d\.\d |\bhttp[=: ]|\bstatus[=: ]|\bcode[=: ]|\[Errno |\bexit(?: code| status)? |\bsignal |\bresponse |\breturned )$/i;
|
|
51
|
+
// The longest alternative above is 12 characters, so 17 characters of context
|
|
52
|
+
// (one more than Python's 16, so `\b` sees the real previous character) decide it.
|
|
53
|
+
const STATUS_WINDOW = 17;
|
|
54
|
+
/** First `limit` code points, like Python's `text[:limit]`. */
|
|
55
|
+
export function cut(text, limit) {
|
|
56
|
+
if (text.length <= limit)
|
|
57
|
+
return text;
|
|
58
|
+
return Array.from(text).slice(0, limit).join("");
|
|
59
|
+
}
|
|
60
|
+
/** Python's `" ".join(text.split())`: whitespace runs become one space. */
|
|
61
|
+
export function squash(text) {
|
|
62
|
+
return text.split(/\s+/).filter(Boolean).join(" ");
|
|
63
|
+
}
|
|
64
|
+
/** Tokens and keys masked; the rest untouched. Applied to every example before it is stored or printed. */
|
|
65
|
+
export function redact(text) {
|
|
66
|
+
let out = text.replace(BEARER, "$1<redacted>").replace(SECRET_PARAMETER, "$1=<redacted>");
|
|
67
|
+
out = out.replace(SECRET_JSON_FIELD, "$1<redacted>");
|
|
68
|
+
for (const shape of TOKEN_SHAPES)
|
|
69
|
+
out = out.replace(shape, "<redacted>");
|
|
70
|
+
return out;
|
|
71
|
+
}
|
|
72
|
+
function keepStatusNumbers(match, offset, whole) {
|
|
73
|
+
const before = whole.slice(Math.max(0, offset - STATUS_WINDOW), offset);
|
|
74
|
+
return STATUS_BEFORE.test(before) ? match : "#";
|
|
75
|
+
}
|
|
76
|
+
function maskPath(path) {
|
|
77
|
+
const name = path.replace(/\/+$/, "").split("/").pop() ?? "";
|
|
78
|
+
return name.endsWith(".py") ? `<path>/${name}` : "<path>";
|
|
79
|
+
}
|
|
80
|
+
function maskQuoted(match, single, double) {
|
|
81
|
+
const inner = single !== undefined ? single : (double ?? "");
|
|
82
|
+
const quote = single !== undefined ? "'" : '"';
|
|
83
|
+
if (Array.from(inner).length > 40 || /\d|\/|</.test(inner))
|
|
84
|
+
return `${quote}<q>${quote}`;
|
|
85
|
+
return match;
|
|
86
|
+
}
|
|
87
|
+
/** The template of one message: every variable part replaced by a placeholder, then cut to 160 characters. */
|
|
88
|
+
export function mask(input) {
|
|
89
|
+
let text = String(input).replace(ANSI, "");
|
|
90
|
+
text = redact(text);
|
|
91
|
+
text = text.replace(MEMORY_ADDRESS, "<addr>");
|
|
92
|
+
text = text.replace(URL_PATTERN, (_m, host) => `<url:${host.toLowerCase()}>`);
|
|
93
|
+
text = text.replace(UUID, "<uuid>");
|
|
94
|
+
text = text.replace(TIMESTAMP, "<ts>");
|
|
95
|
+
text = text.replace(IP_ADDRESS, "<ip>");
|
|
96
|
+
text = text.replace(LONG_HEX, "<hex>");
|
|
97
|
+
text = text.replace(LONG_ID, "<id>");
|
|
98
|
+
text = text.replace(PATH, maskPath);
|
|
99
|
+
text = text.replace(QUOTED, maskQuoted);
|
|
100
|
+
text = text.replace(NUMBER, keepStatusNumbers);
|
|
101
|
+
return cut(squash(text), TEMPLATE_CHARS);
|
|
102
|
+
}
|
|
103
|
+
/** Eight hex characters of sha1(unit group, event, template). Equal problems on two machines share a tid. */
|
|
104
|
+
export function templateId(unitGroup, event, template) {
|
|
105
|
+
return createHash("sha1").update(`${unitGroup}\x1f${event}\x1f${template}`, "utf8").digest("hex").slice(0, 8);
|
|
106
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Several digest results as one (port of Kaiben's `merge_results`): counts
|
|
3
|
+
* summed, times widened, instance sets united. The next slice, a fleet view of
|
|
4
|
+
* every machine's collector digest, merges per-machine results with this.
|
|
5
|
+
*/
|
|
6
|
+
import { type DigestGroup, type DigestResult } from "./digest.js";
|
|
7
|
+
/** A result whose groups may be a list (probe output) or keyed by tid (a stored bucket). */
|
|
8
|
+
export type MergeInput = Omit<Partial<DigestResult>, "groups"> & {
|
|
9
|
+
groups?: DigestGroup[] | Record<string, DigestGroup>;
|
|
10
|
+
};
|
|
11
|
+
export type MergedResult = DigestResult;
|
|
12
|
+
export declare function mergeResults(results: readonly MergeInput[], registry?: Record<string, Partial<DigestGroup>>): MergedResult;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Several digest results as one (port of Kaiben's `merge_results`): counts
|
|
3
|
+
* summed, times widened, instance sets united. The next slice, a fleet view of
|
|
4
|
+
* every machine's collector digest, merges per-machine results with this.
|
|
5
|
+
*/
|
|
6
|
+
import { SUBJECTS_TRACKED } from "./digest.js";
|
|
7
|
+
function earliest(a, b) {
|
|
8
|
+
const values = [a, b].filter((value) => Boolean(value));
|
|
9
|
+
return values.length > 0 ? Math.min(...values) : null;
|
|
10
|
+
}
|
|
11
|
+
function latest(a, b) {
|
|
12
|
+
const value = Math.max(a ?? 0, b ?? 0);
|
|
13
|
+
return value || null;
|
|
14
|
+
}
|
|
15
|
+
export function mergeResults(results, registry = {}) {
|
|
16
|
+
const merged = {
|
|
17
|
+
lines: 0, noise: 0,
|
|
18
|
+
span: [null, null],
|
|
19
|
+
cursors: [null, null],
|
|
20
|
+
groups: new Map(),
|
|
21
|
+
routine: Object.create(null),
|
|
22
|
+
};
|
|
23
|
+
for (const result of results) {
|
|
24
|
+
merged.lines += result.lines ?? 0;
|
|
25
|
+
merged.noise += result.noise ?? 0;
|
|
26
|
+
const [start, end] = result.span ?? [null, null];
|
|
27
|
+
if (start && (merged.span[0] === null || start < merged.span[0]))
|
|
28
|
+
merged.span[0] = start;
|
|
29
|
+
if (end && (merged.span[1] === null || end > merged.span[1]))
|
|
30
|
+
merged.span[1] = end;
|
|
31
|
+
const [first, last] = result.cursors ?? [null, null];
|
|
32
|
+
merged.cursors[0] = merged.cursors[0] ?? first;
|
|
33
|
+
merged.cursors[1] = last ?? merged.cursors[1];
|
|
34
|
+
const groups = result.groups ?? [];
|
|
35
|
+
for (const record of Array.isArray(groups) ? groups : Object.values(groups)) {
|
|
36
|
+
const known = merged.groups.get(record.tid);
|
|
37
|
+
if (!known) {
|
|
38
|
+
merged.groups.set(record.tid, { ...registry[record.tid], ...record, instances: [...(record.instances ?? [])], tid: record.tid });
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
known.count += record.count;
|
|
42
|
+
known.first = earliest(known.first, record.first);
|
|
43
|
+
known.last = latest(known.last, record.last);
|
|
44
|
+
for (const instance of record.instances ?? []) {
|
|
45
|
+
if (!known.instances.includes(instance) && known.instances.length < 64)
|
|
46
|
+
known.instances.push(instance);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
for (const [group, events] of Object.entries(result.routine ?? {})) {
|
|
50
|
+
const into = (merged.routine[group] ??= Object.create(null));
|
|
51
|
+
for (const [event, [count, subjects]] of Object.entries(events)) {
|
|
52
|
+
const record = (into[event] ??= [0, Object.create(null)]);
|
|
53
|
+
record[0] += count;
|
|
54
|
+
for (const [subject, amount] of Object.entries(subjects)) {
|
|
55
|
+
if (subject in record[1] || Object.keys(record[1]).length < SUBJECTS_TRACKED)
|
|
56
|
+
record[1][subject] = (record[1][subject] ?? 0) + amount;
|
|
57
|
+
else
|
|
58
|
+
record[1]["…"] = (record[1]["…"] ?? 0) + amount;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
const groups = [...merged.groups.values()].sort((a, b) => b.count - a.count || (a.tid < b.tid ? -1 : a.tid > b.tid ? 1 : 0));
|
|
64
|
+
return { lines: merged.lines, noise: merged.noise, span: merged.span, cursors: merged.cursors, groups, routine: merged.routine, breaker: {} };
|
|
65
|
+
}
|
|
@@ -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,31 @@
|
|
|
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
|
+
/** Patterns seeded from each project's first real day. Specific patterns first; first match wins. */
|
|
18
|
+
const SEEDED = {
|
|
19
|
+
tower: TOWER_PATTERNS,
|
|
20
|
+
};
|
|
21
|
+
export const PROJECT_TABLES = Object.fromEntries(LOG_PROJECT_IDS.map((id) => [id, { version: 1, classes: TOWER_CLASSES, patterns: SEEDED[id] ?? SHARED, noiseUnits: [] }]));
|
|
22
|
+
const compiled = new Map();
|
|
23
|
+
/** The compiled table of one project (built once per process); an unknown project gets the shared one. */
|
|
24
|
+
export function projectClassTable(project) {
|
|
25
|
+
let table = compiled.get(project);
|
|
26
|
+
if (!table) {
|
|
27
|
+
table = new ClassTable(PROJECT_TABLES[project] ?? { version: 1, classes: TOWER_CLASSES, patterns: SHARED, noiseUnits: [] });
|
|
28
|
+
compiled.set(project, table);
|
|
29
|
+
}
|
|
30
|
+
return table;
|
|
31
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Text renderings of a digest (port of Kaiben's `render_local` and
|
|
3
|
+
* `render_fleet`, plus `renderCapped`, the 2 KB view `cockpit logs` prints).
|
|
4
|
+
*
|
|
5
|
+
* Every renderer is a pure function of its input: the same digest renders
|
|
6
|
+
* byte-identically.
|
|
7
|
+
*/
|
|
8
|
+
import type { Classify } from "./classify.js";
|
|
9
|
+
import type { DigestResult, RoutineEvents } from "./digest.js";
|
|
10
|
+
import type { MergedResult } from "./merge.js";
|
|
11
|
+
export declare function numberText(value: number): string;
|
|
12
|
+
export declare function clock(epoch: number | null | undefined): string;
|
|
13
|
+
export declare function timeRange(first: number | null | undefined, last: number | null | undefined): string;
|
|
14
|
+
/** Caveman's class-invariant enumeration: exact counts for a small value set, else nothing (never a partial list). */
|
|
15
|
+
export declare function subjectsText(subjects: Record<string, number>): string;
|
|
16
|
+
/** `stored=2,280(Volkswagen) retiredLocalCache=12,962 +3`: biggest event counts first. */
|
|
17
|
+
export declare function routineText(routine: Record<string, RoutineEvents>, limit?: number): string;
|
|
18
|
+
/** One machine's (or source's) digest as text. */
|
|
19
|
+
export declare function renderLocal(result: DigestResult, server?: string, classify?: Classify, maxLines?: number): string;
|
|
20
|
+
export interface FleetView {
|
|
21
|
+
window: [number, number];
|
|
22
|
+
servers: Record<string, MergedResult | DigestResult>;
|
|
23
|
+
classify: Classify;
|
|
24
|
+
newTids?: ReadonlySet<string>;
|
|
25
|
+
backTids?: ReadonlySet<string>;
|
|
26
|
+
machines?: string;
|
|
27
|
+
incidents?: string;
|
|
28
|
+
cursorFile?: string;
|
|
29
|
+
}
|
|
30
|
+
/** A fleet view straight from per-server results (no operator state): `--file` runs and tests. */
|
|
31
|
+
export declare function fleetView(resultsByServer: Record<string, MergedResult | DigestResult>, classify: Classify, window?: [number, number]): FleetView;
|
|
32
|
+
/** The fleet digest: every server's templates merged by tid, ERROR first, hiccups counted, WARNINGs one line. */
|
|
33
|
+
export declare function renderFleet(view: FleetView): string;
|
|
34
|
+
export interface CappedOptions {
|
|
35
|
+
/** `dashboard`, `railway:ladder`... */
|
|
36
|
+
source: string;
|
|
37
|
+
/** `last 1h`, `since 2026-10-07T03:00Z`. */
|
|
38
|
+
window: string;
|
|
39
|
+
classify: Classify;
|
|
40
|
+
/** Hard ceiling on the printed bytes. About 2 KB by default. */
|
|
41
|
+
maxBytes?: number;
|
|
42
|
+
/** Plain-words facts about the read itself (capped at N lines, no per-line timestamps...), printed as they are. */
|
|
43
|
+
notes?: readonly string[];
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* The view an agent or a person reads: ERROR classes first (unknown, our_bug,
|
|
47
|
+
* config_drift, capacity), then hiccups, then ONE line counting what is harmless,
|
|
48
|
+
* then the routine work counts. Whatever does not fit the byte budget becomes a
|
|
49
|
+
* `+N more` line naming the next template ids, so nothing is dropped silently.
|
|
50
|
+
*/
|
|
51
|
+
export declare function renderCapped(result: DigestResult, options: CappedOptions): string;
|