@runblackcat/sdk 0.1.0-alpha.127 → 0.1.0-alpha.129

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@runblackcat/sdk",
3
- "version": "0.1.0-alpha.127",
3
+ "version": "0.1.0-alpha.129",
4
4
  "description": "TypeScript SDK for the Blackcat sandbox gateway",
5
5
  "license": "Apache-2.0",
6
6
  "repository": "https://github.com/TreebeardHQ/blackcat",
@@ -466,6 +466,118 @@ export type CapacityReservation = CapacityReservationBase & ({
466
466
  };
467
467
  count?: never;
468
468
  });
469
+ /** CPU busy time by the class of thread that spent it, in millicores. */
470
+ export interface ReservationTelemetryClassCpu {
471
+ vcpu: number;
472
+ vmm: number;
473
+ agent: number;
474
+ uffd: number;
475
+ ublk: number;
476
+ kernel: number;
477
+ other: number;
478
+ }
479
+ /**
480
+ * What the host as a whole did during one interval: `at_ms` is its start and
481
+ * `span_secs` its length. CPU, memory and the sandbox count are means over the
482
+ * span as recorded; disk and network fields are bytes moved over the span.
483
+ * With `stepSecs`, a row is a bucket: CPU is the span-weighted mean, memory
484
+ * and `running_sandboxes` the largest value (`mem_available_bytes` the
485
+ * smallest), bytes the sum.
486
+ */
487
+ export interface ReservationTelemetryHostRow {
488
+ at_ms: number;
489
+ span_secs: number;
490
+ busy_mcpu: number;
491
+ class_mcpu: ReservationTelemetryClassCpu;
492
+ mem_used_bytes: number;
493
+ mem_available_bytes: number;
494
+ disk_read_bytes: number;
495
+ disk_write_bytes: number;
496
+ net_rx_bytes: number;
497
+ net_tx_bytes: number;
498
+ running_sandboxes: number;
499
+ }
500
+ /** One sandbox's interval. A field is null when the node could not read it:
501
+ * unknown, never zero. With `stepSecs`, CPU and stall are sums and RSS the
502
+ * largest reading. */
503
+ export interface ReservationTelemetrySandboxRow {
504
+ at_ms: number;
505
+ span_secs: number;
506
+ cpu_usec: number | null;
507
+ stall_usec: number | null;
508
+ rss_bytes: number | null;
509
+ }
510
+ /** A sandbox's totals, in place of its rows, when the read asked for a summary. */
511
+ export interface ReservationTelemetrySandboxSummary {
512
+ started_at_ms: number | null;
513
+ destroyed_at_ms: number | null;
514
+ /** Null when no row had a reading: unknown, never zero. */
515
+ cpu_usec_total: number | null;
516
+ stall_usec_total: number | null;
517
+ rss_peak_bytes: number | null;
518
+ /** Rows folded, at the resolution recorded (before any `stepSecs`). */
519
+ samples: number;
520
+ }
521
+ export interface ReservationTelemetrySandboxSeries {
522
+ started_at_ms: number | null;
523
+ destroyed_at_ms: number | null;
524
+ /** Empty when the read asked for a summary. */
525
+ rows: ReservationTelemetrySandboxRow[];
526
+ /** Present only when the read asked for a summary. */
527
+ summary?: ReservationTelemetrySandboxSummary;
528
+ }
529
+ export interface ReservationTelemetryHeader {
530
+ node_id: string;
531
+ instance_type: string | null;
532
+ logical_cpus: number;
533
+ physical_cores: number;
534
+ smt: boolean;
535
+ release_version: string;
536
+ window_from_ms: number;
537
+ window_to_ms: number;
538
+ /** Rows before this instant are 10-second buckets; null when the ring holds
539
+ * no rollups or the read asked for `stepSecs`. */
540
+ rollup_boundary_ms: number | null;
541
+ dropped_at_cap: boolean;
542
+ dropped_before_ms: number | null;
543
+ host_scan_ms_mean: number;
544
+ host_scan_ms_max: number;
545
+ host_scan_truncated: boolean;
546
+ }
547
+ /** The telemetry of one host of a reservation. */
548
+ export interface ReservationTelemetryDocument {
549
+ header: ReservationTelemetryHeader;
550
+ host: ReservationTelemetryHostRow[];
551
+ /** Keyed by sandbox id. */
552
+ sandboxes: Record<string, ReservationTelemetrySandboxSeries>;
553
+ /** When the document was archived; null while live. */
554
+ flushed_at_ms: number | null;
555
+ }
556
+ export interface ReservationTelemetry {
557
+ reservation: string;
558
+ state: "active" | "released" | "expired";
559
+ source: "live" | "archive";
560
+ from_ms: number;
561
+ to_ms: number;
562
+ /** One document per host that answered. */
563
+ nodes: ReservationTelemetryDocument[];
564
+ /** Hosts with nothing to show: unreachable while live, never flushed or past
565
+ * retention once archived. */
566
+ unavailable: string[];
567
+ }
568
+ export interface ReservationTelemetryOptions {
569
+ /** Window start, epoch milliseconds (default: 15 minutes before `to`). */
570
+ from?: number;
571
+ /** Window end, epoch milliseconds (default: now while active, the end of the archive after). */
572
+ to?: number;
573
+ /** `"none"` for host rows only, or up to 256 sandbox ids (each at most 128
574
+ * bytes, none of them `"none"`) to return (default: all). */
575
+ sandboxes?: "none" | string[];
576
+ /** Fold rows into aligned buckets of this many seconds (default: as recorded). */
577
+ stepSecs?: 10 | 60;
578
+ /** Replace each sandbox's rows with its totals. */
579
+ summary?: boolean;
580
+ }
469
581
  export interface WaitOptions {
470
582
  /**
471
583
  * Have the gateway hold a still-pending claim for up to this many seconds
@@ -975,6 +1087,13 @@ declare class ReservationsResource {
975
1087
  * (`retarget_cpu_incompatible`) or claims are waiting
976
1088
  * (`retarget_claims_waiting`). */
977
1089
  retarget(id: string, template: string): Promise<CapacityReservation>;
1090
+ /** The per-second host and per-sandbox rows a dedicated reservation's hosts
1091
+ * recorded: live while it is active, from the archive after. A packed host
1092
+ * is tens of MiB at full detail, so ask for what you need: `sandboxes: "none"`
1093
+ * or a list of ids, `stepSecs` for coarser rows, `summary` for per-sandbox
1094
+ * totals. 400 for a reservation that holds no host of its own or a bad
1095
+ * option; 404 for another tenant's reservation. */
1096
+ telemetry(id: string, options?: ReservationTelemetryOptions): Promise<ReservationTelemetry>;
978
1097
  renew(id: string, input: {
979
1098
  ttl_secs: number;
980
1099
  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
  }