@blogic-cz/agent-tools 0.8.0 → 0.8.2
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/package.json
CHANGED
|
@@ -121,11 +121,11 @@ function parseMemoryToMi(memory: string): number {
|
|
|
121
121
|
case "ti":
|
|
122
122
|
return Math.round(value * 1024 * 1024);
|
|
123
123
|
case "k":
|
|
124
|
-
return Math.round(value
|
|
124
|
+
return Math.round((value * 1000) / (1024 * 1024));
|
|
125
125
|
case "m":
|
|
126
|
-
return Math.round(value
|
|
126
|
+
return Math.round((value * 1_000_000) / (1024 * 1024));
|
|
127
127
|
case "g":
|
|
128
|
-
return Math.round(value / 1024);
|
|
128
|
+
return Math.round((value * 1_000_000_000) / (1024 * 1024));
|
|
129
129
|
default:
|
|
130
130
|
return Math.round(value);
|
|
131
131
|
}
|
|
@@ -456,12 +456,7 @@ export function transformDescribe(textOutput: string): string {
|
|
|
456
456
|
return outputLines.join("\n").trim();
|
|
457
457
|
}
|
|
458
458
|
|
|
459
|
-
export
|
|
460
|
-
return deduplicateLines(textOutput, {
|
|
461
|
-
normalizeTimestamps: true,
|
|
462
|
-
normalizeUUIDs: true,
|
|
463
|
-
});
|
|
464
|
-
}
|
|
459
|
+
export { transformLogOutput as transformLogs } from "#logs/transformers";
|
|
465
460
|
|
|
466
461
|
export function transformGenericKubectl(
|
|
467
462
|
textOutput: string,
|
|
@@ -478,9 +473,8 @@ export function transformGenericKubectl(
|
|
|
478
473
|
if (parsed && typeof parsed === "object") {
|
|
479
474
|
return parsed as Record<string, unknown>;
|
|
480
475
|
}
|
|
481
|
-
} catch
|
|
482
|
-
|
|
483
|
-
void ignored;
|
|
476
|
+
} catch {
|
|
477
|
+
// not JSON — fall through to table/text detection
|
|
484
478
|
}
|
|
485
479
|
}
|
|
486
480
|
|
|
@@ -66,9 +66,28 @@ function toText(value: unknown): string | undefined {
|
|
|
66
66
|
return undefined;
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
-
function
|
|
69
|
+
function formatTimestamp(value: unknown): string | undefined {
|
|
70
|
+
if (typeof value === "number" && value > 1_000_000_000_000) {
|
|
71
|
+
return new Date(value).toISOString();
|
|
72
|
+
}
|
|
73
|
+
if (typeof value === "number" && value > 1_000_000_000) {
|
|
74
|
+
return new Date(value * 1000).toISOString();
|
|
75
|
+
}
|
|
76
|
+
return undefined;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function firstMappedField(
|
|
80
|
+
obj: unknown,
|
|
81
|
+
fields: ReadonlyArray<string>,
|
|
82
|
+
isTimestamp = false,
|
|
83
|
+
): string | undefined {
|
|
70
84
|
for (const field of fields) {
|
|
71
|
-
const
|
|
85
|
+
const raw = getByPath(obj, field);
|
|
86
|
+
if (isTimestamp) {
|
|
87
|
+
const formatted = formatTimestamp(raw);
|
|
88
|
+
if (formatted) return formatted;
|
|
89
|
+
}
|
|
90
|
+
const value = toText(raw);
|
|
72
91
|
if (value) {
|
|
73
92
|
return value;
|
|
74
93
|
}
|
|
@@ -84,6 +103,15 @@ function normalizeLevel(rawLevel: string | undefined): LogLevel {
|
|
|
84
103
|
return "INFO";
|
|
85
104
|
}
|
|
86
105
|
|
|
106
|
+
// Pino numeric levels: 10=trace, 20=debug, 30=info, 40=warn, 50=error, 60=fatal
|
|
107
|
+
const numericLevel = Number(normalized);
|
|
108
|
+
if (Number.isFinite(numericLevel)) {
|
|
109
|
+
if (numericLevel >= 50) return "ERROR";
|
|
110
|
+
if (numericLevel >= 40) return "WARN";
|
|
111
|
+
if (numericLevel >= 30) return "INFO";
|
|
112
|
+
return "DEBUG";
|
|
113
|
+
}
|
|
114
|
+
|
|
87
115
|
if (normalized === "error" || normalized === "err" || normalized === "fatal") {
|
|
88
116
|
return "ERROR";
|
|
89
117
|
}
|
|
@@ -114,7 +142,7 @@ function formatLine({ level, timestamp, message }: ParsedLogLine): string {
|
|
|
114
142
|
function parseJsonLogLine(line: string, originalIndex: number): ParsedLogLine {
|
|
115
143
|
try {
|
|
116
144
|
const parsed = JSON.parse(line) as unknown;
|
|
117
|
-
const timestamp = firstMappedField(parsed, TIMESTAMP_FIELDS);
|
|
145
|
+
const timestamp = firstMappedField(parsed, TIMESTAMP_FIELDS, true);
|
|
118
146
|
const level = normalizeLevel(firstMappedField(parsed, LEVEL_FIELDS));
|
|
119
147
|
const message =
|
|
120
148
|
firstMappedField(parsed, MESSAGE_FIELDS) ??
|