@granular-software/fractory 0.0.0-stage → 0.1.24
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 +4 -0
- package/README.md +28 -2
- package/dist/activity-volume.d.ts +18 -0
- package/dist/activity-volume.js +94 -0
- package/dist/annotations.d.ts +118 -0
- package/dist/annotations.js +304 -0
- package/dist/benchmark-cli.d.ts +1 -0
- package/dist/benchmark-cli.js +95 -0
- package/dist/benchmark-worker.d.ts +2 -0
- package/dist/benchmark-worker.js +22 -0
- package/dist/benchmarks.d.ts +19 -0
- package/dist/benchmarks.js +414 -0
- package/dist/bin.d.ts +2 -0
- package/dist/bin.js +63 -0
- package/dist/block-cli.d.ts +1 -0
- package/dist/block-cli.js +88 -0
- package/dist/block-documents.d.ts +35 -0
- package/dist/block-documents.js +84 -0
- package/dist/change-impact.d.ts +55 -0
- package/dist/change-impact.js +223 -0
- package/dist/check-source.d.ts +2 -0
- package/dist/check-source.js +66 -0
- package/dist/checks-model.d.ts +64 -0
- package/dist/checks-model.js +36 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +359 -0
- package/dist/code-model.d.ts +38 -0
- package/dist/code-model.js +94 -0
- package/dist/code-store.d.ts +9 -0
- package/dist/code-store.js +79 -0
- package/dist/compare-artifact.d.ts +6 -0
- package/dist/compare-artifact.js +277 -0
- package/dist/compare.d.ts +81 -0
- package/dist/compare.js +291 -0
- package/dist/compiler.d.ts +10 -0
- package/dist/compiler.js +1083 -0
- package/dist/compose.d.ts +9 -0
- package/dist/compose.js +72 -0
- package/dist/core.d.ts +86 -0
- package/dist/core.js +206 -0
- package/dist/coverage-cli.d.ts +1 -0
- package/dist/coverage-cli.js +42 -0
- package/dist/declaration-sources.d.ts +3 -0
- package/dist/declaration-sources.js +51 -0
- package/dist/declared-graph.d.ts +3 -0
- package/dist/declared-graph.js +66 -0
- package/dist/display-name.d.ts +2 -0
- package/dist/display-name.js +8 -0
- package/dist/error-heat.d.ts +58 -0
- package/dist/error-heat.js +96 -0
- package/dist/evidence.d.ts +3 -0
- package/dist/evidence.js +68 -0
- package/dist/factory-graph.d.ts +4 -0
- package/dist/factory-graph.js +318 -0
- package/dist/factory-model.d.ts +97 -0
- package/dist/factory-model.js +1 -0
- package/dist/git-code.d.ts +47 -0
- package/dist/git-code.js +352 -0
- package/dist/git-refs.d.ts +4 -0
- package/dist/git-refs.js +37 -0
- package/dist/history-activity.d.ts +4 -0
- package/dist/history-activity.js +129 -0
- package/dist/history-churn.d.ts +36 -0
- package/dist/history-churn.js +302 -0
- package/dist/history-git.d.ts +21 -0
- package/dist/history-git.js +125 -0
- package/dist/history-ledger.d.ts +43 -0
- package/dist/history-ledger.js +450 -0
- package/dist/history-ownership.d.ts +10 -0
- package/dist/history-ownership.js +75 -0
- package/dist/history-source.d.ts +13 -0
- package/dist/history-source.js +100 -0
- package/dist/integrations-cli.d.ts +2 -0
- package/dist/integrations-cli.js +159 -0
- package/dist/issue-cache.d.ts +9 -0
- package/dist/issue-cache.js +68 -0
- package/dist/issue-cli.d.ts +1 -0
- package/dist/issue-cli.js +89 -0
- package/dist/issue-links.d.ts +15 -0
- package/dist/issue-links.js +125 -0
- package/dist/linear-issues.d.ts +19 -0
- package/dist/linear-issues.js +124 -0
- package/dist/local-runtime.d.ts +8 -0
- package/dist/local-runtime.js +59 -0
- package/dist/map-activity.d.ts +73 -0
- package/dist/map-activity.js +234 -0
- package/dist/map-model.d.ts +5 -0
- package/dist/map-model.js +166 -0
- package/dist/map-quality.d.ts +14 -0
- package/dist/map-quality.js +56 -0
- package/dist/mapping-coverage.d.ts +87 -0
- package/dist/mapping-coverage.js +404 -0
- package/dist/model.d.ts +182 -0
- package/dist/model.js +66 -0
- package/dist/operation-benchmark-worker.d.ts +2 -0
- package/dist/operation-benchmark-worker.js +60 -0
- package/dist/operation-benchmark.d.ts +29 -0
- package/dist/operation-benchmark.js +1 -0
- package/dist/otel-metrics.d.ts +21 -0
- package/dist/otel-metrics.js +146 -0
- package/dist/performance-model.d.ts +185 -0
- package/dist/performance-model.js +396 -0
- package/dist/product-map.d.ts +69 -0
- package/dist/product-map.js +168 -0
- package/dist/provider-access.cjs +207 -0
- package/dist/provider-access.d.cts +14 -0
- package/dist/reports-cli.d.ts +1 -0
- package/dist/reports-cli.js +111 -0
- package/dist/reports-model.d.ts +27 -0
- package/dist/reports-model.js +39 -0
- package/dist/reports.d.ts +23 -0
- package/dist/reports.js +223 -0
- package/dist/repository-map.d.ts +22 -0
- package/dist/repository-map.js +151 -0
- package/dist/resource-cache.d.ts +17 -0
- package/dist/resource-cache.js +65 -0
- package/dist/review-cli.d.ts +19 -0
- package/dist/review-cli.js +224 -0
- package/dist/review.d.ts +48 -0
- package/dist/review.js +289 -0
- package/dist/runtime-metrics.d.ts +26 -0
- package/dist/runtime-metrics.js +290 -0
- package/dist/scope.d.ts +12 -0
- package/dist/scope.js +94 -0
- package/dist/sentry-activity.d.ts +39 -0
- package/dist/sentry-activity.js +174 -0
- package/dist/sentry.d.ts +130 -0
- package/dist/sentry.js +369 -0
- package/dist/service-release.d.ts +16 -0
- package/dist/service-release.js +14 -0
- package/dist/setup-cli.d.ts +2 -0
- package/dist/setup-cli.js +52 -0
- package/dist/setup-kit.cjs +163 -0
- package/dist/setup-kit.d.cts +32 -0
- package/dist/source-index.d.ts +37 -0
- package/dist/source-index.js +166 -0
- package/dist/source-review-git.d.ts +7 -0
- package/dist/source-review-git.js +103 -0
- package/dist/source-review.d.ts +16 -0
- package/dist/source-review.js +493 -0
- package/dist/telemetry.d.ts +17 -0
- package/dist/telemetry.js +51 -0
- package/dist/time-window.d.ts +9 -0
- package/dist/time-window.js +35 -0
- package/dist/trace-evidence.d.ts +23 -0
- package/dist/trace-evidence.js +55 -0
- package/dist/trace-model.d.ts +26 -0
- package/dist/trace-model.js +1 -0
- package/dist/tracing.d.ts +44 -0
- package/dist/tracing.js +123 -0
- package/dist/work-check.d.ts +17 -0
- package/dist/work-check.js +110 -0
- package/dist/work-cli.d.ts +1 -0
- package/dist/work-cli.js +148 -0
- package/dist/work-context.d.ts +57 -0
- package/dist/work-context.js +568 -0
- package/dist/work-intents.d.ts +6 -0
- package/dist/work-intents.js +140 -0
- package/dist/work-items.d.ts +58 -0
- package/dist/work-items.js +86 -0
- package/dist/work-model.d.ts +110 -0
- package/dist/work-model.js +261 -0
- package/dist/work-review-git.d.ts +8 -0
- package/dist/work-review-git.js +111 -0
- package/dist/work-review.d.ts +26 -0
- package/dist/work-review.js +426 -0
- package/dist/work-switcher-model.d.ts +43 -0
- package/dist/work-switcher-model.js +79 -0
- package/dist/work-switcher.d.ts +6 -0
- package/dist/work-switcher.js +171 -0
- package/dist/working-cli.d.ts +1 -0
- package/dist/working-cli.js +33 -0
- package/dist/working-code.d.ts +74 -0
- package/dist/working-code.js +421 -0
- package/dist/workspace-notes.d.ts +71 -0
- package/dist/workspace-notes.js +177 -0
- package/dist/workspace-tests.d.ts +21 -0
- package/dist/workspace-tests.js +573 -0
- package/package.json +547 -4
- package/src/activity-volume.ts +149 -0
- package/src/annotations.ts +481 -0
- package/src/benchmark-cli.ts +118 -0
- package/src/benchmark-worker.ts +22 -0
- package/src/benchmarks.ts +493 -0
- package/src/bin.ts +54 -0
- package/src/block-cli.ts +106 -0
- package/src/block-documents.ts +117 -0
- package/src/change-impact.ts +280 -0
- package/src/check-source.ts +82 -0
- package/src/checks-model.ts +108 -0
- package/src/cli.ts +440 -0
- package/src/code-model.ts +159 -0
- package/src/code-store.ts +98 -0
- package/src/compare-artifact.ts +314 -0
- package/src/compare.ts +440 -0
- package/src/compiler.ts +1326 -0
- package/src/compose.ts +94 -0
- package/src/core.ts +357 -0
- package/src/coverage-cli.ts +52 -0
- package/src/declaration-sources.ts +69 -0
- package/src/declared-graph.ts +74 -0
- package/src/display-name.ts +8 -0
- package/src/error-heat.ts +161 -0
- package/src/evidence.ts +94 -0
- package/src/factory-graph.ts +378 -0
- package/src/factory-model.ts +73 -0
- package/src/git-code.ts +461 -0
- package/src/git-refs.ts +43 -0
- package/src/history-activity.ts +146 -0
- package/src/history-churn.ts +416 -0
- package/src/history-git.ts +163 -0
- package/src/history-ledger.ts +636 -0
- package/src/history-ownership.ts +116 -0
- package/src/history-source.ts +117 -0
- package/src/integrations-cli.ts +187 -0
- package/src/issue-cache.ts +96 -0
- package/src/issue-cli.ts +137 -0
- package/src/issue-links.ts +153 -0
- package/src/linear-issues.ts +154 -0
- package/src/local-runtime.ts +70 -0
- package/src/map-activity.ts +309 -0
- package/src/map-model.ts +213 -0
- package/src/map-quality.ts +61 -0
- package/src/mapping-coverage.ts +570 -0
- package/src/model.ts +221 -0
- package/src/operation-benchmark-worker.ts +60 -0
- package/src/operation-benchmark.ts +28 -0
- package/src/otel-metrics.ts +176 -0
- package/src/performance-model.ts +575 -0
- package/src/product-map.ts +236 -0
- package/src/provider-access.cjs +207 -0
- package/src/provider-access.d.cts +14 -0
- package/src/reports-cli.ts +125 -0
- package/src/reports-model.ts +73 -0
- package/src/reports.ts +276 -0
- package/src/repository-map.ts +189 -0
- package/src/resource-cache.ts +76 -0
- package/src/review-cli.ts +256 -0
- package/src/review.ts +376 -0
- package/src/runtime-metrics.ts +386 -0
- package/src/scope.ts +103 -0
- package/src/sentry-activity.ts +234 -0
- package/src/sentry.ts +545 -0
- package/src/service-release.ts +18 -0
- package/src/setup-cli.ts +58 -0
- package/src/setup-kit.cjs +163 -0
- package/src/setup-kit.d.cts +32 -0
- package/src/source-index.ts +205 -0
- package/src/source-review-git.ts +129 -0
- package/src/source-review.ts +637 -0
- package/src/telemetry.ts +68 -0
- package/src/time-window.ts +51 -0
- package/src/trace-evidence.ts +80 -0
- package/src/trace-model.ts +26 -0
- package/src/tracing.ts +165 -0
- package/src/work-check.ts +143 -0
- package/src/work-cli.ts +195 -0
- package/src/work-context.ts +713 -0
- package/src/work-intents.ts +196 -0
- package/src/work-items.ts +151 -0
- package/src/work-model.ts +400 -0
- package/src/work-review-git.ts +130 -0
- package/src/work-review.ts +573 -0
- package/src/work-switcher-model.ts +121 -0
- package/src/work-switcher.ts +191 -0
- package/src/working-cli.ts +38 -0
- package/src/working-code.ts +582 -0
- package/src/workspace-notes.ts +203 -0
- package/src/workspace-tests.ts +654 -0
- package/toolkit/GUIDE.md +305 -0
- package/toolkit/SKILL.md +131 -0
- package/toolkit/bin/fractory +2 -0
- package/toolkit/build.json +1 -0
|
@@ -0,0 +1,575 @@
|
|
|
1
|
+
import type { DefinitionGraph } from "./model";
|
|
2
|
+
import type { ActivityCell } from "./map-activity";
|
|
3
|
+
import type { TimeWindow } from "./time-window";
|
|
4
|
+
export interface MetricBoundary {
|
|
5
|
+
target: string;
|
|
6
|
+
caller?: string;
|
|
7
|
+
calls: number;
|
|
8
|
+
callsKnown?: boolean;
|
|
9
|
+
errors: number;
|
|
10
|
+
buckets: { le: number; count: number }[];
|
|
11
|
+
trend: { at: number; value: number }[];
|
|
12
|
+
failedTrend?: { at: number; value: number }[];
|
|
13
|
+
latencyTrend?: { at: number; buckets: { le: number; count: number }[] }[];
|
|
14
|
+
}
|
|
15
|
+
export interface MetricGauge {
|
|
16
|
+
id: string;
|
|
17
|
+
label: string;
|
|
18
|
+
unit: string;
|
|
19
|
+
aggregation: "sum" | "max";
|
|
20
|
+
description?: string;
|
|
21
|
+
chart?: "line" | "bar";
|
|
22
|
+
sources?: { block: string; query: string }[];
|
|
23
|
+
status?: "ready" | "empty" | "error";
|
|
24
|
+
error?: string;
|
|
25
|
+
values: {
|
|
26
|
+
block: string;
|
|
27
|
+
value: number;
|
|
28
|
+
trend: { at: number; value: number }[];
|
|
29
|
+
}[];
|
|
30
|
+
}
|
|
31
|
+
export interface RuntimeMetrics {
|
|
32
|
+
source: "prometheus";
|
|
33
|
+
configured: boolean;
|
|
34
|
+
window: TimeWindow;
|
|
35
|
+
environment: string;
|
|
36
|
+
checkedAt: string;
|
|
37
|
+
lastSampleAt?: string;
|
|
38
|
+
boundaries: MetricBoundary[];
|
|
39
|
+
gauges: MetricGauge[];
|
|
40
|
+
warnings: string[];
|
|
41
|
+
}
|
|
42
|
+
export interface BlockMetric {
|
|
43
|
+
callsKnown?: boolean;
|
|
44
|
+
failedTrend?: { at: number; value: number }[];
|
|
45
|
+
latencyTrend?: { at: number; value: number }[];
|
|
46
|
+
calls: number;
|
|
47
|
+
errors: number;
|
|
48
|
+
errorRate: number | null;
|
|
49
|
+
p95Ms: number | null;
|
|
50
|
+
buckets: { le: number; count: number }[];
|
|
51
|
+
trend: { at: number; value: number }[];
|
|
52
|
+
}
|
|
53
|
+
export function histogramPercentile(
|
|
54
|
+
buckets: { le: number; count: number }[],
|
|
55
|
+
q = 0.95,
|
|
56
|
+
): number | null {
|
|
57
|
+
const sorted = [...buckets].sort((a, b) => a.le - b.le);
|
|
58
|
+
const total = sorted.at(-1)?.count || 0;
|
|
59
|
+
if (
|
|
60
|
+
!(total > 0) ||
|
|
61
|
+
sorted.some((bucket, i) => bucket.count < (sorted[i - 1]?.count || 0))
|
|
62
|
+
)
|
|
63
|
+
return null;
|
|
64
|
+
let previous = 0,
|
|
65
|
+
lower = 0;
|
|
66
|
+
for (const bucket of sorted) {
|
|
67
|
+
if (bucket.count >= total * q) {
|
|
68
|
+
if (!Number.isFinite(bucket.le) || bucket.le === Number.MAX_VALUE)
|
|
69
|
+
return null;
|
|
70
|
+
return (
|
|
71
|
+
lower +
|
|
72
|
+
((bucket.le - lower) * (total * q - previous)) /
|
|
73
|
+
Math.max(1e-12, bucket.count - previous)
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
previous = bucket.count;
|
|
77
|
+
lower = bucket.le;
|
|
78
|
+
}
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
function mergeBuckets(rows: MetricBoundary[]) {
|
|
82
|
+
if (!rows.length) return [];
|
|
83
|
+
rows = rows.map((row) => ({
|
|
84
|
+
...row,
|
|
85
|
+
buckets: [...row.buckets].sort((a, b) => a.le - b.le),
|
|
86
|
+
}));
|
|
87
|
+
const first = rows[0].buckets.map((bucket) => bucket.le).join(",");
|
|
88
|
+
if (
|
|
89
|
+
rows.some(
|
|
90
|
+
(row) => row.buckets.map((bucket) => bucket.le).join(",") !== first,
|
|
91
|
+
)
|
|
92
|
+
)
|
|
93
|
+
return [];
|
|
94
|
+
return rows[0].buckets.map((bucket, i) => ({
|
|
95
|
+
le: bucket.le,
|
|
96
|
+
count: rows.reduce((sum, row) => sum + row.buckets[i].count, 0),
|
|
97
|
+
}));
|
|
98
|
+
}
|
|
99
|
+
export function metricRollup(graph: DefinitionGraph, source: RuntimeMetrics) {
|
|
100
|
+
const byId = new Map(graph.elements.map((node) => [node.id, node]));
|
|
101
|
+
const identity = (id?: string) => (id ? graph.aliases?.[id] || id : "");
|
|
102
|
+
const ancestry = new Map<string, Set<string>>();
|
|
103
|
+
const ancestors = (id: string) => {
|
|
104
|
+
if (ancestry.has(id)) return ancestry.get(id)!;
|
|
105
|
+
const result = new Set<string>();
|
|
106
|
+
let node = byId.get(identity(id));
|
|
107
|
+
while (node && !result.has(node.id)) {
|
|
108
|
+
result.add(node.id);
|
|
109
|
+
node = byId.get(node.parent || "");
|
|
110
|
+
}
|
|
111
|
+
ancestry.set(id, result);
|
|
112
|
+
return result;
|
|
113
|
+
};
|
|
114
|
+
const entries = new Map<string, MetricBoundary[]>();
|
|
115
|
+
let unmapped = 0;
|
|
116
|
+
for (const row of source.boundaries) {
|
|
117
|
+
const target = ancestors(row.target),
|
|
118
|
+
caller = ancestors(row.caller || "");
|
|
119
|
+
if (!target.size) {
|
|
120
|
+
unmapped++;
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
for (const id of target)
|
|
124
|
+
if (!caller.has(id)) entries.set(id, [...(entries.get(id) || []), row]);
|
|
125
|
+
}
|
|
126
|
+
const blocks: Record<string, BlockMetric> = {};
|
|
127
|
+
for (const [id, rows] of entries) {
|
|
128
|
+
const calls = rows.reduce((sum, row) => sum + row.calls, 0),
|
|
129
|
+
errors = rows.reduce((sum, row) => sum + row.errors, 0);
|
|
130
|
+
const buckets = mergeBuckets(rows),
|
|
131
|
+
points = new Map<number, number>();
|
|
132
|
+
for (const row of rows)
|
|
133
|
+
for (const point of row.trend)
|
|
134
|
+
points.set(point.at, (points.get(point.at) || 0) + point.value);
|
|
135
|
+
const failed = new Map<number, number>();
|
|
136
|
+
const latency = new Map<number, MetricBoundary[]>();
|
|
137
|
+
for (const row of rows) {
|
|
138
|
+
for (const point of row.failedTrend || [])
|
|
139
|
+
failed.set(point.at, (failed.get(point.at) || 0) + point.value);
|
|
140
|
+
for (const point of row.latencyTrend || [])
|
|
141
|
+
latency.set(point.at, [
|
|
142
|
+
...(latency.get(point.at) || []),
|
|
143
|
+
{ ...row, buckets: point.buckets },
|
|
144
|
+
]);
|
|
145
|
+
}
|
|
146
|
+
blocks[id] = {
|
|
147
|
+
failedTrend: [...points]
|
|
148
|
+
.flatMap(([at, calls]) =>
|
|
149
|
+
calls > 0
|
|
150
|
+
? [{ at, value: (100 * (failed.get(at) || 0)) / calls }]
|
|
151
|
+
: [],
|
|
152
|
+
)
|
|
153
|
+
.sort((a, b) => a.at - b.at),
|
|
154
|
+
latencyTrend: [...latency]
|
|
155
|
+
.flatMap(([at, rows]) => {
|
|
156
|
+
const value =
|
|
157
|
+
rows.length === entries.get(id)?.length
|
|
158
|
+
? histogramPercentile(mergeBuckets(rows))
|
|
159
|
+
: null;
|
|
160
|
+
return value === null ? [] : [{ at, value: value * 1000 }];
|
|
161
|
+
})
|
|
162
|
+
.sort((a, b) => a.at - b.at),
|
|
163
|
+
calls,
|
|
164
|
+
errors,
|
|
165
|
+
callsKnown: rows.every((row) => row.callsKnown !== false),
|
|
166
|
+
errorRate:
|
|
167
|
+
rows.every((row) => row.callsKnown !== false) && calls > 0
|
|
168
|
+
? (errors / calls) * 100
|
|
169
|
+
: null,
|
|
170
|
+
p95Ms:
|
|
171
|
+
histogramPercentile(buckets) === null
|
|
172
|
+
? null
|
|
173
|
+
: histogramPercentile(buckets)! * 1000,
|
|
174
|
+
buckets,
|
|
175
|
+
trend: [...points]
|
|
176
|
+
.map(([at, value]) => ({ at, value }))
|
|
177
|
+
.sort((a, b) => a.at - b.at),
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
const links: Record<string, { count: number; label: string }> = {};
|
|
181
|
+
const pairKey = (caller: string, target: string) =>
|
|
182
|
+
JSON.stringify([caller, target]);
|
|
183
|
+
const pairs = new Map<string, number>();
|
|
184
|
+
for (const row of source.boundaries) {
|
|
185
|
+
const key = pairKey(identity(row.caller), identity(row.target));
|
|
186
|
+
pairs.set(key, (pairs.get(key) || 0) + row.calls);
|
|
187
|
+
}
|
|
188
|
+
const assigned = new Set<string>();
|
|
189
|
+
for (const edge of graph.connections) {
|
|
190
|
+
if (edge.relation !== "calls") continue;
|
|
191
|
+
const key = pairKey(edge.source, edge.target);
|
|
192
|
+
if (assigned.has(key)) continue;
|
|
193
|
+
assigned.add(key);
|
|
194
|
+
// Counters identify boundary pairs, not individual source call sites.
|
|
195
|
+
// Assign once so collapsed duplicate call sites cannot multiply traffic.
|
|
196
|
+
const count = pairs.get(key) || 0;
|
|
197
|
+
if (count > 0)
|
|
198
|
+
links[edge.id] = {
|
|
199
|
+
count,
|
|
200
|
+
label: `${formatNumber(count)} measured calls`,
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
const gauges: Record<
|
|
204
|
+
string,
|
|
205
|
+
Record<string, { value: number; trend: { at: number; value: number }[] }>
|
|
206
|
+
> = {};
|
|
207
|
+
for (const gauge of source.gauges) {
|
|
208
|
+
const candidates = new Map<string, typeof gauge.values>();
|
|
209
|
+
for (const row of gauge.values)
|
|
210
|
+
for (const id of ancestors(row.block))
|
|
211
|
+
candidates.set(id, [...(candidates.get(id) || []), row]);
|
|
212
|
+
gauges[gauge.id] = {};
|
|
213
|
+
for (const [id, rows] of candidates) {
|
|
214
|
+
const points = new Map<number, number[]>();
|
|
215
|
+
for (const row of rows)
|
|
216
|
+
for (const point of row.trend)
|
|
217
|
+
points.set(point.at, [...(points.get(point.at) || []), point.value]);
|
|
218
|
+
const reduce = (values: number[]) =>
|
|
219
|
+
gauge.aggregation === "sum"
|
|
220
|
+
? values.reduce((a, b) => a + b, 0)
|
|
221
|
+
: Math.max(...values);
|
|
222
|
+
gauges[gauge.id][id] = {
|
|
223
|
+
value: reduce(rows.map((row) => row.value)),
|
|
224
|
+
trend: [...points]
|
|
225
|
+
.filter(([, values]) => values.length === rows.length)
|
|
226
|
+
.map(([at, values]) => ({ at, value: reduce(values) }))
|
|
227
|
+
.sort((a, b) => a.at - b.at),
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
return { blocks, links, gauges, unmapped };
|
|
232
|
+
}
|
|
233
|
+
export function formatNumber(value: number) {
|
|
234
|
+
return new Intl.NumberFormat("en", {
|
|
235
|
+
notation: value >= 10000 ? "compact" : "standard",
|
|
236
|
+
...(Math.abs(value) > 0 && Math.abs(value) < 1
|
|
237
|
+
? { maximumSignificantDigits: 3 }
|
|
238
|
+
: { maximumFractionDigits: 1 }),
|
|
239
|
+
}).format(value);
|
|
240
|
+
}
|
|
241
|
+
export function durationLabel(ms: number) {
|
|
242
|
+
return ms < 1
|
|
243
|
+
? `${formatNumber(ms * 1000)} µs`
|
|
244
|
+
: ms < 1000
|
|
245
|
+
? `${formatNumber(ms)} ms`
|
|
246
|
+
: `${formatNumber(ms / 1000)} s`;
|
|
247
|
+
}
|
|
248
|
+
export function metricCells(
|
|
249
|
+
graph: DefinitionGraph,
|
|
250
|
+
source: RuntimeMetrics,
|
|
251
|
+
metric: string,
|
|
252
|
+
) {
|
|
253
|
+
const rolled = metricRollup(graph, source),
|
|
254
|
+
cells: Record<string, ActivityCell> = {};
|
|
255
|
+
if (metric === "block") {
|
|
256
|
+
for (const node of graph.elements) {
|
|
257
|
+
const measurements = source.gauges.flatMap((gauge) => {
|
|
258
|
+
const row = rolled.gauges[gauge.id]?.[node.id];
|
|
259
|
+
return row ? [{ gauge, row }] : [];
|
|
260
|
+
});
|
|
261
|
+
if (measurements.length === 1) {
|
|
262
|
+
const { gauge, row } = measurements[0];
|
|
263
|
+
cells[node.id] = {
|
|
264
|
+
count: row.value,
|
|
265
|
+
intensity: 0,
|
|
266
|
+
label: gauge.label,
|
|
267
|
+
displayValue: `${formatNumber(row.value)} ${gauge.unit}`,
|
|
268
|
+
summary: gauge.label,
|
|
269
|
+
series: row.trend.map((p) => p.value),
|
|
270
|
+
};
|
|
271
|
+
} else if (measurements.length > 1) {
|
|
272
|
+
cells[node.id] = {
|
|
273
|
+
count: measurements.length,
|
|
274
|
+
intensity: 0,
|
|
275
|
+
label: "Measurements",
|
|
276
|
+
measurements: measurements.map(({ gauge, row }) => ({
|
|
277
|
+
label: gauge.label,
|
|
278
|
+
value: `${formatNumber(row.value)} ${gauge.unit}`,
|
|
279
|
+
series: row.trend.map((p) => p.value),
|
|
280
|
+
})),
|
|
281
|
+
displayValue: String(measurements.length),
|
|
282
|
+
summary: measurements
|
|
283
|
+
.map(
|
|
284
|
+
({ gauge, row }) =>
|
|
285
|
+
`${gauge.label}: ${formatNumber(row.value)} ${gauge.unit}`,
|
|
286
|
+
)
|
|
287
|
+
.join(" · "),
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
return { cells, ...rolled };
|
|
292
|
+
}
|
|
293
|
+
const minutes =
|
|
294
|
+
(Date.parse(source.window.to) - Date.parse(source.window.from)) / 60000;
|
|
295
|
+
for (const [id, row] of Object.entries(rolled.blocks)) {
|
|
296
|
+
if (
|
|
297
|
+
row.callsKnown === false &&
|
|
298
|
+
(metric === "traffic" || metric === "errors")
|
|
299
|
+
)
|
|
300
|
+
continue;
|
|
301
|
+
if (!["traffic", "errors", "latency"].includes(metric)) continue;
|
|
302
|
+
const value =
|
|
303
|
+
metric === "traffic"
|
|
304
|
+
? row.calls / minutes
|
|
305
|
+
: metric === "errors"
|
|
306
|
+
? row.errorRate
|
|
307
|
+
: row.p95Ms;
|
|
308
|
+
if (value === null) continue;
|
|
309
|
+
cells[id] = {
|
|
310
|
+
count: value,
|
|
311
|
+
intensity: 0,
|
|
312
|
+
displayValue:
|
|
313
|
+
metric === "traffic"
|
|
314
|
+
? `${formatNumber(value)}/min`
|
|
315
|
+
: metric === "errors"
|
|
316
|
+
? `${formatNumber(value)}%`
|
|
317
|
+
: durationLabel(value),
|
|
318
|
+
label:
|
|
319
|
+
metric === "traffic"
|
|
320
|
+
? "calls"
|
|
321
|
+
: metric === "errors"
|
|
322
|
+
? "failures"
|
|
323
|
+
: "p95",
|
|
324
|
+
summary: `${row.callsKnown === false ? "Unknown" : formatNumber(row.calls)} boundary calls · ${formatNumber(row.errors)} failed${metric === "latency" ? " · histogram estimate" : ""}`,
|
|
325
|
+
...(metric === "traffic"
|
|
326
|
+
? { series: row.trend.map((point) => point.value) }
|
|
327
|
+
: {}),
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
const gauge = source.gauges.find((item) => item.id === metric);
|
|
331
|
+
if (gauge)
|
|
332
|
+
for (const [id, row] of Object.entries(rolled.gauges[metric] || {}))
|
|
333
|
+
cells[id] = {
|
|
334
|
+
count: row.value,
|
|
335
|
+
intensity: 0,
|
|
336
|
+
displayValue: `${formatNumber(row.value)} ${gauge.unit}`,
|
|
337
|
+
label: gauge.label,
|
|
338
|
+
summary: `Latest measured gauge · ${gauge.aggregation} across distinct attached sources`,
|
|
339
|
+
series: row.trend.map((point) => point.value),
|
|
340
|
+
};
|
|
341
|
+
return { cells, ...rolled };
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
export interface BenchmarkCase {
|
|
345
|
+
name: string;
|
|
346
|
+
samples: number;
|
|
347
|
+
meanMs: number;
|
|
348
|
+
marginMs: number;
|
|
349
|
+
p95Ms: number;
|
|
350
|
+
hz: number;
|
|
351
|
+
attemptsMs?: number[];
|
|
352
|
+
attemptPhases?: Record<string, number>[];
|
|
353
|
+
}
|
|
354
|
+
export interface BenchmarkRun {
|
|
355
|
+
runnerPid?: number;
|
|
356
|
+
heartbeatAt?: number;
|
|
357
|
+
kind?: "function" | "operation";
|
|
358
|
+
fixture?: string;
|
|
359
|
+
fixtureVersion?: string;
|
|
360
|
+
fixtureDescription?: string;
|
|
361
|
+
target?: {
|
|
362
|
+
name: string;
|
|
363
|
+
url: string;
|
|
364
|
+
revision: string;
|
|
365
|
+
measurement: "client" | "server";
|
|
366
|
+
};
|
|
367
|
+
id: string;
|
|
368
|
+
file: string;
|
|
369
|
+
blockIds: string[];
|
|
370
|
+
at: string;
|
|
371
|
+
status: "queued" | "running" | "passed" | "failed";
|
|
372
|
+
commit: string | null;
|
|
373
|
+
baseCommit: string;
|
|
374
|
+
codeDigest: string;
|
|
375
|
+
scenario: string;
|
|
376
|
+
environment: string;
|
|
377
|
+
machine: string;
|
|
378
|
+
cases: BenchmarkCase[];
|
|
379
|
+
output: string;
|
|
380
|
+
error?: string;
|
|
381
|
+
durationMs?: number;
|
|
382
|
+
}
|
|
383
|
+
export interface BenchmarkView {
|
|
384
|
+
plans: {
|
|
385
|
+
file: string;
|
|
386
|
+
blocks: string[];
|
|
387
|
+
label: string;
|
|
388
|
+
kind?: "function" | "operation";
|
|
389
|
+
fixture?: string;
|
|
390
|
+
description?: string;
|
|
391
|
+
startsWhen?: string;
|
|
392
|
+
endsWhen?: string;
|
|
393
|
+
attempts?: number;
|
|
394
|
+
}[];
|
|
395
|
+
runs: BenchmarkRun[];
|
|
396
|
+
baselines: Record<string, string>;
|
|
397
|
+
}
|
|
398
|
+
/** A reason is preferable to silently comparing unrelated workloads or a run with itself. */
|
|
399
|
+
export function benchmarkComparisonReason(
|
|
400
|
+
current: BenchmarkRun,
|
|
401
|
+
baseline: BenchmarkRun | undefined,
|
|
402
|
+
name: string,
|
|
403
|
+
): string | undefined {
|
|
404
|
+
if (!baseline) return "Choose a reference run.";
|
|
405
|
+
if (current.id === baseline.id) return "Choose two different runs.";
|
|
406
|
+
if (current.file !== baseline.file || current.kind !== baseline.kind)
|
|
407
|
+
return "Different benchmark operations.";
|
|
408
|
+
if (current.status !== "passed" || baseline.status !== "passed")
|
|
409
|
+
return "Both runs must finish successfully.";
|
|
410
|
+
if (current.scenario !== baseline.scenario)
|
|
411
|
+
return "The workload or fixture changed.";
|
|
412
|
+
if (current.environment !== baseline.environment)
|
|
413
|
+
return "Different test environment or timing conditions.";
|
|
414
|
+
if (
|
|
415
|
+
current.target?.url !== baseline.target?.url ||
|
|
416
|
+
current.target?.measurement !== baseline.target?.measurement
|
|
417
|
+
)
|
|
418
|
+
return "Different deployment target or timing source.";
|
|
419
|
+
const value = current.cases.find((item) => item.name === name),
|
|
420
|
+
before = baseline.cases.find((item) => item.name === name);
|
|
421
|
+
if (!value || !before) return "This measurement is missing from one run.";
|
|
422
|
+
if (
|
|
423
|
+
value.samples < (current.kind === "operation" ? 3 : 20) ||
|
|
424
|
+
before.samples < (current.kind === "operation" ? 3 : 20)
|
|
425
|
+
)
|
|
426
|
+
return "Too few successful samples to compare.";
|
|
427
|
+
if (!(before.meanMs > 0))
|
|
428
|
+
return "The reference duration must be greater than zero.";
|
|
429
|
+
}
|
|
430
|
+
export function benchmarkReference(view: BenchmarkView, current: BenchmarkRun) {
|
|
431
|
+
const name = current.cases[0]?.name || "";
|
|
432
|
+
const pinned = view.runs.find(
|
|
433
|
+
(run) => run.id === view.baselines[current.file],
|
|
434
|
+
);
|
|
435
|
+
if (pinned && !benchmarkComparisonReason(current, pinned, name))
|
|
436
|
+
return pinned;
|
|
437
|
+
return view.runs.find(
|
|
438
|
+
(run) =>
|
|
439
|
+
run.at < current.at && !benchmarkComparisonReason(current, run, name),
|
|
440
|
+
);
|
|
441
|
+
}
|
|
442
|
+
export function compareBenchmark(
|
|
443
|
+
current: BenchmarkRun,
|
|
444
|
+
baseline: BenchmarkRun | undefined,
|
|
445
|
+
name: string,
|
|
446
|
+
) {
|
|
447
|
+
const value = current.cases.find((item) => item.name === name),
|
|
448
|
+
before = baseline?.cases.find((item) => item.name === name);
|
|
449
|
+
if (benchmarkComparisonReason(current, baseline, name) || !value || !before)
|
|
450
|
+
return null;
|
|
451
|
+
const percent = (value.meanMs / before.meanMs - 1) * 100;
|
|
452
|
+
const slower =
|
|
453
|
+
value.meanMs - value.marginMs > before.meanMs + before.marginMs;
|
|
454
|
+
const faster =
|
|
455
|
+
value.meanMs + value.marginMs < before.meanMs - before.marginMs;
|
|
456
|
+
return {
|
|
457
|
+
percent,
|
|
458
|
+
significant: (percent > 5 && slower) || (percent < -5 && faster),
|
|
459
|
+
direction:
|
|
460
|
+
slower && percent > 5
|
|
461
|
+
? "slower"
|
|
462
|
+
: faster && percent < -5
|
|
463
|
+
? "faster"
|
|
464
|
+
: "similar",
|
|
465
|
+
} as const;
|
|
466
|
+
}
|
|
467
|
+
export function benchmarkCells(graph: DefinitionGraph, view: BenchmarkView) {
|
|
468
|
+
const byId = new Map(graph.elements.map((n) => [n.id, n]));
|
|
469
|
+
const owned = new Map<
|
|
470
|
+
string,
|
|
471
|
+
Map<
|
|
472
|
+
string,
|
|
473
|
+
{
|
|
474
|
+
label: string;
|
|
475
|
+
value: string;
|
|
476
|
+
series: number[];
|
|
477
|
+
tone: "regression" | "improvement" | "neutral";
|
|
478
|
+
summary: string;
|
|
479
|
+
count: number;
|
|
480
|
+
}
|
|
481
|
+
>
|
|
482
|
+
>();
|
|
483
|
+
for (const plan of view.plans.filter((p) => p.kind === "operation")) {
|
|
484
|
+
const history = view.runs.filter((r) => r.file === plan.file),
|
|
485
|
+
latest = history[0],
|
|
486
|
+
passing = history.find((r) => r.status === "passed");
|
|
487
|
+
const reference = passing ? benchmarkReference(view, passing) : undefined;
|
|
488
|
+
const cases = passing?.cases.length ? passing.cases : [undefined];
|
|
489
|
+
for (const item of cases) {
|
|
490
|
+
const change =
|
|
491
|
+
passing && item
|
|
492
|
+
? compareBenchmark(passing, reference, item.name)
|
|
493
|
+
: null;
|
|
494
|
+
const pending =
|
|
495
|
+
latest && ["running", "queued", "failed"].includes(latest.status);
|
|
496
|
+
const row = {
|
|
497
|
+
label: item?.name || plan.label,
|
|
498
|
+
value: pending
|
|
499
|
+
? latest.status === "failed"
|
|
500
|
+
? "Failed"
|
|
501
|
+
: "Running"
|
|
502
|
+
: item
|
|
503
|
+
? durationLabel(item.meanMs)
|
|
504
|
+
: "Not run",
|
|
505
|
+
count: pending ? 0 : item?.meanMs || 0,
|
|
506
|
+
series: pending
|
|
507
|
+
? []
|
|
508
|
+
: history
|
|
509
|
+
.filter(
|
|
510
|
+
(r) =>
|
|
511
|
+
r.status === "passed" &&
|
|
512
|
+
r.environment === passing?.environment &&
|
|
513
|
+
r.scenario === passing.scenario,
|
|
514
|
+
)
|
|
515
|
+
.slice(0, 24)
|
|
516
|
+
.reverse()
|
|
517
|
+
.flatMap((r) =>
|
|
518
|
+
r.cases
|
|
519
|
+
.filter((c) => c.name === item?.name)
|
|
520
|
+
.map((c) => c.meanMs),
|
|
521
|
+
),
|
|
522
|
+
tone: (pending && latest.status === "failed"
|
|
523
|
+
? "regression"
|
|
524
|
+
: change?.direction === "slower"
|
|
525
|
+
? "regression"
|
|
526
|
+
: change?.direction === "faster"
|
|
527
|
+
? "improvement"
|
|
528
|
+
: "neutral") as "regression" | "improvement" | "neutral",
|
|
529
|
+
summary: pending
|
|
530
|
+
? latest.error || `Measuring ${plan.label}`
|
|
531
|
+
: item
|
|
532
|
+
? `${item.name} · mean of ${item.samples} attempts · deployed ${passing?.target?.revision.slice(0, 8) || "revision unknown"}${change ? ` · ${formatNumber(Math.abs(change.percent))}% ${change.direction}` : ""}`
|
|
533
|
+
: `${plan.label} has not been measured`,
|
|
534
|
+
};
|
|
535
|
+
for (const block of plan.blocks) {
|
|
536
|
+
let node = byId.get(block);
|
|
537
|
+
const seen = new Set<string>();
|
|
538
|
+
while (node && !seen.has(node.id)) {
|
|
539
|
+
seen.add(node.id);
|
|
540
|
+
if (!owned.has(node.id)) owned.set(node.id, new Map());
|
|
541
|
+
owned
|
|
542
|
+
.get(node.id)!
|
|
543
|
+
.set(plan.file + "#" + (item?.name || plan.label), row);
|
|
544
|
+
node = byId.get(node.parent || "");
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
const cells: Record<string, ActivityCell> = {};
|
|
550
|
+
for (const [id, rows] of owned) {
|
|
551
|
+
const values = [...rows.values()],
|
|
552
|
+
first = values[0];
|
|
553
|
+
cells[id] =
|
|
554
|
+
values.length === 1
|
|
555
|
+
? {
|
|
556
|
+
count: first.count,
|
|
557
|
+
intensity: 0,
|
|
558
|
+
displayValue: first.value,
|
|
559
|
+
label: first.label,
|
|
560
|
+
summary: first.summary,
|
|
561
|
+
series: first.series,
|
|
562
|
+
tone: first.tone,
|
|
563
|
+
}
|
|
564
|
+
: {
|
|
565
|
+
count: values.length,
|
|
566
|
+
intensity: 0,
|
|
567
|
+
displayValue: String(values.length),
|
|
568
|
+
label: "Product benchmarks",
|
|
569
|
+
summary: values.map((v) => v.summary).join(" · "),
|
|
570
|
+
measurements: values,
|
|
571
|
+
tone: "neutral",
|
|
572
|
+
};
|
|
573
|
+
}
|
|
574
|
+
return cells;
|
|
575
|
+
}
|