@bli-cockpit/telemetry-core 0.1.74 → 0.1.75
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.
|
@@ -17,3 +17,4 @@ export { BLIND_TEMPLATE_PREFIX, LOCAL_ACCESS_REFUSALS, STORED_MAX_TEMPLATES_PER_
|
|
|
17
17
|
export { PROJECT_TABLES, projectClassTable } from "./project-classes.js";
|
|
18
18
|
export { BRAIN_PROJECT_IDS, LOG_EXCLUDED, LOG_EXCLUDED_SUPABASE_REFS, LOG_PROJECTS, LOG_PROJECT_IDS, LOG_PROJECT_PATTERN, TOWER_RAILWAY, VERCEL_TEAM_ID, brainRouteFor, findLogProject, type PushSource, type BrainConfig, type BrainMergePolicy, type BrainRoute, type GcpSource, type LogProject, type LogSource, type NotWiredSource, type RailwaySource, type SupabaseSource, type SupabaseStream, type VercelSource, } from "./log-projects.js";
|
|
19
19
|
export { STORED_EXAMPLE_CHARS, STORED_TEMPLATE_CHARS, scrubForStorage, scrubLine, scrubUnit } from "./scrub.js";
|
|
20
|
+
export { isStaleTemplate, remaskedTemplate, sameFailureUnderCurrentMask } from "./remask.js";
|
package/dist/log-digest/index.js
CHANGED
|
@@ -17,3 +17,4 @@ export { BLIND_TEMPLATE_PREFIX, LOCAL_ACCESS_REFUSALS, STORED_MAX_TEMPLATES_PER_
|
|
|
17
17
|
export { PROJECT_TABLES, projectClassTable } from "./project-classes.js";
|
|
18
18
|
export { BRAIN_PROJECT_IDS, LOG_EXCLUDED, LOG_EXCLUDED_SUPABASE_REFS, LOG_PROJECTS, LOG_PROJECT_IDS, LOG_PROJECT_PATTERN, TOWER_RAILWAY, VERCEL_TEAM_ID, brainRouteFor, findLogProject, } from "./log-projects.js";
|
|
19
19
|
export { STORED_EXAMPLE_CHARS, STORED_TEMPLATE_CHARS, scrubForStorage, scrubLine, scrubUnit } from "./scrub.js";
|
|
20
|
+
export { isStaleTemplate, remaskedTemplate, sameFailureUnderCurrentMask } from "./remask.js";
|
package/dist/log-digest/mask.js
CHANGED
|
@@ -7,9 +7,15 @@
|
|
|
7
7
|
*
|
|
8
8
|
* Fixed masking order, so a memory address can never fake a status code
|
|
9
9
|
* (`0x7f...403...`): memory addresses, URLs, UUIDs, timestamps, IPs, long hex,
|
|
10
|
-
* long ids,
|
|
11
|
-
*
|
|
12
|
-
* `
|
|
10
|
+
* long ids, build-chunk names and minified frame names, absolute paths, long or
|
|
11
|
+
* numeric quoted strings, `#<digits>` ids, long digit runs glued to a word
|
|
12
|
+
* (`call_490779`), then every other number except a status code in a status
|
|
13
|
+
* position (`HTTP 403`, `status=500`, `[Errno 28]`).
|
|
14
|
+
*
|
|
15
|
+
* BLI-17921: `Call #490779` used to keep its id (the number rule skips a digit
|
|
16
|
+
* run right after `#`), so every call id was its own template, its own incident
|
|
17
|
+
* and its own ticket. The id shapes widened since the Python original are marked
|
|
18
|
+
* below; `python-contract.test.ts` still pins every other line.
|
|
13
19
|
*
|
|
14
20
|
* Known difference from the Python original: `\b`, `\w` and `\d` here are ASCII
|
|
15
21
|
* only, Python's are Unicode. A template next to a non-ASCII letter can differ.
|
|
@@ -38,12 +44,23 @@ const URL_PATTERN = /\b[a-zA-Z][a-zA-Z0-9+.-]*:\/\/([^/\s"'<>?#:]+)[^\s"'<>]*/g;
|
|
|
38
44
|
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
45
|
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
46
|
const IP_ADDRESS = /\b\d{1,3}(?:\.\d{1,3}){3}(?::\d+)?\b/g;
|
|
41
|
-
|
|
47
|
+
// 8+ hex characters that mix digits and letters, or any 32+ hex run (a md5, sha1, sha256 or a dashless uuid
|
|
48
|
+
// is never a word, even when luck left it without a digit).
|
|
49
|
+
const LONG_HEX = /\b(?=[0-9a-fA-F]*[0-9])(?=[0-9a-fA-F]*[a-fA-F])[0-9a-fA-F]{8,}\b|\b[0-9a-fA-F]{32,}\b/g;
|
|
42
50
|
// 4+ digits: an id, not a unit name.
|
|
43
51
|
const LONG_ID = /\b(?=(?:[A-Za-z_-]*\d){4})(?=[A-Za-z0-9_-]*[A-Za-z])[A-Za-z0-9_-]{20,}={0,2}/g;
|
|
52
|
+
// A Next/Turbopack chunk file name carries a per-build hash: `[root-of-the-server]__14_qotf._.js` (BLI-17921).
|
|
53
|
+
const BUILD_CHUNK = /(\[[\w.-]+\])__[A-Za-z0-9_]{4,}(?=\._\.js)/g;
|
|
54
|
+
// A minified stack frame names a function by one to three letters that change with every build (`at iz (.next/...)`).
|
|
55
|
+
const MINIFIED_FRAME = /\b(at (?:async )?)[A-Za-z_$][\w$]{0,2}( \((?=[^)\s]*\.next\/))/g;
|
|
44
56
|
// A ':' or ',' inside a segment, never a trailing one.
|
|
45
57
|
const PATH = /(?<![\w.<>/])(?:\/(?:[\w.@%+~-]|[:,](?=\w))+){2,}\/?/g;
|
|
46
58
|
const QUOTED = /'([^'\n]{0,300})'|"([^"\n]{0,300})"/g;
|
|
59
|
+
// `Call #490779`, `order #1042`: an id written with a hash sign (BLI-17921). Not `'`, not `#123abc`, not after a digit or another `#`.
|
|
60
|
+
const HASH_NUMBER = /(?<![\d#&])#\d+(?:[.,]\d+)*(?!\w)/g;
|
|
61
|
+
// Digits glued to a word are an id from five after an underscore or six after a letter (`call_49077`, `rec490779`),
|
|
62
|
+
// never `sha256`, `utf8`, `ipv6` or the `ED25519` key type that the Python golden pins.
|
|
63
|
+
const GLUED_DIGITS = /(?<=_)\d{5,}(?!\w)|(?<=[A-Za-z])\d{6,}(?!\w)/g;
|
|
47
64
|
const NUMBER = /(?<![A-Za-z_\d#])\d+(?:[.,]\d+)*/g;
|
|
48
65
|
// A number right after one of these is a status, not a quantity: kept so
|
|
49
66
|
// "HTTP 403" and "HTTP 404" stay different templates.
|
|
@@ -95,8 +112,12 @@ export function mask(input) {
|
|
|
95
112
|
text = text.replace(IP_ADDRESS, "<ip>");
|
|
96
113
|
text = text.replace(LONG_HEX, "<hex>");
|
|
97
114
|
text = text.replace(LONG_ID, "<id>");
|
|
115
|
+
text = text.replace(BUILD_CHUNK, "$1__<hash>");
|
|
116
|
+
text = text.replace(MINIFIED_FRAME, "$1<fn>$2");
|
|
98
117
|
text = text.replace(PATH, maskPath);
|
|
99
118
|
text = text.replace(QUOTED, maskQuoted);
|
|
119
|
+
text = text.replace(HASH_NUMBER, "#");
|
|
120
|
+
text = text.replace(GLUED_DIGITS, "#");
|
|
100
121
|
text = text.replace(NUMBER, keepStatusNumbers);
|
|
101
122
|
return cut(squash(text), TEMPLATE_CHARS);
|
|
102
123
|
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** The stored text a line with this old stored text would get today. */
|
|
2
|
+
export declare function remaskedTemplate(stored: string): string;
|
|
3
|
+
/** True when today's masker changes this stored text, so the id it was filed under is not the id a new sighting would get. */
|
|
4
|
+
export declare function isStaleTemplate(stored: string): boolean;
|
|
5
|
+
/** True when a sighting whose text today is `current` is the same failure as an incident stored as `stored`. */
|
|
6
|
+
export declare function sameFailureUnderCurrentMask(stored: string, current: string): boolean;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Re-masking a stored template under today's masker (BLI-17921).
|
|
3
|
+
*
|
|
4
|
+
* Plain words: when the masker learns a new id shape (`Call #490779` used to keep its number), the same log
|
|
5
|
+
* line gets a NEW template id, and an incident filed under the old id would look like it vanished while a
|
|
6
|
+
* twin opened under the new one. The old row still holds the old masked text, so running today's masker over
|
|
7
|
+
* that text yields the text the new id would have, and the two can be matched. The official term: a lazy
|
|
8
|
+
* schema migration, re-deriving a stored key from stored data at read time.
|
|
9
|
+
*
|
|
10
|
+
* Two rules keep the match honest:
|
|
11
|
+
* - A stored text that re-masks to itself was never touched by the new rules: it is not stale, and its
|
|
12
|
+
* template id is still the right one, so there is nothing to adopt.
|
|
13
|
+
* - The digest cuts a template at 160 characters. A text that was cut by the OLD masker holds fewer of the
|
|
14
|
+
* line's words than the NEW masker's text (the new placeholders are shorter), so equality is the wrong test
|
|
15
|
+
* for a cut text; its prefix, minus the last (possibly chopped) word, is.
|
|
16
|
+
*/
|
|
17
|
+
import { STORED_TEMPLATE_CHARS, scrubForStorage } from "./scrub.js";
|
|
18
|
+
/** A cut text shorter than this gives a prefix too short to tell two failures apart. */
|
|
19
|
+
const MIN_PREFIX_CHARS = 80;
|
|
20
|
+
/** The stored text a line with this old stored text would get today. */
|
|
21
|
+
export function remaskedTemplate(stored) {
|
|
22
|
+
return scrubForStorage(stored, STORED_TEMPLATE_CHARS);
|
|
23
|
+
}
|
|
24
|
+
/** True when today's masker changes this stored text, so the id it was filed under is not the id a new sighting would get. */
|
|
25
|
+
export function isStaleTemplate(stored) {
|
|
26
|
+
return remaskedTemplate(stored) !== stored;
|
|
27
|
+
}
|
|
28
|
+
/** True when a sighting whose text today is `current` is the same failure as an incident stored as `stored`. */
|
|
29
|
+
export function sameFailureUnderCurrentMask(stored, current) {
|
|
30
|
+
const again = remaskedTemplate(stored);
|
|
31
|
+
if (again === current)
|
|
32
|
+
return true;
|
|
33
|
+
if (Array.from(stored).length < STORED_TEMPLATE_CHARS)
|
|
34
|
+
return false;
|
|
35
|
+
const wholeWords = again.slice(0, Math.max(0, again.lastIndexOf(" ")));
|
|
36
|
+
return Array.from(wholeWords).length >= MIN_PREFIX_CHARS && current.startsWith(wholeWords);
|
|
37
|
+
}
|