@langwatch/server 3.4.0 → 3.4.1

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.
@@ -0,0 +1,259 @@
1
+ import { afterEach, beforeEach, describe, expect, it } from "vitest";
2
+ import {
3
+ _resetOpsClickHouseClientForTesting,
4
+ buildExplainQuery,
5
+ getOpsClickHouseClient,
6
+ parseOpsConnection,
7
+ redactQueryForAudit,
8
+ stripCommentsAndStrings,
9
+ } from "../explain-core";
10
+
11
+ const TENANT_OK = "SELECT count() FROM stored_spans WHERE TenantId = 'p_x'";
12
+
13
+ describe("buildExplainQuery", () => {
14
+ it("wraps a tenant-scoped SELECT with EXPLAIN PLAN by default", () => {
15
+ const r = buildExplainQuery(TENANT_OK);
16
+ expect(r.ok).toBe(true);
17
+ expect(r.type).toBe("PLAN");
18
+ expect(r.wrapped).toBe(`EXPLAIN PLAN ${TENANT_OK}`);
19
+ });
20
+
21
+ it("respects an explicit type", () => {
22
+ const r = buildExplainQuery(TENANT_OK, "PIPELINE");
23
+ expect(r.wrapped).toBe(`EXPLAIN PIPELINE ${TENANT_OK}`);
24
+ });
25
+
26
+ it("accepts every allowed type", () => {
27
+ for (const t of ["PLAN", "SYNTAX", "PIPELINE", "AST", "INDEXES"] as const) {
28
+ const r = buildExplainQuery(TENANT_OK, t);
29
+ expect(r.ok, `type ${t} should be allowed`).toBe(true);
30
+ }
31
+ });
32
+
33
+ it("expands INDEXES to `EXPLAIN PLAN indexes = 1, actions = 1` (CH parser quirk)", () => {
34
+ const r = buildExplainQuery(TENANT_OK, "INDEXES");
35
+ expect(r.ok).toBe(true);
36
+ expect(r.wrapped).toBe(`EXPLAIN PLAN indexes = 1, actions = 1 ${TENANT_OK}`);
37
+ });
38
+
39
+ it("rejects an empty / whitespace-only query", () => {
40
+ expect(buildExplainQuery("").ok).toBe(false);
41
+ expect(buildExplainQuery(" ").ok).toBe(false);
42
+ });
43
+
44
+ it("rejects a query that already starts with EXPLAIN — pick `type` instead", () => {
45
+ const r = buildExplainQuery(`EXPLAIN PLAN ${TENANT_OK}`);
46
+ expect(r.ok).toBe(false);
47
+ expect(r.reason).toMatch(/already starts with EXPLAIN/i);
48
+ });
49
+
50
+ it("rejects multi-statement queries (semicolon)", () => {
51
+ const r = buildExplainQuery(`${TENANT_OK}; DROP TABLE stored_spans`);
52
+ expect(r.ok).toBe(false);
53
+ expect(r.reason).toMatch(/single statement/i);
54
+ });
55
+
56
+ it("rejects forbidden mutation keywords", () => {
57
+ const cases = [
58
+ "INSERT INTO foo VALUES (1)",
59
+ "ALTER TABLE foo ADD COLUMN x Int",
60
+ "SYSTEM RELOAD CONFIG",
61
+ "OPTIMIZE TABLE foo FINAL",
62
+ `ANALYZE ${TENANT_OK}`,
63
+ ];
64
+ for (const q of cases) {
65
+ const r = buildExplainQuery(q);
66
+ expect(r.ok, `should reject: ${q}`).toBe(false);
67
+ expect(r.reason).toMatch(/forbidden keyword/i);
68
+ }
69
+ });
70
+
71
+ it("does not reject a forbidden keyword that only appears inside a string literal", () => {
72
+ const q = "SELECT * FROM foo WHERE bar = 'DELETE' AND TenantId = 'p_x'";
73
+ expect(buildExplainQuery(q).ok).toBe(true);
74
+ });
75
+
76
+ it("accepts realistic agent shapes (arrayJoin, WHERE, GROUP BY)", () => {
77
+ const realistic = `
78
+ SELECT arrayJoin(SpanAttributes.keys) AS key, count() AS n
79
+ FROM stored_spans
80
+ WHERE TenantId = 'p_x' AND OccurredAt > now() - INTERVAL 1 DAY
81
+ GROUP BY key ORDER BY n DESC LIMIT 50
82
+ `.trim();
83
+ expect(buildExplainQuery(realistic).ok).toBe(true);
84
+ });
85
+
86
+ it("rejects ClickHouse table functions (SSRF surface)", () => {
87
+ const cases = [
88
+ `SELECT * FROM url('http://evil.example/x', CSV, 'a String')`,
89
+ `SELECT * FROM s3('s3://bucket/x', 'k', 's', 'CSV')`,
90
+ `SELECT * FROM remote('other-host:9000', default.stored_spans)`,
91
+ `SELECT * FROM postgresql('host:5432', 'db', 'tab', 'u', 'p')`,
92
+ `SELECT * FROM file('/etc/passwd', CSV, 'l String')`,
93
+ `SELECT * FROM mysql('host:3306', 'db', 'tab', 'u', 'p')`,
94
+ `SELECT * FROM cluster('ch', default.stored_spans)`,
95
+ `SELECT * FROM redis('host:6379', 0, 'key UInt64, val String')`,
96
+ ];
97
+ for (const q of cases) {
98
+ const r = buildExplainQuery(q);
99
+ expect(r.ok, `should reject: ${q}`).toBe(false);
100
+ expect(r.reason).toMatch(/table function/i);
101
+ }
102
+ });
103
+
104
+ it("accepts a cross-tenant query — operator endpoint by design", () => {
105
+ expect(buildExplainQuery("SELECT count() FROM stored_spans").ok).toBe(true);
106
+ });
107
+
108
+ it("rejects references to the system.* schema", () => {
109
+ const r = buildExplainQuery("SELECT * FROM system.users");
110
+ expect(r.ok).toBe(false);
111
+ expect(r.reason).toMatch(/system/i);
112
+ });
113
+
114
+ describe("comment / string-literal bypasses", () => {
115
+ it("rejects table functions hidden behind a block comment", () => {
116
+ const r = buildExplainQuery(`SELECT * FROM url/**/('http://127.0.0.1:9/', CSV)`);
117
+ expect(r.ok).toBe(false);
118
+ expect(r.reason).toMatch(/table function/i);
119
+ });
120
+
121
+ it("rejects a string-opener-inside-string bypass", () => {
122
+ const q = `SELECT * FROM stored_spans WHERE '/*' = 'literal' OR SpanId IN (SELECT SpanId FROM url('http://127.0.0.1:9/', CSV)) /* trailing */`;
123
+ const r = buildExplainQuery(q);
124
+ expect(r.ok).toBe(false);
125
+ expect(r.reason).toMatch(/table function/i);
126
+ });
127
+
128
+ it("rejects DROP split by a block comment", () => {
129
+ const r = buildExplainQuery(`DROP/**/TABLE stored_spans`);
130
+ expect(r.ok).toBe(false);
131
+ expect(r.reason).toMatch(/forbidden keyword/i);
132
+ });
133
+
134
+ it("does not treat `;` inside a string as multi-statement", () => {
135
+ expect(buildExplainQuery(`SELECT name FROM stored_spans WHERE name = 'a;b'`).ok).toBe(true);
136
+ });
137
+
138
+ it("treats a quoted block-comment marker as data", () => {
139
+ expect(
140
+ buildExplainQuery(`SELECT count() FROM stored_spans WHERE name = '/* not a comment */'`).ok,
141
+ ).toBe(true);
142
+ });
143
+ });
144
+ });
145
+
146
+ describe("stripCommentsAndStrings", () => {
147
+ it("drops block comments", () => {
148
+ expect(stripCommentsAndStrings("SELECT /* x */ 1")).toMatch(/SELECT\s+\s+1/);
149
+ });
150
+ it("drops line comments", () => {
151
+ expect(stripCommentsAndStrings("SELECT 1 -- trailing\nFROM x")).not.toMatch(/trailing/);
152
+ });
153
+ it("collapses string literals", () => {
154
+ expect(stripCommentsAndStrings("SELECT 'abc', \"def\" FROM x")).toMatch(/SELECT '', "" FROM x/);
155
+ });
156
+ it("handles nested block comments", () => {
157
+ const out = stripCommentsAndStrings("WHERE 1=1 /* outer /* inner */ TenantId = 'p_fake' */");
158
+ expect(out).not.toMatch(/TenantId/i);
159
+ expect(out).not.toMatch(/p_fake/);
160
+ });
161
+ it("does NOT open a block comment for /* inside a string literal", () => {
162
+ const out = stripCommentsAndStrings(
163
+ `SELECT * FROM x WHERE '/*' = 'y' OR id IN (SELECT id FROM url('http://h/', CSV))`,
164
+ );
165
+ expect(out).toMatch(/url\s*\(/i);
166
+ });
167
+ it("consumes to EOF on an unbalanced opener", () => {
168
+ const out = stripCommentsAndStrings("SELECT 1 /* unterminated TenantId = 'p_x'");
169
+ expect(out).toMatch(/SELECT 1/);
170
+ expect(out).not.toMatch(/TenantId/i);
171
+ });
172
+ });
173
+
174
+ describe("redactQueryForAudit", () => {
175
+ it("strips quoted string literals", () => {
176
+ const { shape } = redactQueryForAudit(
177
+ "SELECT * FROM events WHERE TenantId = 'p_acme' AND email = 'alice@example.com'",
178
+ );
179
+ expect(shape).toContain("TenantId = '?'");
180
+ expect(shape).not.toContain("p_acme");
181
+ expect(shape).not.toContain("alice");
182
+ });
183
+ it("strips numeric literals", () => {
184
+ const { shape } = redactQueryForAudit("SELECT * FROM x WHERE id = 12345");
185
+ expect(shape).not.toMatch(/\b12345\b/);
186
+ });
187
+ it("returns a stable 16-char sha256 prefix", () => {
188
+ const a = redactQueryForAudit("SELECT 1 FROM x");
189
+ const b = redactQueryForAudit("SELECT 1 FROM x");
190
+ expect(a.sha256).toBe(b.sha256);
191
+ expect(a.sha256).toMatch(/^[0-9a-f]{16}$/);
192
+ });
193
+ });
194
+
195
+ describe("parseOpsConnection", () => {
196
+ it("splits scheme/host from userinfo/database", () => {
197
+ const r = parseOpsConnection("http://langwatch_ops:secret@ch.example:8123/langwatch");
198
+ expect(r).toEqual({
199
+ url: "http://ch.example:8123",
200
+ username: "langwatch_ops",
201
+ password: "secret",
202
+ database: "langwatch",
203
+ });
204
+ });
205
+
206
+ it("percent-decodes a password Terraform urlencode()'d (the prod failure mode)", () => {
207
+ // random_password override_special = "_%@" -> a real prod value would
208
+ // look like this once urlencode() wraps the '@' and '%' chars for the
209
+ // URL to parse at all. URL.password returns the encoded string, so the
210
+ // client used to authenticate with the literal "%40" instead of "@" —
211
+ // that's the "Authentication failed" we saw against prod CH.
212
+ const r = parseOpsConnection(
213
+ "http://langwatch_ops:_1a4ZZx_kpR%40%25efk_lL%40fm%25WSwa5C%40AN@ch.example:8123/langwatch",
214
+ );
215
+ expect(r?.username).toBe("langwatch_ops");
216
+ expect(r?.password).toBe("_1a4ZZx_kpR@%efk_lL@fm%WSwa5C@AN");
217
+ });
218
+
219
+ it("returns empty strings when userinfo is absent", () => {
220
+ const r = parseOpsConnection("http://ch.example:8123/langwatch");
221
+ expect(r?.username).toBe("");
222
+ expect(r?.password).toBe("");
223
+ expect(r?.database).toBe("langwatch");
224
+ });
225
+
226
+ it("returns undefined database when path is empty or '/'", () => {
227
+ expect(parseOpsConnection("http://u:p@ch:8123")?.database).toBeUndefined();
228
+ expect(parseOpsConnection("http://u:p@ch:8123/")?.database).toBeUndefined();
229
+ });
230
+
231
+ it("returns null on a non-URL string", () => {
232
+ expect(parseOpsConnection("not a url at all")).toBeNull();
233
+ });
234
+ });
235
+
236
+ describe("getOpsClickHouseClient", () => {
237
+ const saved = process.env.CLICKHOUSE_OPS_URL;
238
+ beforeEach(() => {
239
+ _resetOpsClickHouseClientForTesting();
240
+ });
241
+ afterEach(() => {
242
+ if (saved === undefined) delete process.env.CLICKHOUSE_OPS_URL;
243
+ else process.env.CLICKHOUSE_OPS_URL = saved;
244
+ _resetOpsClickHouseClientForTesting();
245
+ });
246
+
247
+ it("returns null when CLICKHOUSE_OPS_URL is unset", () => {
248
+ delete process.env.CLICKHOUSE_OPS_URL;
249
+ expect(getOpsClickHouseClient()).toBeNull();
250
+ });
251
+
252
+ it("builds and caches a client when set", () => {
253
+ process.env.CLICKHOUSE_OPS_URL = "http://langwatch_ops:secret@ch.example:8123/langwatch";
254
+ const a = getOpsClickHouseClient();
255
+ const b = getOpsClickHouseClient();
256
+ expect(a).not.toBeNull();
257
+ expect(b).toBe(a);
258
+ });
259
+ });
@@ -0,0 +1,264 @@
1
+ import { createHash } from "node:crypto";
2
+ import { type ClickHouseClient, createClient } from "@clickhouse/client";
3
+ import { z } from "zod";
4
+
5
+ /// Pure helpers for the /api/ops/clickhouse/explain endpoint. The handler
6
+ /// itself lives in src/server/routes/ops.ts (Hono); these functions stay
7
+ /// pure so they can be unit-tested in isolation.
8
+
9
+ export const ALLOWED_EXPLAIN_TYPES = ["PLAN", "SYNTAX", "PIPELINE", "AST", "INDEXES"] as const;
10
+ export type ExplainType = (typeof ALLOWED_EXPLAIN_TYPES)[number];
11
+
12
+ /// `ANALYZE` would execute the inner query — never allow it. The other
13
+ /// entries here are tokens that would let a caller break out of the
14
+ /// EXPLAIN wrapper into a statement that mutates state. Even though our
15
+ /// EXPLAIN wrapping should prevent execution, ClickHouse's parser is
16
+ /// flexible enough that we keep this as a fast pre-check.
17
+ const FORBIDDEN_KEYWORD_RE =
18
+ /\b(ANALYZE|INSERT|UPDATE|DELETE|ALTER|DROP|TRUNCATE|CREATE|RENAME|OPTIMIZE|SYSTEM|GRANT|REVOKE|ATTACH|DETACH|EXCHANGE|FREEZE|UNFREEZE|KILL)\b/i;
19
+
20
+ /// ClickHouse table functions that can reach external/internal network
21
+ /// targets or read arbitrary local files. `readonly=1` does NOT block
22
+ /// these — read-only just means "no INSERT/ALTER/DROP", and table
23
+ /// functions are read operations. We deny them at the pre-check layer;
24
+ /// the dedicated `langwatch_ops` user adds the access-layer boundary.
25
+ const TABLE_FUNCTION_RE =
26
+ /\b(url|urlCluster|s3|s3Cluster|remote|remoteSecure|cluster|clusterAllReplicas|file|fileCluster|hdfs|hdfsCluster|mysql|postgresql|mongodb|odbc|jdbc|sqlite|redis|deltaLake|deltaLakeCluster|iceberg|icebergCluster|hudi|hudiCluster|azureBlobStorage|azureBlobStorageCluster|executable|input|merge|loop|view|fuzzJSON|values|format|generateRandom|numbers|numbers_mt)\s*\(/i;
27
+
28
+ /// `system.*` schema exposes server internals (users, settings, queries
29
+ /// of other tenants, etc.). Reject any reference to it.
30
+ const SYSTEM_SCHEMA_RE = /\bsystem\s*\./i;
31
+
32
+ /// Per-query ClickHouse-side guardrails. Must stay aligned with the
33
+ /// langwatch_ops profile in
34
+ /// infrastructure/clickhouse-serverless/config/users.xml.template.
35
+ /// ClickHouseSettings is picky: `readonly` / `max_result_bytes` /
36
+ /// `max_memory_usage` are typed `UInt64 = string`, `max_execution_time`
37
+ /// is `Seconds = number`.
38
+ export const CLICKHOUSE_GUARDRAILS = {
39
+ readonly: "1",
40
+ max_execution_time: 10,
41
+ max_result_bytes: "10000000",
42
+ max_memory_usage: "1073741824",
43
+ } as const;
44
+
45
+ export const explainBodySchema = z.object({
46
+ query: z.string().trim().min(1, "query is required").max(50_000),
47
+ type: z.enum(ALLOWED_EXPLAIN_TYPES).optional(),
48
+ });
49
+
50
+ export interface ParseResult {
51
+ ok: boolean;
52
+ wrapped?: string;
53
+ type?: ExplainType;
54
+ reason?: string;
55
+ }
56
+
57
+ /// Normalize the query for the regex safety pass with a single lexer that
58
+ /// tracks string, line-comment, and (nested) block-comment state in
59
+ /// ClickHouse order. A character is either inside a string, inside a
60
+ /// comment, or in normal SQL — never two at once — so we walk char-by-char
61
+ /// with one state variable. See the full rationale in the previous
62
+ /// commits' reviewer threads (string-vs-comment bypass, nested comments).
63
+ export function stripCommentsAndStrings(query: string): string {
64
+ let out = "";
65
+ let i = 0;
66
+ const n = query.length;
67
+ while (i < n) {
68
+ const c = query[i];
69
+ const next = query[i + 1];
70
+
71
+ if (c === "/" && next === "*") {
72
+ let depth = 1;
73
+ i += 2;
74
+ while (i < n && depth > 0) {
75
+ if (query[i] === "/" && query[i + 1] === "*") {
76
+ depth++;
77
+ i += 2;
78
+ } else if (query[i] === "*" && query[i + 1] === "/") {
79
+ depth--;
80
+ i += 2;
81
+ } else {
82
+ i++;
83
+ }
84
+ }
85
+ out += " ";
86
+ continue;
87
+ }
88
+
89
+ if (c === "-" && next === "-") {
90
+ i += 2;
91
+ while (i < n && query[i] !== "\n") i++;
92
+ out += " ";
93
+ continue;
94
+ }
95
+
96
+ if (c === "#" && (i === 0 || /\s/.test(query[i - 1] ?? ""))) {
97
+ i++;
98
+ while (i < n && query[i] !== "\n") i++;
99
+ out += " ";
100
+ continue;
101
+ }
102
+
103
+ if (c === "'") {
104
+ i++;
105
+ while (i < n) {
106
+ if (query[i] === "\\" && i + 1 < n) {
107
+ i += 2;
108
+ continue;
109
+ }
110
+ if (query[i] === "'" && query[i + 1] === "'") {
111
+ i += 2;
112
+ continue;
113
+ }
114
+ if (query[i] === "'") {
115
+ i++;
116
+ break;
117
+ }
118
+ i++;
119
+ }
120
+ out += "''";
121
+ continue;
122
+ }
123
+
124
+ if (c === '"') {
125
+ i++;
126
+ while (i < n) {
127
+ if (query[i] === "\\" && i + 1 < n) {
128
+ i += 2;
129
+ continue;
130
+ }
131
+ if (query[i] === '"' && query[i + 1] === '"') {
132
+ i += 2;
133
+ continue;
134
+ }
135
+ if (query[i] === '"') {
136
+ i++;
137
+ break;
138
+ }
139
+ i++;
140
+ }
141
+ out += '""';
142
+ continue;
143
+ }
144
+
145
+ out += c;
146
+ i++;
147
+ }
148
+ return out;
149
+ }
150
+
151
+ export function buildExplainQuery(query: string, type: ExplainType = "PLAN"): ParseResult {
152
+ const trimmed = query.trim();
153
+ if (!trimmed) return { ok: false, reason: "query is empty" };
154
+ if (/^\s*EXPLAIN\b/i.test(trimmed)) {
155
+ return { ok: false, reason: "query already starts with EXPLAIN — pass the inner SELECT only and choose type via the `type` field" };
156
+ }
157
+ const normalized = stripCommentsAndStrings(trimmed);
158
+ if (normalized.includes(";")) {
159
+ return { ok: false, reason: "query must be a single statement (no `;`)" };
160
+ }
161
+ const forbidden = FORBIDDEN_KEYWORD_RE.exec(normalized);
162
+ if (forbidden) {
163
+ return { ok: false, reason: `forbidden keyword in query: ${(forbidden[1] ?? "").toUpperCase()}` };
164
+ }
165
+ const tableFn = TABLE_FUNCTION_RE.exec(normalized);
166
+ if (tableFn) {
167
+ return {
168
+ ok: false,
169
+ reason: `table function not allowed (SSRF / external-read surface): ${(tableFn[1] ?? "").toLowerCase()}()`,
170
+ };
171
+ }
172
+ if (SYSTEM_SCHEMA_RE.test(normalized)) {
173
+ return { ok: false, reason: "references to the system.* schema are not allowed" };
174
+ }
175
+ // `INDEXES` is not a top-level EXPLAIN type in ClickHouse — it's a
176
+ // modifier on `EXPLAIN PLAN` (`EXPLAIN PLAN indexes = 1 ...`). Sending
177
+ // `EXPLAIN INDEXES <query>` raises a parser error and the endpoint
178
+ // 502s. Expand it to the canonical form so callers can pass `INDEXES`
179
+ // as a logical type without needing to know that wrinkle.
180
+ const prefix =
181
+ type === "INDEXES" ? "EXPLAIN PLAN indexes = 1, actions = 1" : `EXPLAIN ${type}`;
182
+ return { ok: true, wrapped: `${prefix} ${trimmed}`, type };
183
+ }
184
+
185
+ export function redactQueryForAudit(query: string): { shape: string; sha256: string } {
186
+ const shape = query
187
+ .replace(/'(?:\\.|[^'\\])*'/g, "'?'")
188
+ .replace(/"(?:\\.|[^"\\])*"/g, '"?"')
189
+ .replace(/\b\d[\d_.]*\b/g, "?")
190
+ .replace(/\s+/g, " ")
191
+ .trim();
192
+ const sha256 = createHash("sha256").update(query).digest("hex").slice(0, 16);
193
+ return { shape: shape.slice(0, 300), sha256 };
194
+ }
195
+
196
+ let opsClickHouseClient: ClickHouseClient | null = null;
197
+ let warnedAboutMissingOpsUrl = false;
198
+
199
+ /**
200
+ * Parse CLICKHOUSE_OPS_URL into the pieces @clickhouse/client wants as
201
+ * separate config fields. We do the userinfo split + percent-decoding
202
+ * ourselves because the lib forwards `URL.username` / `URL.password`
203
+ * to the wire as-is — both getters return the URL-encoded form. With a
204
+ * Terraform-generated password that may contain '@' or '%' (which TF
205
+ * wraps via `urlencode()` to keep the URL parseable), passing the URL
206
+ * verbatim ends up authenticating with the encoded form (e.g. "p%40ss")
207
+ * and ClickHouse rejects with "Authentication failed". Decoding here
208
+ * means the wire password matches what users.xml hashes.
209
+ */
210
+ export function parseOpsConnection(raw: string): {
211
+ url: string;
212
+ username: string;
213
+ password: string;
214
+ database?: string;
215
+ } | null {
216
+ try {
217
+ const u = new URL(raw);
218
+ const username = u.username ? decodeURIComponent(u.username) : "";
219
+ const password = u.password ? decodeURIComponent(u.password) : "";
220
+ const database =
221
+ u.pathname && u.pathname !== "/"
222
+ ? decodeURIComponent(u.pathname.replace(/^\//, ""))
223
+ : undefined;
224
+ const cleanUrl = `${u.protocol}//${u.host}`;
225
+ return { url: cleanUrl, username, password, database };
226
+ } catch {
227
+ return null;
228
+ }
229
+ }
230
+
231
+ export function getOpsClickHouseClient(): ClickHouseClient | null {
232
+ if (opsClickHouseClient) return opsClickHouseClient;
233
+ const url = process.env.CLICKHOUSE_OPS_URL;
234
+ if (!url || url.trim() === "") return null;
235
+ const parsed = parseOpsConnection(url);
236
+ // No client-side `clickhouse_settings` here: the langwatch_ops user runs
237
+ // under the `readonly_safe` profile (readonly=1) which forbids modifying
238
+ // any session setting client-side, so the previous default of
239
+ // date_time_input_format=best_effort made every request fail with
240
+ // "Cannot modify ... in readonly mode". EXPLAIN never parses input
241
+ // values anyway, so dropping the setting is also functionally correct.
242
+ // The execution/result/memory caps that USED to live here are enforced
243
+ // server-side by the profile.
244
+ opsClickHouseClient = createClient({
245
+ url: parsed?.url ?? url,
246
+ username: parsed?.username || undefined,
247
+ password: parsed?.password || undefined,
248
+ database: parsed?.database,
249
+ max_open_connections: 5,
250
+ keep_alive: { enabled: true, idle_socket_ttl: 1500 },
251
+ });
252
+ return opsClickHouseClient;
253
+ }
254
+
255
+ export function consumeMissingOpsUrlWarning(): boolean {
256
+ if (warnedAboutMissingOpsUrl) return false;
257
+ warnedAboutMissingOpsUrl = true;
258
+ return true;
259
+ }
260
+
261
+ export function _resetOpsClickHouseClientForTesting(): void {
262
+ opsClickHouseClient = null;
263
+ warnedAboutMissingOpsUrl = false;
264
+ }