Skip to content

Commit 349a24f

Browse files
committed
style: fix Prettier formatting in packages/agent (CI format:check)
1 parent 240beb8 commit 349a24f

15 files changed

Lines changed: 293 additions & 198 deletions

packages/agent/src/analysis/explain-analyzer.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ export class ExplainAnalyzer extends EventEmitter {
5050
/** Attach to an EventEmitter that emits TracedQuery events on the 'query' channel. */
5151
attach(source: EventEmitter): this {
5252
if (this.sources.has(source)) return this;
53-
const listener = (q: TracedQuery) => { void this._onQuery(q); };
53+
const listener = (q: TracedQuery) => {
54+
void this._onQuery(q);
55+
};
5456
source.on("query", listener);
5557
this.sources.set(source, listener);
5658
return this;

packages/agent/src/analysis/slow-query-monitor.ts

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -26,33 +26,33 @@ export interface SlowQueryRecord {
2626
*/
2727
export const DRIVER_DEFAULTS: Readonly<Record<string, number>> = {
2828
// ── relational ───────────────────────────────────────────
29-
pg: 500,
30-
mysql2: 500,
31-
mssql: 500,
32-
tedious: 500, // underlying MS SQL driver
33-
"better-sqlite3": 100, // local disk — fast
29+
pg: 500,
30+
mysql2: 500,
31+
mssql: 500,
32+
tedious: 500, // underlying MS SQL driver
33+
"better-sqlite3": 100, // local disk — fast
3434

3535
// ── in-memory / cache ────────────────────────────────────
36-
redis: 50,
37-
ioredis: 50,
36+
redis: 50,
37+
ioredis: 50,
3838

3939
// ── document / NoSQL ─────────────────────────────────────
40-
mongodb: 500,
41-
"@google-cloud/firestore": 1000,
40+
mongodb: 500,
41+
"@google-cloud/firestore": 1000,
4242
"@aws-sdk/client-dynamodb": 200,
43-
"@aws-sdk/lib-dynamodb": 200,
43+
"@aws-sdk/lib-dynamodb": 200,
4444

4545
// ── graph / search ───────────────────────────────────────
46-
"neo4j-driver": 1000,
47-
"@elastic/elasticsearch": 2000,
46+
"neo4j-driver": 1000,
47+
"@elastic/elasticsearch": 2000,
4848

4949
// ── analytics (large scans are normal) ───────────────────
50-
"@clickhouse/client": 5000,
51-
"@google-cloud/bigquery": 10000,
52-
"cassandra-driver": 500,
50+
"@clickhouse/client": 5000,
51+
"@google-cloud/bigquery": 10000,
52+
"cassandra-driver": 500,
5353

5454
// ── ORM (overhead from the underlying driver) ────────────
55-
"@prisma/client": 1000,
55+
"@prisma/client": 1000,
5656
};
5757

5858
export interface SlowQueryOptions {
@@ -99,7 +99,7 @@ export class SlowQueryMonitor {
9999
private readonly warnedDrivers = new Set<string>();
100100

101101
constructor(options: SlowQueryOptions = {}) {
102-
const envDefault = parseInt(process.env.ARGUS_SLOW_QUERY_THRESHOLD_MS ?? '', 10);
102+
const envDefault = parseInt(process.env.ARGUS_SLOW_QUERY_THRESHOLD_MS ?? "", 10);
103103
this.defaultThreshold = !isNaN(envDefault) ? envDefault : (options.defaultThresholdMs ?? 1000);
104104
this.topN = options.topN ?? 5;
105105
this.thresholds = new Map(Object.entries(options.thresholds ?? {}));
@@ -112,19 +112,20 @@ export class SlowQueryMonitor {
112112
public getThreshold(driver: string): number {
113113
// 1. Per-driver env var (highest priority)
114114
const envKey = `ARGUS_SLOW_QUERY_THRESHOLD_${this.driverToEnvKey(driver)}`;
115-
const envVal = parseInt(process.env[envKey] ?? '', 10);
115+
const envVal = parseInt(process.env[envKey] ?? "", 10);
116116
if (!isNaN(envVal)) return envVal;
117117
// 2. Per-driver options value
118118
if (this.thresholds.has(driver)) return this.thresholds.get(driver)!;
119119
// 3. Built-in per-driver default
120-
if (Object.prototype.hasOwnProperty.call(DRIVER_DEFAULTS, driver)) return DRIVER_DEFAULTS[driver];
120+
if (Object.prototype.hasOwnProperty.call(DRIVER_DEFAULTS, driver))
121+
return DRIVER_DEFAULTS[driver];
121122
// 4. Global fallback — warn once in non-production so new drivers don't silently inherit 1000 ms
122-
if (process.env.NODE_ENV !== 'production' && !this.warnedDrivers.has(driver)) {
123+
if (process.env.NODE_ENV !== "production" && !this.warnedDrivers.has(driver)) {
123124
this.warnedDrivers.add(driver);
124125
process.emitWarning(
125126
`[SlowQueryMonitor] No threshold registered for driver "${driver}" — falling back to ${this.defaultThreshold} ms. ` +
126-
`Add an entry to DRIVER_DEFAULTS in slow-query-monitor.ts or set ARGUS_SLOW_QUERY_THRESHOLD_${this.driverToEnvKey(driver)}.`,
127-
{ code: 'ARGUS_MISSING_DRIVER_THRESHOLD' },
127+
`Add an entry to DRIVER_DEFAULTS in slow-query-monitor.ts or set ARGUS_SLOW_QUERY_THRESHOLD_${this.driverToEnvKey(driver)}.`,
128+
{ code: "ARGUS_MISSING_DRIVER_THRESHOLD" },
128129
);
129130
}
130131
return this.defaultThreshold;
@@ -185,6 +186,9 @@ export class SlowQueryMonitor {
185186

186187
/** Convert a driver name to the uppercase env-var suffix form. */
187188
private driverToEnvKey(driver: string): string {
188-
return driver.replace(/[^a-zA-Z0-9]+/g, '_').toUpperCase().replace(/^_+|_+$/g, '');
189+
return driver
190+
.replace(/[^a-zA-Z0-9]+/g, "_")
191+
.toUpperCase()
192+
.replace(/^_+|_+$/g, "");
189193
}
190194
}

packages/agent/src/diagnostic-agent.ts

Lines changed: 96 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,35 @@ import { OTLPExporter, type ExporterConfig } from "./export/exporter.ts";
1515
import { EntropyChecker } from "./sanitization/entropy-checker.ts";
1616
import { applyDriverPatches, removeDriverPatches } from "./instrumentation/drivers/index.ts";
1717
import { QueryAnalyzer, type QueryAnalyzerOptions } from "./analysis/query-analyzer.ts";
18-
import { SlowQueryMonitor, type SlowQueryOptions, type SlowQueryRecord } from "./analysis/slow-query-monitor.ts";
18+
import {
19+
SlowQueryMonitor,
20+
type SlowQueryOptions,
21+
type SlowQueryRecord,
22+
} from "./analysis/slow-query-monitor.ts";
1923
import { GcMonitor, type GcMonitorOptions, type GcPressureEvent } from "./profiling/gc-monitor.ts";
20-
import { PoolMonitor, type PoolMonitorOptions, type PoolLike, type PoolExhaustionEvent, type SlowAcquireEvent } from "./profiling/pool-monitor.ts";
21-
import { createRequestContext, runWithContext, type RequestContext } from "./instrumentation/correlation.ts";
22-
import { TransactionMonitor, type TransactionMonitorOptions, type TransactionEvent } from "./analysis/transaction-monitor.ts";
24+
import {
25+
PoolMonitor,
26+
type PoolMonitorOptions,
27+
type PoolLike,
28+
type PoolExhaustionEvent,
29+
type SlowAcquireEvent,
30+
} from "./profiling/pool-monitor.ts";
31+
import {
32+
createRequestContext,
33+
runWithContext,
34+
type RequestContext,
35+
} from "./instrumentation/correlation.ts";
36+
import {
37+
TransactionMonitor,
38+
type TransactionMonitorOptions,
39+
type TransactionEvent,
40+
} from "./analysis/transaction-monitor.ts";
2341
import { CacheMonitor, type CacheMonitorOptions } from "./analysis/cache-monitor.ts";
2442
import { DnsMonitor, type DnsMonitorOptions } from "./instrumentation/dns-monitor.ts";
25-
import { AdaptiveSampler, type AdaptiveSamplerOptions } from "./instrumentation/adaptive-sampler.ts";
43+
import {
44+
AdaptiveSampler,
45+
type AdaptiveSamplerOptions,
46+
} from "./instrumentation/adaptive-sampler.ts";
2647
import { StaticScanner } from "./analysis/static-scanner.ts";
2748
import { HttpInstrumentation } from "./instrumentation/http.ts";
2849
import { FsInstrumentation } from "./instrumentation/fs.ts";
@@ -672,7 +693,11 @@ export class DiagnosticAgent extends EventEmitter {
672693
traced.traceId,
673694
);
674695
if (slow) {
675-
aggregator.record("slow-query", slow.durationMs, slow as unknown as Record<string, unknown>);
696+
aggregator.record(
697+
"slow-query",
698+
slow.durationMs,
699+
slow as unknown as Record<string, unknown>,
700+
);
676701
this.emit("slow-query", slow);
677702
}
678703
}
@@ -688,7 +713,11 @@ export class DiagnosticAgent extends EventEmitter {
688713
this.transactionMonitor = new TransactionMonitor(this.transactionMonitorOptions);
689714
this.transactionMonitor.attach(this.engine);
690715
this.transactionMonitor.on("transaction", (event: TransactionEvent) => {
691-
aggregator.record("transaction", event.durationMs, event as unknown as Record<string, unknown>);
716+
aggregator.record(
717+
"transaction",
718+
event.durationMs,
719+
event as unknown as Record<string, unknown>,
720+
);
692721
this.emit("transaction", event);
693722
});
694723
}
@@ -697,7 +726,11 @@ export class DiagnosticAgent extends EventEmitter {
697726
this.cacheMonitor = new CacheMonitor(this.cacheMonitorOptions);
698727
this.cacheMonitor.attach(this.engine);
699728
this.cacheMonitor.on("cache-degraded", (event) => {
700-
aggregator.record("cache-degraded", event.hitRate, event as unknown as Record<string, unknown>);
729+
aggregator.record(
730+
"cache-degraded",
731+
event.hitRate,
732+
event as unknown as Record<string, unknown>,
733+
);
701734
this.emit("cache-degraded", event);
702735
});
703736
}
@@ -727,11 +760,19 @@ export class DiagnosticAgent extends EventEmitter {
727760
if (this.dnsMonitorOptions !== null) {
728761
this.dnsMonitor = new DnsMonitor(this.dnsMonitorOptions);
729762
this.dnsMonitor.on("dns", (event) => {
730-
this.aggregator!.record("dns", event.durationMs, event as unknown as Record<string, unknown>);
763+
this.aggregator!.record(
764+
"dns",
765+
event.durationMs,
766+
event as unknown as Record<string, unknown>,
767+
);
731768
this.emit("dns", event);
732769
});
733770
this.dnsMonitor.on("slow-dns", (event) => {
734-
this.aggregator!.record("slow-dns", event.durationMs, event as unknown as Record<string, unknown>);
771+
this.aggregator!.record(
772+
"slow-dns",
773+
event.durationMs,
774+
event as unknown as Record<string, unknown>,
775+
);
735776
this.emit("slow-dns", event);
736777
});
737778
this.dnsMonitor.enable();
@@ -758,7 +799,11 @@ export class DiagnosticAgent extends EventEmitter {
758799
if (this.gcMonitorOptions !== null) {
759800
this.gcMonitor = new GcMonitor(this.gcMonitorOptions);
760801
this.gcMonitor.on("gc-pressure", (event: GcPressureEvent) => {
761-
this.aggregator!.record("gc-pressure", event.totalPauseMs, event as unknown as Record<string, unknown>);
802+
this.aggregator!.record(
803+
"gc-pressure",
804+
event.totalPauseMs,
805+
event as unknown as Record<string, unknown>,
806+
);
762807
this.emit("gc-pressure", event);
763808
});
764809
this.gcMonitor.start();
@@ -767,11 +812,19 @@ export class DiagnosticAgent extends EventEmitter {
767812
if (this.poolMonitorOptions !== null) {
768813
this.poolMonitor = new PoolMonitor(this.poolMonitorOptions);
769814
this.poolMonitor.on("pool-exhaustion", (event: PoolExhaustionEvent) => {
770-
this.aggregator!.record("pool-exhaustion", event.waitingCount, event as unknown as Record<string, unknown>);
815+
this.aggregator!.record(
816+
"pool-exhaustion",
817+
event.waitingCount,
818+
event as unknown as Record<string, unknown>,
819+
);
771820
this.emit("pool-exhaustion", event);
772821
});
773822
this.poolMonitor.on("slow-acquire", (event: SlowAcquireEvent) => {
774-
this.aggregator!.record("slow-acquire", event.waitMs, event as unknown as Record<string, unknown>);
823+
this.aggregator!.record(
824+
"slow-acquire",
825+
event.waitMs,
826+
event as unknown as Record<string, unknown>,
827+
);
775828
this.emit("slow-acquire", event);
776829
});
777830
}
@@ -838,11 +891,26 @@ export class DiagnosticAgent extends EventEmitter {
838891
this.leakMonitor = null;
839892
this.queryAnalyzer = null;
840893
this.slowQueryMonitor = null;
841-
if (this.gcMonitor) { this.gcMonitor.stop(); this.gcMonitor = null; }
842-
if (this.poolMonitor) { this.poolMonitor.stop(); this.poolMonitor = null; }
843-
if (this.transactionMonitor) { this.transactionMonitor.stop(); this.transactionMonitor = null; }
844-
if (this.cacheMonitor) { this.cacheMonitor.stop(); this.cacheMonitor = null; }
845-
if (this.dnsMonitor) { this.dnsMonitor.disable(); this.dnsMonitor = null; }
894+
if (this.gcMonitor) {
895+
this.gcMonitor.stop();
896+
this.gcMonitor = null;
897+
}
898+
if (this.poolMonitor) {
899+
this.poolMonitor.stop();
900+
this.poolMonitor = null;
901+
}
902+
if (this.transactionMonitor) {
903+
this.transactionMonitor.stop();
904+
this.transactionMonitor = null;
905+
}
906+
if (this.cacheMonitor) {
907+
this.cacheMonitor.stop();
908+
this.cacheMonitor = null;
909+
}
910+
if (this.dnsMonitor) {
911+
this.dnsMonitor.disable();
912+
this.dnsMonitor = null;
913+
}
846914
this.adaptiveSampler = null;
847915

848916
// Remove debug console listeners added by useConsoleLogger (if any).
@@ -895,15 +963,21 @@ export class DiagnosticAgent extends EventEmitter {
895963
});
896964
add("slow-query", (s) => {
897965
const ev = s as SlowQueryRecord;
898-
console.warn(`${prefix} SLOW [${ev.durationMs.toFixed(1)}ms > ${ev.thresholdMs}ms] driver=${ev.driver}${ev.sanitizedQuery}`);
966+
console.warn(
967+
`${prefix} SLOW [${ev.durationMs.toFixed(1)}ms > ${ev.thresholdMs}ms] driver=${ev.driver}${ev.sanitizedQuery}`,
968+
);
899969
});
900970
add("gc-pressure", (g) => {
901971
const ev = g as GcPressureEvent;
902-
console.warn(`${prefix} GC [${ev.totalPauseMs.toFixed(1)}ms | ${ev.pausePct.toFixed(1)}% of ${ev.windowMs}ms window] ${ev.gcCount} cycles`);
972+
console.warn(
973+
`${prefix} GC [${ev.totalPauseMs.toFixed(1)}ms | ${ev.pausePct.toFixed(1)}% of ${ev.windowMs}ms window] ${ev.gcCount} cycles`,
974+
);
903975
});
904976
add("pool-exhaustion", (p) => {
905977
const ev = p as PoolExhaustionEvent;
906-
console.warn(`${prefix} POOL [${ev.driver}] waiting=${ev.waitingCount} idle=${ev.idleCount} total=${ev.totalCount}`);
978+
console.warn(
979+
`${prefix} POOL [${ev.driver}] waiting=${ev.waitingCount} idle=${ev.idleCount} total=${ev.totalCount}`,
980+
);
907981
});
908982
add("slow-acquire", (s) => {
909983
const ev = s as SlowAcquireEvent;
@@ -1004,11 +1078,7 @@ export class DiagnosticAgent extends EventEmitter {
10041078
* Creates and returns a `RequestContext` for manual use (e.g. background jobs, queue workers).
10051079
* Pass the returned context to `runWithContext(ctx, fn)` to propagate tracing.
10061080
*/
1007-
public createContext(
1008-
method?: string,
1009-
url?: string,
1010-
traceparent?: string,
1011-
): RequestContext {
1081+
public createContext(method?: string, url?: string, traceparent?: string): RequestContext {
10121082
return createRequestContext(method, url, traceparent);
10131083
}
10141084

packages/agent/src/export/otlp-compatible-exporter.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@ export class OTLPCompatibleExporter {
2626
try {
2727
parsed = new URL(config.endpointUrl);
2828
} catch {
29-
throw new TypeError(
30-
`OTLPCompatibleExporter: invalid endpointUrl "${config.endpointUrl}"`,
31-
);
29+
throw new TypeError(`OTLPCompatibleExporter: invalid endpointUrl "${config.endpointUrl}"`);
3230
}
3331
if (parsed.protocol !== "https:" && parsed.protocol !== "http:") {
3432
throw new TypeError(
@@ -63,9 +61,7 @@ export class OTLPCompatibleExporter {
6361
resourceMetrics: [
6462
{
6563
resource: {
66-
attributes: [
67-
{ key: "service.name", value: { stringValue: serviceName } },
68-
],
64+
attributes: [{ key: "service.name", value: { stringValue: serviceName } }],
6965
},
7066
scopeMetrics: [
7167
{
@@ -109,9 +105,7 @@ export class OTLPCompatibleExporter {
109105
res.resume(); // drain response
110106
if (res.statusCode && res.statusCode >= 400) {
111107
reject(
112-
new Error(
113-
`OTLPCompatibleExporter: export failed with status ${res.statusCode}`,
114-
),
108+
new Error(`OTLPCompatibleExporter: export failed with status ${res.statusCode}`),
115109
);
116110
} else {
117111
resolve();
@@ -120,9 +114,7 @@ export class OTLPCompatibleExporter {
120114
);
121115

122116
req.on("timeout", () => {
123-
req.destroy(
124-
new Error(`OTLPCompatibleExporter: request timed out after ${timeoutMs}ms`),
125-
);
117+
req.destroy(new Error(`OTLPCompatibleExporter: request timed out after ${timeoutMs}ms`));
126118
});
127119
req.on("error", reject);
128120
req.write(body);

packages/agent/src/instrumentation/dns-monitor.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,7 @@ export class DnsMonitor extends EventEmitter {
6666
this._origLookup = origLookup;
6767

6868
// dns.lookup has several overloads; we intercept the callback variant only.
69-
(dns as Record<string, unknown>).lookup = (
70-
hostname: string,
71-
...rest: unknown[]
72-
): void => {
69+
(dns as Record<string, unknown>).lookup = (hostname: string, ...rest: unknown[]): void => {
7370
const lastArg = rest[rest.length - 1];
7471
if (typeof lastArg !== "function") {
7572
// Non-callback form (options without callback) — pass through unmodified

packages/agent/tests/analysis/cache-monitor.test.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
import { describe, it, afterEach } from "node:test";
22
import assert from "node:assert/strict";
33
import { EventEmitter } from "node:events";
4-
import {
5-
CacheMonitor,
6-
type CacheDegradedEvent,
7-
} from "../../src/analysis/cache-monitor.ts";
4+
import { CacheMonitor, type CacheDegradedEvent } from "../../src/analysis/cache-monitor.ts";
85
import type { TracedQuery } from "../../src/instrumentation/engine.ts";
96

107
function makeQuery(overrides: Partial<TracedQuery> = {}): TracedQuery {

0 commit comments

Comments
 (0)