hammerkit 1.27.0-next.30 → 1.27.0-next.31

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 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32"><rect width="32" height="32" rx="7" fill="#059669"/><path d="M9 8h4v6h6V8h4v16h-4v-6h-6v6H9z" fill="#fff"/></svg>
@@ -0,0 +1,15 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
6
+ <meta name="robots" content="noindex" />
7
+ <link rel="icon" href="/favicon.svg" type="image/svg+xml" />
8
+ <title>hammerkit</title>
9
+ <script type="module" crossorigin src="/assets/index-zPXa4klZ.js"></script>
10
+ <link rel="stylesheet" crossorigin href="/assets/index-CjnKm5-3.css">
11
+ </head>
12
+ <body>
13
+ <div id="root"></div>
14
+ </body>
15
+ </html>
@@ -24,6 +24,7 @@ function createKubernetesInstances(kubernetes) {
24
24
  return {
25
25
  objectApi,
26
26
  log: new client_node_1.Log(kc),
27
+ metrics: new client_node_1.Metrics(kc),
27
28
  exec,
28
29
  appsApi,
29
30
  coreApi,
@@ -178,6 +178,9 @@ passthrough = []) {
178
178
  if (me.repos.length > 0) {
179
179
  environment.stdout.write(`repositories: ${me.repos.map(server_client_1.printable).join(', ')}\n`);
180
180
  }
181
+ if (me.observe) {
182
+ environment.stdout.write('you observe every run of the server, see them with: hammerkit remote runs --all\n');
183
+ }
181
184
  }));
