@runblackcat/sdk 0.1.0-alpha.128 → 0.1.0-alpha.130
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/package.json +1 -1
- package/sdk/dist/index.d.ts +140 -5
- package/sdk/dist/index.js +24 -0
package/package.json
CHANGED
package/sdk/dist/index.d.ts
CHANGED
|
@@ -447,11 +447,27 @@ interface CapacityReservationBase {
|
|
|
447
447
|
* holds it, no room under the fleet ceiling or quota, ...), or null. */
|
|
448
448
|
unmet_reason?: string | null;
|
|
449
449
|
/** The latest launch made for it, or null. */
|
|
450
|
-
launch?:
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
450
|
+
launch?: CapacityReservationLaunch | null;
|
|
451
|
+
/** Every launch made for it, oldest first. */
|
|
452
|
+
launches?: CapacityReservationLaunch[];
|
|
453
|
+
/** When it first became fully met (epoch milliseconds), or null until it
|
|
454
|
+
* does. */
|
|
455
|
+
ready_at?: number | null;
|
|
456
|
+
/** `ready_at` less its creation time, in milliseconds, or null. */
|
|
457
|
+
time_to_ready_ms?: number | null;
|
|
458
|
+
}
|
|
459
|
+
export interface CapacityReservationLaunch {
|
|
460
|
+
state: string;
|
|
461
|
+
shape: string;
|
|
462
|
+
detail: string | null;
|
|
463
|
+
/** When the plan chose the launch (epoch milliseconds). */
|
|
464
|
+
created_at?: number;
|
|
465
|
+
/** When the provider accepted or refused it; null while unanswered. */
|
|
466
|
+
settled_at?: number | null;
|
|
467
|
+
/** When the first of its hosts registered, or null. */
|
|
468
|
+
enrolled_at?: number | null;
|
|
469
|
+
/** The availability zone it launched in, when known. */
|
|
470
|
+
az?: string | null;
|
|
455
471
|
}
|
|
456
472
|
export type CapacityReservation = CapacityReservationBase & ({
|
|
457
473
|
capacity: {
|
|
@@ -466,6 +482,118 @@ export type CapacityReservation = CapacityReservationBase & ({
|
|
|
466
482
|
};
|
|
467
483
|
count?: never;
|
|
468
484
|
});
|
|
485
|
+
/** CPU busy time by the class of thread that spent it, in millicores. */
|
|
486
|
+
export interface ReservationTelemetryClassCpu {
|
|
487
|
+
vcpu: number;
|
|
488
|
+
vmm: number;
|
|
489
|
+
agent: number;
|
|
490
|
+
uffd: number;
|
|
491
|
+
ublk: number;
|
|
492
|
+
kernel: number;
|
|
493
|
+
other: number;
|
|
494
|
+
}
|
|
495
|
+
/**
|
|
496
|
+
* What the host as a whole did during one interval: `at_ms` is its start and
|
|
497
|
+
* `span_secs` its length. CPU, memory and the sandbox count are means over the
|
|
498
|
+
* span as recorded; disk and network fields are bytes moved over the span.
|
|
499
|
+
* With `stepSecs`, a row is a bucket: CPU is the span-weighted mean, memory
|
|
500
|
+
* and `running_sandboxes` the largest value (`mem_available_bytes` the
|
|
501
|
+
* smallest), bytes the sum.
|
|
502
|
+
*/
|
|
503
|
+
export interface ReservationTelemetryHostRow {
|
|
504
|
+
at_ms: number;
|
|
505
|
+
span_secs: number;
|
|
506
|
+
busy_mcpu: number;
|
|
507
|
+
class_mcpu: ReservationTelemetryClassCpu;
|
|
508
|
+
mem_used_bytes: number;
|
|
509
|
+
mem_available_bytes: number;
|
|
510
|
+
disk_read_bytes: number;
|
|
511
|
+
disk_write_bytes: number;
|
|
512
|
+
net_rx_bytes: number;
|
|
513
|
+
net_tx_bytes: number;
|
|
514
|
+
running_sandboxes: number;
|
|
515
|
+
}
|
|
516
|
+
/** One sandbox's interval. A field is null when the node could not read it:
|
|
517
|
+
* unknown, never zero. With `stepSecs`, CPU and stall are sums and RSS the
|
|
518
|
+
* largest reading. */
|
|
519
|
+
export interface ReservationTelemetrySandboxRow {
|
|
520
|
+
at_ms: number;
|
|
521
|
+
span_secs: number;
|
|
522
|
+
cpu_usec: number | null;
|
|
523
|
+
stall_usec: number | null;
|
|
524
|
+
rss_bytes: number | null;
|
|
525
|
+
}
|
|
526
|
+
/** A sandbox's totals, in place of its rows, when the read asked for a summary. */
|
|
527
|
+
export interface ReservationTelemetrySandboxSummary {
|
|
528
|
+
started_at_ms: number | null;
|
|
529
|
+
destroyed_at_ms: number | null;
|
|
530
|
+
/** Null when no row had a reading: unknown, never zero. */
|
|
531
|
+
cpu_usec_total: number | null;
|
|
532
|
+
stall_usec_total: number | null;
|
|
533
|
+
rss_peak_bytes: number | null;
|
|
534
|
+
/** Rows folded, at the resolution recorded (before any `stepSecs`). */
|
|
535
|
+
samples: number;
|
|
536
|
+
}
|
|
537
|
+
export interface ReservationTelemetrySandboxSeries {
|
|
538
|
+
started_at_ms: number | null;
|
|
539
|
+
destroyed_at_ms: number | null;
|
|
540
|
+
/** Empty when the read asked for a summary. */
|
|
541
|
+
rows: ReservationTelemetrySandboxRow[];
|
|
542
|
+
/** Present only when the read asked for a summary. */
|
|
543
|
+
summary?: ReservationTelemetrySandboxSummary;
|
|
544
|
+
}
|
|
545
|
+
export interface ReservationTelemetryHeader {
|
|
546
|
+
node_id: string;
|
|
547
|
+
instance_type: string | null;
|
|
548
|
+
logical_cpus: number;
|
|
549
|
+
physical_cores: number;
|
|
550
|
+
smt: boolean;
|
|
551
|
+
release_version: string;
|
|
552
|
+
window_from_ms: number;
|
|
553
|
+
window_to_ms: number;
|
|
554
|
+
/** Rows before this instant are 10-second buckets; null when the ring holds
|
|
555
|
+
* no rollups or the read asked for `stepSecs`. */
|
|
556
|
+
rollup_boundary_ms: number | null;
|
|
557
|
+
dropped_at_cap: boolean;
|
|
558
|
+
dropped_before_ms: number | null;
|
|
559
|
+
host_scan_ms_mean: number;
|
|
560
|
+
host_scan_ms_max: number;
|
|
561
|
+
host_scan_truncated: boolean;
|
|
562
|
+
}
|
|
563
|
+
/** The telemetry of one host of a reservation. */
|
|
564
|
+
export interface ReservationTelemetryDocument {
|
|
565
|
+
header: ReservationTelemetryHeader;
|
|
566
|
+
host: ReservationTelemetryHostRow[];
|
|
567
|
+
/** Keyed by sandbox id. */
|
|
568
|
+
sandboxes: Record<string, ReservationTelemetrySandboxSeries>;
|
|
569
|
+
/** When the document was archived; null while live. */
|
|
570
|
+
flushed_at_ms: number | null;
|
|
571
|
+
}
|
|
572
|
+
export interface ReservationTelemetry {
|
|
573
|
+
reservation: string;
|
|
574
|
+
state: "active" | "released" | "expired";
|
|
575
|
+
source: "live" | "archive";
|
|
576
|
+
from_ms: number;
|
|
577
|
+
to_ms: number;
|
|
578
|
+
/** One document per host that answered. */
|
|
579
|
+
nodes: ReservationTelemetryDocument[];
|
|
580
|
+
/** Hosts with nothing to show: unreachable while live, never flushed or past
|
|
581
|
+
* retention once archived. */
|
|
582
|
+
unavailable: string[];
|
|
583
|
+
}
|
|
584
|
+
export interface ReservationTelemetryOptions {
|
|
585
|
+
/** Window start, epoch milliseconds (default: 15 minutes before `to`). */
|
|
586
|
+
from?: number;
|
|
587
|
+
/** Window end, epoch milliseconds (default: now while active, the end of the archive after). */
|
|
588
|
+
to?: number;
|
|
589
|
+
/** `"none"` for host rows only, or up to 256 sandbox ids (each at most 128
|
|
590
|
+
* bytes, none of them `"none"`) to return (default: all). */
|
|
591
|
+
sandboxes?: "none" | string[];
|
|
592
|
+
/** Fold rows into aligned buckets of this many seconds (default: as recorded). */
|
|
593
|
+
stepSecs?: 10 | 60;
|
|
594
|
+
/** Replace each sandbox's rows with its totals. */
|
|
595
|
+
summary?: boolean;
|
|
596
|
+
}
|
|
469
597
|
export interface WaitOptions {
|
|
470
598
|
/**
|
|
471
599
|
* Have the gateway hold a still-pending claim for up to this many seconds
|
|
@@ -975,6 +1103,13 @@ declare class ReservationsResource {
|
|
|
975
1103
|
* (`retarget_cpu_incompatible`) or claims are waiting
|
|
976
1104
|
* (`retarget_claims_waiting`). */
|
|
977
1105
|
retarget(id: string, template: string): Promise<CapacityReservation>;
|
|
1106
|
+
/** The per-second host and per-sandbox rows a dedicated reservation's hosts
|
|
1107
|
+
* recorded: live while it is active, from the archive after. A packed host
|
|
1108
|
+
* is tens of MiB at full detail, so ask for what you need: `sandboxes: "none"`
|
|
1109
|
+
* or a list of ids, `stepSecs` for coarser rows, `summary` for per-sandbox
|
|
1110
|
+
* totals. 400 for a reservation that holds no host of its own or a bad
|
|
1111
|
+
* option; 404 for another tenant's reservation. */
|
|
1112
|
+
telemetry(id: string, options?: ReservationTelemetryOptions): Promise<ReservationTelemetry>;
|
|
978
1113
|
renew(id: string, input: {
|
|
979
1114
|
ttl_secs: number;
|
|
980
1115
|
idempotency_key: string;
|
package/sdk/dist/index.js
CHANGED
|
@@ -27,6 +27,8 @@ var BLACKCAT_ERROR_CODES = {
|
|
|
27
27
|
function withTemplate(input) {
|
|
28
28
|
return { ...input, template: input.template ?? "default" };
|
|
29
29
|
}
|
|
30
|
+
var MAX_TELEMETRY_SANDBOXES = 256;
|
|
31
|
+
var MAX_TELEMETRY_SANDBOX_ID_BYTES = 128;
|
|
30
32
|
function waitQuery({ wait_secs }) {
|
|
31
33
|
return wait_secs === undefined ? "" : `?wait_secs=${wait_secs}`;
|
|
32
34
|
}
|
|
@@ -459,6 +461,28 @@ class ReservationsResource {
|
|
|
459
461
|
retarget(id, template) {
|
|
460
462
|
return this.client.json("PUT", `/v1/capacity-reservations/${pathSegment(id)}/template`, { template }, "either");
|
|
461
463
|
}
|
|
464
|
+
async telemetry(id, options = {}) {
|
|
465
|
+
const query = new URLSearchParams;
|
|
466
|
+
if (options.from !== undefined)
|
|
467
|
+
query.set("from", String(options.from));
|
|
468
|
+
if (options.to !== undefined)
|
|
469
|
+
query.set("to", String(options.to));
|
|
470
|
+
if (options.sandboxes !== undefined) {
|
|
471
|
+
const ids = options.sandboxes === "none" ? ["none"] : options.sandboxes;
|
|
472
|
+
const unusable = (id2) => id2 === "" || id2.includes(",") || options.sandboxes !== "none" && id2 === "none" || new TextEncoder().encode(id2).length > MAX_TELEMETRY_SANDBOX_ID_BYTES;
|
|
473
|
+
if (ids.length === 0 || ids.length > MAX_TELEMETRY_SANDBOXES || ids.some(unusable)) {
|
|
474
|
+
throw new RangeError(`sandboxes must be "none" or 1 to ${MAX_TELEMETRY_SANDBOXES} sandbox ids of at most ` + `${MAX_TELEMETRY_SANDBOX_ID_BYTES} bytes, without commas, none of them "none"`);
|
|
475
|
+
}
|
|
476
|
+
query.set("sandboxes", ids.join(","));
|
|
477
|
+
}
|
|
478
|
+
if (options.stepSecs !== undefined)
|
|
479
|
+
query.set("step_secs", String(options.stepSecs));
|
|
480
|
+
if (options.summary === true)
|
|
481
|
+
query.set("summary", "1");
|
|
482
|
+
const search = query.toString();
|
|
483
|
+
const suffix = search === "" ? "" : `?${search}`;
|
|
484
|
+
return this.client.json("GET", `/v1/capacity-reservations/${pathSegment(id)}/telemetry${suffix}`, undefined, "either");
|
|
485
|
+
}
|
|
462
486
|
renew(id, input) {
|
|
463
487
|
return this.client.json("POST", `/v1/capacity-reservations/${pathSegment(id)}/renew`, input, "either");
|
|
464
488
|
}
|