postgresai 0.18.0-dev.1 → 0.18.0-dev.2
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/dist/bin/postgres-ai.js +31 -14
- package/package.json +1 -1
package/dist/bin/postgres-ai.js
CHANGED
|
@@ -13533,7 +13533,7 @@ var {
|
|
|
13533
13533
|
// package.json
|
|
13534
13534
|
var package_default = {
|
|
13535
13535
|
name: "postgresai",
|
|
13536
|
-
version: "0.18.0-dev.
|
|
13536
|
+
version: "0.18.0-dev.2",
|
|
13537
13537
|
description: "postgres_ai CLI",
|
|
13538
13538
|
license: "Apache-2.0",
|
|
13539
13539
|
private: false,
|
|
@@ -16893,7 +16893,7 @@ var Result = import_lib.default.Result;
|
|
|
16893
16893
|
var TypeOverrides = import_lib.default.TypeOverrides;
|
|
16894
16894
|
var defaults = import_lib.default.defaults;
|
|
16895
16895
|
// package.json
|
|
16896
|
-
var version = "0.18.0-dev.
|
|
16896
|
+
var version = "0.18.0-dev.2";
|
|
16897
16897
|
var package_default2 = {
|
|
16898
16898
|
name: "postgresai",
|
|
16899
16899
|
version,
|
|
@@ -17183,8 +17183,16 @@ function positiveSeconds(v) {
|
|
|
17183
17183
|
return typeof v === "number" && Number.isFinite(v) && v > 0 ? v : null;
|
|
17184
17184
|
}
|
|
17185
17185
|
function asyncPollDelayMs(attempt) {
|
|
17186
|
-
|
|
17186
|
+
if (attempt < FAST_POLLS)
|
|
17187
|
+
return FAST_POLL_MS;
|
|
17188
|
+
return Math.min(1000 * 2 ** (attempt - FAST_POLLS), 15000);
|
|
17187
17189
|
}
|
|
17190
|
+
var FAST_POLLS = 4;
|
|
17191
|
+
var FAST_POLL_MS = 500;
|
|
17192
|
+
function asyncRetryDelayMs(consecutiveFailures) {
|
|
17193
|
+
return Math.min(1000 * 2 ** Math.max(consecutiveFailures - 1, 0), 15000);
|
|
17194
|
+
}
|
|
17195
|
+
var SLOW_ANSWER_MS = 2000;
|
|
17188
17196
|
var DEFAULT_HTTP_REQUEST_TIMEOUT_MS = 25000;
|
|
17189
17197
|
|
|
17190
17198
|
class HttpRequestTimeoutError extends Error {
|
|
@@ -38367,7 +38375,7 @@ async function runCommand(params) {
|
|
|
38367
38375
|
if (now() >= deadline || started.asyncWaitMs !== null && transientFailures >= JOE_ASYNC_MAX_POLL_FAILURES) {
|
|
38368
38376
|
return { commandId, status, output: null, budgetExpired: true, budgetMs };
|
|
38369
38377
|
}
|
|
38370
|
-
await sleep(
|
|
38378
|
+
await sleep(params.pollIntervalMs ?? (started.asyncWaitMs === null ? DEFAULT_POLL_INTERVAL_MS : asyncRetryDelayMs(transientFailures)));
|
|
38371
38379
|
continue;
|
|
38372
38380
|
}
|
|
38373
38381
|
throw err;
|
|
@@ -38622,7 +38630,8 @@ async function awaitDblabCall(handle, params) {
|
|
|
38622
38630
|
const now = params.now ?? (() => Date.now());
|
|
38623
38631
|
const sleep = params.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
|
|
38624
38632
|
const waitMs = Math.min((positiveSeconds(handle.expires_in_s) ?? 0) * 1000 || DBLAB_ASYNC_FALLBACK_WAIT_MS, DBLAB_ASYNC_MAX_WAIT_MS);
|
|
38625
|
-
const
|
|
38633
|
+
const started = now();
|
|
38634
|
+
const deadline = started + waitMs;
|
|
38626
38635
|
const estimate = positiveSeconds(handle.first_answer_estimate_s);
|
|
38627
38636
|
let announced = false;
|
|
38628
38637
|
let failures = 0;
|
|
@@ -38652,11 +38661,11 @@ async function awaitDblabCall(handle, params) {
|
|
|
38652
38661
|
throw new Error(`${operation}: the DBLab instance did not complete the call (status ${scrubBoxText(res.status)}) — ` + `${scrubBoxText(why)}${klass}.${advice}`);
|
|
38653
38662
|
}
|
|
38654
38663
|
}
|
|
38655
|
-
if (!announced && outcome.kind === "result") {
|
|
38664
|
+
if (!announced && outcome.kind === "result" && now() - started >= SLOW_ANSWER_MS) {
|
|
38656
38665
|
announced = true;
|
|
38657
38666
|
console.error(`Waiting for the DBLab instance to pick up the call (job ${jobId}` + (estimate ? `, typically ~${estimate}s` : "") + ")...");
|
|
38658
38667
|
}
|
|
38659
|
-
const delay = asyncPollDelayMs(attempt);
|
|
38668
|
+
const delay = outcome.kind === "transient" ? asyncRetryDelayMs(failures) : asyncPollDelayMs(attempt);
|
|
38660
38669
|
if (now() + delay >= deadline) {
|
|
38661
38670
|
throw new Error(`${operation}: timed out waiting for the DBLab instance (job ${jobId}, last status ${lastStatus}). ` + dblabNotResentAdvice(jobId));
|
|
38662
38671
|
}
|
|
@@ -40013,18 +40022,21 @@ var TERMINAL = new Set(["done", "failed", "expired"]);
|
|
|
40013
40022
|
function isTerminal2(status) {
|
|
40014
40023
|
return TERMINAL.has(status);
|
|
40015
40024
|
}
|
|
40016
|
-
function pollDelay(attempt) {
|
|
40017
|
-
return Math.min(1000 * 2 ** attempt, 15000);
|
|
40018
|
-
}
|
|
40019
40025
|
async function awaitQueryResult(apiKey, jobId, opts) {
|
|
40020
40026
|
const now = opts.now ?? (() => Date.now());
|
|
40021
40027
|
const sleep = opts.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
|
|
40022
|
-
const
|
|
40028
|
+
const started = now();
|
|
40029
|
+
const deadline = started + opts.timeoutMs;
|
|
40030
|
+
let announced = false;
|
|
40023
40031
|
for (let attempt = 0;; attempt++) {
|
|
40024
40032
|
const res = await readQueryResult(apiKey, jobId, opts);
|
|
40025
40033
|
if (isTerminal2(res.status))
|
|
40026
40034
|
return res;
|
|
40027
|
-
|
|
40035
|
+
if (!announced && opts.onSlow && now() - started >= SLOW_ANSWER_MS) {
|
|
40036
|
+
announced = true;
|
|
40037
|
+
opts.onSlow();
|
|
40038
|
+
}
|
|
40039
|
+
const delay = asyncPollDelayMs(attempt);
|
|
40028
40040
|
if (now() + delay >= deadline)
|
|
40029
40041
|
return res;
|
|
40030
40042
|
await sleep(delay);
|
|
@@ -50341,6 +50353,7 @@ program2.command("orgs").description("list organizations this credential can rea
|
|
|
50341
50353
|
}
|
|
50342
50354
|
});
|
|
50343
50355
|
withOrgOptions(program2.command("promql")).description("run a PromQL query on a monitoring instance's own metric store").argument("<expr>", "PromQL expression").option("--instance <uuid>", "monitoring instance id (default: this box's .pgwatch-config); not with --project").option("--project <id|alias>", "the project's monitoring instance, by project id, alias or name; not with --instance").option("--at <rfc3339>", "evaluate an instant query at this time (default: now; ignored with --range)").option("--range", "run a range query (requires --start, --end, --step)").option("--start <rfc3339>", "range start").option("--end <rfc3339>", "range end").option("--step <duration>", "range step, e.g. 60s or 5m").option("--timeout <duration>", "how long to wait for an answer (default: sized from the instance's poll pacing; 11m if the platform does not report it)").option("--json", "output the raw result payload").action(async (expr, opts) => {
|
|
50356
|
+
let queuedJobId = null;
|
|
50344
50357
|
try {
|
|
50345
50358
|
const rootOpts = program2.opts();
|
|
50346
50359
|
const cfg = readConfig();
|
|
@@ -50395,11 +50408,13 @@ withOrgOptions(program2.command("promql")).description("run a PromQL query on a
|
|
|
50395
50408
|
return;
|
|
50396
50409
|
}
|
|
50397
50410
|
const { jobId, firstAnswerEstimateS } = await enqueueQuery(apiKey, enqueue, { apiBaseUrl });
|
|
50411
|
+
queuedJobId = jobId;
|
|
50398
50412
|
const timeoutS = explicitTimeoutS ?? (firstAnswerEstimateS === null ? DEFAULT_PROMQL_TIMEOUT_S : Math.min(Math.max(Math.ceil(firstAnswerEstimateS * 1.5) + 30, 60), 1800));
|
|
50399
|
-
console.error(firstAnswerEstimateS === null ? `Queued as job ${jobId}; waiting up to ${formatSeconds(timeoutS)} for the instance's next poll.` : `Queued as job ${jobId}; this instance polls roughly every ${formatSeconds(firstAnswerEstimateS)} ` + `(jittered, so sometimes longer). Waiting up to ${formatSeconds(timeoutS)}.`);
|
|
50413
|
+
const announce = () => console.error(firstAnswerEstimateS === null ? `Queued as job ${jobId}; waiting up to ${formatSeconds(timeoutS)} for the instance's next poll.` : `Queued as job ${jobId}; this instance polls roughly every ${formatSeconds(firstAnswerEstimateS)} ` + `(jittered, so sometimes longer). Waiting up to ${formatSeconds(timeoutS)}.`);
|
|
50400
50414
|
const res = await awaitQueryResult(apiKey, jobId, {
|
|
50401
50415
|
apiBaseUrl,
|
|
50402
|
-
timeoutMs: timeoutS * 1000
|
|
50416
|
+
timeoutMs: timeoutS * 1000,
|
|
50417
|
+
onSlow: announce
|
|
50403
50418
|
});
|
|
50404
50419
|
if (!isTerminal2(res.status)) {
|
|
50405
50420
|
console.error(`Timed out after ${timeoutS}s. Job ${jobId} is still ${res.status}.`);
|
|
@@ -50426,6 +50441,8 @@ withOrgOptions(program2.command("promql")).description("run a PromQL query on a
|
|
|
50426
50441
|
console.log(renderPromQL(res.result));
|
|
50427
50442
|
} catch (err) {
|
|
50428
50443
|
console.error(err instanceof Error ? err.message : String(err));
|
|
50444
|
+
if (queuedJobId)
|
|
50445
|
+
console.error(`Job ${queuedJobId} was queued; it was not re-sent.`);
|
|
50429
50446
|
process.exitCode = 1;
|
|
50430
50447
|
}
|
|
50431
50448
|
});
|