182
185
  (0, remote_work_commands_1.registerWorkCommands)(remote, {
183
186
  environment,
@@ -0,0 +1,112 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.describeTaskStats = exports.describeCapacity = exports.describeOverview = exports.describeServiceRun = exports.describeWork = exports.describeWait = void 0;
7
+ const colors_1 = __importDefault(require("colors"));
8
+ const capacity_format_1 = require("../server/capacity-format");
9
+ const timings_1 = require("../server/timings");
10
+ const wait_reason_1 = require("../server/wait-reason");
11
+ Object.defineProperty(exports, "describeWait", { enumerable: true, get: function () { return wait_reason_1.describeWait; } });
12
+ const server_client_1 = require("./server-client");
13
+ // What a run does, in a few words: its tasks, or the services it keeps up.
14
+ function describeWork(run) {
15
+ if (run.up) {
16
+ return `${(0, server_client_1.printable)(run.up.name)}: up ${run.up.services.map(server_client_1.printable).join(', ')}`;
17
+ }
18
+ return run.tasks.length > 0 ? run.tasks.map(server_client_1.printable).join(', ') : 'by labels';
19
+ }
20
+ exports.describeWork = describeWork;
21
+ function ownerOf(run) {
22
+ return run.owner ? ` of ${(0, server_client_1.printable)(run.owner.sub)}` : '';
23
+ }
24
+ function describeMeter(name, meter) {
25
+ const full = meter.limit !== undefined && meter.used >= meter.limit;
26
+ const count = `${meter.used}${meter.limit !== undefined ? ` of ${meter.limit}` : ''}`;
27
+ return ` ${name.padEnd(9)} ${count.padEnd(9)} ${meter.runs.length > 0 ? meter.runs.map(server_client_1.printable).join(', ') : '-'}${full ? colors_1.default.yellow(' full') : ''}`;
28
+ }
29
+ // A service run on one line, then a line per endpoint: when it ends, when it sleeps.
30
+ function describeServiceRun(run) {
31
+ const times = [
32
+ run.state === 'up' || run.state === 'asleep' ? (run.expiresAt ? `until ${run.expiresAt}` : '') : '',
33
+ run.state === 'up' && run.sleepsAt ? `sleeps at ${run.sleepsAt}` : '',
34
+ run.wakes ? `woken ${run.wakes}×` : '',
35
+ ].filter(Boolean);
36
+ return [
37
+ ` ${(0, server_client_1.printable)(run.id)} ${(0, server_client_1.printable)(run.state)} ${describeWork(run)}${ownerOf(run)}${times.length > 0 ? ` ${(0, server_client_1.printable)(times.join(', '))}` : ''}`,
38
+ ...(run.up?.endpoints ?? []).map((endpoint) => ` ${(0, server_client_1.printable)(endpoint.service)}:${endpoint.port}${endpoint.url ? ` ${(0, server_client_1.printable)(endpoint.url)}` : ''}`),
39
+ ];
40
+ }
41
+ exports.describeServiceRun = describeServiceRun;
42
+ // What `hammerkit remote status` prints: the places, the queue, the caller's limits.
43
+ function describeOverview(server, overview, now = Date.now()) {
44
+ const lines = [
45
+ `${(0, server_client_1.printable)(server)}: signed in as ${(0, server_client_1.printable)(overview.you.sub)}${overview.you.observe ? ', you observe every run' : ''}`,
46
+ `places: ${overview.places.used} of ${overview.places.max} taken (runs.maxConcurrent)`,
47
+ ...overview.places.runs.map((run) => ` ${(0, server_client_1.printable)(run.id)} ${describeWork(run)}${ownerOf(run)}${run.startedAt ? ` since ${(0, server_client_1.printable)(run.startedAt)}, ${(0, timings_1.roughly)((0, timings_1.ranMs)(run, now) ?? 0)}` : ''}`),
48
+ ];
49
+ if (overview.places.others > 0) {
50
+ lines.push(` ${overview.places.others} ${overview.places.others === 1 ? 'run' : 'runs'} of others`);
51
+ }
52
+ // a place a run holds that is not running: a service run waking up, or a place not given back
53
+ const unaccounted = overview.places.used - overview.places.runs.length - overview.places.others;
54
+ if (unaccounted > 0) {
55
+ lines.push(` ${unaccounted} taken by no running run`);
56
+ }
57
+ lines.push(`queue: ${overview.queue.length === 0 ? 'empty' : overview.queue.length}`);
58
+ for (const entry of overview.queue) {
59
+ const waited = entry.run ? (0, timings_1.waitedMs)(entry.run, now) : undefined;
60
+ const what = entry.run
61
+ ? `${(0, server_client_1.printable)(entry.run.id)} ${describeWork(entry.run)}${ownerOf(entry.run)}${waited !== undefined ? ` waiting ${(0, timings_1.roughly)(waited)}` : ''}`
62
+ : 'a run of somebody else';
63
+ lines.push(` ${entry.position}. ${what} waits: ${(0, server_client_1.printable)((0, wait_reason_1.describeWait)(entry.waitsFor, entry.mine))}`);
64
+ }
65
+ lines.push(`waiting for an approval: ${overview.approvals.waiting} of at most ${overview.approvals.max}`);
66
+ for (const run of overview.approvals.runs) {
67
+ const accounts = (run.approvals ?? [])
68
+ .filter((approval) => !approval.approvedBy)
69
+ .map((approval) => approval.account);
70
+ lines.push(` ${(0, server_client_1.printable)(run.id)} ${describeWork(run)}${ownerOf(run)} needs ${accounts
71
+ .map(server_client_1.printable)
72
+ .join(', ')} until ${(0, server_client_1.printable)(run.approvals?.[0]?.expiresAt ?? '-')}`);
73
+ }
74
+ lines.push(`service runs: ${overview.services.open}${overview.services.max !== undefined ? ` of ${overview.services.max}` : ''} places taken on the server`);
75
+ for (const run of overview.services.runs) {
76
+ lines.push(...describeServiceRun(run));
77
+ }
78
+ lines.push('your limits:', describeMeter('running', overview.limits.running), describeMeter('queued', overview.limits.queued), describeMeter('approval', overview.limits.waiting), describeMeter('services', overview.limits.services), ...(overview.limits.asleep ? [describeMeter('asleep', overview.limits.asleep)] : []));
79
+ return lines;
80
+ }
81
+ exports.describeOverview = describeOverview;
82
+ // The machines of the server and what runs take of them, for `remote capacity`; `short` for
83
+ // the two lines of `remote status`.
84
+ function describeCapacity(capacity, short = false) {
85
+ const { machines, runs } = capacity;
86
+ const resources = (value) => value ? `${(0, capacity_format_1.formatCpu)(value.cpu)} CPU, ${(0, capacity_format_1.formatMemory)(value.memory)}` : '?';
87
+ const kind = capacity.backend === 'kubernetes' ? (machines?.count === 1 ? 'node' : 'nodes') : 'machine';
88
+ const lines = [
89
+ `capacity: ${machines
90
+ ? `${machines.count} ${kind} with ${resources(machines.allocatable)}`
91
+ : 'what the machines have is not known'}${machines?.used ? `, ${resources(machines.used)} in use` : ''}${machines?.load ? `, load ${machines.load.map((load) => load.toFixed(2)).join(' ')}` : ''}`,
92
+ ` runs: ${runs.pods !== undefined ? `${(0, capacity_format_1.plural)(runs.pods, 'pod')}, ` : ''}${runs.containers !== undefined ? `${runs.containers} containers, ` : ''}${capacity.backend === 'kubernetes' ? `requested ${resources(runs.requested)}` : ''}${runs.used ? `${capacity.backend === 'kubernetes' ? ', ' : ''}in use ${resources(runs.used)}` : ''}`,
93
+ ];
94
+ if (short) {
95
+ return lines;
96
+ }
97
+ for (const group of capacity.groups) {
98
+ lines.push(` ${(0, server_client_1.printable)(group.name)} ${group.kind === 'service-run' ? 'service run' : 'caller'}${group.owner ? ` of ${(0, server_client_1.printable)(group.owner.sub)}` : ''}${group.run ? ` ${(0, server_client_1.printable)(group.run)}` : ''} ${(0, capacity_format_1.plural)(group.pods ?? 0, 'pod')} requested ${resources(group.requested)}${group.quota ? ` of ${resources(group.quota)}` : ''}${group.used ? ` in use ${resources(group.used)}` : ''}`);
99
+ }
100
+ for (const problem of capacity.problems) {
101
+ lines.push(colors_1.default.yellow(` not shown: ${(0, server_client_1.printable)(problem)}`));
102
+ }
103
+ return lines;
104
+ }
105
+ exports.describeCapacity = describeCapacity;
106
+ // What the past runs of each task took, for `remote tasks`.
107
+ function describeTaskStats(stats) {
108
+ const span = (ms) => (ms === undefined ? '-' : (0, timings_1.roughly)(ms));
109
+ return stats.map((entry) => `${(0, server_client_1.printable)(entry.task)} ${(0, server_client_1.printable)(entry.repo)} last ${(0, server_client_1.printable)(entry.last.status)} ${(0, server_client_1.printable)(entry.last.at)}${entry.last.durationMs !== undefined ? ` took ${(0, timings_1.roughly)(entry.last.durationMs)}` : ''} ${(0, capacity_format_1.plural)(entry.runs, 'run')}${entry.failed ? `, ${entry.failed} failed` : ''}${entry.cached ? `, ${entry.cached} cached` : ''} median ${span(entry.medianMs)}, 90% ${span(entry.p90Ms)}, waited ${span(entry.medianWaitMs)}`);
110
+ }
111
+ exports.describeTaskStats = describeTaskStats;
112
+ //# sourceMappingURL=remote-status.js.map
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.registerWorkCommands = exports.describePlan = exports.describeApproval = exports.describeListedRun = exports.describeRunEnd = void 0;
6
+ exports.registerWorkCommands = exports.describePlan = exports.describeApproval = exports.keepRuns = exports.describeListedRun = exports.describeRunEnd = void 0;
7
7
  const commander_1 = require("commander");
8
8
  const colors_1 = __importDefault(require("colors"));
9
9
  const token_source_1 = require("./token-source");
@@ -17,6 +17,8 @@ const units_1 = require("../utils/units");
17
17
  const service_tools_1 = require("../harness/service-tools");
18
18
  const path_1 = require("path");
19
19
  const check_keys_1 = require("../optimizer/check-keys");
20
+ const remote_status_1 = require("./remote-status");
21
+ const timings_1 = require("../server/timings");
20
22
  const terminal_prompt_1 = require("../utils/terminal-prompt");
21
23
  function describeOutcome(planned) {
22
24
  switch (planned.outcome) {
@@ -86,13 +88,28 @@ function describeRunEnd(run) {
86
88
  return lines;
87
89
  }
88
90
  exports.describeRunEnd = describeRunEnd;
89
- // What `remote runs` shows of a run, on one line.
90
- function describeListedRun(run) {
91
+ // What `remote runs` shows of a run, on one line: how long it waited for a place and ran.
92
+ function describeListedRun(run, now = Date.now()) {
91
93
  const what = run.up ? `up ${run.up.services.join(', ')}` : run.tasks.join(', ') || 'by labels';
92
94
  const until = run.up && (run.state === 'up' || run.state === 'asleep') && run.expiresAt ? ` until ${run.expiresAt}` : '';
93
- return `${(0, server_client_1.printable)(run.id)} ${(0, server_client_1.printable)(run.createdAt)} ${(0, server_client_1.printable)(run.state)}${(0, server_client_1.printable)(until)} ${(0, server_client_1.printable)(what)}${run.error ? `: ${(0, server_client_1.printable)(run.error)}` : ''}`;
95
+ const queue = run.queue
96
+ ? ` (${run.queue.position}. in the queue, waits: ${(0, server_client_1.printable)((0, remote_status_1.describeWait)(run.queue.waitsFor, !run.owner))})`
97
+ : '';
98
+ const waited = (0, timings_1.waitedMs)(run, now);
99
+ const ran = (0, timings_1.ranMs)(run, now);
100
+ const times = [
101
+ waited !== undefined ? `waited ${(0, timings_1.roughly)(waited)}` : '',
102
+ ran !== undefined ? `${run.up ? 'up after' : 'ran'} ${(0, timings_1.roughly)(ran)}` : '',
103
+ ].filter(Boolean);
104
+ return `${(0, server_client_1.printable)(run.id)} ${(0, server_client_1.printable)(run.createdAt)} ${(0, server_client_1.printable)(run.state)}${(0, server_client_1.printable)(until)}${queue} ${(0, server_client_1.printable)(what)}${run.owner ? ` of ${(0, server_client_1.printable)(run.owner.sub)}` : ''}${times.length > 0 ? ` ${times.join(', ')}` : ''}${run.error ? `: ${(0, server_client_1.printable)(run.error)}` : ''}`;
94
105
  }
95
106
  exports.describeListedRun = describeListedRun;
107
+ // What a server from before the filters of GET /v1/runs answers is filtered here, so an
108
+ // older server never shows task runs as service runs.
109
+ function keepRuns(runs, states, kind) {
110
+ return runs.filter((run) => (!states || states.includes(run.state)) && (!kind || (kind === 'services') === !!run.up));
111
+ }
112
+ exports.keepRuns = keepRuns;
96
113
  // What a person who approves is shown of a run: everything the decision rests on.
97
114
  function describeApproval(run) {
98
115
  const source = run.source.type === 'ref'
@@ -444,19 +461,121 @@ function registerWorkCommands(remote, context) {
444
461
  }
445
462
  environment.stdout.write(`extend it with: hammerkit remote extend ${(0, server_client_1.printable)(run.id)} 8h, stop it with: hammerkit remote stop ${(0, server_client_1.printable)(run.id)}\n`);
446
463
  }));
464
+ remote
465
+ .command('status [server]')
466
+ .description('show how a server stands for you: the places that run, the queue and why each run in it waits, your limits and the runs that count against them, your service runs')
467
+ .addOption(new commander_1.Option('--json', 'print the overview as the server answers it, for scripts and agents'))
468
+ .action(guarded('Remote status was not successful', async (name, options) => {
469
+ const { name: serverName, server, token } = await connect(name);
470
+ const overview = (await (0, server_client_1.callServer)(server, token, 'GET', '/v1/overview')).body;
471
+ if (options.json) {
472
+ environment.stdout.write(`${JSON.stringify(overview, null, 2)}\n`);
473
+ return;
474
+ }
475
+ for (const line of (0, remote_status_1.describeOverview)(serverName, overview)) {
476
+ environment.stdout.write(`${line}\n`);
477
+ }
478
+ // a server from before /v1/capacity, or one that can not read it, prints without
479
+ const capacity = await (0, server_client_1.callServer)(server, token, 'GET', '/v1/capacity').catch(() => undefined);
480
+ if (capacity) {
481
+ for (const line of (0, remote_status_1.describeCapacity)(capacity.body, true)) {
482
+ environment.stdout.write(`${line}\n`);
483
+ }
484
+ }
485
+ }));
486
+ remote
487
+ .command('capacity [server]')
488
+ .description('show what the machines of a server have and what its runs take: CPU and memory requested and in use, per namespace on Kubernetes')
489
+ .addOption(new commander_1.Option('--json', 'print it as the server answers it'))
490
+ .action(guarded('Remote capacity was not successful', async (name, options) => {
491
+ const { server, token } = await connect(name);
492
+ const capacity = (await (0, server_client_1.callServer)(server, token, 'GET', '/v1/capacity')).body;
493
+ if (options.json) {
494
+ environment.stdout.write(`${JSON.stringify(capacity, null, 2)}\n`);
495
+ return;
496
+ }
497
+ for (const line of (0, remote_status_1.describeCapacity)(capacity)) {
498
+ environment.stdout.write(`${line}\n`);
499
+ }
500
+ }));
501
+ remote
502
+ .command('tasks [server]')
503
+ .description('show what the past runs of each task took, over the runs the server keeps: how often it ran, failed and came from the cache, the median and 90th percentile of its time, and how long its runs waited for a place')
504
+ .addOption(new commander_1.Option('--mine', 'only your runs'))
505
+ .addOption(new commander_1.Option('--json', 'print it as the server answers it'))
506
+ .action(guarded('Remote tasks was not successful', async (name, options) => {
507
+ const { name: serverName, server, token } = await connect(name);
508
+ const { tasks } = (await (0, server_client_1.callServer)(server, token, 'GET', `/v1/tasks?scope=${options.mine ? 'mine' : 'visible'}`)).body;
509
+ if (options.json) {
510
+ environment.stdout.write(`${JSON.stringify(tasks, null, 2)}\n`);
511
+ return;
512
+ }
513
+ if (tasks.length === 0) {
514
+ environment.stdout.write(`${serverName}: no task ran in the runs it keeps\n`);
515
+ return;
516
+ }
517
+ for (const line of (0, remote_status_1.describeTaskStats)(tasks)) {
518
+ environment.stdout.write(`${line}\n`);
519
+ }
520
+ }));
521
+ remote
522
+ .command('dashboard [server]')
523
+ .description('print the address of the dashboard of a server, the pages of remote status, services, runs and logs')
524
+ .action(guarded('Remote dashboard was not successful', async (name) => {
525
+ const { name: serverName, server } = await getServer(name);
526
+ const discovery = await (0, server_client_1.getDiscovery)(server);
527
+ if (!discovery.dashboard) {
528
+ throw new Error(`${serverName} has no dashboard: it needs endpoints with a login in its config, see https://hammerkit.dev/docs/remote-compute/status#dashboard`);
529
+ }
530
+ environment.stdout.write(`${(0, server_client_1.printable)(discovery.dashboard)}\n`);
531
+ }));
532
+ remote
533
+ .command('services [server]')
534
+ .description('list the service runs that are starting, up or asleep: yours, and those whose endpoints you may open, with their addresses and when they end or sleep')
535
+ .addOption(new commander_1.Option('--ended', 'also the ones that ended, as long as the server keeps them'))
536
+ .action(guarded('Remote services was not successful', async (name, options) => {
537
+ const { name: serverName, server, token } = await connect(name);
538
+ const open = ['awaiting-approval', 'queued', 'running', 'up', 'asleep'];
539
+ const states = options.ended ? '' : `&state=${open.join(',')}`;
540
+ const runs = keepRuns((await (0, server_client_1.callServer)(server, token, 'GET', `/v1/runs?scope=visible&kind=services${states}`)).body.runs, options.ended ? undefined : open, 'services');
541
+ if (runs.length === 0) {
542
+ environment.stdout.write(`${serverName}: no service runs${options.ended ? '' : ' are starting, up or asleep'}\n`);
543
+ return;
544
+ }
545
+ for (const run of runs) {
546
+ for (const line of (0, remote_status_1.describeServiceRun)(run)) {
547
+ environment.stdout.write(`${line}\n`);
548
+ }
549
+ }
550
+ }));
447
551
  remote
448
552
  .command('runs [server]')
449
- .description('list your runs on a server, newest first: their state, and why one failed')
553
+ .description('list your runs on a server, newest first: their state, where a queued one stands, and why one failed')
450
554
  .addOption(new commander_1.Option('--limit <count>', 'show at most this many').default('20'))
555
+ .addOption(new commander_1.Option('--state <states>', 'only runs in these states, comma separated: awaiting-approval, queued, running, up, asleep, succeeded, failed, cancelled, rejected'))
556
+ .addOption(new commander_1.Option('--services', 'only service runs').conflicts('tasks'))
557
+ .addOption(new commander_1.Option('--tasks', 'only runs of tasks'))
558
+ .addOption(new commander_1.Option('--all', 'also the runs of others you may see: those you may approve, service runs you may open, every run with observe'))
451
559
  .action(guarded('Remote runs was not successful', async (name, options) => {
452
560
  const limit = Number(options.limit);
453
561
  if (!Number.isInteger(limit) || limit < 1) {
454
562
  throw new Error('--limit is a number of runs, 1 or more');
455
563
  }
564
+ const query = new URLSearchParams();
565
+ if (options.all) {
566
+ query.set('scope', 'visible');
567
+ }
568
+ if (options.state) {
569
+ query.set('state', options.state);
570
+ }
571
+ if (options.services || options.tasks) {
572
+ query.set('kind', options.services ? 'services' : 'tasks');
573
+ }
456
574
  const { name: serverName, server, token } = await connect(name);
457
- const { runs } = (await (0, server_client_1.callServer)(server, token, 'GET', '/v1/runs')).body;
575
+ const path = `/v1/runs${query.toString() ? `?${query}` : ''}`;
576
+ const runs = keepRuns((await (0, server_client_1.callServer)(server, token, 'GET', path)).body.runs, options.state ? String(options.state).split(',') : undefined, options.services ? 'services' : options.tasks ? 'tasks' : undefined);
458
577
  if (runs.length === 0) {
459
- environment.stdout.write(`${serverName}: you have no runs it still keeps\n`);
578
+ environment.stdout.write(`${serverName}: ${query.toString() ? 'no runs it keeps are like that' : 'you have no runs it still keeps'}\n`);
460
579
  return;
461
580
  }
462
581
  for (const run of runs.slice(0, limit)) {
@@ -34,6 +34,7 @@ async function handleAccounts(config, log, principal, req, res, url) {
34
34
  checks: grant.checks || grant.builds !== null ? 'read' : null,
35
35
  sandboxes: grant.sandboxes,
36
36
  endpoints: grant.endpoints,
37
+ observe: grant.observe,
37
38
  });
38
39
  return true;
39
40
  }
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ // How CPU and memory read, for the dashboard and the CLI (without the clients of capacity.ts).
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.formatMemory = exports.plural = exports.formatCpu = void 0;
5
+ // cores as a person reads them: 0.25, 1.5, 12
6
+ function formatCpu(cores) {
7
+ if (cores === undefined) {
8
+ return '?';
9
+ }
10
+ if (cores === 0) {
11
+ return '0';
12
+ }
13
+ return cores < 10 ? String(Math.round(cores * 100) / 100) : String(Math.round(cores * 10) / 10);
14
+ }
15
+ exports.formatCpu = formatCpu;
16
+ // a count and what it counts: 1 pod, 2 pods
17
+ function plural(count, one, more = `${one}s`) {
18
+ return `${count} ${count === 1 ? one : more}`;
19
+ }
20
+ exports.plural = plural;
21
+ // bytes as a person reads them: 512 MiB, 3.4 GiB
22
+ function formatMemory(bytes) {
23
+ if (bytes === undefined) {
24
+ return '?';
25
+ }
26
+ const units = ['B', 'KiB', 'MiB', 'GiB', 'TiB'];
27
+ let value = bytes;
28
+ let unit = 0;
29
+ while (value >= 1024 && unit < units.length - 1) {
30
+ value /= 1024;
31
+ unit++;
32
+ }
33
+ return `${value < 10 && unit > 0 ? Math.round(value * 10) / 10 : Math.round(value)} ${units[unit]}`;
34
+ }
35
+ exports.formatMemory = formatMemory;
36
+ //# sourceMappingURL=capacity-format.js.map