diff options
author | Elizabeth <me@liz.coffee> | 2025-05-29 00:57:46 -0700 |
---|---|---|
committer | Elizabeth <me@liz.coffee> | 2025-05-29 01:10:49 -0700 |
commit | 646c5eb11d3b9240f8434163d103a117d30c88c7 (patch) | |
tree | 42d9b4372ba429ff0e4fa4f67aa415377f2477c2 | |
parent | 8f4415bff3918e98a4eadeba655af934e52ac5e2 (diff) | |
download | ci-646c5eb11d3b9240f8434163d103a117d30c88c7.tar.gz ci-646c5eb11d3b9240f8434163d103a117d30c88c7.zip |
Fixes recursion stack exhaustion when creating metrics
-rw-r--r-- | hooks/server/job/queuer.ts | 4 | ||||
-rw-r--r-- | u/trace/metrics.ts | 36 |
2 files changed, 24 insertions, 16 deletions
diff --git a/hooks/server/job/queuer.ts b/hooks/server/job/queuer.ts index 069cca4..d30de22 100644 --- a/hooks/server/job/queuer.ts +++ b/hooks/server/job/queuer.ts @@ -48,7 +48,9 @@ export class LaminarJobQueuer }) .peek((c) => c.trace.trace( - `im so excited to see how this queue job will end!! (>ᴗ<): ${c.get().toString()}`, + `im so excited to see how this queue job will end!! (>ᴗ<): ${c + .get() + .toString()}`, ), ) .map(getStdout) diff --git a/u/trace/metrics.ts b/u/trace/metrics.ts index f57b725..69322b9 100644 --- a/u/trace/metrics.ts +++ b/u/trace/metrics.ts @@ -15,9 +15,9 @@ export enum Unit { export interface IMetric { readonly count: IEmittableMetric; readonly time: IEmittableMetric; - readonly failure: IMetric; - readonly success: IMetric; - readonly warn: IMetric; + readonly failure?: IMetric; + readonly success?: IMetric; + readonly warn?: IMetric; readonly children: Supplier<Array<IMetric>>; readonly _tag: "IMetric"; @@ -52,23 +52,25 @@ export class Metric implements IMetric { constructor( public readonly count: IEmittableMetric, public readonly time: IEmittableMetric, - public readonly failure: Metric, - public readonly success: Metric, - public readonly warn: Metric, + public readonly failure?: Metric, + public readonly success?: Metric, + public readonly warn?: Metric, public readonly _tag: "IMetric" = "IMetric", ) {} public children() { - return [this.failure, this.success, this.warn]; + return [this.failure, this.success, this.warn].filter( + (x) => x, + ) as IMetric[]; } - static fromName(name: string): Metric { + static fromName(name: string, addChildren = true): Metric { return new Metric( new EmittableMetric(`${name}.count`, Unit.COUNT), new EmittableMetric(`${name}.elapsed`, Unit.MILLISECONDS), - Metric.fromName(`${name}.failure`), - Metric.fromName(`${name}.success`), - Metric.fromName(`${name}.warn`), + addChildren ? Metric.fromName(`${name}.failure`, false) : undefined, + addChildren ? Metric.fromName(`${name}.success`, false) : undefined, + addChildren ? Metric.fromName(`${name}.warn`, false) : undefined, ); } } @@ -86,7 +88,9 @@ export const isMetricValue = (t: unknown): t is MetricValue => export const isMetricsTraceSupplier = (t: unknown): t is MetricsTraceSupplier => isMetricValue(t) || isIMetric(t); -export type MetricsTraceSupplier = ITraceWith<IMetric | MetricValue>; +export type MetricsTraceSupplier = ITraceWith< + IMetric | MetricValue | undefined +>; type MetricTracingTuple = [IMetric, Date]; export class MetricsTrace implements ITrace<MetricsTraceSupplier> { constructor( @@ -96,12 +100,13 @@ export class MetricsTrace implements ITrace<MetricsTraceSupplier> { ) {} public addTrace(trace: MetricsTraceSupplier) { - if (isMetricValue(trace) || typeof trace === "string") return this; + if (!isIMetric(trace)) return this; return new MetricsTrace(this.metricConsumer)._nowTracing(trace); } public trace(metric: MetricsTraceSupplier) { - if (typeof metric === "string") return this; + if (typeof metric === "undefined" || typeof metric === "string") + return this; if (isMetricValue(metric)) { this.metricConsumer([metric]); return this; @@ -138,7 +143,8 @@ export class MetricsTrace implements ITrace<MetricsTraceSupplier> { ]; } - private _nowTracing(metric: IMetric): MetricsTrace { + private _nowTracing(metric?: IMetric): MetricsTrace { + if (!metric) return this; this.tracing.push([metric, new Date()]); return this; } |