@tellagen/mcp-server 0.5.1 → 0.6.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/README.md +29 -3
- package/SKILL.md +40 -3
- package/contracts/mcp-protocol.json +13 -1
- package/contracts/runbooks/manifest.json +20 -10
- package/contracts/runbooks/v2/client-protocol.json +59 -2
- package/contracts/runbooks/v2/client-writes.guidance.json +16 -1
- package/contracts/runbooks/v2/fixtures/timeline-event-blocks-rejected.json +15 -1
- package/contracts/runbooks/v2/investigation-window.guidance.json +45 -0
- package/contracts/runbooks/v2/question-checks.guidance.json +49 -0
- package/contracts/runbooks/v2/timeline-event-blocks.schema.json +62 -1
- package/contracts/tellagen-runbook-contracts.json +3 -3
- package/dist/cli/doctor.d.ts +19 -0
- package/dist/cli/doctor.js +212 -0
- package/dist/cli/doctor.js.map +1 -0
- package/dist/cli/main.js +5 -0
- package/dist/cli/main.js.map +1 -1
- package/dist/diagnosis-structure.d.ts +103 -78
- package/dist/diagnosis-structure.js +62 -7
- package/dist/diagnosis-structure.js.map +1 -1
- package/dist/doctor/checks.d.ts +42 -0
- package/dist/doctor/checks.js +175 -0
- package/dist/doctor/checks.js.map +1 -0
- package/dist/doctor/config-files.d.ts +49 -0
- package/dist/doctor/config-files.js +121 -0
- package/dist/doctor/config-files.js.map +1 -0
- package/dist/doctor/toml.d.ts +13 -0
- package/dist/doctor/toml.js +205 -0
- package/dist/doctor/toml.js.map +1 -0
- package/dist/figures.d.ts +407 -83
- package/dist/figures.js +297 -5
- package/dist/figures.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/k8s-safety.d.ts +42 -0
- package/dist/k8s-safety.js +33 -0
- package/dist/k8s-safety.js.map +1 -0
- package/dist/log-lines.d.ts +118 -0
- package/dist/log-lines.js +534 -0
- package/dist/log-lines.js.map +1 -0
- package/dist/redact.d.ts +21 -0
- package/dist/redact.js +212 -5
- package/dist/redact.js.map +1 -1
- package/dist/run-window.d.ts +59 -0
- package/dist/run-window.js +141 -0
- package/dist/run-window.js.map +1 -0
- package/dist/server.d.ts +1 -1
- package/dist/server.js +1 -1
- package/dist/tool-report.d.ts +2 -0
- package/dist/tool-report.js +3 -0
- package/dist/tool-report.js.map +1 -0
- package/dist/tools/catalog.js +1 -0
- package/dist/tools/catalog.js.map +1 -1
- package/dist/tools/diagnostics.js +85 -2
- package/dist/tools/diagnostics.js.map +1 -1
- package/dist/tools/figures.d.ts +2 -2
- package/dist/tools/figures.js +29 -7
- package/dist/tools/figures.js.map +1 -1
- package/dist/tools/findings.d.ts +8 -0
- package/dist/tools/findings.js +63 -2
- package/dist/tools/findings.js.map +1 -1
- package/dist/tools/investigations.d.ts +1 -1
- package/dist/tools/investigations.js +43 -4
- package/dist/tools/investigations.js.map +1 -1
- package/dist/tools/postmortem-runbooks.d.ts +20 -20
- package/dist/tools/source-links.d.ts +7 -0
- package/dist/tools/source-links.js +32 -5
- package/dist/tools/source-links.js.map +1 -1
- package/dist/tools/timeline.js +13 -2
- package/dist/tools/timeline.js.map +1 -1
- package/dist/version.d.ts +2 -2
- package/dist/version.js +3 -1
- package/dist/version.js.map +1 -1
- package/package.json +1 -1
- package/server.json +1 -1
package/dist/figures.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { diffHunksFromPatch, diffShapeAdvice, hasDiffLineDetail, MAX_DIFF_CHANGED_LINES, MAX_DIFF_CONTEXT_EDGE, MAX_DIFF_CONTEXT_GAP, MAX_SELECTED_HUNKS, withoutDiffLineDetail, } from "./diff-figure.js";
|
|
3
|
+
import { MAX_LOG_COUNT, MAX_LOG_FIELD_KEY, MAX_LOG_FIELD_VALUE, MAX_LOG_FIELDS, MAX_LOG_LINES, MAX_LOG_NOTE, MAX_LOG_TEXT, readLogEntries, relationCounts, selectLogLines, } from "./log-lines.js";
|
|
4
|
+
import { redactLogText } from "./redact.js";
|
|
5
|
+
import { windowEnd } from "./run-window.js";
|
|
3
6
|
/**
|
|
4
7
|
* Figures are the typed widgets Tellagen draws in the Diagnosis tab, on the
|
|
5
8
|
* timeline and in the postmortem. The agent sends data and Tellagen draws it.
|
|
@@ -23,6 +26,7 @@ export const STEP_FIGURE_TYPES = [
|
|
|
23
26
|
"histogram",
|
|
24
27
|
"run_history",
|
|
25
28
|
"diff",
|
|
29
|
+
"log_lines",
|
|
26
30
|
];
|
|
27
31
|
/** Types the API accepts in a timeline event's `blocks`. */
|
|
28
32
|
export const TIMELINE_BLOCK_TYPES = [
|
|
@@ -36,9 +40,20 @@ export const TIMELINE_BLOCK_TYPES = [
|
|
|
36
40
|
"histogram",
|
|
37
41
|
"run_history",
|
|
38
42
|
"diff",
|
|
43
|
+
"log_lines",
|
|
39
44
|
];
|
|
40
45
|
/** The most JSON one step figure may take, as the backend measures it. */
|
|
41
46
|
export const MAX_STEP_FIGURE_BYTES = 16 * 1024;
|
|
47
|
+
/**
|
|
48
|
+
* A log_lines figure may take more: 8 lines of 500 characters with fields are
|
|
49
|
+
* about 20 KB. A Tellagen that lists log_lines_v1 accepts a step figure of
|
|
50
|
+
* this size.
|
|
51
|
+
*/
|
|
52
|
+
export const MAX_LOG_LINES_STEP_FIGURE_BYTES = 48 * 1024;
|
|
53
|
+
/** The most JSON a step figure of this type may take. */
|
|
54
|
+
export function maxStepFigureBytes(type) {
|
|
55
|
+
return type === "log_lines" ? MAX_LOG_LINES_STEP_FIGURE_BYTES : MAX_STEP_FIGURE_BYTES;
|
|
56
|
+
}
|
|
42
57
|
const MAX_ABS = 1_000_000_000_000;
|
|
43
58
|
const MAX_TREND_POINTS = 500;
|
|
44
59
|
/** Stats a server with figure_extras_v1 takes; the first MAX_STATS_TILES are tiles. */
|
|
@@ -47,6 +62,8 @@ export const MAX_STATS_TILES = 4;
|
|
|
47
62
|
const MAX_RUNS_NOT_SHOWN = 1_000_000;
|
|
48
63
|
/** The server takes a stats title, more than 4 stats and runs_not_shown. */
|
|
49
64
|
export const FIGURE_EXTRAS_CAPABILITY = "figure_extras_v1";
|
|
65
|
+
/** The server takes a log_lines figure. */
|
|
66
|
+
export const LOG_LINES_CAPABILITY = "log_lines_v1";
|
|
50
67
|
const number = z.number().finite().min(-MAX_ABS).max(MAX_ABS);
|
|
51
68
|
const positive = z.number().finite().gt(0).max(MAX_ABS);
|
|
52
69
|
const text = (min, max) => z.string().min(min).max(max);
|
|
@@ -352,12 +369,70 @@ const diffBase = z
|
|
|
352
369
|
.describe("1 to 6 hunks, at most 12 changed lines (+ and -) in all. Send every line of a short change, each removed line next to the line that replaced it."),
|
|
353
370
|
})
|
|
354
371
|
.strict();
|
|
372
|
+
const logSourceSchema = z
|
|
373
|
+
.object({
|
|
374
|
+
kind: blockText(80).optional().describe("logql for Loki"),
|
|
375
|
+
datasource: blockText(80).optional().describe("The Grafana data source uid or name, so the page can open Explore"),
|
|
376
|
+
// Only source.query may hold line breaks and tabs.
|
|
377
|
+
query: z
|
|
378
|
+
.string()
|
|
379
|
+
.max(2000)
|
|
380
|
+
.refine((value) => !CODE_UNSAFE.test(value.replace(/\n/g, "")), { message: "must not contain control characters other than line breaks and tabs" })
|
|
381
|
+
.optional(),
|
|
382
|
+
from: rfc3339.optional(),
|
|
383
|
+
to: rfc3339.optional(),
|
|
384
|
+
})
|
|
385
|
+
.strict();
|
|
386
|
+
// A log line keeps its indentation and may hold tabs; other control characters are refused.
|
|
387
|
+
const logTextLine = codeLine(MAX_LOG_TEXT).refine((value) => value.trim() !== "", { message: "is required" });
|
|
388
|
+
const logLineSchema = z
|
|
389
|
+
.object({
|
|
390
|
+
time: rfc3339,
|
|
391
|
+
level: z.enum(["error", "warn", "info", "debug", "other"]),
|
|
392
|
+
text: logTextLine,
|
|
393
|
+
fields: z
|
|
394
|
+
.record(blockText(MAX_LOG_FIELD_VALUE, true))
|
|
395
|
+
.superRefine((fields, ctx) => {
|
|
396
|
+
const keys = Object.keys(fields);
|
|
397
|
+
if (keys.length > MAX_LOG_FIELDS) {
|
|
398
|
+
ctx.addIssue({ code: z.ZodIssueCode.custom, message: `at most ${MAX_LOG_FIELDS} fields (got ${keys.length})` });
|
|
399
|
+
}
|
|
400
|
+
for (const key of keys) {
|
|
401
|
+
const trimmed = key.trim();
|
|
402
|
+
if (trimmed === "" || charCount(trimmed) > MAX_LOG_FIELD_KEY || BLOCK_UNSAFE.test(trimmed)) {
|
|
403
|
+
ctx.addIssue({ code: z.ZodIssueCode.custom, message: `the field name "${key.slice(0, 20).replace(/[\u0000-\u001f]/g, " ")}" must be 1 to ${MAX_LOG_FIELD_KEY} characters, on one line` });
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
const trimmedKeys = keys.map((key) => key.trim());
|
|
407
|
+
if (new Set(trimmedKeys).size !== trimmedKeys.length) {
|
|
408
|
+
ctx.addIssue({ code: z.ZodIssueCode.custom, message: "has two field names that are the same once trimmed" });
|
|
409
|
+
}
|
|
410
|
+
})
|
|
411
|
+
.optional(),
|
|
412
|
+
relation: z.enum(["matches_event", "context", "unrelated"]).optional(),
|
|
413
|
+
note: blockText(MAX_LOG_NOTE).optional(),
|
|
414
|
+
})
|
|
415
|
+
.strict();
|
|
416
|
+
const logCount = z.number().int().min(0).max(MAX_LOG_COUNT);
|
|
417
|
+
const logLinesBase = z
|
|
418
|
+
.object({
|
|
419
|
+
type: z.literal("log_lines"),
|
|
420
|
+
title: blockText(80).optional(),
|
|
421
|
+
source: logSourceSchema.optional(),
|
|
422
|
+
matched: logCount.describe("How many lines matched the query in the range"),
|
|
423
|
+
scanned: logCount.optional().describe("How many lines the query looked at. Not below matched."),
|
|
424
|
+
event_at: rfc3339.optional().describe("The moment of the event the lines are about"),
|
|
425
|
+
lines: z.array(logLineSchema).max(MAX_LOG_LINES).optional(),
|
|
426
|
+
lines_not_shown: logCount.optional().describe("How many matches are not in lines"),
|
|
427
|
+
})
|
|
428
|
+
.strict();
|
|
355
429
|
/** Exported for the step figure schema of tellagen_complete_investigation. */
|
|
356
430
|
export const checksBlockSchema = checksBase;
|
|
357
431
|
export const rangeOverlapBlockSchema = rangeOverlapBase;
|
|
358
432
|
export const histogramBlockSchema = histogramBase;
|
|
359
433
|
export const runHistoryBlockSchema = runHistoryBase;
|
|
360
434
|
export const diffBlockSchema = diffBase;
|
|
435
|
+
export const logLinesBlockSchema = logLinesBase;
|
|
361
436
|
const formatEdge = (n) => String(n);
|
|
362
437
|
/**
|
|
363
438
|
* The rules of a diff's hunks that span lines, with the API's messages: the
|
|
@@ -531,6 +606,31 @@ export function figureRuleIssues(block) {
|
|
|
531
606
|
const b = block;
|
|
532
607
|
issues.push(...diffRuleIssues(b.hunks));
|
|
533
608
|
}
|
|
609
|
+
if (block.type === "log_lines") {
|
|
610
|
+
const b = block;
|
|
611
|
+
const shown = b.lines?.length ?? 0;
|
|
612
|
+
if (b.scanned !== undefined && b.scanned < b.matched)
|
|
613
|
+
add(["scanned"], "must not be below matched");
|
|
614
|
+
if (shown > b.matched)
|
|
615
|
+
add(["lines"], `has ${shown} lines but matched is ${b.matched}`);
|
|
616
|
+
else if (b.matched > 0 && shown === 0) {
|
|
617
|
+
add(["lines"], "needs at least 1 line when matched is above 0; send matched 0 for a query with no result");
|
|
618
|
+
}
|
|
619
|
+
else if ((b.lines_not_shown ?? 0) > b.matched - shown) {
|
|
620
|
+
add(["lines_not_shown"], "must not be more than the matches that are not in lines");
|
|
621
|
+
}
|
|
622
|
+
if (b.matched === 0) {
|
|
623
|
+
if (b.scanned === undefined)
|
|
624
|
+
add(["scanned"], "is required when matched is 0, so the empty result says how much was searched");
|
|
625
|
+
if (b.source?.from === undefined || b.source?.to === undefined) {
|
|
626
|
+
add(["source"], "needs from and to when matched is 0, so the empty result says where and when it searched");
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
const from = b.source?.from === undefined ? undefined : Date.parse(b.source.from);
|
|
630
|
+
const to = b.source?.to === undefined ? undefined : Date.parse(b.source.to);
|
|
631
|
+
if (from !== undefined && to !== undefined && from > to)
|
|
632
|
+
add(["source", "to"], "must not be before from");
|
|
633
|
+
}
|
|
534
634
|
return issues;
|
|
535
635
|
}
|
|
536
636
|
/** Where a block sits on a timeline event. Not together. */
|
|
@@ -555,6 +655,7 @@ export const timelineBlockSchema = z.discriminatedUnion("type", [
|
|
|
555
655
|
histogramBase.extend(placementFields),
|
|
556
656
|
runHistoryBase.extend(placementFields),
|
|
557
657
|
diffBase.extend(placementFields),
|
|
658
|
+
logLinesBase.extend(placementFields),
|
|
558
659
|
]);
|
|
559
660
|
/**
|
|
560
661
|
* The light check the timeline tools apply to `blocks`. The full schema above
|
|
@@ -746,6 +847,59 @@ const diffInput = z
|
|
|
746
847
|
.describe("With patch: the numbers (1 is the first @@ header) of the hunks the claim cites, in file order, when the change has more than 12 changed lines."),
|
|
747
848
|
})
|
|
748
849
|
.strict();
|
|
850
|
+
const logMarkSchema = z
|
|
851
|
+
.object({
|
|
852
|
+
contains: z.string().min(1).max(200).optional().describe("Marks every line that holds this text (case does not count)"),
|
|
853
|
+
field: z
|
|
854
|
+
.object({ key: z.string().min(1).max(MAX_LOG_FIELD_KEY), value: z.string().min(1).max(MAX_LOG_FIELD_VALUE) })
|
|
855
|
+
.strict()
|
|
856
|
+
.optional()
|
|
857
|
+
.describe("Marks every line whose JSON or logfmt field, or whose stream label, has this value, for example company_id 578"),
|
|
858
|
+
relation: z.enum(["matches_event", "context", "unrelated"]),
|
|
859
|
+
note: blockText(MAX_LOG_NOTE).optional().describe("Why the line is what its relation says, for example Company 578, 11 hours after the event"),
|
|
860
|
+
})
|
|
861
|
+
.strict()
|
|
862
|
+
.refine((mark) => mark.contains !== undefined || mark.field !== undefined, { message: "send contains or field" });
|
|
863
|
+
const logLinesInput = z
|
|
864
|
+
.object({
|
|
865
|
+
type: z.literal("log_lines"),
|
|
866
|
+
title: blockText(80).optional(),
|
|
867
|
+
query: z.string().max(2000).optional().describe("The LogQL that ran. It becomes source.query so the page can open it in Grafana Explore."),
|
|
868
|
+
datasource: blockText(80).optional().describe("The Grafana data source uid or name the query ran against"),
|
|
869
|
+
kind: blockText(80).optional().describe("Defaults to logql when query is sent"),
|
|
870
|
+
from: rfc3339.optional().describe("Start of the range the query searched. Defaults to the start of the run window."),
|
|
871
|
+
to: rfc3339.optional().describe("End of the range. Defaults to the end of the run window, or now for an open one."),
|
|
872
|
+
streams: z
|
|
873
|
+
.unknown()
|
|
874
|
+
.optional()
|
|
875
|
+
.describe("The streams of a Loki result, as returned: [{stream: {labels}, values: [[time, line], ...]}]. The whole Loki response body is accepted too."),
|
|
876
|
+
entries: z
|
|
877
|
+
.array(z.record(z.unknown()))
|
|
878
|
+
.max(5000)
|
|
879
|
+
.optional()
|
|
880
|
+
.describe("Or a flat list of entries: [{timestamp, line, labels}], as the Grafana log tools return them."),
|
|
881
|
+
matched: logCount
|
|
882
|
+
.optional()
|
|
883
|
+
.describe("How many lines the query matched in the range, when it is more than you send (the query had a limit). Defaults to the number of lines you send."),
|
|
884
|
+
scanned: logCount.optional().describe("How many lines the query looked at (query_loki_stats entries). Always send it with matched 0."),
|
|
885
|
+
event_at: rfc3339.optional().describe("The moment of the event, so the page can say how far a line is from it"),
|
|
886
|
+
match: z
|
|
887
|
+
.array(z.string().min(1).max(200))
|
|
888
|
+
.max(8)
|
|
889
|
+
.optional()
|
|
890
|
+
.describe("Terms that show the event. Lines that hold one are marked matches_event and come first."),
|
|
891
|
+
marks: z
|
|
892
|
+
.array(logMarkSchema)
|
|
893
|
+
.max(12)
|
|
894
|
+
.optional()
|
|
895
|
+
.describe("Mark lines by text or by a field: lines of another tenant, company or request are unrelated, with a note that says why. The first mark that fits a line wins."),
|
|
896
|
+
field_keys: z
|
|
897
|
+
.array(z.string().min(1).max(MAX_LOG_FIELD_KEY))
|
|
898
|
+
.max(MAX_LOG_FIELDS)
|
|
899
|
+
.optional()
|
|
900
|
+
.describe("The fields to show on each line, in order. Without it the builder takes up to six from the line and its labels."),
|
|
901
|
+
})
|
|
902
|
+
.strict();
|
|
749
903
|
/** What tellagen_build_figure accepts. */
|
|
750
904
|
export const figureInputSchema = z.discriminatedUnion("type", [
|
|
751
905
|
statsBase,
|
|
@@ -758,9 +912,10 @@ export const figureInputSchema = z.discriminatedUnion("type", [
|
|
|
758
912
|
histogramInput,
|
|
759
913
|
runHistoryInput,
|
|
760
914
|
diffInput,
|
|
915
|
+
logLinesInput,
|
|
761
916
|
]);
|
|
762
917
|
/** The four figure types whose fields the tool listing leaves to the guide. */
|
|
763
|
-
export const GUIDE_ONLY_FIGURE_TYPES = ["range_overlap", "histogram", "run_history", "diff"];
|
|
918
|
+
export const GUIDE_ONLY_FIGURE_TYPES = ["range_overlap", "histogram", "run_history", "diff", "log_lines"];
|
|
764
919
|
/**
|
|
765
920
|
* The figure as tellagen_build_figure lists it. The six original types carry
|
|
766
921
|
* their full schema; the four newer ones only their type, so the listing stays
|
|
@@ -777,7 +932,7 @@ export const figureToolInputSchema = z.discriminatedUnion("type", [
|
|
|
777
932
|
z
|
|
778
933
|
.object({ type: z.enum(GUIDE_ONLY_FIGURE_TYPES) })
|
|
779
934
|
.passthrough()
|
|
780
|
-
.describe("range_overlap, histogram, run_history or
|
|
935
|
+
.describe("range_overlap, histogram, run_history, diff or log_lines, with the fields in resource://tellagen/figure-guide. Checked in full when the tool runs."),
|
|
781
936
|
]);
|
|
782
937
|
const issuesOf = (error) => error.issues.map((issue) => {
|
|
783
938
|
const path = issue.path.join(".");
|
|
@@ -1242,6 +1397,114 @@ function buildDiff(input, options) {
|
|
|
1242
1397
|
notes.push(...diffShapeAdvice(out, input.additions, input.deletions));
|
|
1243
1398
|
return { block: { ...rest, hunks: out }, notes };
|
|
1244
1399
|
}
|
|
1400
|
+
/**
|
|
1401
|
+
* A log_lines block from the result of a Loki query. The builder reads the
|
|
1402
|
+
* lines, parses the level, keeps at most 8 (the ones that show the event
|
|
1403
|
+
* first), and counts what is left out. Counts and times come from the result
|
|
1404
|
+
* or from what the agent sent; a range the agent did not send is the run
|
|
1405
|
+
* window, and the notes say so.
|
|
1406
|
+
*/
|
|
1407
|
+
function buildLogLines(input, options) {
|
|
1408
|
+
const { streams, entries: rawEntries, query, datasource, kind, from, to, matched, scanned, event_at, match, marks, field_keys, ...rest } = input;
|
|
1409
|
+
const notes = [];
|
|
1410
|
+
const read = readLogEntries({ streams, entries: rawEntries });
|
|
1411
|
+
if (read.issues.length > 0)
|
|
1412
|
+
return { issues: read.issues.slice(0, 8) };
|
|
1413
|
+
if (streams === undefined && rawEntries === undefined) {
|
|
1414
|
+
return {
|
|
1415
|
+
issues: [
|
|
1416
|
+
"streams: send the streams of the Loki result, or entries, even for a query with no result (an empty list, with matched 0, scanned, from and to).",
|
|
1417
|
+
],
|
|
1418
|
+
};
|
|
1419
|
+
}
|
|
1420
|
+
const eventMs = event_at === undefined ? undefined : Date.parse(event_at);
|
|
1421
|
+
const selection = selectLogLines(read.entries, {
|
|
1422
|
+
match,
|
|
1423
|
+
marks,
|
|
1424
|
+
fieldKeys: field_keys,
|
|
1425
|
+
eventAt: eventMs,
|
|
1426
|
+
});
|
|
1427
|
+
notes.push(...selection.notes);
|
|
1428
|
+
const total = selection.total;
|
|
1429
|
+
// Values beyond the input cap were counted, not kept: they are matches too.
|
|
1430
|
+
const overflow = read.overflow;
|
|
1431
|
+
if (overflow > 0) {
|
|
1432
|
+
notes.push(`The result held ${total + overflow} lines; only the first ${total} were read. The rest are counted in matched and lines_not_shown.`);
|
|
1433
|
+
}
|
|
1434
|
+
const matchedCount = matched ?? total + overflow;
|
|
1435
|
+
if (matched === undefined) {
|
|
1436
|
+
notes.push(`matched is the ${total + overflow} lines you sent. If the query had a limit and more lines matched, send matched with the real count.`);
|
|
1437
|
+
}
|
|
1438
|
+
else if (matched < total + overflow) {
|
|
1439
|
+
return { issues: [`matched: ${matched} is below the ${total + overflow} lines you sent. Send the number the query matched in the range.`] };
|
|
1440
|
+
}
|
|
1441
|
+
const source = {};
|
|
1442
|
+
if (query !== undefined && query.trim() !== "")
|
|
1443
|
+
source.query = redactLogText(query.replace(/[\u0000-\u0008\u000b-\u001f\u007f-\u009f\u2028\u2029]/g, " "));
|
|
1444
|
+
if (datasource !== undefined && datasource.trim() !== "")
|
|
1445
|
+
source.datasource = datasource;
|
|
1446
|
+
if (kind !== undefined && kind.trim() !== "")
|
|
1447
|
+
source.kind = kind;
|
|
1448
|
+
else if (source.query !== undefined)
|
|
1449
|
+
source.kind = "logql";
|
|
1450
|
+
let rangeFrom = from;
|
|
1451
|
+
let rangeTo = to;
|
|
1452
|
+
const window = options.window;
|
|
1453
|
+
if (window !== undefined && (rangeFrom === undefined || rangeTo === undefined)) {
|
|
1454
|
+
const used = [];
|
|
1455
|
+
if (rangeFrom === undefined) {
|
|
1456
|
+
rangeFrom = window.from;
|
|
1457
|
+
used.push("from");
|
|
1458
|
+
}
|
|
1459
|
+
if (rangeTo === undefined) {
|
|
1460
|
+
rangeTo = windowEnd(window, options.now);
|
|
1461
|
+
used.push("to");
|
|
1462
|
+
}
|
|
1463
|
+
notes.push(`${used.join(" and ")} ${used.length === 1 ? "was" : "were"} set to the run window because you sent none. If the query ran over another range, send from and to.`);
|
|
1464
|
+
}
|
|
1465
|
+
if (rangeFrom !== undefined)
|
|
1466
|
+
source.from = rangeFrom;
|
|
1467
|
+
if (rangeTo !== undefined)
|
|
1468
|
+
source.to = rangeTo;
|
|
1469
|
+
if (window !== undefined && rangeFrom !== undefined && rangeTo !== undefined && (from !== undefined || to !== undefined)) {
|
|
1470
|
+
const start = Date.parse(rangeFrom);
|
|
1471
|
+
const end = Date.parse(rangeTo);
|
|
1472
|
+
const lowest = Date.parse(window.baseline_from ?? window.from);
|
|
1473
|
+
const highest = window.to === undefined ? Number.POSITIVE_INFINITY : Date.parse(window.to);
|
|
1474
|
+
if (Number.isFinite(start) && Number.isFinite(end) && (start < lowest || end > highest)) {
|
|
1475
|
+
notes.push("The range reaches outside the run window and its baseline. Search for the cause inside the window; if the signal really starts outside it, send window_suggestion with the result.");
|
|
1476
|
+
}
|
|
1477
|
+
}
|
|
1478
|
+
const lines = selection.lines;
|
|
1479
|
+
if (matchedCount > 0 && lines.length === 0) {
|
|
1480
|
+
return { issues: ["streams: the result holds no usable line, but matched is above 0. Send the lines the query returned."] };
|
|
1481
|
+
}
|
|
1482
|
+
const block = { ...rest, matched: matchedCount };
|
|
1483
|
+
if (Object.keys(source).length > 0)
|
|
1484
|
+
block.source = source;
|
|
1485
|
+
if (scanned !== undefined)
|
|
1486
|
+
block.scanned = scanned;
|
|
1487
|
+
if (event_at !== undefined)
|
|
1488
|
+
block.event_at = event_at;
|
|
1489
|
+
block.lines = lines;
|
|
1490
|
+
const notShown = matchedCount - lines.length;
|
|
1491
|
+
if (notShown > 0)
|
|
1492
|
+
block.lines_not_shown = notShown;
|
|
1493
|
+
if (matchedCount === 0 && scanned === undefined) {
|
|
1494
|
+
return {
|
|
1495
|
+
issues: [
|
|
1496
|
+
"scanned: send how many lines the query looked at (for example from query_loki_stats) with matched 0. An empty result without the range and the count is not proof.",
|
|
1497
|
+
],
|
|
1498
|
+
};
|
|
1499
|
+
}
|
|
1500
|
+
if (lines.some((line) => line.relation === "unrelated")) {
|
|
1501
|
+
notes.push("A line marked unrelated is not proof: never use its text as the quote of a finding.");
|
|
1502
|
+
}
|
|
1503
|
+
if (lines.length > 0 && lines.every((line) => line.relation === undefined) && match === undefined && marks === undefined) {
|
|
1504
|
+
notes.push("No line is marked. Send match terms for the lines that show the event, and marks for a line of another tenant, company or request, so a reader can tell proof from noise.");
|
|
1505
|
+
}
|
|
1506
|
+
return { block, notes };
|
|
1507
|
+
}
|
|
1245
1508
|
/**
|
|
1246
1509
|
* A diff block as a server without diff_lines_v1 takes it: no unchanged lines
|
|
1247
1510
|
* and no line numbers. Any other block is returned as it is.
|
|
@@ -1283,6 +1546,10 @@ export function withoutFigureExtrasInBlock(block) {
|
|
|
1283
1546
|
}
|
|
1284
1547
|
return what.length > 0 ? { block: record, what } : { block, what };
|
|
1285
1548
|
}
|
|
1549
|
+
/** Whether a block is a log_lines figure. */
|
|
1550
|
+
export function isLogLinesBlock(block) {
|
|
1551
|
+
return typeof block === "object" && block !== null && block.type === "log_lines";
|
|
1552
|
+
}
|
|
1286
1553
|
const plural = (n, word) => `${n} ${word}${n === 1 ? "" : "s"}`;
|
|
1287
1554
|
const describe = (block) => {
|
|
1288
1555
|
switch (block.type) {
|
|
@@ -1324,6 +1591,17 @@ const describe = (block) => {
|
|
|
1324
1591
|
const numbered = lines.some((l) => l.old_no !== undefined || l.new_no !== undefined);
|
|
1325
1592
|
return `diff of ${block.path} at ${block.ref}: +${block.additions} -${block.deletions} in the whole change, ${plural(changed, "changed line")} shown${context > 0 ? ` with ${plural(context, "unchanged line")}` : ""}${numbered ? " and line numbers" : ""}`;
|
|
1326
1593
|
}
|
|
1594
|
+
case "log_lines": {
|
|
1595
|
+
const lines = block.lines ?? [];
|
|
1596
|
+
const counts = relationCounts(lines);
|
|
1597
|
+
const marked = [
|
|
1598
|
+
counts.matches_event > 0 ? `${counts.matches_event} matching the event` : "",
|
|
1599
|
+
counts.context > 0 ? `${counts.context} context` : "",
|
|
1600
|
+
counts.unrelated > 0 ? `${counts.unrelated} unrelated` : "",
|
|
1601
|
+
].filter((part) => part !== "");
|
|
1602
|
+
const scanned = typeof block.scanned === "number" ? ` of ${block.scanned} scanned` : "";
|
|
1603
|
+
return `log_lines: ${block.matched} lines matched${scanned}, ${plural(lines.length, "line")} shown${marked.length > 0 ? ` (${marked.join(", ")})` : ""}`;
|
|
1604
|
+
}
|
|
1327
1605
|
default:
|
|
1328
1606
|
return `changes with ${block.rows.length} rows`;
|
|
1329
1607
|
}
|
|
@@ -1378,6 +1656,19 @@ export function buildFigure(input, options = {}) {
|
|
|
1378
1656
|
if (failed)
|
|
1379
1657
|
return failed;
|
|
1380
1658
|
}
|
|
1659
|
+
else if (figure.type === "log_lines") {
|
|
1660
|
+
if (options.logLines !== true) {
|
|
1661
|
+
return {
|
|
1662
|
+
ok: false,
|
|
1663
|
+
issues: [
|
|
1664
|
+
`type: this Tellagen does not list ${LOG_LINES_CAPABILITY} in server_capabilities, so it would drop a log_lines figure. Show the log evidence as a checks or stats figure, and put the lines in the finding's evidence_summary.`,
|
|
1665
|
+
],
|
|
1666
|
+
};
|
|
1667
|
+
}
|
|
1668
|
+
const failed = take(buildLogLines(figure, options));
|
|
1669
|
+
if (failed)
|
|
1670
|
+
return failed;
|
|
1671
|
+
}
|
|
1381
1672
|
else if (figure.type === "table") {
|
|
1382
1673
|
block = {
|
|
1383
1674
|
...figure,
|
|
@@ -1408,10 +1699,11 @@ export function buildFigure(input, options = {}) {
|
|
|
1408
1699
|
return { ok: false, issues };
|
|
1409
1700
|
if (input.placement === "step_figure") {
|
|
1410
1701
|
const bytes = new TextEncoder().encode(JSON.stringify(block)).length;
|
|
1411
|
-
|
|
1702
|
+
const limit = maxStepFigureBytes(block.type);
|
|
1703
|
+
if (bytes > limit) {
|
|
1412
1704
|
return {
|
|
1413
1705
|
ok: false,
|
|
1414
|
-
issues: [`figure: ${bytes} bytes; a step figure holds at most ${
|
|
1706
|
+
issues: [`figure: ${bytes} bytes; a step figure holds at most ${limit}. Send fewer points, runs or rows, or put it on a timeline event.`],
|
|
1415
1707
|
};
|
|
1416
1708
|
}
|
|
1417
1709
|
}
|
|
@@ -1423,7 +1715,7 @@ export function buildFigure(input, options = {}) {
|
|
|
1423
1715
|
summary: describe(block),
|
|
1424
1716
|
notes,
|
|
1425
1717
|
use: input.placement === "step_figure"
|
|
1426
|
-
? "Put this object in result_summary.causal_paths[].steps[].figure. One figure per step. It needs the diagnosis structure the pickup advertises as diagnosis_structure_v1. A Tellagen older than these figure types drops a checks, range_overlap, histogram, run_history or
|
|
1718
|
+
? "Put this object in result_summary.causal_paths[].steps[].figure. One figure per step. It needs the diagnosis structure the pickup advertises as diagnosis_structure_v1. A Tellagen older than these figure types drops a checks, range_overlap, histogram, run_history, diff or log_lines figure and says so in the completion warnings (figure_invalid)."
|
|
1427
1719
|
: "Put this object in the blocks array of tellagen_post_timeline_event or tellagen_update_timeline_event. An update replaces the whole array, so send every block you want to keep.",
|
|
1428
1720
|
};
|
|
1429
1721
|
}
|