postgresai 0.18.0-dev.0 → 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 +130 -42
- 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 {
|
|
@@ -28091,8 +28099,8 @@ function nameFromDatabase(url) {
|
|
|
28091
28099
|
const slug = (db || "dblab").toLowerCase().replace(/[^a-z0-9-]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 48).replace(/-+$/, "");
|
|
28092
28100
|
return slug.length >= 2 ? slug : `db-${slug || "x"}`.slice(0, 48);
|
|
28093
28101
|
}
|
|
28094
|
-
function sharedDeployOptions(cmd, waitDefaultMinutes, nameHelp) {
|
|
28095
|
-
return cmd.argument("[database-url]", "the database: postgresql://user:password@host:5432/dbname").option("--db-url <url>", "the database URL (the same as the argument)").option("--name <name>", nameHelp).option("--location <location>",
|
|
28102
|
+
function sharedDeployOptions(cmd, waitDefaultMinutes, nameHelp, locationHelp = "Hetzner location: fsn1, nbg1 or hel1 (default: any with capacity)") {
|
|
28103
|
+
return cmd.argument("[database-url]", "the database: postgresql://user:password@host:5432/dbname").option("--db-url <url>", "the database URL (the same as the argument)").option("--name <name>", nameHelp).option("--location <location>", locationHelp).option("--wait <minutes>", "how long to wait for it to be ready (0 = do not wait)", String(waitDefaultMinutes)).option("--no-wait", "return once the deploy has started (the same as --wait 0)").option("-y, --yes", "never prompt: accept the price and every confirmation").option("--json", "JSON output: one result on stdout, progress on stderr (the default when stdout is not a terminal)").option("--debug", "print HTTP requests (secrets masked)");
|
|
28096
28104
|
}
|
|
28097
28105
|
|
|
28098
28106
|
// lib/joe.ts
|
|
@@ -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
|
}
|
|
@@ -38927,6 +38936,7 @@ init_util();
|
|
|
38927
38936
|
|
|
38928
38937
|
// lib/deploy-commands.ts
|
|
38929
38938
|
import { createInterface } from "readline";
|
|
38939
|
+
import { lookup } from "dns/promises";
|
|
38930
38940
|
|
|
38931
38941
|
// lib/json-stderr.ts
|
|
38932
38942
|
function writeEvent(event) {
|
|
@@ -39016,6 +39026,9 @@ function withEnvPassword(dbUrl, env = process.env) {
|
|
|
39016
39026
|
return u.toString();
|
|
39017
39027
|
}
|
|
39018
39028
|
var DBLAB_PROVIDERS = ["rds", "supabase", "self-managed"];
|
|
39029
|
+
var DBLAB_CLOUDS = ["hetzner", "aws", "gcp"];
|
|
39030
|
+
var CLOUD_NAMES = { hetzner: "Hetzner", aws: "AWS", gcp: "Google Cloud" };
|
|
39031
|
+
var cloudName = (cloud) => CLOUD_NAMES[cloud ?? "hetzner"] ?? String(cloud);
|
|
39019
39032
|
var SOURCE_NAMES = {
|
|
39020
39033
|
generic: "PostgreSQL",
|
|
39021
39034
|
rds: "Amazon RDS",
|
|
@@ -39041,7 +39054,7 @@ function sourceLine(p) {
|
|
|
39041
39054
|
return `Source: ${name} (self-managed)`;
|
|
39042
39055
|
}
|
|
39043
39056
|
}
|
|
39044
|
-
var getDeployOptions = (p) => callDeployRpc(p, "dblab_cloud_deploy_options", {}, "Read deploy options");
|
|
39057
|
+
var getDeployOptions = (p, cloud) => callDeployRpc(p, "dblab_cloud_deploy_options", cloud && cloud !== "hetzner" ? { cloud } : {}, "Read deploy options");
|
|
39045
39058
|
var listCloudInstances = async (p, instanceId) => await callDeployRpc(p, "dblab_cloud_instances", instanceId === undefined ? {} : { p_instance_id: instanceId }, "List DBLab instances") ?? [];
|
|
39046
39059
|
var deployDblab = (p, args) => callDeployRpc(p, "dblab_instance_deploy", {
|
|
39047
39060
|
name: args.name,
|
|
@@ -39050,7 +39063,8 @@ var deployDblab = (p, args) => callDeployRpc(p, "dblab_instance_deploy", {
|
|
|
39050
39063
|
disk_gib: args.diskGib,
|
|
39051
39064
|
ssh_key_ids: args.sshKeyIds,
|
|
39052
39065
|
...args.location ? { location: args.location } : {},
|
|
39053
|
-
...args.provider ? { provider: args.provider } : {}
|
|
39066
|
+
...args.provider ? { provider: args.provider } : {},
|
|
39067
|
+
...args.cloud && args.cloud !== "hetzner" ? { cloud: args.cloud } : {}
|
|
39054
39068
|
}, "Deploy DBLab");
|
|
39055
39069
|
var probeSource = (p, dbUrl, provider) => callDeployRpc(p, "dblab_cloud_source_probe", { db_url: dbUrl, ...provider ? { provider } : {} }, "Test the source database");
|
|
39056
39070
|
function hasPassword(dbUrl) {
|
|
@@ -39320,6 +39334,20 @@ function emit(deps, result, json) {
|
|
|
39320
39334
|
console.error(result.next);
|
|
39321
39335
|
process.exitCode = DEPLOY_EXIT[result.status];
|
|
39322
39336
|
}
|
|
39337
|
+
async function looksPrivate(dbUrl) {
|
|
39338
|
+
let host = "";
|
|
39339
|
+
try {
|
|
39340
|
+
host = new URL(dbUrl).hostname;
|
|
39341
|
+
} catch {
|
|
39342
|
+
return false;
|
|
39343
|
+
}
|
|
39344
|
+
try {
|
|
39345
|
+
const { address } = await lookup(host, { family: 4 });
|
|
39346
|
+
return /^(10\.|192\.168\.|172\.(1[6-9]|2\d|3[01])\.)/.test(address);
|
|
39347
|
+
} catch {
|
|
39348
|
+
return false;
|
|
39349
|
+
}
|
|
39350
|
+
}
|
|
39323
39351
|
var failed = (deps, err, json) => emit(deps, { status: "failed", next: err instanceof Error ? err.message : String(err) }, json);
|
|
39324
39352
|
async function withDetach(view, resumeHint, watch) {
|
|
39325
39353
|
let detached = false;
|
|
@@ -39345,7 +39373,7 @@ function sshHint(inst) {
|
|
|
39345
39373
|
return "";
|
|
39346
39374
|
return [
|
|
39347
39375
|
`Connect to a clone through SSH (clones listen on the server's localhost), e.g. port 6000:`,
|
|
39348
|
-
` ssh -N -L 6000:127.0.0.1:6000 root@${inst.server_ip}`,
|
|
39376
|
+
` ssh -N -L 6000:127.0.0.1:6000 ${inst.ssh_user ?? "root"}@${inst.server_ip}`,
|
|
39349
39377
|
` psql "host=127.0.0.1 port=6000 user=<user> dbname=<db>"`
|
|
39350
39378
|
].join(`
|
|
39351
39379
|
`);
|
|
@@ -39366,7 +39394,12 @@ var viewFor = (title, steps, tty, json) => jsonOutput(json) ? new StepView(title
|
|
|
39366
39394
|
function dblabResult(outcome, id) {
|
|
39367
39395
|
const inst = outcome.instance;
|
|
39368
39396
|
const ipShown = inst?.server_ip && inst.deploy_status !== "destroyed" && inst.deploy_status !== "failed";
|
|
39369
|
-
const base = {
|
|
39397
|
+
const base = {
|
|
39398
|
+
id,
|
|
39399
|
+
name: inst?.project_name,
|
|
39400
|
+
...ipShown ? { server_ip: inst.server_ip } : {},
|
|
39401
|
+
...inst?.cloud ? { cloud: inst.cloud, location: inst.location } : {}
|
|
39402
|
+
};
|
|
39370
39403
|
switch (outcome.kind) {
|
|
39371
39404
|
case "ready":
|
|
39372
39405
|
return { ...base, status: "ready", next: `PGAI_CLONE_DB_PASSWORD=<password> pgai dblab clone create --project ${inst.project_name} --db-user <user>` };
|
|
@@ -39408,8 +39441,9 @@ ${result.next}`);
|
|
|
39408
39441
|
emit(deps, result, json);
|
|
39409
39442
|
process.exitCode = DEPLOY_EXIT[result.status];
|
|
39410
39443
|
}
|
|
39411
|
-
async function followDblab(api, id, name, tty, json, minutes, deps) {
|
|
39412
|
-
const
|
|
39444
|
+
async function followDblab(api, id, name, tty, json, minutes, deps, where) {
|
|
39445
|
+
const on = where?.location ? ` on ${cloudName(where.cloud || "hetzner")}, ${where.location}` : "";
|
|
39446
|
+
const view = viewFor(`Deploying DBLab "${name}" (id ${id})${on}`, DBLAB_STEPS, tty, json);
|
|
39413
39447
|
view.start();
|
|
39414
39448
|
const outcome = await withDetach(view, `pgai dblab instances watch ${id}`, () => watchDblabDeploy(api, id, view, { pollMs: pollMs(), maxMs: minutes * 60000 }));
|
|
39415
39449
|
if (outcome === "detached")
|
|
@@ -39426,7 +39460,7 @@ function failureSummary(error) {
|
|
|
39426
39460
|
}
|
|
39427
39461
|
function registerDblabDeployCommands(dblab, deps) {
|
|
39428
39462
|
const tty = deps.isTty ?? isTtyDefault;
|
|
39429
|
-
sharedDeployOptions(deps.withOrgOptions(dblab.command("deploy")), 120, "instance name: lowercase letters, digits, hyphens (default: from the database's name)").description("deploy DBLab + Joe in PostgresAI cloud, then follow it until it is ready").option("--size <size>", "server size (S, M, L)", "S").option("--disk <gib>", "disk size in GiB", "50").option("--ssh-key <name|id...>", "org SSH key(s) for reaching the server and its clones (required)").option("--provider <provider>", "where the database runs: rds, supabase or self-managed (default: detected)").addHelpText("after", [
|
|
39463
|
+
sharedDeployOptions(deps.withOrgOptions(dblab.command("deploy")), 120, "instance name: lowercase letters, digits, hyphens (default: from the database's name)", "Hetzner location: fsn1, nbg1 or hel1 (default: any with capacity); with --cloud aws or gcp, a region " + "(default: the source's region, else us-east-1 / us-central1)").description("deploy DBLab + Joe in PostgresAI cloud, then follow it until it is ready").option("--size <size>", "server size (S, M, L)", "S").option("--disk <gib>", "disk size in GiB", "50").option("--ssh-key <name|id...>", "org SSH key(s) for reaching the server and its clones (required)").option("--provider <provider>", "where the database runs: rds, supabase or self-managed (default: detected)").option("--cloud <cloud>", "where the DBLab server runs: hetzner, aws or gcp (default: hetzner); --location is then its region").addHelpText("after", [
|
|
39430
39464
|
"",
|
|
39431
39465
|
"The password: in the URL, or set PGPASSWORD.",
|
|
39432
39466
|
"A Supabase project without its password: deploy it from the Console (Connect Supabase).",
|
|
@@ -39441,6 +39475,10 @@ function registerDblabDeployCommands(dblab, deps) {
|
|
|
39441
39475
|
if (provider && !DBLAB_PROVIDERS.includes(provider)) {
|
|
39442
39476
|
throw new Error(`--provider must be one of: ${DBLAB_PROVIDERS.join(", ")}`);
|
|
39443
39477
|
}
|
|
39478
|
+
const cloud = opts.cloud?.trim().toLowerCase();
|
|
39479
|
+
if (cloud !== undefined && !DBLAB_CLOUDS.includes(cloud)) {
|
|
39480
|
+
throw new Error(`--cloud must be one of: ${DBLAB_CLOUDS.join(", ")}`);
|
|
39481
|
+
}
|
|
39444
39482
|
const name = opts.name?.trim() || nameFromDatabase(url);
|
|
39445
39483
|
const minutes = waitMinutes(opts.wait, 120);
|
|
39446
39484
|
const api = deps.resolveApi(!!opts.debug);
|
|
@@ -39448,7 +39486,13 @@ function registerDblabDeployCommands(dblab, deps) {
|
|
|
39448
39486
|
if (!Number.isFinite(diskGib) || String(diskGib) !== opts.disk.trim()) {
|
|
39449
39487
|
throw new Error("--disk must be a whole number of GiB");
|
|
39450
39488
|
}
|
|
39451
|
-
const options = await getDeployOptions(api);
|
|
39489
|
+
const options = await getDeployOptions(api, cloud);
|
|
39490
|
+
const offered = cloud ? options.clouds?.find((c) => c.code === cloud) : undefined;
|
|
39491
|
+
if (cloud && offered && !offered.available)
|
|
39492
|
+
throw new Error(`${cloudName(cloud)} is not available.`);
|
|
39493
|
+
if (cloud && opts.location && options.locations?.length && !options.locations.includes(opts.location)) {
|
|
39494
|
+
throw new Error(`Unknown location "${opts.location}" for ${cloudName(cloud)}. Choose one of: ${options.locations.join(", ")}.`);
|
|
39495
|
+
}
|
|
39452
39496
|
const notAdmin = () => emit(deps, { status: "action_required", name, next: notAdminNext }, opts.json);
|
|
39453
39497
|
if (options.is_admin === false)
|
|
39454
39498
|
return notAdmin();
|
|
@@ -39463,16 +39507,8 @@ function registerDblabDeployCommands(dblab, deps) {
|
|
|
39463
39507
|
}, opts.json);
|
|
39464
39508
|
}
|
|
39465
39509
|
const cents = estimateMonthlyCents(options, opts.size, diskGib);
|
|
39466
|
-
const
|
|
39467
|
-
|
|
39468
|
-
if (jsonOutput(opts.json))
|
|
39469
|
-
writeEvent({ event: "billing", message: estimateLine(price) });
|
|
39470
|
-
else
|
|
39471
|
-
console.error(estimateLine(price));
|
|
39472
|
-
}
|
|
39473
|
-
const noCard = () => emit(deps, { status: "action_required", name, next: noCardNext(billingPage(deps.uiBaseUrl?.(), options.org_alias)) }, opts.json);
|
|
39474
|
-
if (options.has_payment_method === false)
|
|
39475
|
-
return noCard();
|
|
39510
|
+
const on = cloud ? ` on ${cloudName(cloud)}` : "";
|
|
39511
|
+
const price = cents === null ? null : `${formatCents(cents)}/month (size ${opts.size.toUpperCase()}${on}, ${diskGib} GiB), prorated.`;
|
|
39476
39512
|
let probe = null;
|
|
39477
39513
|
try {
|
|
39478
39514
|
probe = await probeSource(api, dbUrl, provider);
|
|
@@ -39480,10 +39516,29 @@ function registerDblabDeployCommands(dblab, deps) {
|
|
|
39480
39516
|
if (err instanceof HttpStatusError && err.status === 403)
|
|
39481
39517
|
return notAdmin();
|
|
39482
39518
|
}
|
|
39519
|
+
if (probe && !probe.reachable && (probe.provider === "rds" || probe.provider === "aurora") && await looksPrivate(dbUrl)) {
|
|
39520
|
+
const console_ = `${(deps.uiBaseUrl?.() ?? "https://console.postgres.ai").replace(/\/+$/, "")}/${options.org_alias ?? "<org>"}`;
|
|
39521
|
+
return emit(deps, {
|
|
39522
|
+
status: "action_required",
|
|
39523
|
+
name,
|
|
39524
|
+
next: "This RDS is not reachable from the internet. If it is private, deploy it over PrivateLink in the Console: " + `${console_}/instances/deploy?source=rds&network=private`
|
|
39525
|
+
}, opts.json);
|
|
39526
|
+
}
|
|
39483
39527
|
if (probe && !probe.reachable) {
|
|
39528
|
+
const viaPrivateLink = (probe.provider === "rds" || probe.provider === "aurora") && /timeout|timed out/i.test(probe.error ?? "") ? `
|
|
39529
|
+
A private RDS deploys over PrivateLink in the Console: ${(deps.uiBaseUrl?.() ?? "https://console.postgres.ai").replace(/\/+$/, "")}/${options.org_alias ?? "<org>"}/instances/deploy?source=rds&network=private` : "";
|
|
39484
39530
|
throw new Error(`Cannot connect to the source database: ${probe.error ?? "unknown error"}${probe.hint ? `
|
|
39485
|
-
Hint: ${probe.hint}` : ""}`);
|
|
39531
|
+
Hint: ${probe.hint}` : ""}${viaPrivateLink}`);
|
|
39532
|
+
}
|
|
39533
|
+
if (price) {
|
|
39534
|
+
if (jsonOutput(opts.json))
|
|
39535
|
+
writeEvent({ event: "billing", message: estimateLine(price) });
|
|
39536
|
+
else
|
|
39537
|
+
console.error(estimateLine(price));
|
|
39486
39538
|
}
|
|
39539
|
+
const noCard = () => emit(deps, { status: "action_required", name, next: noCardNext(billingPage(deps.uiBaseUrl?.(), options.org_alias)) }, opts.json);
|
|
39540
|
+
if (options.has_payment_method === false)
|
|
39541
|
+
return noCard();
|
|
39487
39542
|
if (probe) {
|
|
39488
39543
|
if (jsonOutput(opts.json))
|
|
39489
39544
|
writeEvent({ event: "source", message: sourceLine(probe) });
|
|
@@ -39513,7 +39568,8 @@ Hint: ${probe.hint}` : ""}`);
|
|
|
39513
39568
|
diskGib,
|
|
39514
39569
|
sshKeyIds,
|
|
39515
39570
|
location: opts.location,
|
|
39516
|
-
provider
|
|
39571
|
+
provider,
|
|
39572
|
+
cloud
|
|
39517
39573
|
});
|
|
39518
39574
|
} catch (err) {
|
|
39519
39575
|
if (err instanceof HttpStatusError && err.status === 402)
|
|
@@ -39523,13 +39579,19 @@ Hint: ${probe.hint}` : ""}`);
|
|
|
39523
39579
|
throw err;
|
|
39524
39580
|
}
|
|
39525
39581
|
if (minutes === 0) {
|
|
39526
|
-
const started = {
|
|
39582
|
+
const started = {
|
|
39583
|
+
status: "in_progress",
|
|
39584
|
+
id: reply.id,
|
|
39585
|
+
name: reply.project_name,
|
|
39586
|
+
...reply.cloud ? { cloud: reply.cloud, location: reply.location ?? null } : {},
|
|
39587
|
+
next: `pgai dblab instances watch ${reply.id}`
|
|
39588
|
+
};
|
|
39527
39589
|
if (!jsonOutput(opts.json))
|
|
39528
39590
|
console.error(`Deploy started: id ${reply.id}. Follow it: ${started.next}`);
|
|
39529
39591
|
emit(deps, started, opts.json);
|
|
39530
39592
|
return;
|
|
39531
39593
|
}
|
|
39532
|
-
await followDblab(api, reply.id, reply.project_name, tty(), opts.json, minutes, deps);
|
|
39594
|
+
await followDblab(api, reply.id, reply.project_name, tty(), opts.json, minutes, deps, reply);
|
|
39533
39595
|
} catch (err) {
|
|
39534
39596
|
failed(deps, err, opts.json);
|
|
39535
39597
|
}
|
|
@@ -39552,7 +39614,8 @@ Hint: ${probe.hint}` : ""}`);
|
|
|
39552
39614
|
const status = r.is_cloud ? failedDeploy ? "Deploy failed" : STATE_LABELS[r.deploy_status ?? ""] ?? r.deploy_status : r.is_job_backed ? "Connected" : "Self-managed";
|
|
39553
39615
|
const ip = r.server_ip && r.deploy_status !== "destroyed" && r.deploy_status !== "failed" ? ` ${r.server_ip}` : "";
|
|
39554
39616
|
const source = sourceName(r.source_provider, r.source_name);
|
|
39555
|
-
const
|
|
39617
|
+
const where = r.cloud && r.cloud !== "hetzner" ? ` ${cloudName(r.cloud)} ${r.location ?? ""}` : "";
|
|
39618
|
+
const extra = r.is_cloud ? ` ${r.size ?? ""} ${r.disk_gib ?? ""}GiB${where}${ip}${source ? ` from ${source}` : ""}` : "";
|
|
39556
39619
|
console.log(`${String(r.id).padEnd(6)} ${r.project_name.padEnd(28)} ${String(status).padEnd(14)}${extra}`);
|
|
39557
39620
|
if (r.deploy_error && r.deploy_status !== "ready") {
|
|
39558
39621
|
const summary = failureSummary(r.deploy_error);
|
|
@@ -39579,7 +39642,7 @@ Hint: ${probe.hint}` : ""}`);
|
|
|
39579
39642
|
return reportEnd(deps, ended, inst.id, opts.json);
|
|
39580
39643
|
if (minutes === 0)
|
|
39581
39644
|
return reportEnd(deps, { kind: "timeout", instance: inst }, inst.id, opts.json);
|
|
39582
|
-
await followDblab(api, inst.id, inst.project_name, tty(), opts.json, minutes, deps);
|
|
39645
|
+
await followDblab(api, inst.id, inst.project_name, tty(), opts.json, minutes, deps, inst);
|
|
39583
39646
|
} catch (err) {
|
|
39584
39647
|
failed(deps, err, opts.json);
|
|
39585
39648
|
}
|
|
@@ -39858,8 +39921,8 @@ function assertEncodedUserinfo2(url) {
|
|
|
39858
39921
|
throw new Error("The database URL has an '@' after the host: percent-encode it as %40 (in the password, the database name or the query; also / as %2F, ? as %3F, # as %23 in the password).");
|
|
39859
39922
|
}
|
|
39860
39923
|
}
|
|
39861
|
-
function sharedDeployOptions2(cmd, waitDefaultMinutes, nameHelp) {
|
|
39862
|
-
return cmd.argument("[database-url]", "the database: postgresql://user:password@host:5432/dbname").option("--db-url <url>", "the database URL (the same as the argument)").option("--name <name>", nameHelp).option("--location <location>",
|
|
39924
|
+
function sharedDeployOptions2(cmd, waitDefaultMinutes, nameHelp, locationHelp = "Hetzner location: fsn1, nbg1 or hel1 (default: any with capacity)") {
|
|
39925
|
+
return cmd.argument("[database-url]", "the database: postgresql://user:password@host:5432/dbname").option("--db-url <url>", "the database URL (the same as the argument)").option("--name <name>", nameHelp).option("--location <location>", locationHelp).option("--wait <minutes>", "how long to wait for it to be ready (0 = do not wait)", String(waitDefaultMinutes)).option("--no-wait", "return once the deploy has started (the same as --wait 0)").option("-y, --yes", "never prompt: accept the price and every confirmation").option("--json", "JSON output: one result on stdout, progress on stderr (the default when stdout is not a terminal)").option("--debug", "print HTTP requests (secrets masked)");
|
|
39863
39926
|
}
|
|
39864
39927
|
|
|
39865
39928
|
// lib/promql.ts
|
|
@@ -39959,18 +40022,21 @@ var TERMINAL = new Set(["done", "failed", "expired"]);
|
|
|
39959
40022
|
function isTerminal2(status) {
|
|
39960
40023
|
return TERMINAL.has(status);
|
|
39961
40024
|
}
|
|
39962
|
-
function pollDelay(attempt) {
|
|
39963
|
-
return Math.min(1000 * 2 ** attempt, 15000);
|
|
39964
|
-
}
|
|
39965
40025
|
async function awaitQueryResult(apiKey, jobId, opts) {
|
|
39966
40026
|
const now = opts.now ?? (() => Date.now());
|
|
39967
40027
|
const sleep = opts.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
|
|
39968
|
-
const
|
|
40028
|
+
const started = now();
|
|
40029
|
+
const deadline = started + opts.timeoutMs;
|
|
40030
|
+
let announced = false;
|
|
39969
40031
|
for (let attempt = 0;; attempt++) {
|
|
39970
40032
|
const res = await readQueryResult(apiKey, jobId, opts);
|
|
39971
40033
|
if (isTerminal2(res.status))
|
|
39972
40034
|
return res;
|
|
39973
|
-
|
|
40035
|
+
if (!announced && opts.onSlow && now() - started >= SLOW_ANSWER_MS) {
|
|
40036
|
+
announced = true;
|
|
40037
|
+
opts.onSlow();
|
|
40038
|
+
}
|
|
40039
|
+
const delay = asyncPollDelayMs(attempt);
|
|
39974
40040
|
if (now() + delay >= deadline)
|
|
39975
40041
|
return res;
|
|
39976
40042
|
await sleep(delay);
|
|
@@ -42241,6 +42307,22 @@ function trimmedEnv(name) {
|
|
|
42241
42307
|
// bin/postgres-ai.ts
|
|
42242
42308
|
init_util();
|
|
42243
42309
|
|
|
42310
|
+
// lib/connect-timeout.ts
|
|
42311
|
+
import * as net from "node:net";
|
|
42312
|
+
var CONNECT_ATTEMPT_TIMEOUT_MS = 2000;
|
|
42313
|
+
var ATTEMPT_TIMEOUT_FLAG = "--network-family-autoselection-attempt-timeout";
|
|
42314
|
+
var nodeNet = net;
|
|
42315
|
+
function raiseConnectAttemptTimeout(execArgv = process.execArgv, nodeOptions = process.env.NODE_OPTIONS) {
|
|
42316
|
+
if (!nodeNet.getDefaultAutoSelectFamilyAttemptTimeout || !nodeNet.setDefaultAutoSelectFamilyAttemptTimeout) {
|
|
42317
|
+
return;
|
|
42318
|
+
}
|
|
42319
|
+
const userSet = [...execArgv, ...(nodeOptions ?? "").split(/\s+/)].some((arg) => arg.replace(/_/g, "-").startsWith(ATTEMPT_TIMEOUT_FLAG));
|
|
42320
|
+
if (!userSet && nodeNet.getDefaultAutoSelectFamilyAttemptTimeout() < CONNECT_ATTEMPT_TIMEOUT_MS) {
|
|
42321
|
+
nodeNet.setDefaultAutoSelectFamilyAttemptTimeout(CONNECT_ATTEMPT_TIMEOUT_MS);
|
|
42322
|
+
}
|
|
42323
|
+
return nodeNet.getDefaultAutoSelectFamilyAttemptTimeout();
|
|
42324
|
+
}
|
|
42325
|
+
|
|
42244
42326
|
// lib/feedback.ts
|
|
42245
42327
|
var FEEDBACK_URL = "https://gitlab.com/postgres-ai/postgresai/-/work_items/300";
|
|
42246
42328
|
var FEEDBACK_SUPPRESS_ENV = "PGAI_NO_FEEDBACK_TIP";
|
|
@@ -50271,6 +50353,7 @@ program2.command("orgs").description("list organizations this credential can rea
|
|
|
50271
50353
|
}
|
|
50272
50354
|
});
|
|
50273
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;
|
|
50274
50357
|
try {
|
|
50275
50358
|
const rootOpts = program2.opts();
|
|
50276
50359
|
const cfg = readConfig();
|
|
@@ -50325,11 +50408,13 @@ withOrgOptions(program2.command("promql")).description("run a PromQL query on a
|
|
|
50325
50408
|
return;
|
|
50326
50409
|
}
|
|
50327
50410
|
const { jobId, firstAnswerEstimateS } = await enqueueQuery(apiKey, enqueue, { apiBaseUrl });
|
|
50411
|
+
queuedJobId = jobId;
|
|
50328
50412
|
const timeoutS = explicitTimeoutS ?? (firstAnswerEstimateS === null ? DEFAULT_PROMQL_TIMEOUT_S : Math.min(Math.max(Math.ceil(firstAnswerEstimateS * 1.5) + 30, 60), 1800));
|
|
50329
|
-
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)}.`);
|
|
50330
50414
|
const res = await awaitQueryResult(apiKey, jobId, {
|
|
50331
50415
|
apiBaseUrl,
|
|
50332
|
-
timeoutMs: timeoutS * 1000
|
|
50416
|
+
timeoutMs: timeoutS * 1000,
|
|
50417
|
+
onSlow: announce
|
|
50333
50418
|
});
|
|
50334
50419
|
if (!isTerminal2(res.status)) {
|
|
50335
50420
|
console.error(`Timed out after ${timeoutS}s. Job ${jobId} is still ${res.status}.`);
|
|
@@ -50356,6 +50441,8 @@ withOrgOptions(program2.command("promql")).description("run a PromQL query on a
|
|
|
50356
50441
|
console.log(renderPromQL(res.result));
|
|
50357
50442
|
} catch (err) {
|
|
50358
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.`);
|
|
50359
50446
|
process.exitCode = 1;
|
|
50360
50447
|
}
|
|
50361
50448
|
});
|
|
@@ -51644,6 +51731,7 @@ mcp.command("install [client]").description("install MCP server configuration fo
|
|
|
51644
51731
|
}
|
|
51645
51732
|
});
|
|
51646
51733
|
if (__require.main == __require.module) {
|
|
51734
|
+
raiseConnectAttemptTimeout();
|
|
51647
51735
|
if (process.argv.length <= 2) {
|
|
51648
51736
|
program2.outputHelp();
|
|
51649
51737
|
closeReadline();
|