@mastra/factory 0.29.0-alpha.2 → 0.29.0-alpha.4
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 +44 -5
- package/dist/factory.d.ts +8 -0
- package/dist/factory.d.ts.map +1 -1
- package/dist/factory.js +26 -10
- package/dist/factory.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -2
- package/dist/integrations/dependabot/rules.d.ts.map +1 -1
- package/dist/integrations/dependabot/rules.js +1 -5
- package/dist/integrations/dependabot/rules.js.map +1 -1
- package/dist/integrations/github/commits.d.ts +0 -21
- package/dist/integrations/github/commits.d.ts.map +1 -1
- package/dist/integrations/github/commits.js +1 -24
- package/dist/integrations/github/commits.js.map +1 -1
- package/dist/integrations/github/integration.d.ts +1 -1
- package/dist/integrations/github/integration.d.ts.map +1 -1
- package/dist/integrations/github/integration.js +2 -6
- package/dist/integrations/github/integration.js.map +1 -1
- package/dist/integrations/github/reconcile-worker.d.ts.map +1 -1
- package/dist/integrations/github/reconcile-worker.js +30 -1
- package/dist/integrations/github/reconcile-worker.js.map +1 -1
- package/dist/integrations/github/routes.d.ts +1 -11
- package/dist/integrations/github/routes.d.ts.map +1 -1
- package/dist/integrations/github/routes.js +6 -515
- package/dist/integrations/github/routes.js.map +1 -1
- package/dist/integrations/github/rules.d.ts.map +1 -1
- package/dist/integrations/github/rules.js +76 -13
- package/dist/integrations/github/rules.js.map +1 -1
- package/dist/integrations/github/sandbox.d.ts.map +1 -1
- package/dist/integrations/github/sandbox.js +11 -2
- package/dist/integrations/github/sandbox.js.map +1 -1
- package/dist/integrations/gitlab/discovery.d.ts +1 -1
- package/dist/integrations/gitlab/discovery.js +1 -1
- package/dist/integrations/gitlab/discovery.js.map +1 -1
- package/dist/integrations/gitlab/integration.d.ts.map +1 -1
- package/dist/integrations/gitlab/integration.js +0 -1
- package/dist/integrations/gitlab/integration.js.map +1 -1
- package/dist/integrations/gitlab/routes.d.ts +0 -2
- package/dist/integrations/gitlab/routes.d.ts.map +1 -1
- package/dist/integrations/gitlab/routes.js +49 -165
- package/dist/integrations/gitlab/routes.js.map +1 -1
- package/dist/integrations/gitlab/rules.d.ts.map +1 -1
- package/dist/integrations/gitlab/rules.js +20 -7
- package/dist/integrations/gitlab/rules.js.map +1 -1
- package/dist/integrations/incidentio/routes.d.ts +5 -5
- package/dist/integrations/incidentio/routes.d.ts.map +1 -1
- package/dist/integrations/incidentio/routes.js +3 -59
- package/dist/integrations/incidentio/routes.js.map +1 -1
- package/dist/integrations/incidentio/rules.d.ts.map +1 -1
- package/dist/integrations/incidentio/rules.js +1 -5
- package/dist/integrations/incidentio/rules.js.map +1 -1
- package/dist/integrations/jira/issue-reconciler.d.ts +1 -1
- package/dist/integrations/jira/issue-reconciler.d.ts.map +1 -1
- package/dist/integrations/jira/issue-reconciler.js.map +1 -1
- package/dist/integrations/jira/routes.d.ts +2 -2
- package/dist/integrations/jira/routes.d.ts.map +1 -1
- package/dist/integrations/jira/routes.js +0 -68
- package/dist/integrations/jira/routes.js.map +1 -1
- package/dist/integrations/jira/rules.d.ts.map +1 -1
- package/dist/integrations/jira/rules.js +1 -5
- package/dist/integrations/jira/rules.js.map +1 -1
- package/dist/integrations/linear/routes.d.ts +2 -2
- package/dist/integrations/linear/routes.d.ts.map +1 -1
- package/dist/integrations/linear/routes.js +0 -83
- package/dist/integrations/linear/routes.js.map +1 -1
- package/dist/integrations/linear/rules.d.ts.map +1 -1
- package/dist/integrations/linear/rules.js +12 -5
- package/dist/integrations/linear/rules.js.map +1 -1
- package/dist/integrations/platform/github/integration.d.ts.map +1 -1
- package/dist/integrations/platform/github/integration.js +1 -3
- package/dist/integrations/platform/github/integration.js.map +1 -1
- package/dist/integrations/platform/jira/routes.d.ts +2 -2
- package/dist/integrations/platform/jira/routes.d.ts.map +1 -1
- package/dist/integrations/platform/jira/routes.js +0 -69
- package/dist/integrations/platform/jira/routes.js.map +1 -1
- package/dist/integrations/vanta/rules.d.ts.map +1 -1
- package/dist/integrations/vanta/rules.js +1 -5
- package/dist/integrations/vanta/rules.js.map +1 -1
- package/dist/metrics/collectors/postgres.d.ts +29 -0
- package/dist/metrics/collectors/postgres.d.ts.map +1 -0
- package/dist/metrics/collectors/postgres.js +121 -0
- package/dist/metrics/collectors/postgres.js.map +1 -0
- package/dist/metrics/collectors/probe.d.ts +22 -0
- package/dist/metrics/collectors/probe.d.ts.map +1 -0
- package/dist/metrics/collectors/probe.js +69 -0
- package/dist/metrics/collectors/probe.js.map +1 -0
- package/dist/metrics/collectors/process.d.ts +13 -0
- package/dist/metrics/collectors/process.d.ts.map +1 -0
- package/dist/metrics/collectors/process.js +85 -0
- package/dist/metrics/collectors/process.js.map +1 -0
- package/dist/metrics/collectors/redis.d.ts +29 -0
- package/dist/metrics/collectors/redis.d.ts.map +1 -0
- package/dist/metrics/collectors/redis.js +97 -0
- package/dist/metrics/collectors/redis.js.map +1 -0
- package/dist/metrics/config.d.ts +33 -0
- package/dist/metrics/config.d.ts.map +1 -0
- package/dist/metrics/config.js +65 -0
- package/dist/metrics/config.js.map +1 -0
- package/dist/metrics/index.d.ts +20 -0
- package/dist/metrics/index.d.ts.map +1 -0
- package/dist/metrics/index.js +65 -0
- package/dist/metrics/index.js.map +1 -0
- package/dist/metrics/intake.d.ts +28 -0
- package/dist/metrics/intake.d.ts.map +1 -0
- package/dist/metrics/intake.js +76 -0
- package/dist/metrics/intake.js.map +1 -0
- package/dist/metrics/metrics.d.ts +60 -0
- package/dist/metrics/metrics.d.ts.map +1 -0
- package/dist/metrics/metrics.js +182 -0
- package/dist/metrics/metrics.js.map +1 -0
- package/dist/metrics/sandbox.d.ts +35 -0
- package/dist/metrics/sandbox.d.ts.map +1 -0
- package/dist/metrics/sandbox.js +156 -0
- package/dist/metrics/sandbox.js.map +1 -0
- package/dist/packages/_internals/workspace/dist/index.js.map +1 -1
- package/dist/routes/automation-runs.d.ts +0 -2
- package/dist/routes/automation-runs.d.ts.map +1 -1
- package/dist/routes/automation-runs.js +2 -6
- package/dist/routes/automation-runs.js.map +1 -1
- package/dist/routes/contracts.d.ts +0 -5
- package/dist/routes/contracts.d.ts.map +1 -1
- package/dist/routes/contracts.js +2 -4
- package/dist/routes/contracts.js.map +1 -1
- package/dist/routes/fs.d.ts +10 -0
- package/dist/routes/fs.d.ts.map +1 -1
- package/dist/routes/fs.js +184 -11
- package/dist/routes/fs.js.map +1 -1
- package/dist/routes/projects.d.ts.map +1 -1
- package/dist/routes/projects.js +4 -17
- package/dist/routes/projects.js.map +1 -1
- package/dist/routes/source-control-sessions.d.ts +0 -3
- package/dist/routes/source-control-sessions.d.ts.map +1 -1
- package/dist/routes/source-control-sessions.js +0 -19
- package/dist/routes/source-control-sessions.js.map +1 -1
- package/dist/routes/surface.d.ts +0 -2
- package/dist/routes/surface.d.ts.map +1 -1
- package/dist/routes/surface.js +2 -12
- package/dist/routes/surface.js.map +1 -1
- package/dist/rules/dispatcher.d.ts +1 -0
- package/dist/rules/dispatcher.d.ts.map +1 -1
- package/dist/rules/dispatcher.js +27 -13
- package/dist/rules/dispatcher.js.map +1 -1
- package/dist/rules/processor.d.ts.map +1 -1
- package/dist/rules/processor.js +1 -6
- package/dist/rules/processor.js.map +1 -1
- package/dist/rules/start-coordinator.d.ts +1 -0
- package/dist/rules/start-coordinator.d.ts.map +1 -1
- package/dist/rules/start-coordinator.js +2 -1
- package/dist/rules/start-coordinator.js.map +1 -1
- package/dist/rules/transition-service.d.ts.map +1 -1
- package/dist/rules/transition-service.js +0 -2
- package/dist/rules/transition-service.js.map +1 -1
- package/dist/sandbox/session-retirement.d.ts.map +1 -1
- package/dist/sandbox/session-retirement.js +22 -14
- package/dist/sandbox/session-retirement.js.map +1 -1
- package/dist/sandbox/session-sandbox.d.ts +2 -0
- package/dist/sandbox/session-sandbox.d.ts.map +1 -1
- package/dist/sandbox/session-sandbox.js +7 -1
- package/dist/sandbox/session-sandbox.js.map +1 -1
- package/dist/storage/domains/boards/schemas.d.ts.map +1 -1
- package/dist/storage/domains/boards/schemas.js +0 -4
- package/dist/storage/domains/boards/schemas.js.map +1 -1
- package/dist/storage/domains/intake/base.d.ts +11 -10
- package/dist/storage/domains/intake/base.d.ts.map +1 -1
- package/dist/storage/domains/intake/base.js +30 -65
- package/dist/storage/domains/intake/base.js.map +1 -1
- package/dist/storage/domains/integrations/base.d.ts +0 -2
- package/dist/storage/domains/integrations/base.d.ts.map +1 -1
- package/dist/storage/domains/integrations/base.js +0 -6
- package/dist/storage/domains/integrations/base.js.map +1 -1
- package/dist/storage/domains/projects/base.d.ts.map +1 -1
- package/dist/storage/domains/projects/base.js +0 -12
- package/dist/storage/domains/projects/base.js.map +1 -1
- package/dist/storage/domains/source-control/base.d.ts +0 -10
- package/dist/storage/domains/source-control/base.d.ts.map +1 -1
- package/dist/storage/domains/source-control/base.js +1 -19
- package/dist/storage/domains/source-control/base.js.map +1 -1
- package/dist/storage/domains/source-control/inmemory.d.ts +1 -1
- package/dist/storage/domains/source-control/inmemory.d.ts.map +1 -1
- package/dist/storage/domains/source-control/inmemory.js +1 -6
- package/dist/storage/domains/source-control/inmemory.js.map +1 -1
- package/dist/storage/domains/work-items/base.d.ts +6 -36
- package/dist/storage/domains/work-items/base.d.ts.map +1 -1
- package/dist/storage/domains/work-items/base.js +42 -82
- package/dist/storage/domains/work-items/base.js.map +1 -1
- package/dist/storage/domains/work-items/work-item-schema.d.ts +12 -3
- package/dist/storage/domains/work-items/work-item-schema.d.ts.map +1 -1
- package/dist/storage/domains/work-items/work-item-schema.js +12 -3
- package/dist/storage/domains/work-items/work-item-schema.js.map +1 -1
- package/dist/storage/legacy-collections.d.ts +9 -0
- package/dist/storage/legacy-collections.d.ts.map +1 -0
- package/dist/storage/legacy-collections.js +17 -0
- package/dist/storage/legacy-collections.js.map +1 -0
- package/dist/timing.d.ts +4 -1
- package/dist/timing.d.ts.map +1 -1
- package/dist/timing.js +12 -4
- package/dist/timing.js.map +1 -1
- package/dist/workspace.d.ts.map +1 -1
- package/dist/workspace.js +8 -4
- package/dist/workspace.js.map +1 -1
- package/factory-skills/configure-factory-rules/SKILL.md +2 -2
- package/package.json +10 -10
- package/dist/session/filesystem-capture.d.ts +0 -50
- package/dist/session/filesystem-capture.d.ts.map +0 -1
- package/dist/session/filesystem-capture.js +0 -229
- package/dist/session/filesystem-capture.js.map +0 -1
- package/dist/storage/domains/filesystem/base.d.ts +0 -30
- package/dist/storage/domains/filesystem/base.d.ts.map +0 -1
- package/dist/storage/domains/filesystem/base.js +0 -78
- package/dist/storage/domains/filesystem/base.js.map +0 -1
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { MetricsContext } from '@mastra/core/observability';
|
|
2
|
+
import type { MetricGroup, MetricsService, ResolvedMetricsConfig } from './config.js';
|
|
3
|
+
export type MetricLabels = Record<string, string>;
|
|
4
|
+
/** The subset of the Mastra logger metrics write to. */
|
|
5
|
+
export interface MetricsLogger {
|
|
6
|
+
info(message: string, ...args: unknown[]): void;
|
|
7
|
+
warn(message: string, ...args: unknown[]): void;
|
|
8
|
+
}
|
|
9
|
+
/** Where collectors send their samples; capped per tick. */
|
|
10
|
+
export interface MetricSink {
|
|
11
|
+
emit(name: string, value: number, labels?: MetricLabels): void;
|
|
12
|
+
}
|
|
13
|
+
/** Sampled once per interval. */
|
|
14
|
+
export interface MetricsCollector {
|
|
15
|
+
collect(sink: MetricSink): Promise<void> | void;
|
|
16
|
+
/** Releases anything the collector holds (observers, histograms). */
|
|
17
|
+
stop?(): void;
|
|
18
|
+
}
|
|
19
|
+
export interface MetricsTargets {
|
|
20
|
+
/**
|
|
21
|
+
* The metrics context to send to. Read on every flush: Platform registers its exporter on the
|
|
22
|
+
* Mastra instance after the app module has loaded, replacing the no-op context.
|
|
23
|
+
*/
|
|
24
|
+
getMetrics: () => Pick<MetricsContext, 'emit'> | undefined;
|
|
25
|
+
getLogger: () => MetricsLogger | undefined;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Factory's metrics. Call sites check `enabled(group)` (or just call `count`/`observe`, which do
|
|
29
|
+
* nothing for a group that's off). Counts and timings are aggregated in-process and sent once per
|
|
30
|
+
* interval, so a burst of events costs one record per series, not one per event.
|
|
31
|
+
*/
|
|
32
|
+
export declare class FactoryMetrics {
|
|
33
|
+
#private;
|
|
34
|
+
constructor(config: ResolvedMetricsConfig | undefined, service: MetricsService);
|
|
35
|
+
get service(): MetricsService;
|
|
36
|
+
get intervalMs(): number;
|
|
37
|
+
enabled(group: MetricGroup): boolean;
|
|
38
|
+
/** Adds `value` to a counter, sent as one record per series per interval. */
|
|
39
|
+
count(group: MetricGroup, name: string, labels?: MetricLabels, value?: number): void;
|
|
40
|
+
/**
|
|
41
|
+
* Sends this counter series every interval, as 0 when nothing happened, so a quiet interval
|
|
42
|
+
* reads as zero instead of looking like the group is off. Keep it to a few series.
|
|
43
|
+
*/
|
|
44
|
+
keepCounter(group: MetricGroup, name: string, labels?: MetricLabels): void;
|
|
45
|
+
/** Records a timing, sent per interval as `stat=avg|p95|max` plus a `<name>_count` series. */
|
|
46
|
+
observe(group: MetricGroup, name: string, value: number, labels?: MetricLabels): void;
|
|
47
|
+
/** Starts the interval timer. Does nothing when every group is off. */
|
|
48
|
+
start(targets: MetricsTargets, collectors: MetricsCollector[]): void;
|
|
49
|
+
stop(): void;
|
|
50
|
+
/**
|
|
51
|
+
* Sends aggregated counters and timings, then samples the collectors. Skipped while the previous
|
|
52
|
+
* tick is still running, so a hung dependency never piles up probes. Exposed for tests.
|
|
53
|
+
*/
|
|
54
|
+
tick(): Promise<void>;
|
|
55
|
+
}
|
|
56
|
+
/** The process's Factory metrics. A no-op until a `MastraFactory` with metrics is constructed. */
|
|
57
|
+
export declare function factoryMetrics(): FactoryMetrics;
|
|
58
|
+
/** Replaces the process's Factory metrics, stopping the previous one. One Factory per process. */
|
|
59
|
+
export declare function installFactoryMetrics(metrics: FactoryMetrics): void;
|
|
60
|
+
//# sourceMappingURL=metr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MAAM,CAEvB;IAED,OAAO,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAEnC;IAED,6EAA6E;IAC7E,KAAK,CAAC,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,GAAE,YAAiB,EAAE,KAAK,SAAI,GAAG,IAAI,CAMlF;IAED;;;OAGG;IACH,WAAW,CAAC,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,GAAE,YAAiB,GAAG,IAAI,CAM7E;IAED,8FAA8F;IAC9F,OAAO,CAAC,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,GAAE,YAAiB,GAAG,IAAI,CAkBxF;IAED,uEAAuE;IACvE,KAAK,CAAC,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,gBAAgB,EAAE,GAAG,IAAI,CAanE;IAED,IAAI,IAAI,IAAI,CAKX;IAED;;;OAGG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CA2D1B;CACF;AAID,kGAAkG;AAClG,wBAAgB,cAAc,IAAI,cAAc,CAE/C;AAED,kGAAkG;AAClG,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,cAAc,GAAG,IAAI,CAGnE"}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
// src/metrics/metrics.ts
|
|
2
|
+
const MAX_SAMPLES = 1e3;
|
|
3
|
+
function seriesKey(name, labels) {
|
|
4
|
+
return `${name}\u0000${Object.keys(labels).sort().map((key) => `${key}=${labels[key]}`).join(",")}`;
|
|
5
|
+
}
|
|
6
|
+
function percentile(sorted, p) {
|
|
7
|
+
if (sorted.length === 0) return 0;
|
|
8
|
+
return sorted[Math.min(sorted.length - 1, Math.ceil(p * sorted.length) - 1)];
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Factory's metrics. Call sites check `enabled(group)` (or just call `count`/`observe`, which do
|
|
12
|
+
* nothing for a group that's off). Counts and timings are aggregated in-process and sent once per
|
|
13
|
+
* interval, so a burst of events costs one record per series, not one per event.
|
|
14
|
+
*/
|
|
15
|
+
var FactoryMetrics = class {
|
|
16
|
+
#config;
|
|
17
|
+
#service;
|
|
18
|
+
#counters = /* @__PURE__ */ new Map();
|
|
19
|
+
#observations = /* @__PURE__ */ new Map();
|
|
20
|
+
#collectors = [];
|
|
21
|
+
#targets;
|
|
22
|
+
#timer;
|
|
23
|
+
#running = false;
|
|
24
|
+
#credit;
|
|
25
|
+
constructor(config, service) {
|
|
26
|
+
this.#config = config;
|
|
27
|
+
this.#service = service;
|
|
28
|
+
}
|
|
29
|
+
get service() {
|
|
30
|
+
return this.#service;
|
|
31
|
+
}
|
|
32
|
+
get intervalMs() {
|
|
33
|
+
return this.#config?.intervalMs ?? 0;
|
|
34
|
+
}
|
|
35
|
+
enabled(group) {
|
|
36
|
+
return this.#config?.groups.has(group) ?? false;
|
|
37
|
+
}
|
|
38
|
+
/** Adds `value` to a counter, sent as one record per series per interval. */
|
|
39
|
+
count(group, name, labels = {}, value = 1) {
|
|
40
|
+
if (!this.enabled(group) || !Number.isFinite(value)) return;
|
|
41
|
+
const key = seriesKey(name, labels);
|
|
42
|
+
const counter = this.#counters.get(key);
|
|
43
|
+
if (counter) counter.value += value;
|
|
44
|
+
else this.#counters.set(key, {
|
|
45
|
+
name,
|
|
46
|
+
labels,
|
|
47
|
+
value
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Sends this counter series every interval, as 0 when nothing happened, so a quiet interval
|
|
52
|
+
* reads as zero instead of looking like the group is off. Keep it to a few series.
|
|
53
|
+
*/
|
|
54
|
+
keepCounter(group, name, labels = {}) {
|
|
55
|
+
if (!this.enabled(group)) return;
|
|
56
|
+
const key = seriesKey(name, labels);
|
|
57
|
+
const counter = this.#counters.get(key);
|
|
58
|
+
if (counter) counter.keep = true;
|
|
59
|
+
else this.#counters.set(key, {
|
|
60
|
+
name,
|
|
61
|
+
labels,
|
|
62
|
+
value: 0,
|
|
63
|
+
keep: true
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
/** Records a timing, sent per interval as `stat=avg|p95|max` plus a `<name>_count` series. */
|
|
67
|
+
observe(group, name, value, labels = {}) {
|
|
68
|
+
if (!this.enabled(group) || !Number.isFinite(value)) return;
|
|
69
|
+
const key = seriesKey(name, labels);
|
|
70
|
+
let observation = this.#observations.get(key);
|
|
71
|
+
if (!observation) {
|
|
72
|
+
observation = {
|
|
73
|
+
name,
|
|
74
|
+
labels,
|
|
75
|
+
count: 0,
|
|
76
|
+
sum: 0,
|
|
77
|
+
max: -Infinity,
|
|
78
|
+
samples: []
|
|
79
|
+
};
|
|
80
|
+
this.#observations.set(key, observation);
|
|
81
|
+
}
|
|
82
|
+
observation.count++;
|
|
83
|
+
observation.sum += value;
|
|
84
|
+
observation.max = Math.max(observation.max, value);
|
|
85
|
+
if (observation.samples.length < MAX_SAMPLES) observation.samples.push(value);
|
|
86
|
+
else {
|
|
87
|
+
const slot = Math.floor(Math.random() * observation.count);
|
|
88
|
+
if (slot < MAX_SAMPLES) observation.samples[slot] = value;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/** Starts the interval timer. Does nothing when every group is off. */
|
|
92
|
+
start(targets, collectors) {
|
|
93
|
+
if (!this.#config || this.#timer) return;
|
|
94
|
+
this.#targets = targets;
|
|
95
|
+
this.#collectors = collectors;
|
|
96
|
+
for (const name of this.#config.unknownGroups) targets.getLogger()?.warn(`[factory:metrics] Unknown metric group "${name}" ignored.`);
|
|
97
|
+
this.#timer = setInterval(() => {
|
|
98
|
+
this.tick().catch((error) => this.#targets?.getLogger()?.warn("[factory:metrics] Metrics tick failed.", { error: String(error) }));
|
|
99
|
+
}, this.#config.intervalMs);
|
|
100
|
+
this.#timer.unref?.();
|
|
101
|
+
}
|
|
102
|
+
stop() {
|
|
103
|
+
if (this.#timer) clearInterval(this.#timer);
|
|
104
|
+
this.#timer = void 0;
|
|
105
|
+
for (const collector of this.#collectors) collector.stop?.();
|
|
106
|
+
this.#collectors = [];
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Sends aggregated counters and timings, then samples the collectors. Skipped while the previous
|
|
110
|
+
* tick is still running, so a hung dependency never piles up probes. Exposed for tests.
|
|
111
|
+
*/
|
|
112
|
+
async tick() {
|
|
113
|
+
if (!this.#config || this.#running) return;
|
|
114
|
+
this.#running = true;
|
|
115
|
+
try {
|
|
116
|
+
const metrics = this.#targets?.getMetrics();
|
|
117
|
+
const perTick = this.#config.maxPerMinute * this.#config.intervalMs / 6e4;
|
|
118
|
+
const available = Math.floor(this.#credit = Math.min((this.#credit ?? 0) + perTick, Math.max(perTick, 1)));
|
|
119
|
+
const budget = available > 1 ? available - 1 : available;
|
|
120
|
+
let used = 0;
|
|
121
|
+
let dropped = 0;
|
|
122
|
+
const service = this.#service;
|
|
123
|
+
const sink = { emit(name, value, labels) {
|
|
124
|
+
if (!Number.isFinite(value)) return;
|
|
125
|
+
if (used >= budget) {
|
|
126
|
+
dropped++;
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
used++;
|
|
130
|
+
metrics?.emit(name, value, {
|
|
131
|
+
...labels,
|
|
132
|
+
service
|
|
133
|
+
});
|
|
134
|
+
} };
|
|
135
|
+
for (const [key, counter] of this.#counters) {
|
|
136
|
+
sink.emit(counter.name, counter.value, counter.labels);
|
|
137
|
+
if (counter.keep) counter.value = 0;
|
|
138
|
+
else this.#counters.delete(key);
|
|
139
|
+
}
|
|
140
|
+
for (const observation of this.#observations.values()) {
|
|
141
|
+
const { name, labels, count, sum, max } = observation;
|
|
142
|
+
const sorted = observation.samples.sort((a, b) => a - b);
|
|
143
|
+
sink.emit(`${name}_count`, count, labels);
|
|
144
|
+
sink.emit(name, sum / count, {
|
|
145
|
+
...labels,
|
|
146
|
+
stat: "avg"
|
|
147
|
+
});
|
|
148
|
+
sink.emit(name, percentile(sorted, .95), {
|
|
149
|
+
...labels,
|
|
150
|
+
stat: "p95"
|
|
151
|
+
});
|
|
152
|
+
sink.emit(name, max, {
|
|
153
|
+
...labels,
|
|
154
|
+
stat: "max"
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
this.#observations.clear();
|
|
158
|
+
const results = await Promise.allSettled(this.#collectors.map((collector) => Promise.resolve().then(() => collector.collect(sink))));
|
|
159
|
+
for (const result of results) if (result.status === "rejected") this.#targets?.getLogger()?.warn("[factory:metrics] Collector failed.", { error: String(result.reason) });
|
|
160
|
+
if (dropped > 0 && used < available) {
|
|
161
|
+
used++;
|
|
162
|
+
metrics?.emit("mastra_factory_metrics_dropped_total", dropped, { service });
|
|
163
|
+
}
|
|
164
|
+
this.#credit -= used;
|
|
165
|
+
} finally {
|
|
166
|
+
this.#running = false;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
let current = new FactoryMetrics(void 0, "all");
|
|
171
|
+
/** The process's Factory metrics. A no-op until a `MastraFactory` with metrics is constructed. */
|
|
172
|
+
function factoryMetrics() {
|
|
173
|
+
return current;
|
|
174
|
+
}
|
|
175
|
+
/** Replaces the process's Factory metrics, stopping the previous one. One Factory per process. */
|
|
176
|
+
function installFactoryMetrics(metrics) {
|
|
177
|
+
current.stop();
|
|
178
|
+
current = metrics;
|
|
179
|
+
}
|
|
180
|
+
export { FactoryMetrics, factoryMetrics, installFactoryMetrics };
|
|
181
|
+
|
|
182
|
+
//# sourceMappingURL=metrics.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"metrics.js","names":[],"sources":["../../src/metrics/metrics.ts"],"sourcesContent":["import type { MetricsContext } from '@mastra/core/observability';\n\nimport type { MetricGroup, MetricsService, ResolvedMetricsConfig } from './config.js';\n\nexport type MetricLabels = Record<string, string>;\n\n/** The subset of the Mastra logger metrics write to. */\nexport interface MetricsLogger {\n info(message: string, ...args: unknown[]): void;\n warn(message: string, ...args: unknown[]): void;\n}\n\n/** Where collectors send their samples; capped per tick. */\nexport interface MetricSink {\n emit(name: string, value: number, labels?: MetricLabels): void;\n}\n\n/** Sampled once per interval. */\nexport interface MetricsCollector {\n collect(sink: MetricSink): Promise<void> | void;\n /** Releases anything the collector holds (observers, histograms). */\n stop?(): void;\n}\n\nexport interface MetricsTargets {\n /**\n * The metrics context to send to. Read on every flush: Platform registers its exporter on the\n * Mastra instance after the app module has loaded, replacing the no-op context.\n */\n getMetrics: () => Pick<MetricsContext, 'emit'> | undefined;\n getLogger: () => MetricsLogger | undefined;\n}\n\n// Observations kept per series per interval for the p95; count, sum and max stay exact past it.\nconst MAX_SAMPLES = 1_000;\n\ninterface Observation {\n name: string;\n labels: MetricLabels;\n count: number;\n sum: number;\n max: number;\n samples: number[];\n}\n\ninterface Counter {\n name: string;\n labels: MetricLabels;\n value: number;\n /** Sent as 0 on intervals with no events, instead of being left out. */\n keep?: boolean;\n}\n\nfunction seriesKey(name: string, labels: MetricLabels): string {\n return `${name}\\u0000${Object.keys(labels)\n .sort()\n .map(key => `${key}=${labels[key]}`)\n .join(',')}`;\n}\n\nfunction percentile(sorted: number[], p: number): number {\n if (sorted.length === 0) return 0;\n return sorted[Math.min(sorted.length - 1, Math.ceil(p * sorted.length) - 1)]!;\n}\n\n/**\n * Factory's metrics. Call sites check `enabled(group)` (or just call `count`/`observe`, which do\n * nothing for a group that's off). Counts and timings are aggregated in-process and sent once per\n * interval, so a burst of events costs one record per series, not one per event.\n */\nexport class FactoryMetrics {\n readonly #config: ResolvedMetricsConfig | undefined;\n readonly #service: MetricsService;\n readonly #counters = new Map<string, Counter>();\n readonly #observations = new Map<string, Observation>();\n #collectors: MetricsCollector[] = [];\n #targets: MetricsTargets | undefined;\n #timer: ReturnType<typeof setInterval> | undefined;\n #running = false;\n // Records this process may still send. Refilled each tick by the interval's share of the\n // per-minute cap, so a cap below one record per tick still holds over a minute.\n #credit: number | undefined;\n\n constructor(config: ResolvedMetricsConfig | undefined, service: MetricsService) {\n this.#config = config;\n this.#service = service;\n }\n\n get service(): MetricsService {\n return this.#service;\n }\n\n get intervalMs(): number {\n return this.#config?.intervalMs ?? 0;\n }\n\n enabled(group: MetricGroup): boolean {\n return this.#config?.groups.has(group) ?? false;\n }\n\n /** Adds `value` to a counter, sent as one record per series per interval. */\n count(group: MetricGroup, name: string, labels: MetricLabels = {}, value = 1): void {\n if (!this.enabled(group) || !Number.isFinite(value)) return;\n const key = seriesKey(name, labels);\n const counter = this.#counters.get(key);\n if (counter) counter.value += value;\n else this.#counters.set(key, { name, labels, value });\n }\n\n /**\n * Sends this counter series every interval, as 0 when nothing happened, so a quiet interval\n * reads as zero instead of looking like the group is off. Keep it to a few series.\n */\n keepCounter(group: MetricGroup, name: string, labels: MetricLabels = {}): void {\n if (!this.enabled(group)) return;\n const key = seriesKey(name, labels);\n const counter = this.#counters.get(key);\n if (counter) counter.keep = true;\n else this.#counters.set(key, { name, labels, value: 0, keep: true });\n }\n\n /** Records a timing, sent per interval as `stat=avg|p95|max` plus a `<name>_count` series. */\n observe(group: MetricGroup, name: string, value: number, labels: MetricLabels = {}): void {\n if (!this.enabled(group) || !Number.isFinite(value)) return;\n const key = seriesKey(name, labels);\n let observation = this.#observations.get(key);\n if (!observation) {\n observation = { name, labels, count: 0, sum: 0, max: -Infinity, samples: [] };\n this.#observations.set(key, observation);\n }\n observation.count++;\n observation.sum += value;\n observation.max = Math.max(observation.max, value);\n // Reservoir sampling: every observation in the interval has the same chance of being kept,\n // so a p95 over a busy interval still reflects its last minutes.\n if (observation.samples.length < MAX_SAMPLES) observation.samples.push(value);\n else {\n const slot = Math.floor(Math.random() * observation.count);\n if (slot < MAX_SAMPLES) observation.samples[slot] = value;\n }\n }\n\n /** Starts the interval timer. Does nothing when every group is off. */\n start(targets: MetricsTargets, collectors: MetricsCollector[]): void {\n if (!this.#config || this.#timer) return;\n this.#targets = targets;\n this.#collectors = collectors;\n for (const name of this.#config.unknownGroups) {\n targets.getLogger()?.warn(`[factory:metrics] Unknown metric group \"${name}\" ignored.`);\n }\n this.#timer = setInterval(() => {\n this.tick().catch(error =>\n this.#targets?.getLogger()?.warn('[factory:metrics] Metrics tick failed.', { error: String(error) }),\n );\n }, this.#config.intervalMs);\n this.#timer.unref?.();\n }\n\n stop(): void {\n if (this.#timer) clearInterval(this.#timer);\n this.#timer = undefined;\n for (const collector of this.#collectors) collector.stop?.();\n this.#collectors = [];\n }\n\n /**\n * Sends aggregated counters and timings, then samples the collectors. Skipped while the previous\n * tick is still running, so a hung dependency never piles up probes. Exposed for tests.\n */\n async tick(): Promise<void> {\n if (!this.#config || this.#running) return;\n this.#running = true;\n try {\n const metrics = this.#targets?.getMetrics();\n const perTick = (this.#config.maxPerMinute * this.#config.intervalMs) / 60_000;\n const available = Math.floor((this.#credit = Math.min((this.#credit ?? 0) + perTick, Math.max(perTick, 1))));\n // One record is held back for the dropped-records count, so the cap includes it.\n const budget = available > 1 ? available - 1 : available;\n let used = 0;\n let dropped = 0;\n const service = this.#service;\n const sink: MetricSink = {\n emit(name, value, labels) {\n if (!Number.isFinite(value)) return;\n if (used >= budget) {\n dropped++;\n return;\n }\n used++;\n metrics?.emit(name, value, { ...labels, service });\n },\n };\n\n // Event counts and timings go first: they are lost if dropped, while gauges are sampled again next tick.\n for (const [key, counter] of this.#counters) {\n sink.emit(counter.name, counter.value, counter.labels);\n if (counter.keep) counter.value = 0;\n else this.#counters.delete(key);\n }\n for (const observation of this.#observations.values()) {\n const { name, labels, count, sum, max } = observation;\n const sorted = observation.samples.sort((a, b) => a - b);\n sink.emit(`${name}_count`, count, labels);\n sink.emit(name, sum / count, { ...labels, stat: 'avg' });\n sink.emit(name, percentile(sorted, 0.95), { ...labels, stat: 'p95' });\n sink.emit(name, max, { ...labels, stat: 'max' });\n }\n this.#observations.clear();\n\n // A collector that throws synchronously becomes a rejection here, so it never orphans the others.\n const results = await Promise.allSettled(\n this.#collectors.map(collector => Promise.resolve().then(() => collector.collect(sink))),\n );\n for (const result of results) {\n if (result.status === 'rejected') {\n this.#targets?.getLogger()?.warn('[factory:metrics] Collector failed.', { error: String(result.reason) });\n }\n }\n\n // Sent from the held-back record, so a capped deployment can see it is capped.\n if (dropped > 0 && used < available) {\n used++;\n metrics?.emit('mastra_factory_metrics_dropped_total', dropped, { service });\n }\n this.#credit -= used;\n } finally {\n this.#running = false;\n }\n }\n}\n\nlet current = new FactoryMetrics(undefined, 'all');\n\n/** The process's Factory metrics. A no-op until a `MastraFactory` with metrics is constructed. */\nexport function factoryMetrics(): FactoryMetrics {\n return current;\n}\n\n/** Replaces the process's Factory metrics, stopping the previous one. One Factory per process. */\nexport function installFactoryMetrics(metrics: FactoryMetrics): void {\n current.stop();\n current = metrics;\n}\n"],"mappings":";AAkCA,MAAM,cAAc;AAmBpB,SAAS,UAAU,MAAc,QAA8B;CAC7D,OAAO,GAAG,KAAK,QAAQ,OAAO,KAAK,MAAM,CAAC,CACvC,KAAK,CAAC,CACN,KAAI,QAAO,GAAG,IAAI,GAAG,OAAO,MAAM,CAAC,CACnC,KAAK,GAAG;AACb;AAEA,SAAS,WAAW,QAAkB,GAAmB;CACvD,IAAI,OAAO,WAAW,GAAG,OAAO;CAChC,OAAO,OAAO,KAAK,IAAI,OAAO,SAAS,GAAG,KAAK,KAAK,IAAI,OAAO,MAAM,IAAI,CAAC;AAC5E;;;;;;AAOA,IAAa,iBAAb,MAA4B;CAC1B;CACA;CACA,4BAAqB,IAAI,IAAqB;CAC9C,gCAAyB,IAAI,IAAyB;CACtD,cAAkC,CAAC;CACnC;CACA;CACA,WAAW;CAGX;CAEA,YAAY,QAA2C,SAAyB;EAC9E,KAAK,UAAU;EACf,KAAK,WAAW;CAClB;CAEA,IAAI,UAA0B;EAC5B,OAAO,KAAK;CACd;CAEA,IAAI,aAAqB;EACvB,OAAO,KAAK,SAAS,cAAc;CACrC;CAEA,QAAQ,OAA6B;EACnC,OAAO,KAAK,SAAS,OAAO,IAAI,KAAK,KAAK;CAC5C;;CAGA,MAAM,OAAoB,MAAc,SAAuB,CAAC,GAA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**
|
|
3
|
+
* Maps a `timedPhase` name to the `phase` label. Only session workspace phases count; boot
|
|
4
|
+
* phases (`prepare.*`, `background.*`) don't. The `(…)` argument names a repository or an outcome
|
|
5
|
+
* and is never sent: repository names are unbounded.
|
|
6
|
+
*/
|
|
7
|
+
export declare function workspacePhaseLabel(phase: string): string | undefined;
|
|
8
|
+
/** Maps a sandbox command `phase` (e.g. `repository clone`, `environment branch fetch`) to the `step` label. */
|
|
9
|
+
export declare function commandStepLabel(phase: string): string;
|
|
10
|
+
/** `timedPhase` hook: records a workspace phase duration. */
|
|
11
|
+
export declare function recordWorkspacePhase(phase: string, ms: number, ok: boolean): void;
|
|
12
|
+
/** Records one attempt of a sandbox command run during workspace setup. */
|
|
13
|
+
export declare function recordSandboxCommand(phase: string, ms: number, outcome: 'ok' | 'exit' | 'threw'): void;
|
|
14
|
+
/** Marks the next start of `sandbox` as the eager start fired when the workspace resolves. */
|
|
15
|
+
export declare function markEagerSandboxStart(sandbox: object): void;
|
|
16
|
+
/**
|
|
17
|
+
* Times every real start of `sandbox`:
|
|
18
|
+
* - the provider's part (lease and boot, up to the onStart hook), so a slow or failing provider is
|
|
19
|
+
* told apart from slow or failing repository setup;
|
|
20
|
+
* - the whole start, up to the end of the onStart hook (`mastra_factory_session_ready_ms`), with
|
|
21
|
+
* failures included. `kind` is `first` for a session's first sandbox and `resume` for later starts;
|
|
22
|
+
* - how long the first caller other than the eager start waited for it
|
|
23
|
+
* (`mastra_factory_session_sandbox_wait_ms`): the start-up time someone actually waits through.
|
|
24
|
+
* Patches `_start` in place: `start()`, `ensureRunning()` and the lazy start before the first command
|
|
25
|
+
* all go through it. `hadSandbox` says whether the session already had a sandbox before this instance.
|
|
26
|
+
*/
|
|
27
|
+
export declare function instrumentSandboxStart(sandbox: object, provider: string, hadSandbox: boolean): void;
|
|
28
|
+
/** Called as the sandbox's onStart hook begins: the provider has handed over a running VM. */
|
|
29
|
+
export declare function recordSandboxAcquired(sandbox: object, outcome: string | undefined): void;
|
|
30
|
+
/**
|
|
31
|
+
* Starts in flight and the age of the oldest, sent every interval (0 when none), so a start that hangs
|
|
32
|
+
* shows while it's happening instead of only when it ends. Also shows the group is on while idle.
|
|
33
|
+
*/
|
|
34
|
+
export declare function sessionStartsCollector(): MetricsCollector;
|
|
35
|
+
//# sourceMappingURL=sandbox.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sandbox.d.ts","sourceRoot":"","sources":["../../src/metrics/sandbox.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAYrD;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAGrE;AAED,gHAAgH;AAChH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAOtD;AAED,6DAA6D;AAC7D,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,OAAO,GAAG,IAAI,CAMjF;AAED,2EAA2E;AAC3E,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAKtG;AA6BD,8FAA8F;AAC9F,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAE3D;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,GAAG,IAAI,CAiEnG;AAED,8FAA8F;AAC9F,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAQxF;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,IAAI,gBAAgB,CAUzD"}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { factoryMetrics } from "./metrics.js";
|
|
2
|
+
// src/metrics/sandbox.ts
|
|
3
|
+
const PHASES = {
|
|
4
|
+
materialize: "materialize",
|
|
5
|
+
checkout: "checkout",
|
|
6
|
+
setup: "setup",
|
|
7
|
+
"setup-marker": "setup_marker",
|
|
8
|
+
sync: "sync",
|
|
9
|
+
onStart: "on_start"
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Maps a `timedPhase` name to the `phase` label. Only session workspace phases count; boot
|
|
13
|
+
* phases (`prepare.*`, `background.*`) don't. The `(…)` argument names a repository or an outcome
|
|
14
|
+
* and is never sent: repository names are unbounded.
|
|
15
|
+
*/
|
|
16
|
+
function workspacePhaseLabel(phase) {
|
|
17
|
+
const match = /^workspace\.([A-Za-z-]+)(?:\(.*\))?$/.exec(phase);
|
|
18
|
+
return match ? PHASES[match[1]] : void 0;
|
|
19
|
+
}
|
|
20
|
+
/** Maps a sandbox command `phase` (e.g. `repository clone`, `environment branch fetch`) to the `step` label. */
|
|
21
|
+
function commandStepLabel(phase) {
|
|
22
|
+
if (phase === "repository clone") return "clone";
|
|
23
|
+
if (phase === "setup" || phase === "teardown") return phase;
|
|
24
|
+
if (phase.endsWith(" probe")) return "probe";
|
|
25
|
+
if (phase.endsWith(" fetch") || phase.endsWith(" refresh")) return "fetch";
|
|
26
|
+
if (/(checkout|create|retry)$/.test(phase)) return "checkout";
|
|
27
|
+
return "other";
|
|
28
|
+
}
|
|
29
|
+
/** `timedPhase` hook: records a workspace phase duration. */
|
|
30
|
+
function recordWorkspacePhase(phase, ms, ok) {
|
|
31
|
+
const metrics = factoryMetrics();
|
|
32
|
+
if (!metrics.enabled("sandbox")) return;
|
|
33
|
+
const label = workspacePhaseLabel(phase);
|
|
34
|
+
if (!label) return;
|
|
35
|
+
metrics.observe("sandbox", "mastra_factory_sandbox_phase_ms", ms, {
|
|
36
|
+
phase: label,
|
|
37
|
+
outcome: ok ? "ok" : "error"
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
/** Records one attempt of a sandbox command run during workspace setup. */
|
|
41
|
+
function recordSandboxCommand(phase, ms, outcome) {
|
|
42
|
+
factoryMetrics().observe("sandbox", "mastra_factory_sandbox_command_ms", ms, {
|
|
43
|
+
step: commandStepLabel(phase),
|
|
44
|
+
outcome
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
const pendingStarts = /* @__PURE__ */ new WeakMap();
|
|
48
|
+
const sessionStarts = /* @__PURE__ */ new Map();
|
|
49
|
+
const eagerStarts = /* @__PURE__ */ new WeakSet();
|
|
50
|
+
function isTimeout(error) {
|
|
51
|
+
const text = error instanceof Error ? `${error.name} ${error.message}` : String(error);
|
|
52
|
+
return /time(d)?\s?out/i.test(text);
|
|
53
|
+
}
|
|
54
|
+
/** Marks the next start of `sandbox` as the eager start fired when the workspace resolves. */
|
|
55
|
+
function markEagerSandboxStart(sandbox) {
|
|
56
|
+
if (factoryMetrics().enabled("sandbox")) eagerStarts.add(sandbox);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Times every real start of `sandbox`:
|
|
60
|
+
* - the provider's part (lease and boot, up to the onStart hook), so a slow or failing provider is
|
|
61
|
+
* told apart from slow or failing repository setup;
|
|
62
|
+
* - the whole start, up to the end of the onStart hook (`mastra_factory_session_ready_ms`), with
|
|
63
|
+
* failures included. `kind` is `first` for a session's first sandbox and `resume` for later starts;
|
|
64
|
+
* - how long the first caller other than the eager start waited for it
|
|
65
|
+
* (`mastra_factory_session_sandbox_wait_ms`): the start-up time someone actually waits through.
|
|
66
|
+
* Patches `_start` in place: `start()`, `ensureRunning()` and the lazy start before the first command
|
|
67
|
+
* all go through it. `hadSandbox` says whether the session already had a sandbox before this instance.
|
|
68
|
+
*/
|
|
69
|
+
function instrumentSandboxStart(sandbox, provider, hadSandbox) {
|
|
70
|
+
const metrics = factoryMetrics();
|
|
71
|
+
if (!metrics.enabled("sandbox")) return;
|
|
72
|
+
for (const cause of ["timeout", "error"]) metrics.keepCounter("sandbox", "mastra_factory_sandbox_start_failures_total", {
|
|
73
|
+
sandbox_provider: provider,
|
|
74
|
+
cause
|
|
75
|
+
});
|
|
76
|
+
const target = sandbox;
|
|
77
|
+
const original = target._start;
|
|
78
|
+
if (typeof original !== "function") return;
|
|
79
|
+
let started = hadSandbox;
|
|
80
|
+
target._start = async (...args) => {
|
|
81
|
+
const eager = eagerStarts.delete(sandbox);
|
|
82
|
+
if (target.status === "running") return original.apply(sandbox, args);
|
|
83
|
+
const callStartedAt = performance.now();
|
|
84
|
+
let start = sessionStarts.get(sandbox);
|
|
85
|
+
const real = !start;
|
|
86
|
+
if (!start) {
|
|
87
|
+
start = {
|
|
88
|
+
startedAt: callStartedAt,
|
|
89
|
+
kind: started ? "resume" : "first",
|
|
90
|
+
waitRecorded: false
|
|
91
|
+
};
|
|
92
|
+
started = true;
|
|
93
|
+
sessionStarts.set(sandbox, start);
|
|
94
|
+
pendingStarts.set(sandbox, {
|
|
95
|
+
startedAt: callStartedAt,
|
|
96
|
+
provider
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
const waits = !eager && !start.waitRecorded;
|
|
100
|
+
if (waits) start.waitRecorded = true;
|
|
101
|
+
const done = (outcome) => {
|
|
102
|
+
const now = performance.now();
|
|
103
|
+
if (waits) factoryMetrics().observe("sandbox", "mastra_factory_session_sandbox_wait_ms", now - callStartedAt, {
|
|
104
|
+
kind: start.kind,
|
|
105
|
+
outcome
|
|
106
|
+
});
|
|
107
|
+
if (real) factoryMetrics().observe("sandbox", "mastra_factory_session_ready_ms", now - start.startedAt, {
|
|
108
|
+
kind: start.kind,
|
|
109
|
+
outcome
|
|
110
|
+
});
|
|
111
|
+
};
|
|
112
|
+
try {
|
|
113
|
+
const result = await original.apply(sandbox, args);
|
|
114
|
+
done("ok");
|
|
115
|
+
return result;
|
|
116
|
+
} catch (error) {
|
|
117
|
+
if (real && pendingStarts.has(sandbox)) factoryMetrics().count("sandbox", "mastra_factory_sandbox_start_failures_total", {
|
|
118
|
+
sandbox_provider: provider,
|
|
119
|
+
cause: isTimeout(error) ? "timeout" : "error"
|
|
120
|
+
});
|
|
121
|
+
done("error");
|
|
122
|
+
throw error;
|
|
123
|
+
} finally {
|
|
124
|
+
if (real) {
|
|
125
|
+
pendingStarts.delete(sandbox);
|
|
126
|
+
sessionStarts.delete(sandbox);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
/** Called as the sandbox's onStart hook begins: the provider has handed over a running VM. */
|
|
132
|
+
function recordSandboxAcquired(sandbox, outcome) {
|
|
133
|
+
const pending = pendingStarts.get(sandbox);
|
|
134
|
+
if (!pending) return;
|
|
135
|
+
pendingStarts.delete(sandbox);
|
|
136
|
+
factoryMetrics().observe("sandbox", "mastra_factory_sandbox_start_ms", performance.now() - pending.startedAt, {
|
|
137
|
+
sandbox_provider: pending.provider,
|
|
138
|
+
outcome: outcome === "created" || outcome === "connected" ? outcome : "unknown"
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Starts in flight and the age of the oldest, sent every interval (0 when none), so a start that hangs
|
|
143
|
+
* shows while it's happening instead of only when it ends. Also shows the group is on while idle.
|
|
144
|
+
*/
|
|
145
|
+
function sessionStartsCollector() {
|
|
146
|
+
return { collect(sink) {
|
|
147
|
+
const now = performance.now();
|
|
148
|
+
let oldest = 0;
|
|
149
|
+
for (const start of sessionStarts.values()) oldest = Math.max(oldest, now - start.startedAt);
|
|
150
|
+
sink.emit("mastra_factory_sessions_starting", sessionStarts.size);
|
|
151
|
+
sink.emit("mastra_factory_session_start_oldest_age_ms", oldest);
|
|
152
|
+
} };
|
|
153
|
+
}
|
|
154
|
+
export { commandStepLabel, instrumentSandboxStart, markEagerSandboxStart, recordSandboxAcquired, recordSandboxCommand, recordWorkspacePhase, sessionStartsCollector, workspacePhaseLabel };
|
|
155
|
+
|
|
156
|
+
//# sourceMappingURL=sandbox.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sandbox.js","names":[],"sources":["../../src/metrics/sandbox.ts"],"sourcesContent":["import type { MetricsCollector } from './metrics.js';\nimport { factoryMetrics } from './metrics.js';\n\nconst PHASES: Record<string, string> = {\n materialize: 'materialize',\n checkout: 'checkout',\n setup: 'setup',\n 'setup-marker': 'setup_marker',\n sync: 'sync',\n onStart: 'on_start',\n};\n\n/**\n * Maps a `timedPhase` name to the `phase` label. Only session workspace phases count; boot\n * phases (`prepare.*`, `background.*`) don't. The `(…)` argument names a repository or an outcome\n * and is never sent: repository names are unbounded.\n */\nexport function workspacePhaseLabel(phase: string): string | undefined {\n const match = /^workspace\\.([A-Za-z-]+)(?:\\(.*\\))?$/.exec(phase);\n return match ? PHASES[match[1]!] : undefined;\n}\n\n/** Maps a sandbox command `phase` (e.g. `repository clone`, `environment branch fetch`) to the `step` label. */\nexport function commandStepLabel(phase: string): string {\n if (phase === 'repository clone') return 'clone';\n if (phase === 'setup' || phase === 'teardown') return phase;\n if (phase.endsWith(' probe')) return 'probe';\n if (phase.endsWith(' fetch') || phase.endsWith(' refresh')) return 'fetch';\n if (/(checkout|create|retry)$/.test(phase)) return 'checkout';\n return 'other';\n}\n\n/** `timedPhase` hook: records a workspace phase duration. */\nexport function recordWorkspacePhase(phase: string, ms: number, ok: boolean): void {\n const metrics = factoryMetrics();\n if (!metrics.enabled('sandbox')) return;\n const label = workspacePhaseLabel(phase);\n if (!label) return;\n metrics.observe('sandbox', 'mastra_factory_sandbox_phase_ms', ms, { phase: label, outcome: ok ? 'ok' : 'error' });\n}\n\n/** Records one attempt of a sandbox command run during workspace setup. */\nexport function recordSandboxCommand(phase: string, ms: number, outcome: 'ok' | 'exit' | 'threw'): void {\n factoryMetrics().observe('sandbox', 'mastra_factory_sandbox_command_ms', ms, {\n step: commandStepLabel(phase),\n outcome,\n });\n}\n\ninterface StartableSandbox {\n status?: string;\n _start?: (...args: unknown[]) => Promise<unknown>;\n}\n\n// Sandboxes with a start in flight that hasn't reached their onStart hook yet, with its start time\n// and provider. The hook firing marks the end of the provider's part of the start.\nconst pendingStarts = new WeakMap<object, { startedAt: number; provider: string }>();\n\n// Every start in flight, from the first `_start` call until the onStart hook finishes or the start\n// fails. A `Map` (entries always removed when the start settles) so a collector can list them.\ninterface SessionStart {\n startedAt: number;\n kind: 'first' | 'resume';\n // Whether a caller other than the eager start has had its wait recorded.\n waitRecorded: boolean;\n}\nconst sessionStarts = new Map<object, SessionStart>();\n\n// Sandboxes whose next `_start` call is the eager start, which nobody waits on.\nconst eagerStarts = new WeakSet<object>();\n\nfunction isTimeout(error: unknown): boolean {\n const text = error instanceof Error ? `${error.name} ${error.message}` : String(error);\n return /time(d)?\\s?out/i.test(text);\n}\n\n/** Marks the next start of `sandbox` as the eager start fired when the workspace resolves. */\nexport function markEagerSandboxStart(sandbox: object): void {\n if (factoryMetrics().enabled('sandbox')) eagerStarts.add(sandbox);\n}\n\n/**\n * Times every real start of `sandbox`:\n * - the provider's part (lease and boot, up to the onStart hook), so a slow or failing provider is\n * told apart from slow or failing repository setup;\n * - the whole start, up to the end of the onStart hook (`mastra_factory_session_ready_ms`), with\n * failures included. `kind` is `first` for a session's first sandbox and `resume` for later starts;\n * - how long the first caller other than the eager start waited for it\n * (`mastra_factory_session_sandbox_wait_ms`): the start-up time someone actually waits through.\n * Patches `_start` in place: `start()`, `ensureRunning()` and the lazy start before the first command\n * all go through it. `hadSandbox` says whether the session already had a sandbox before this instance.\n */\nexport function instrumentSandboxStart(sandbox: object, provider: string, hadSandbox: boolean): void {\n const metrics = factoryMetrics();\n if (!metrics.enabled('sandbox')) return;\n // From the first sandbox on, start failures are sent every interval (0 when none).\n for (const cause of ['timeout', 'error']) {\n metrics.keepCounter('sandbox', 'mastra_factory_sandbox_start_failures_total', {\n sandbox_provider: provider,\n cause,\n });\n }\n const target = sandbox as StartableSandbox;\n const original = target._start;\n if (typeof original !== 'function') return;\n let started = hadSandbox;\n target._start = async (...args: unknown[]) => {\n const eager = eagerStarts.delete(sandbox);\n if (target.status === 'running') return original.apply(sandbox, args);\n const callStartedAt = performance.now();\n let start = sessionStarts.get(sandbox);\n const real = !start;\n if (!start) {\n start = { startedAt: callStartedAt, kind: started ? 'resume' : 'first', waitRecorded: false };\n started = true;\n sessionStarts.set(sandbox, start);\n pendingStarts.set(sandbox, { startedAt: callStartedAt, provider });\n }\n const waits = !eager && !start.waitRecorded;\n if (waits) start.waitRecorded = true;\n const done = (outcome: 'ok' | 'error') => {\n const now = performance.now();\n if (waits) {\n factoryMetrics().observe('sandbox', 'mastra_factory_session_sandbox_wait_ms', now - callStartedAt, {\n kind: start.kind,\n outcome,\n });\n }\n if (real) {\n factoryMetrics().observe('sandbox', 'mastra_factory_session_ready_ms', now - start.startedAt, {\n kind: start.kind,\n outcome,\n });\n }\n };\n try {\n const result = await original.apply(sandbox, args);\n done('ok');\n return result;\n } catch (error) {\n // Still pending: the provider failed before the onStart hook ran. Hook failures are setup\n // failures and are counted on the phase instead.\n if (real && pendingStarts.has(sandbox)) {\n factoryMetrics().count('sandbox', 'mastra_factory_sandbox_start_failures_total', {\n sandbox_provider: provider,\n cause: isTimeout(error) ? 'timeout' : 'error',\n });\n }\n done('error');\n throw error;\n } finally {\n if (real) {\n pendingStarts.delete(sandbox);\n sessionStarts.delete(sandbox);\n }\n }\n };\n}\n\n/** Called as the sandbox's onStart hook begins: the provider has handed over a running VM. */\nexport function recordSandboxAcquired(sandbox: object, outcome: string | undefined): void {\n const pending = pendingStarts.get(sandbox);\n if (!pending) return;\n pendingStarts.delete(sandbox);\n factoryMetrics().observe('sandbox', 'mastra_factory_sandbox_start_ms', performance.now() - pending.startedAt, {\n sandbox_provider: pending.provider,\n outcome: outcome === 'created' || outcome === 'connected' ? outcome : 'unknown',\n });\n}\n\n/**\n * Starts in flight and the age of the oldest, sent every interval (0 when none), so a start that hangs\n * shows while it's happening instead of only when it ends. Also shows the group is on while idle.\n */\nexport function sessionStartsCollector(): MetricsCollector {\n return {\n collect(sink) {\n const now = performance.now();\n let oldest = 0;\n for (const start of sessionStarts.values()) oldest = Math.max(oldest, now - start.startedAt);\n sink.emit('mastra_factory_sessions_starting', sessionStarts.size);\n sink.emit('mastra_factory_session_start_oldest_age_ms', oldest);\n },\n };\n}\n"],"mappings":";;AAGA,MAAM,SAAiC;CACrC,aAAa;CACb,UAAU;CACV,OAAO;CACP,gBAAgB;CAChB,MAAM;CACN,SAAS;AACX;;;;;;AAOA,SAAgB,oBAAoB,OAAmC;CACrE,MAAM,QAAQ,uCAAuC,KAAK,KAAK;CAC/D,OAAO,QAAQ,OAAO,MAAM,MAAO,KAAA;AACrC;;AAGA,SAAgB,iBAAiB,OAAuB;CACtD,IAAI,UAAU,oBAAoB,OAAO;CACzC,IAAI,UAAU,WAAW,UAAU,YAAY,OAAO;CACtD,IAAI,MAAM,SAAS,QAAQ,GAAG,OAAO;CACrC,IAAI,MAAM,SAAS,QAAQ,KAAK,MAAM,SAAS,UAAU,GAAG,OAAO;CACnE,IAAI,2BAA2B,KAAK,KAAK,GAAG,OAAO;CACnD,OAAO;AACT;;AAGA,SAAgB,qBAAqB,OAAe,IAAY,IAAmB;CACjF,MAAM,UAAU,eAAe;CAC/B,IAAI,CAAC,QAAQ,QAAQ,SAAS,GAAG;CACjC,MAAM,QAAQ,oBAAoB,KAAK;CACvC,IAAI,CAAC,OAAO;CACZ,QAAQ,QAAQ,WAAW,mCAAmC,IAAI;EAAE,OAAO;EAAO,SAAS,KAAK,OAAO;CAAQ,CAAC;AAClH;;AAGA,SAAgB,qBAAqB,OAAe,IAAY,SAAwC;CACtG,eAAe,CAAC,CAAC,QAAQ,WAAW,qCAAqC,IAAI;EAC3E,MAAM,iBAAiB,KAAK;EAC5B;CACF,CAAC;AACH;AASA,MAAM,gCAAgB,IAAI,QAAyD;AAUnF,MAAM,gCAAgB,IAAI,IAA0B;AAGpD,MAAM,8BAAc,IAAI,QAAgB;AAExC,SAAS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