@yadsh/dsh-kv-persist 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +110 -0
- package/compatibility.json +16 -0
- package/cordis.patch.yml +4 -0
- package/docs/dsh-kv-persist.md +3311 -0
- package/lib/backends/llama-cpp/backend.d.ts +20 -0
- package/lib/backends/llama-cpp/backend.d.ts.map +1 -0
- package/lib/backends/llama-cpp/backend.js +37 -0
- package/lib/backends/llama-cpp/backend.js.map +1 -0
- package/lib/backends/llama-cpp/client.d.ts +31 -0
- package/lib/backends/llama-cpp/client.d.ts.map +1 -0
- package/lib/backends/llama-cpp/client.js +120 -0
- package/lib/backends/llama-cpp/client.js.map +1 -0
- package/lib/backends/llama-cpp/discovery.d.ts +20 -0
- package/lib/backends/llama-cpp/discovery.d.ts.map +1 -0
- package/lib/backends/llama-cpp/discovery.js +33 -0
- package/lib/backends/llama-cpp/discovery.js.map +1 -0
- package/lib/backends/llama-cpp/types.d.ts +30 -0
- package/lib/backends/llama-cpp/types.d.ts.map +1 -0
- package/lib/backends/llama-cpp/types.js +9 -0
- package/lib/backends/llama-cpp/types.js.map +1 -0
- package/lib/backends/types.d.ts +52 -0
- package/lib/backends/types.d.ts.map +1 -0
- package/lib/backends/types.js +6 -0
- package/lib/backends/types.js.map +1 -0
- package/lib/config.d.ts +258 -0
- package/lib/config.d.ts.map +1 -0
- package/lib/config.js +169 -0
- package/lib/config.js.map +1 -0
- package/lib/coordinator/checkpoint-policy.d.ts +19 -0
- package/lib/coordinator/checkpoint-policy.d.ts.map +1 -0
- package/lib/coordinator/checkpoint-policy.js +40 -0
- package/lib/coordinator/checkpoint-policy.js.map +1 -0
- package/lib/coordinator/circuit-breaker.d.ts +29 -0
- package/lib/coordinator/circuit-breaker.d.ts.map +1 -0
- package/lib/coordinator/circuit-breaker.js +62 -0
- package/lib/coordinator/circuit-breaker.js.map +1 -0
- package/lib/coordinator/coordinator.d.ts +74 -0
- package/lib/coordinator/coordinator.d.ts.map +1 -0
- package/lib/coordinator/coordinator.js +542 -0
- package/lib/coordinator/coordinator.js.map +1 -0
- package/lib/coordinator/slot-lease.d.ts +22 -0
- package/lib/coordinator/slot-lease.d.ts.map +1 -0
- package/lib/coordinator/slot-lease.js +38 -0
- package/lib/coordinator/slot-lease.js.map +1 -0
- package/lib/coordinator/state-machine.d.ts +65 -0
- package/lib/coordinator/state-machine.d.ts.map +1 -0
- package/lib/coordinator/state-machine.js +40 -0
- package/lib/coordinator/state-machine.js.map +1 -0
- package/lib/errors.d.ts +82 -0
- package/lib/errors.d.ts.map +1 -0
- package/lib/errors.js +113 -0
- package/lib/errors.js.map +1 -0
- package/lib/index.d.ts +26 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +17 -0
- package/lib/index.js.map +1 -0
- package/lib/logging/dsh-home.d.ts +13 -0
- package/lib/logging/dsh-home.d.ts.map +1 -0
- package/lib/logging/dsh-home.js +18 -0
- package/lib/logging/dsh-home.js.map +1 -0
- package/lib/logging/index.d.ts +10 -0
- package/lib/logging/index.d.ts.map +1 -0
- package/lib/logging/index.js +10 -0
- package/lib/logging/index.js.map +1 -0
- package/lib/logging/plugin-logger.d.ts +94 -0
- package/lib/logging/plugin-logger.d.ts.map +1 -0
- package/lib/logging/plugin-logger.js +397 -0
- package/lib/logging/plugin-logger.js.map +1 -0
- package/lib/observability/diagnostics.d.ts +37 -0
- package/lib/observability/diagnostics.d.ts.map +1 -0
- package/lib/observability/diagnostics.js +75 -0
- package/lib/observability/diagnostics.js.map +1 -0
- package/lib/observability/metrics.d.ts +38 -0
- package/lib/observability/metrics.d.ts.map +1 -0
- package/lib/observability/metrics.js +29 -0
- package/lib/observability/metrics.js.map +1 -0
- package/lib/service.d.ts +231 -0
- package/lib/service.d.ts.map +1 -0
- package/lib/service.js +232 -0
- package/lib/service.js.map +1 -0
- package/lib/snapshots/fingerprint.d.ts +53 -0
- package/lib/snapshots/fingerprint.d.ts.map +1 -0
- package/lib/snapshots/fingerprint.js +69 -0
- package/lib/snapshots/fingerprint.js.map +1 -0
- package/lib/snapshots/manifest.d.ts +51 -0
- package/lib/snapshots/manifest.d.ts.map +1 -0
- package/lib/snapshots/manifest.js +0 -0
- package/lib/snapshots/manifest.js.map +1 -0
- package/lib/snapshots/naming.d.ts +18 -0
- package/lib/snapshots/naming.d.ts.map +1 -0
- package/lib/snapshots/naming.js +33 -0
- package/lib/snapshots/naming.js.map +1 -0
- package/lib/snapshots/repository.d.ts +52 -0
- package/lib/snapshots/repository.d.ts.map +1 -0
- package/lib/snapshots/repository.js +270 -0
- package/lib/snapshots/repository.js.map +1 -0
- package/package.json +83 -0
|
@@ -0,0 +1,397 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plugin file logger — the seed of the future `@yadsh/dsh-plugin-log` package.
|
|
3
|
+
*
|
|
4
|
+
* Every plugin currently carries its own verbatim copy of `src/logging/`
|
|
5
|
+
* (guidelines §5.2); the exported API below is frozen so that switching to
|
|
6
|
+
* the extracted package later is a one-line import change. The wrapper:
|
|
7
|
+
*
|
|
8
|
+
* - wraps `pino` for severity levels and NDJSON serialization;
|
|
9
|
+
* - writes daily files `<dir>/<YYYY-MM-DD>.log`, by default under
|
|
10
|
+
* `<$DSH_HOME>/logs/<pluginId>`;
|
|
11
|
+
* - mirrors selected records to an injectable console sink (default level
|
|
12
|
+
* `warn`) so operators still see problems live;
|
|
13
|
+
* - never throws at runtime: file-system failures degrade to console-only
|
|
14
|
+
* logging (fail-open), and closed loggers silently drop records;
|
|
15
|
+
* - disables file output when `DSH_LOG_DISABLED=1`, and under `NODE_ENV=test`
|
|
16
|
+
* unless `dir` is set explicitly (unit tests never touch a real home).
|
|
17
|
+
*
|
|
18
|
+
* Record shape (one JSON object per line): pino's `level` (numeric),
|
|
19
|
+
* `time` (epoch ms) and `msg` (= the event code), plus `plugin` and the
|
|
20
|
+
* caller's fields; `child(module)` adds `module`. Reserved pino keys
|
|
21
|
+
* (`level`, `time`, `msg`, `plugin`, `module`) must not be used as field
|
|
22
|
+
* names.
|
|
23
|
+
*/
|
|
24
|
+
import { mkdirSync } from "node:fs";
|
|
25
|
+
import { readdir, unlink } from "node:fs/promises";
|
|
26
|
+
import { join } from "node:path";
|
|
27
|
+
import { Writable } from "node:stream";
|
|
28
|
+
import pino from "pino";
|
|
29
|
+
import { resolveDshHome } from "./dsh-home.js";
|
|
30
|
+
/** Ordered severity levels; `silent` disables the logger entirely. */
|
|
31
|
+
export const PLUGIN_LOG_LEVELS = [
|
|
32
|
+
"trace",
|
|
33
|
+
"debug",
|
|
34
|
+
"info",
|
|
35
|
+
"warn",
|
|
36
|
+
"error",
|
|
37
|
+
"fatal",
|
|
38
|
+
"silent",
|
|
39
|
+
];
|
|
40
|
+
/** Default console mirror threshold. */
|
|
41
|
+
export const DEFAULT_CONSOLE_LEVEL = "warn";
|
|
42
|
+
/** Daily log files kept per plugin by default (0 = keep forever). */
|
|
43
|
+
export const DEFAULT_LOG_RETENTION_DAYS = 14;
|
|
44
|
+
const LEVEL_WEIGHT = {
|
|
45
|
+
trace: 10,
|
|
46
|
+
debug: 20,
|
|
47
|
+
info: 30,
|
|
48
|
+
warn: 40,
|
|
49
|
+
error: 50,
|
|
50
|
+
fatal: 60,
|
|
51
|
+
};
|
|
52
|
+
const DAY_MS = 86_400_000;
|
|
53
|
+
const LOG_FILE_PATTERN = /^(\d{4}-\d{2}-\d{2})\.log$/;
|
|
54
|
+
function weightOf(level) {
|
|
55
|
+
return level === "silent" ? Number.POSITIVE_INFINITY : LEVEL_WEIGHT[level];
|
|
56
|
+
}
|
|
57
|
+
/** Type guard for level strings (config parsing, env overrides). */
|
|
58
|
+
export function isPluginLogLevel(value) {
|
|
59
|
+
return typeof value === "string" && PLUGIN_LOG_LEVELS.includes(value);
|
|
60
|
+
}
|
|
61
|
+
function formatConsole(event, fields) {
|
|
62
|
+
if (fields === undefined)
|
|
63
|
+
return event;
|
|
64
|
+
const parts = Object.entries(fields).map(([key, value]) => {
|
|
65
|
+
const rendered = typeof value === "string" ? value : JSON.stringify(value);
|
|
66
|
+
return `${key}=${rendered}`;
|
|
67
|
+
});
|
|
68
|
+
return parts.length === 0 ? event : `${event} ${parts.join(" ")}`;
|
|
69
|
+
}
|
|
70
|
+
/** Local-calendar date stamp used in file names (sorts lexically). */
|
|
71
|
+
function dayStamp(ms) {
|
|
72
|
+
const date = new Date(ms);
|
|
73
|
+
const month = String(date.getMonth() + 1).padStart(2, "0");
|
|
74
|
+
const day = String(date.getDate()).padStart(2, "0");
|
|
75
|
+
return `${date.getFullYear()}-${month}-${day}`;
|
|
76
|
+
}
|
|
77
|
+
function envLevelOverride(pluginId) {
|
|
78
|
+
const env = process.env;
|
|
79
|
+
const specific = env[`DSH_LOG_LEVEL_${pluginId.replaceAll("-", "_").toUpperCase()}`];
|
|
80
|
+
if (isPluginLogLevel(specific))
|
|
81
|
+
return specific;
|
|
82
|
+
return isPluginLogLevel(env.DSH_LOG_LEVEL) ? env.DSH_LOG_LEVEL : undefined;
|
|
83
|
+
}
|
|
84
|
+
function envFileDisabled(explicitDir) {
|
|
85
|
+
const flag = process.env.DSH_LOG_DISABLED ?? process.env.DSH_PLUGIN_LOG_DISABLED;
|
|
86
|
+
if (flag === "1" || flag === "true")
|
|
87
|
+
return true;
|
|
88
|
+
// Unit tests must never write into a real DSH home unless a dir is explicit.
|
|
89
|
+
return process.env.NODE_ENV === "test" && !explicitDir;
|
|
90
|
+
}
|
|
91
|
+
async function sweepOldLogFiles(dir, retentionDays, nowMs) {
|
|
92
|
+
if (retentionDays <= 0)
|
|
93
|
+
return;
|
|
94
|
+
const cutoff = nowMs - retentionDays * DAY_MS;
|
|
95
|
+
const entries = await readdir(dir).catch(() => []);
|
|
96
|
+
for (const entry of entries) {
|
|
97
|
+
const match = LOG_FILE_PATTERN.exec(entry);
|
|
98
|
+
if (match === null || match[1] === undefined)
|
|
99
|
+
continue;
|
|
100
|
+
const stampMs = Date.parse(`${match[1]}T00:00:00`);
|
|
101
|
+
if (!Number.isFinite(stampMs) || stampMs >= cutoff)
|
|
102
|
+
continue;
|
|
103
|
+
await unlink(join(dir, entry)).catch(() => undefined);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
let sharedDevNull;
|
|
107
|
+
function devNull() {
|
|
108
|
+
sharedDevNull ??= new Writable({
|
|
109
|
+
write(_chunk, _encoding, callback) {
|
|
110
|
+
callback();
|
|
111
|
+
},
|
|
112
|
+
});
|
|
113
|
+
return sharedDevNull;
|
|
114
|
+
}
|
|
115
|
+
function closeQuietly(destination) {
|
|
116
|
+
try {
|
|
117
|
+
destination.end?.();
|
|
118
|
+
}
|
|
119
|
+
catch {
|
|
120
|
+
// Fail-open: closing must never surface.
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* SonicBoom's `end()` takes no callback — completion is signaled by the
|
|
125
|
+
* `close` event. A bounded guard keeps a wedged stream from hanging plugin
|
|
126
|
+
* disposal forever.
|
|
127
|
+
*/
|
|
128
|
+
function closeDestination(destination) {
|
|
129
|
+
return new Promise((resolve) => {
|
|
130
|
+
if (destination.destroyed === true) {
|
|
131
|
+
resolve();
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
let settled = false;
|
|
135
|
+
const done = () => {
|
|
136
|
+
if (settled)
|
|
137
|
+
return;
|
|
138
|
+
settled = true;
|
|
139
|
+
clearTimeout(guard);
|
|
140
|
+
resolve();
|
|
141
|
+
};
|
|
142
|
+
const guard = setTimeout(done, 1000);
|
|
143
|
+
guard.unref();
|
|
144
|
+
try {
|
|
145
|
+
destination.once?.("close", done);
|
|
146
|
+
destination.end?.();
|
|
147
|
+
}
|
|
148
|
+
catch {
|
|
149
|
+
done();
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
function errorMessage(error) {
|
|
154
|
+
return error instanceof Error ? error.message : String(error);
|
|
155
|
+
}
|
|
156
|
+
const defaultSink = (level, message) => {
|
|
157
|
+
if (level === "warn")
|
|
158
|
+
console.warn(message);
|
|
159
|
+
else if (level === "error" || level === "fatal")
|
|
160
|
+
console.error(message);
|
|
161
|
+
else if (level === "trace" || level === "debug")
|
|
162
|
+
console.log(message);
|
|
163
|
+
else
|
|
164
|
+
console.info(message);
|
|
165
|
+
};
|
|
166
|
+
/** Mutable state shared by a root logger and all of its `child()` views. */
|
|
167
|
+
class LoggerCore {
|
|
168
|
+
pluginId;
|
|
169
|
+
dir;
|
|
170
|
+
levelName;
|
|
171
|
+
consoleLevel;
|
|
172
|
+
sink;
|
|
173
|
+
retentionDays;
|
|
174
|
+
redact;
|
|
175
|
+
clock;
|
|
176
|
+
fileEnabled;
|
|
177
|
+
closed = false;
|
|
178
|
+
destination;
|
|
179
|
+
destinationDay = "";
|
|
180
|
+
root;
|
|
181
|
+
children = new Map();
|
|
182
|
+
retention;
|
|
183
|
+
constructor(options) {
|
|
184
|
+
if (!/^[A-Za-z0-9][A-Za-z0-9._-]*$/.test(options.pluginId)) {
|
|
185
|
+
throw new TypeError(`pluginId must match [A-Za-z0-9][A-Za-z0-9._-]*, got ${JSON.stringify(options.pluginId)}`);
|
|
186
|
+
}
|
|
187
|
+
this.pluginId = options.pluginId;
|
|
188
|
+
const home = options.dshHome ?? resolveDshHome();
|
|
189
|
+
this.dir = options.dir ?? join(home, "logs", options.pluginId);
|
|
190
|
+
this.levelName = options.level ?? envLevelOverride(options.pluginId) ?? "info";
|
|
191
|
+
this.consoleLevel = options.console ?? DEFAULT_CONSOLE_LEVEL;
|
|
192
|
+
this.sink = options.consoleSink ?? defaultSink;
|
|
193
|
+
this.retentionDays = Math.max(0, Math.floor(options.retentionDays ?? DEFAULT_LOG_RETENTION_DAYS));
|
|
194
|
+
this.redact = options.redact ?? [];
|
|
195
|
+
this.clock = options.now ?? Date.now;
|
|
196
|
+
this.fileEnabled = (options.file ?? true) && !envFileDisabled(options.dir !== undefined);
|
|
197
|
+
}
|
|
198
|
+
isClosed() {
|
|
199
|
+
return this.closed;
|
|
200
|
+
}
|
|
201
|
+
key() {
|
|
202
|
+
return `${this.pluginId}\u0000${this.dir}`;
|
|
203
|
+
}
|
|
204
|
+
get level() {
|
|
205
|
+
return this.levelName;
|
|
206
|
+
}
|
|
207
|
+
setLevel(level) {
|
|
208
|
+
if (!isPluginLogLevel(level)) {
|
|
209
|
+
throw new TypeError(`unknown plugin log level: ${JSON.stringify(level)}`);
|
|
210
|
+
}
|
|
211
|
+
if (level === this.levelName)
|
|
212
|
+
return;
|
|
213
|
+
this.levelName = level;
|
|
214
|
+
// Rebuild the destination on the next write so the new threshold takes
|
|
215
|
+
// effect without touching the file handle while silent.
|
|
216
|
+
this.destinationDay = "";
|
|
217
|
+
}
|
|
218
|
+
write(moduleField, level, event, fields) {
|
|
219
|
+
if (this.closed || this.levelName === "silent")
|
|
220
|
+
return;
|
|
221
|
+
if (weightOf(level) < weightOf(this.levelName)) {
|
|
222
|
+
this.mirror(moduleField, level, event, fields);
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
this.open();
|
|
226
|
+
const target = this.targetFor(moduleField);
|
|
227
|
+
if (target !== undefined) {
|
|
228
|
+
try {
|
|
229
|
+
target[level](fields ?? {}, event);
|
|
230
|
+
}
|
|
231
|
+
catch {
|
|
232
|
+
// Fail-open: serialization problems must never break the plugin.
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
this.mirror(moduleField, level, event, fields);
|
|
236
|
+
}
|
|
237
|
+
flush() {
|
|
238
|
+
try {
|
|
239
|
+
this.destination?.flushSync?.();
|
|
240
|
+
}
|
|
241
|
+
catch {
|
|
242
|
+
// Fail-open.
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
async close() {
|
|
246
|
+
if (this.closed)
|
|
247
|
+
return;
|
|
248
|
+
this.closed = true;
|
|
249
|
+
registry.delete(this.key());
|
|
250
|
+
const destination = this.destination;
|
|
251
|
+
this.destination = undefined;
|
|
252
|
+
this.root = undefined;
|
|
253
|
+
this.children.clear();
|
|
254
|
+
this.destinationDay = "";
|
|
255
|
+
await this.retention;
|
|
256
|
+
if (destination !== undefined)
|
|
257
|
+
await closeDestination(destination);
|
|
258
|
+
}
|
|
259
|
+
/** Open (or roll over to) the destination file for the current day. */
|
|
260
|
+
open() {
|
|
261
|
+
const stamp = dayStamp(this.clock());
|
|
262
|
+
if (this.root !== undefined && stamp === this.destinationDay)
|
|
263
|
+
return;
|
|
264
|
+
this.rollover(stamp);
|
|
265
|
+
}
|
|
266
|
+
rollover(stamp) {
|
|
267
|
+
this.destinationDay = stamp;
|
|
268
|
+
let next;
|
|
269
|
+
if (this.fileEnabled) {
|
|
270
|
+
try {
|
|
271
|
+
mkdirSync(this.dir, { recursive: true });
|
|
272
|
+
next = pino.destination({
|
|
273
|
+
dest: join(this.dir, `${stamp}.log`),
|
|
274
|
+
append: true,
|
|
275
|
+
mkdir: true,
|
|
276
|
+
sync: false,
|
|
277
|
+
minLength: 0,
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
catch (error) {
|
|
281
|
+
// Fail-open: an unusable log directory degrades to console-only.
|
|
282
|
+
this.fileEnabled = false;
|
|
283
|
+
next = undefined;
|
|
284
|
+
this.mirror(undefined, "warn", "logging.file_disabled", { reason: errorMessage(error) });
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
const previous = this.destination;
|
|
288
|
+
this.destination = next;
|
|
289
|
+
this.children.clear();
|
|
290
|
+
this.root = pino({
|
|
291
|
+
level: this.levelName,
|
|
292
|
+
base: { plugin: this.pluginId },
|
|
293
|
+
...(this.redact.length > 0 ? { redact: [...this.redact] } : {}),
|
|
294
|
+
}, next ?? devNull());
|
|
295
|
+
if (previous !== undefined && previous !== next)
|
|
296
|
+
closeQuietly(previous);
|
|
297
|
+
if (this.fileEnabled)
|
|
298
|
+
this.scheduleRetentionSweep();
|
|
299
|
+
}
|
|
300
|
+
targetFor(moduleField) {
|
|
301
|
+
const root = this.root;
|
|
302
|
+
if (root === undefined)
|
|
303
|
+
return undefined;
|
|
304
|
+
if (moduleField === undefined)
|
|
305
|
+
return root;
|
|
306
|
+
const cached = this.children.get(moduleField);
|
|
307
|
+
if (cached !== undefined)
|
|
308
|
+
return cached;
|
|
309
|
+
const created = root.child({ module: moduleField });
|
|
310
|
+
this.children.set(moduleField, created);
|
|
311
|
+
return created;
|
|
312
|
+
}
|
|
313
|
+
mirror(moduleField, level, event, fields) {
|
|
314
|
+
if (this.consoleLevel === "silent")
|
|
315
|
+
return;
|
|
316
|
+
if (weightOf(level) < weightOf(this.consoleLevel))
|
|
317
|
+
return;
|
|
318
|
+
const scope = moduleField === undefined ? "" : `/${moduleField}`;
|
|
319
|
+
try {
|
|
320
|
+
this.sink(level, `[${this.pluginId}${scope}] ${formatConsole(event, fields)}`);
|
|
321
|
+
}
|
|
322
|
+
catch {
|
|
323
|
+
// Fail-open.
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
scheduleRetentionSweep() {
|
|
327
|
+
if (this.retentionDays <= 0 || this.retention !== undefined)
|
|
328
|
+
return;
|
|
329
|
+
this.retention = sweepOldLogFiles(this.dir, this.retentionDays, this.clock()).then(() => undefined, () => undefined);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
const registry = new Map();
|
|
333
|
+
class PluginLoggerImpl {
|
|
334
|
+
core;
|
|
335
|
+
moduleField;
|
|
336
|
+
constructor(core, moduleField) {
|
|
337
|
+
this.core = core;
|
|
338
|
+
this.moduleField = moduleField;
|
|
339
|
+
}
|
|
340
|
+
trace(event, fields) {
|
|
341
|
+
this.core.write(this.moduleField, "trace", event, fields);
|
|
342
|
+
}
|
|
343
|
+
debug(event, fields) {
|
|
344
|
+
this.core.write(this.moduleField, "debug", event, fields);
|
|
345
|
+
}
|
|
346
|
+
info(event, fields) {
|
|
347
|
+
this.core.write(this.moduleField, "info", event, fields);
|
|
348
|
+
}
|
|
349
|
+
warn(event, fields) {
|
|
350
|
+
this.core.write(this.moduleField, "warn", event, fields);
|
|
351
|
+
}
|
|
352
|
+
error(event, fields) {
|
|
353
|
+
this.core.write(this.moduleField, "error", event, fields);
|
|
354
|
+
}
|
|
355
|
+
fatal(event, fields) {
|
|
356
|
+
this.core.write(this.moduleField, "fatal", event, fields);
|
|
357
|
+
}
|
|
358
|
+
child(module) {
|
|
359
|
+
return new PluginLoggerImpl(this.core, module);
|
|
360
|
+
}
|
|
361
|
+
get level() {
|
|
362
|
+
return this.core.level;
|
|
363
|
+
}
|
|
364
|
+
setLevel(level) {
|
|
365
|
+
this.core.setLevel(level);
|
|
366
|
+
}
|
|
367
|
+
flush() {
|
|
368
|
+
this.core.flush();
|
|
369
|
+
}
|
|
370
|
+
close() {
|
|
371
|
+
return this.core.close();
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
/** Create a standalone logger instance (no caching). */
|
|
375
|
+
export function createPluginLogger(options) {
|
|
376
|
+
return new PluginLoggerImpl(new LoggerCore(options));
|
|
377
|
+
}
|
|
378
|
+
/**
|
|
379
|
+
* Create or return the cached logger for `pluginId` + resolved `dir`. A later
|
|
380
|
+
* call with an explicit `level` updates the cached instance's threshold, so
|
|
381
|
+
* plugin config reloads take effect. `close()` evicts the cache entry; the
|
|
382
|
+
* next call creates a fresh instance.
|
|
383
|
+
*/
|
|
384
|
+
export function getPluginLogger(options) {
|
|
385
|
+
const candidate = new LoggerCore(options);
|
|
386
|
+
const key = candidate.key();
|
|
387
|
+
const existing = registry.get(key);
|
|
388
|
+
if (existing === undefined || existing.core.isClosed()) {
|
|
389
|
+
const entry = { core: candidate, root: new PluginLoggerImpl(candidate) };
|
|
390
|
+
registry.set(key, entry);
|
|
391
|
+
return entry.root;
|
|
392
|
+
}
|
|
393
|
+
if (options.level !== undefined)
|
|
394
|
+
existing.core.setLevel(options.level);
|
|
395
|
+
return existing.root;
|
|
396
|
+
}
|
|
397
|
+
//# sourceMappingURL=plugin-logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin-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AK,EAAE,CAAC;IACpB,CAAC;IAED,KAAK;QACH,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;IAC3B,CAAC;CACF;AAED,wDAAwD;AACxD,MAAM,UAAU,kBAAkB,CAAC,OAA4B;IAC7D,OAAO,IAAI,gBAAgB,CAAC,IAAI,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC;AACvD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAAC,OAA4B;IAC1D,MAAM,SAAS,GAAG,IAAI,UAAU,CAAC,OAAO,CAAC,CAAC;IAC1C,MAAM,GAAG,GAAG,SAAS,CAAC,GAAG,EAAE,CAAC;IAC5B,MAAM,QAAQ,GAAG,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACnC,IAAI,QAAQ,KAAK,SAAS,IAAI,QAAQ,CAAC,IAAI,CAAC,QAAQ,EAAE,EAAE,CAAC;QACvD,MAAM,KAAK,GAAkB,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,gBAAgB,CAAC,SAAS,CAAC,EAAE,CAAC;QACxF,QAAQ,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QACzB,OAAO,KAAK,CAAC,IAAI,CAAC;IACpB,CAAC;IACD,IAAI,OAAO,CAAC,KAAK,KAAK,SAAS;QAAE,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IACvE,OAAO,QAAQ,CAAC,IAAI,CAAC;AACvB,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Structured logging events (SPEC §45).
|
|
3
|
+
*
|
|
4
|
+
* Events use stable dotted names (`kv.session.restore.success`); session
|
|
5
|
+
* identifiers are abbreviated hashes at normal verbosity. The management
|
|
6
|
+
* API key never passes through here. Records land in
|
|
7
|
+
* `<$DSH_HOME>/logs/dsh-kv-persist/<YYYY-MM-DD>.log` (NDJSON); `warn` and
|
|
8
|
+
* above are additionally mirrored to the host context logger.
|
|
9
|
+
*/
|
|
10
|
+
export interface KvPersistLogger {
|
|
11
|
+
debug(event: string, fields?: Record<string, unknown>): void;
|
|
12
|
+
info(event: string, fields?: Record<string, unknown>): void;
|
|
13
|
+
warn(event: string, fields?: Record<string, unknown>): void;
|
|
14
|
+
error(event: string, fields?: Record<string, unknown>): void;
|
|
15
|
+
/** Best-effort synchronous flush of buffered file output. */
|
|
16
|
+
flush?(): void;
|
|
17
|
+
/** Flush and close the underlying destination (idempotent). */
|
|
18
|
+
close?(): Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
export type KvPersistLogLevel = "debug" | "info" | "off";
|
|
21
|
+
/** Abbreviated session hash for logs (SPEC §45: avoid full ids). */
|
|
22
|
+
export declare function abbreviateSessionId(sessionId: string): string;
|
|
23
|
+
interface HostLoggerLike {
|
|
24
|
+
info(message: string, ...values: unknown[]): unknown;
|
|
25
|
+
warn(message: string, ...values: unknown[]): unknown;
|
|
26
|
+
error(message: string, ...values: unknown[]): unknown;
|
|
27
|
+
debug?(message: string, ...values: unknown[]): unknown;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Build the plugin logger on top of the shared pino-backed file logger
|
|
31
|
+
* (`<$DSH_HOME>/logs/dsh-kv-persist/<YYYY-MM-DD>.log`) with the host context
|
|
32
|
+
* logger as the console mirror for `warn`+ records. Sensitive fields are
|
|
33
|
+
* abbreviated here, before any record leaves the plugin (SPEC §45).
|
|
34
|
+
*/
|
|
35
|
+
export declare function createKvPersistLogger(host: HostLoggerLike, level: KvPersistLogLevel): KvPersistLogger;
|
|
36
|
+
export {};
|
|
37
|
+
//# sourceMappingURL=diagnostics.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diagnostics.d.ts","sourceRoot":"","sources":["../../src/observability/diagnostics.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAKH,MAAM,WAAW,eAAe;IAC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G"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Structured logging events (SPEC §45).
|
|
3
|
+
*
|
|
4
|
+
* Events use stable dotted names (`kv.session.restore.success`); session
|
|
5
|
+
* identifiers are abbreviated hashes at normal verbosity. The management
|
|
6
|
+
* API key never passes through here. Records land in
|
|
7
|
+
* `<$DSH_HOME>/logs/dsh-kv-persist/<YYYY-MM-DD>.log` (NDJSON); `warn` and
|
|
8
|
+
* above are additionally mirrored to the host context logger.
|
|
9
|
+
*/
|
|
10
|
+
import { getPluginLogger } from "../logging/index.js";
|
|
11
|
+
import { sha256Hex } from "../snapshots/fingerprint.js";
|
|
12
|
+
/** Abbreviated session hash for logs (SPEC §45: avoid full ids). */
|
|
13
|
+
export function abbreviateSessionId(sessionId) {
|
|
14
|
+
return sha256Hex(sessionId).slice(0, 6);
|
|
15
|
+
}
|
|
16
|
+
/** Fields that must be abbreviated before formatting. */
|
|
17
|
+
const SENSITIVE_FIELDS = new Set(["sessionId"]);
|
|
18
|
+
function prepareFields(fields) {
|
|
19
|
+
if (fields === undefined)
|
|
20
|
+
return {};
|
|
21
|
+
const prepared = {};
|
|
22
|
+
for (const [key, value] of Object.entries(fields)) {
|
|
23
|
+
prepared[key] =
|
|
24
|
+
SENSITIVE_FIELDS.has(key) && typeof value === "string" ? abbreviateSessionId(value) : value;
|
|
25
|
+
}
|
|
26
|
+
return prepared;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Build the plugin logger on top of the shared pino-backed file logger
|
|
30
|
+
* (`<$DSH_HOME>/logs/dsh-kv-persist/<YYYY-MM-DD>.log`) with the host context
|
|
31
|
+
* logger as the console mirror for `warn`+ records. Sensitive fields are
|
|
32
|
+
* abbreviated here, before any record leaves the plugin (SPEC §45).
|
|
33
|
+
*/
|
|
34
|
+
export function createKvPersistLogger(host, level) {
|
|
35
|
+
const shared = getPluginLogger({
|
|
36
|
+
pluginId: "dsh-kv-persist",
|
|
37
|
+
level: level === "off" ? "silent" : level,
|
|
38
|
+
console: level === "off" ? "silent" : "warn",
|
|
39
|
+
consoleSink: (logLevel, message) => {
|
|
40
|
+
if (logLevel === "trace" || logLevel === "debug") {
|
|
41
|
+
if (typeof host.debug === "function")
|
|
42
|
+
host.debug(message);
|
|
43
|
+
else
|
|
44
|
+
host.info(message);
|
|
45
|
+
}
|
|
46
|
+
else if (logLevel === "info")
|
|
47
|
+
host.info(message);
|
|
48
|
+
else if (logLevel === "warn")
|
|
49
|
+
host.warn(message);
|
|
50
|
+
else
|
|
51
|
+
host.error(message);
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
return {
|
|
55
|
+
debug(event, fields) {
|
|
56
|
+
shared.debug(event, prepareFields(fields));
|
|
57
|
+
},
|
|
58
|
+
info(event, fields) {
|
|
59
|
+
shared.info(event, prepareFields(fields));
|
|
60
|
+
},
|
|
61
|
+
warn(event, fields) {
|
|
62
|
+
shared.warn(event, prepareFields(fields));
|
|
63
|
+
},
|
|
64
|
+
error(event, fields) {
|
|
65
|
+
shared.error(event, prepareFields(fields));
|
|
66
|
+
},
|
|
67
|
+
flush() {
|
|
68
|
+
shared.flush();
|
|
69
|
+
},
|
|
70
|
+
close() {
|
|
71
|
+
return shared.close();
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=diagnostics.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diagnostics.js","sourceRoot":"","sources":["../../src/observability/diagnostics.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AAexD,oEAAoE;AACpE,MAAM,UAAU,mBAAmB,CAAC,SAAiB;IACnD,OAAO,SAAS,CAAC,SAAS,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAC1C,C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IAAI,QAAQ,KAAK,MAAM;gBAAE,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;;gBAC5C,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAC3B,CAAC;KACF,CAAC,CAAC;IACH,OAAO;QACL,KAAK,CAAC,KAAK,EAAE,MAAM;YACjB,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC;QAC7C,CAAC;QACD,IAAI,CAAC,KAAK,EAAE,MAAM;YAChB,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC;QAC5C,CAAC;QACD,IAAI,CAAC,KAAK,EAAE,MAAM;YAChB,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC;QAC5C,CAAC;QACD,KAAK,CAAC,KAAK,EAAE,MAAM;YACjB,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC;QAC7C,CAAC;QACD,KAAK;YACH,MAAM,CAAC,KAAK,EAAE,CAAC;QACjB,CAAC;QACD,KAAK;YACH,OAAO,MAAM,CAAC,KAAK,EAAE,CAAC;QACxB,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Persistence metrics counters (SPEC §46, MVP subset).
|
|
3
|
+
*
|
|
4
|
+
* Counters are in-memory only in v0.1; they surface through
|
|
5
|
+
* `ctx.kvPersist.status()` and later optional Prometheus integration.
|
|
6
|
+
*/
|
|
7
|
+
export interface KvPersistCounters {
|
|
8
|
+
/** Restore attempts that ended successfully (§46 dsh_kv_restore_total). */
|
|
9
|
+
restores: number;
|
|
10
|
+
/** Successful restores of an existing snapshot (§46 restore_hit_total). */
|
|
11
|
+
restoreHits: number;
|
|
12
|
+
/** Failed restores (§46 restore_failure_total). */
|
|
13
|
+
restoreFailures: number;
|
|
14
|
+
/** Requests served without any snapshot (§46 cold_prefill_total). */
|
|
15
|
+
coldPrefills: number;
|
|
16
|
+
/** Successful saves (§46 save_total). */
|
|
17
|
+
saves: number;
|
|
18
|
+
/** Failed saves (§46 save_failure_total). */
|
|
19
|
+
saveFailures: number;
|
|
20
|
+
/** Successful slot erases. */
|
|
21
|
+
erases: number;
|
|
22
|
+
/** Slot owner switches (§46 slot_switch_total). */
|
|
23
|
+
slotSwitches: number;
|
|
24
|
+
/** Auxiliary requests that went through coordination. */
|
|
25
|
+
auxiliaryRequests: number;
|
|
26
|
+
/** Requests skipped because the circuit was open. */
|
|
27
|
+
circuitSkips: number;
|
|
28
|
+
/** Cumulative restore duration in milliseconds. */
|
|
29
|
+
restoreDurationMs: number;
|
|
30
|
+
/** Cumulative save duration in milliseconds. */
|
|
31
|
+
saveDurationMs: number;
|
|
32
|
+
}
|
|
33
|
+
export declare class KvPersistMetrics {
|
|
34
|
+
#private;
|
|
35
|
+
get counters(): KvPersistCounters;
|
|
36
|
+
snapshot(): KvPersistCounters;
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=metrics.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"metrics.d.ts","sourceRoot":"","sources":["../../src/observability/metrics.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,WAAW,iBAAiB;IAChC,2EAA2E;IAC3E,QAAQ,EAAE,MAAM,CAAC;IACjB,2EAA2E;IAC3E,WAAW,EAAE,MAAM,CAAC;IACpB,mDAAmD;IACnD,eAAe,EAAE,MAAM,CAAC;IACxB,qEAAqE;IACrE,YAAY,EAAE,MAAM,CAAC;IACrB,yCAAyC;IACzC,KAAK,EAAE,MAAM,CAAC;IACd,6CAA6C;IAC7C,YAAY,EAAE,MAAM,CAAC;IACrB,8BAA8B;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,mDAAmD;IACnD,YAAY,EAAE,MAAM,CAAC;IACrB,yDAAyD;IACzD,iBAAiB,EAAE,MAAM,CAAC;IAC1B,qDAAqD;IACrD,YAAY,EAAE,MAAM,CAAC;IACrB,mDAAmD;IACnD,iBAAiB,EAAE,MAAM,CAAC;IAC1B,gDAAgD;IAChD,cAAc,EAAE,MAAM,CAAC;CACxB;AAID,qBAAa,gBAAgB;;IAgB3B,IAAI,QAAQ,IAAI,iBAAiB,CAEhC;IAED,QAAQ,IAAI,iBAAiB;CAG9B"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Persistence metrics counters (SPEC §46, MVP subset).
|
|
3
|
+
*
|
|
4
|
+
* Counters are in-memory only in v0.1; they surface through
|
|
5
|
+
* `ctx.kvPersist.status()` and later optional Prometheus integration.
|
|
6
|
+
*/
|
|
7
|
+
export class KvPersistMetrics {
|
|
8
|
+
#counters = {
|
|
9
|
+
restores: 0,
|
|
10
|
+
restoreHits: 0,
|
|
11
|
+
restoreFailures: 0,
|
|
12
|
+
coldPrefills: 0,
|
|
13
|
+
saves: 0,
|
|
14
|
+
saveFailures: 0,
|
|
15
|
+
erases: 0,
|
|
16
|
+
slotSwitches: 0,
|
|
17
|
+
auxiliaryRequests: 0,
|
|
18
|
+
circuitSkips: 0,
|
|
19
|
+
restoreDurationMs: 0,
|
|
20
|
+
saveDurationMs: 0,
|
|
21
|
+
};
|
|
22
|
+
get counters() {
|
|
23
|
+
return this.#counters;
|
|
24
|
+
}
|
|
25
|
+
snapshot() {
|
|
26
|
+
return { ...this.#counters };
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=metrics.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"metrics.js","sourceRoot":"","sources":["../../src/observability/metrics.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AA+BH,MAAM,OAAO,gBAAgB;IAClB,SAAS,GAAoB;QACpC,QAAQ,EAAE,CAAC;QACX,WAAW,EAAE,CAAC;QACd,eAAe,EAAE,CAAC;QAClB,YAAY,EAAE,CAAC;QACf,KAAK,EAAE,CAAC;QACR,YAAY,EAAE,CAAC;QACf,MAAM,EAAE,CAAC;QACT,YAAY,EAAE,CAAC;QACf,iBAAiB,EAAE,CAAC;QACpB,YAAY,EAAE,CAAC;QACf,iBAAiB,EAAE,CAAC;QACpB,cAAc,EAAE,CAAC;KAClB,CAAC;IAEF,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAED,QAAQ;QACN,OAAO,EAAE,GAAG,IAAI,CAAC,SAAS,EAAE,CAAC;IAC/B,CAAC;CACF"}
|