@agoric/internal 0.3.3-other-dev-8f8782b.0 → 0.3.3-other-dev-fbe72e7.0.fbe72e7

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.
Files changed (131) hide show
  1. package/README.md +7 -2
  2. package/exported.js +2 -0
  3. package/package.json +41 -19
  4. package/src/action-types.d.ts +51 -5
  5. package/src/action-types.d.ts.map +1 -1
  6. package/src/action-types.js +74 -15
  7. package/src/batched-deliver.d.ts +9 -6
  8. package/src/batched-deliver.d.ts.map +1 -1
  9. package/src/batched-deliver.js +9 -3
  10. package/src/callback.d.ts +24 -17
  11. package/src/callback.d.ts.map +1 -1
  12. package/src/callback.js +55 -61
  13. package/src/chain-storage-paths.d.ts +2 -3
  14. package/src/chain-storage-paths.d.ts.map +1 -1
  15. package/src/chain-storage-paths.js +2 -3
  16. package/src/chain-utils.d.ts +27 -0
  17. package/src/chain-utils.d.ts.map +1 -0
  18. package/src/chain-utils.js +62 -0
  19. package/src/cli-utils.d.ts +2 -0
  20. package/src/cli-utils.d.ts.map +1 -0
  21. package/src/cli-utils.js +21 -0
  22. package/src/config.d.ts +22 -12
  23. package/src/config.d.ts.map +1 -1
  24. package/src/config.js +23 -10
  25. package/src/debug.d.ts +1 -1
  26. package/src/errors.d.ts +2 -0
  27. package/src/errors.d.ts.map +1 -0
  28. package/src/errors.js +16 -0
  29. package/src/hex.d.ts +15 -0
  30. package/src/hex.d.ts.map +1 -0
  31. package/src/hex.js +105 -0
  32. package/src/index.d.ts +10 -1
  33. package/src/index.js +13 -2
  34. package/src/install-ses-debug.d.ts +2 -0
  35. package/src/install-ses-debug.d.ts.map +1 -0
  36. package/src/install-ses-debug.js +6 -0
  37. package/src/js-utils.d.ts +40 -0
  38. package/src/js-utils.d.ts.map +1 -0
  39. package/src/js-utils.js +237 -0
  40. package/src/lib-chainStorage.d.ts +59 -67
  41. package/src/lib-chainStorage.d.ts.map +1 -1
  42. package/src/lib-chainStorage.js +95 -92
  43. package/src/lib-nodejs/ava-unhandled-rejection.d.ts +13 -0
  44. package/src/lib-nodejs/ava-unhandled-rejection.d.ts.map +1 -0
  45. package/src/lib-nodejs/ava-unhandled-rejection.js +66 -0
  46. package/src/lib-nodejs/engine-gc.d.ts +3 -0
  47. package/src/lib-nodejs/engine-gc.d.ts.map +1 -0
  48. package/src/lib-nodejs/engine-gc.js +22 -0
  49. package/src/lib-nodejs/gc-and-finalize.d.ts +2 -0
  50. package/src/lib-nodejs/gc-and-finalize.d.ts.map +1 -0
  51. package/src/lib-nodejs/gc-and-finalize.js +91 -0
  52. package/src/lib-nodejs/spawnSubprocessWorker.d.ts +15 -0
  53. package/src/lib-nodejs/spawnSubprocessWorker.d.ts.map +1 -0
  54. package/src/lib-nodejs/spawnSubprocessWorker.js +89 -0
  55. package/src/lib-nodejs/waitUntilQuiescent.d.ts +2 -0
  56. package/src/lib-nodejs/waitUntilQuiescent.d.ts.map +1 -0
  57. package/src/lib-nodejs/waitUntilQuiescent.js +18 -0
  58. package/src/lib-nodejs/worker-protocol.d.ts +4 -0
  59. package/src/lib-nodejs/worker-protocol.d.ts.map +1 -0
  60. package/src/lib-nodejs/worker-protocol.js +54 -0
  61. package/src/magic-cookie-test-only.js +2 -2
  62. package/src/marshal.d.ts +33 -0
  63. package/src/marshal.d.ts.map +1 -0
  64. package/src/marshal.js +156 -0
  65. package/src/method-tools.d.ts +1 -0
  66. package/src/method-tools.d.ts.map +1 -1
  67. package/src/method-tools.js +33 -62
  68. package/src/metrics.d.ts +183 -0
  69. package/src/metrics.d.ts.map +1 -0
  70. package/src/metrics.js +476 -0
  71. package/src/module-utils.d.ts +2 -0
  72. package/src/module-utils.d.ts.map +1 -0
  73. package/src/module-utils.js +27 -0
  74. package/src/natural-sort.d.ts +2 -0
  75. package/src/natural-sort.d.ts.map +1 -0
  76. package/src/natural-sort.js +48 -0
  77. package/src/netstring.d.ts +24 -0
  78. package/src/netstring.d.ts.map +1 -0
  79. package/src/netstring.js +125 -0
  80. package/src/node/buffer-line-transform.d.ts +20 -16
  81. package/src/node/buffer-line-transform.d.ts.map +1 -1
  82. package/src/node/buffer-line-transform.js +12 -9
  83. package/src/node/createBundles.d.ts.map +1 -1
  84. package/src/node/createBundles.js +12 -3
  85. package/src/node/fs-stream.d.ts +1 -1
  86. package/src/node/fs-stream.d.ts.map +1 -1
  87. package/src/node/fs-stream.js +48 -37
  88. package/src/node/shutdown.d.ts.map +1 -1
  89. package/src/node/shutdown.js +0 -1
  90. package/src/priority-senders.d.ts +2 -1
  91. package/src/priority-senders.d.ts.map +1 -1
  92. package/src/priority-senders.js +10 -4
  93. package/src/queue.d.ts +1 -1
  94. package/src/queue.d.ts.map +1 -1
  95. package/src/queue.js +7 -8
  96. package/src/scratch.d.ts +1 -1
  97. package/src/scratch.d.ts.map +1 -1
  98. package/src/ses-utils.d.ts +68 -0
  99. package/src/ses-utils.d.ts.map +1 -0
  100. package/src/ses-utils.js +422 -0
  101. package/src/storage-test-utils.d.ts +49 -84
  102. package/src/storage-test-utils.d.ts.map +1 -1
  103. package/src/storage-test-utils.js +234 -116
  104. package/src/tagged.d.ts +152 -0
  105. package/src/testing-utils.d.ts +2 -0
  106. package/src/testing-utils.d.ts.map +1 -1
  107. package/src/testing-utils.js +44 -5
  108. package/src/tmpDir.d.ts +2 -0
  109. package/src/tmpDir.d.ts.map +1 -0
  110. package/src/tmpDir.js +17 -0
  111. package/src/tokens.d.ts +34 -0
  112. package/src/tokens.d.ts.map +1 -0
  113. package/src/tokens.js +35 -0
  114. package/src/typeCheck.d.ts +9 -0
  115. package/src/typeCheck.d.ts.map +1 -0
  116. package/src/typeCheck.js +23 -0
  117. package/src/typeGuards.d.ts +17 -0
  118. package/src/typeGuards.d.ts.map +1 -1
  119. package/src/typeGuards.js +20 -0
  120. package/src/types-index.d.ts +1 -0
  121. package/src/types-index.js +2 -0
  122. package/src/types.d.ts +83 -18
  123. package/src/types.d.ts.map +1 -0
  124. package/src/types.ts +129 -0
  125. package/src/upgrade-api.d.ts +14 -4
  126. package/src/upgrade-api.d.ts.map +1 -1
  127. package/src/upgrade-api.js +50 -18
  128. package/CHANGELOG.md +0 -106
  129. package/src/utils.d.ts +0 -67
  130. package/src/utils.d.ts.map +0 -1
  131. package/src/utils.js +0 -451
package/src/metrics.js ADDED
@@ -0,0 +1,476 @@
1
+ /**
2
+ * @file Metadata about exported metrics. Note that any embedded unit
3
+ * information should be provided as case-sensitive UCUM (e.g., `s` for
4
+ * seconds, `ms` for milliseconds, `KiBy` for binary kilobytes [each being
5
+ * 1024 bytes]).
6
+ *
7
+ * - https://github.com/open-telemetry/semantic-conventions/blob/main/docs/general/metrics.md#instrument-units
8
+ * - https://ucum.org/ucum
9
+ * - https://ucum.nlm.nih.gov/ucum-lhc/demo.html
10
+ * - https://en.wikipedia.org/wiki/Unified_Code_for_Units_of_Measure
11
+ */
12
+
13
+ import { q } from '@endo/errors';
14
+ import { isNat } from '@endo/nat';
15
+
16
+ /**
17
+ * @import {Meter as OTelMeter, MetricAttributes} from '@opentelemetry/api';
18
+ * @import {TotalMap} from '@agoric/internal';
19
+ */
20
+
21
+ const HISTOGRAM_MS_LATENCY_BOUNDARIES = [
22
+ 5,
23
+ 10,
24
+ 25,
25
+ 50,
26
+ 100,
27
+ 250,
28
+ 500,
29
+ 1000,
30
+ 2500,
31
+ 5000,
32
+ 10000,
33
+ Infinity,
34
+ ];
35
+ const HISTOGRAM_SECONDS_LATENCY_BOUNDARIES =
36
+ HISTOGRAM_MS_LATENCY_BOUNDARIES.map(ms => ms / 1000);
37
+
38
+ // TODO: Validate these boundaries. We're not going to have 5ms blocks, but
39
+ // we probably care about the difference between 10 vs. 30 seconds.
40
+ export const HISTOGRAM_METRICS = /** @type {const} */ ({
41
+ swingset_crank_processing_time: {
42
+ description: 'Processing time per crank (ms)',
43
+ unit: 'ms',
44
+ boundaries: Array.of(1, 11, 21, 31, 41, 51, 61, 71, 81, 91, Infinity),
45
+ },
46
+ swingset_block_processing_seconds: {
47
+ description: 'Processing time per block',
48
+ unit: 's',
49
+ boundaries: HISTOGRAM_SECONDS_LATENCY_BOUNDARIES,
50
+ },
51
+ swingset_vat_startup: {
52
+ description: 'Vat startup time (ms)',
53
+ unit: 'ms',
54
+ boundaries: HISTOGRAM_MS_LATENCY_BOUNDARIES,
55
+ },
56
+ swingset_vat_delivery: {
57
+ description: 'Vat delivery time (ms)',
58
+ unit: 'ms',
59
+ boundaries: HISTOGRAM_MS_LATENCY_BOUNDARIES,
60
+ },
61
+ swingset_meter_usage: {
62
+ description: 'Vat meter usage',
63
+ unit: 'ms',
64
+ boundaries: HISTOGRAM_MS_LATENCY_BOUNDARIES,
65
+ },
66
+ });
67
+
68
+ const blockHistogramMetricDesc = {
69
+ // Disabled because importing from @opentelemetry/api breaks kernel bundling.
70
+ // Thankfully, it's the default anyway:
71
+ // https://github.com/open-telemetry/opentelemetry-js/blob/f4dd2a1062f980cd344cfb172a515d00115df570/api/src/metrics/Metric.ts#L53-L57
72
+ // valueType: ValueType.DOUBLE,
73
+ unit: 's',
74
+ advice: {
75
+ explicitBucketBoundaries: [
76
+ 0.1, 0.2, 0.3, 0.4, 0.5, 1, 2, 3, 4, 5, 6, 7, 10, 15, 30,
77
+ ],
78
+ },
79
+ };
80
+ export const BLOCK_HISTOGRAM_METRICS = /** @type {const} */ ({
81
+ swingsetRunSeconds: {
82
+ description: 'Per-block time spent executing SwingSet',
83
+ ...blockHistogramMetricDesc,
84
+ },
85
+ swingsetChainSaveSeconds: {
86
+ description: 'Per-block time spent propagating SwingSet state into cosmos',
87
+ ...blockHistogramMetricDesc,
88
+ },
89
+ swingsetCommitSeconds: {
90
+ description:
91
+ 'Per-block time spent committing SwingSet state to host storage',
92
+ ...blockHistogramMetricDesc,
93
+ },
94
+ cosmosCommitSeconds: {
95
+ description: 'Per-block time spent committing cosmos state',
96
+ ...blockHistogramMetricDesc,
97
+ },
98
+ fullCommitSeconds: {
99
+ description:
100
+ 'Per-block time spent committing state, inclusive of COMMIT_BLOCK processing plus time spent [outside of cosmic-swingset] before and after it',
101
+ ...blockHistogramMetricDesc,
102
+ },
103
+ interBlockSeconds: {
104
+ description: 'Time spent idle between blocks',
105
+ ...blockHistogramMetricDesc,
106
+ },
107
+ afterCommitHangoverSeconds: {
108
+ description:
109
+ 'Per-block time spent waiting for previous-block afterCommit work',
110
+ ...blockHistogramMetricDesc,
111
+ },
112
+ blockLagSeconds: {
113
+ description: 'The delay of each block from its expected begin time',
114
+ ...blockHistogramMetricDesc,
115
+ // Add buckets for excessively long delays.
116
+ advice: {
117
+ ...blockHistogramMetricDesc.advice,
118
+ explicitBucketBoundaries: /** @type {number[]} */ ([
119
+ ...blockHistogramMetricDesc.advice.explicitBucketBoundaries,
120
+ ...[60, 120, 180, 240, 300, 600, 3600],
121
+ ]),
122
+ },
123
+ },
124
+ });
125
+
126
+ /** @enum {(typeof QueueMetricAspect)[keyof typeof QueueMetricAspect]} */
127
+ export const QueueMetricAspect = /** @type {const} */ ({
128
+ Length: 'length',
129
+ IncrementCount: 'increments',
130
+ DecrementCount: 'decrements',
131
+ });
132
+
133
+ /**
134
+ * Queue metrics come in {length,add,remove} triples sharing a common prefix.
135
+ *
136
+ * @param {string} namePrefix
137
+ * @param {string} descPrefix
138
+ * @returns {Record<
139
+ * QueueMetricAspect,
140
+ * { name: string; options: MetricAttributes }
141
+ * >}
142
+ */
143
+ export const makeQueueMetricsMeta = (namePrefix, descPrefix) => {
144
+ /** @type {[QueueMetricAspect, string, string][]} */
145
+ const metricsMeta = [
146
+ [QueueMetricAspect.Length, 'length', 'length'],
147
+ [QueueMetricAspect.IncrementCount, 'add', 'increments'],
148
+ [QueueMetricAspect.DecrementCount, 'remove', 'decrements'],
149
+ ];
150
+ const entries = metricsMeta.map(([aspect, nameSuffix, descSuffix]) => {
151
+ const name = `${namePrefix}_${nameSuffix}`;
152
+ const description = `${descPrefix} ${descSuffix}`;
153
+ // Future OpenTelemetry SDKs should also support creating Instruments with
154
+ // attribute keys (such as the "queue" attribute for
155
+ // "cosmic_swingset_inbound_queue_{length,add,remove}" measurements):
156
+ // https://opentelemetry.io/docs/specs/otel/metrics/api/#instrument-advisory-parameter-attributes
157
+ // At that time, a new field will be added to this record.
158
+ return [aspect, { name, options: { description } }];
159
+ });
160
+ return Object.fromEntries(entries);
161
+ };
162
+
163
+ /**
164
+ * @template {string} QueueName
165
+ * @typedef QueueMetrics
166
+ * @property {(lengths: Record<QueueName, number>) => void} initLengths must be
167
+ * called before any other function
168
+ * @property {(lengths: Record<QueueName, number>) => void} updateLengths
169
+ * @property {(queue: QueueName, delta?: number) => void} incLength for a
170
+ * non-negative delta
171
+ * @property {(queue: QueueName, delta?: number) => void} decLength for a
172
+ * non-negative delta
173
+ */
174
+
175
+ /**
176
+ * Create {length,add,remove} Instruments for a queue and return functions for
177
+ * consistently initializing and updating them.
178
+ *
179
+ * @template {string} QueueName
180
+ * @param {object} config
181
+ * @param {OTelMeter} config.otelMeter
182
+ * @param {string} config.namePrefix
183
+ * @param {string} config.descPrefix
184
+ * @param {Pick<Console, 'warn'>} [config.console]
185
+ * @returns {QueueMetrics<QueueName>}
186
+ */
187
+ export const makeQueueMetrics = ({
188
+ otelMeter,
189
+ namePrefix,
190
+ descPrefix,
191
+ console,
192
+ }) => {
193
+ const {
194
+ [QueueMetricAspect.Length]: lengthMeta,
195
+ [QueueMetricAspect.IncrementCount]: upMeta,
196
+ [QueueMetricAspect.DecrementCount]: downMeta,
197
+ } = makeQueueMetricsMeta(namePrefix, descPrefix);
198
+ // TODO: When it's deemed safe to change reported metrics, make upCounter and
199
+ // downCounter synchronous (and drop `increments` and `decrements` maps).
200
+ // We can't do so until then because it will add a "_total" suffix to the
201
+ // Prometheus export metric name, diverging from `makeInboundQueueMetrics` in
202
+ // packages/cosmic-swingset/src/kernel-stats.js.
203
+ // https://github.com/open-telemetry/opentelemetry-js/blob/main/doc/upgrade-to-2.x.md#-other-changes
204
+ const lengthCounter = otelMeter.createUpDownCounter(
205
+ lengthMeta.name,
206
+ lengthMeta.options,
207
+ );
208
+ // const upCounter = otelMeter.createCounter(upMeta.name, upMeta.options);
209
+ // const downCounter = otelMeter.createCounter(downMeta.name, downMeta.options);
210
+ const upCounter = otelMeter.createObservableCounter(
211
+ upMeta.name,
212
+ upMeta.options,
213
+ );
214
+ const downCounter = otelMeter.createObservableCounter(
215
+ downMeta.name,
216
+ downMeta.options,
217
+ );
218
+ const increments = /** @type {TotalMap<string, number>} */ (new Map());
219
+ const decrements = /** @type {TotalMap<string, number>} */ (new Map());
220
+ upCounter.addCallback(observer => {
221
+ for (const [queueName, value] of increments.entries()) {
222
+ observer.observe(value, { queue: queueName });
223
+ }
224
+ });
225
+ downCounter.addCallback(observer => {
226
+ for (const [queueName, value] of decrements.entries()) {
227
+ observer.observe(value, { queue: queueName });
228
+ }
229
+ });
230
+
231
+ let ready = false;
232
+ const lengths = /** @type {TotalMap<string, number>} */ (new Map());
233
+ const nudge = (queueName, delta, init = false) => {
234
+ if (!lengths.has(queueName)) {
235
+ if (!init) console?.warn('Unknown queue', queueName);
236
+ lengths.set(queueName, 0);
237
+ increments.set(queueName, 0);
238
+ decrements.set(queueName, 0);
239
+ }
240
+ const oldLength = lengths.get(queueName);
241
+ lengths.set(queueName, oldLength + delta);
242
+ const dimensions = { queue: queueName };
243
+ lengthCounter.add(delta, dimensions);
244
+ if (init) {
245
+ return;
246
+ } else if (delta > 0) {
247
+ // TODO per above: upCounter.add(delta, dimensions);
248
+ increments.set(queueName, (increments.get(queueName) || 0) + delta);
249
+ } else if (delta < 0) {
250
+ // TODO per above: downCounter.add(-delta, dimensions);
251
+ decrements.set(queueName, (decrements.get(queueName) || 0) - delta);
252
+ }
253
+ ready = true;
254
+ };
255
+
256
+ return harden({
257
+ initLengths: initialLengths => {
258
+ !ready ||
259
+ console?.warn(
260
+ `Unexpected repeat queue length initialization from ${q(lengths)} to ${q(initialLengths)}`,
261
+ );
262
+ for (const [queueName, newLength] of Object.entries(initialLengths)) {
263
+ if (!isNat(newLength)) {
264
+ console?.warn(`Invalid length for queue ${q(queueName)}:`, newLength);
265
+ continue;
266
+ }
267
+ nudge(queueName, newLength, true);
268
+ }
269
+ },
270
+ updateLengths: newLengths => {
271
+ ready || console?.warn('Missing initial queue lengths');
272
+ for (const [queueName, newLength] of Object.entries(newLengths)) {
273
+ if (!isNat(newLength)) {
274
+ console?.warn(`Invalid length for queue ${q(queueName)}:`, newLength);
275
+ continue;
276
+ }
277
+ nudge(queueName, newLength - (lengths.get(queueName) || 0));
278
+ }
279
+ },
280
+ incLength: (queueName, delta = 1) => {
281
+ if (!isNat(delta)) {
282
+ console?.warn(`Invalid increment for queue ${q(queueName)}:`, delta);
283
+ return;
284
+ }
285
+ nudge(queueName, delta);
286
+ },
287
+ decLength: (queueName, delta = 1) => {
288
+ if (!isNat(delta)) {
289
+ console?.warn(`Invalid decrement for queue ${q(queueName)}:`, delta);
290
+ return;
291
+ }
292
+ nudge(queueName, -delta);
293
+ },
294
+ });
295
+ };
296
+
297
+ // All the kernel metrics we are prepared for.
298
+ /** @enum {(typeof MetricType)[keyof typeof MetricType]} MetricType */
299
+ const MetricType = /** @type {const} */ ({
300
+ Counter: 'counter',
301
+ Gauge: 'gauge',
302
+ });
303
+ /**
304
+ * @typedef KernelMetricMeta
305
+ * @property {string} key
306
+ * @property {string} name
307
+ * @property {{ dimension: string; value: string }} [sub]
308
+ * @property {string} description
309
+ * @property {boolean} [consensus]
310
+ * @property {MetricType} metricType
311
+ */
312
+ /** @type {Omit<KernelMetricMeta, 'metricType'>[]} */
313
+ export const KERNEL_STATS_SUM_METRICS = [
314
+ {
315
+ key: 'syscalls',
316
+ name: 'swingset_all_syscall_total',
317
+ description: 'Total number of SwingSet kernel calls',
318
+ },
319
+ {
320
+ key: 'syscallSend',
321
+ name: 'swingset_syscall_total',
322
+ sub: { dimension: 'syscall', value: 'send' },
323
+ description: 'Total number of SwingSet message send kernel calls',
324
+ },
325
+ {
326
+ key: 'syscallCallNow',
327
+ name: 'swingset_syscall_total',
328
+ sub: { dimension: 'syscall', value: 'callNow' },
329
+ description: 'Total number of SwingSet synchronous device kernel calls',
330
+ },
331
+ {
332
+ key: 'syscallSubscribe',
333
+ name: 'swingset_syscall_total',
334
+ sub: { dimension: 'syscall', value: 'subscribe' },
335
+ description: 'Total number of SwingSet promise subscription kernel calls',
336
+ },
337
+ {
338
+ key: 'syscallResolve',
339
+ name: 'swingset_syscall_total',
340
+ sub: { dimension: 'syscall', value: 'resolve' },
341
+ description: 'Total number of SwingSet promise resolution kernel calls',
342
+ },
343
+ {
344
+ key: 'syscallExit',
345
+ name: 'swingset_syscall_total',
346
+ sub: { dimension: 'syscall', value: 'exit' },
347
+ description: 'Total number of SwingSet vat exit kernel calls',
348
+ },
349
+ {
350
+ key: 'syscallVatstoreGet',
351
+ name: 'swingset_syscall_total',
352
+ sub: { dimension: 'syscall', value: 'vatstoreGet' },
353
+ description: 'Total number of SwingSet vatstore get kernel calls',
354
+ },
355
+ {
356
+ key: 'syscallVatstoreSet',
357
+ name: 'swingset_syscall_total',
358
+ sub: { dimension: 'syscall', value: 'vatstoreSet' },
359
+ description: 'Total number of SwingSet vatstore set kernel calls',
360
+ },
361
+ {
362
+ key: 'syscallVatstoreGetNextKey',
363
+ name: 'swingset_syscall_total',
364
+ sub: { dimension: 'syscall', value: 'vatstoreGetNext' },
365
+ description: 'Total number of SwingSet vatstore getNextKey kernel calls',
366
+ },
367
+ {
368
+ key: 'syscallVatstoreDelete',
369
+ name: 'swingset_syscall_total',
370
+ sub: { dimension: 'syscall', value: 'vatstoreDelete' },
371
+ description: 'Total number of SwingSet vatstore delete kernel calls',
372
+ },
373
+ {
374
+ key: 'syscallDropImports',
375
+ name: 'swingset_syscall_total',
376
+ sub: { dimension: 'syscall', value: 'dropImports' },
377
+ description: 'Total number of SwingSet drop imports kernel calls',
378
+ },
379
+ {
380
+ key: 'dispatches',
381
+ name: 'swingset_dispatch_total',
382
+ description: 'Total number of SwingSet vat calls',
383
+ },
384
+ {
385
+ key: 'dispatchDeliver',
386
+ name: 'swingset_dispatch_deliver_total',
387
+ description: 'Total number of SwingSet vat message deliveries',
388
+ },
389
+ {
390
+ key: 'dispatchNotify',
391
+ name: 'swingset_dispatch_notify_total',
392
+ description: 'Total number of SwingSet vat promise notifications',
393
+ },
394
+ ];
395
+
396
+ /** @type {Omit<KernelMetricMeta, 'metricType'>[]} */
397
+ export const KERNEL_STATS_UPDOWN_METRICS = [
398
+ {
399
+ key: 'kernelObjects',
400
+ name: 'swingset_kernel_objects',
401
+ description: 'Active kernel objects',
402
+ },
403
+ {
404
+ key: 'kernelDevices',
405
+ name: 'swingset_kernel_devices',
406
+ description: 'Active kernel devices',
407
+ },
408
+ {
409
+ key: 'kernelPromises',
410
+ name: 'swingset_kernel_promises',
411
+ description: 'Active kernel promises',
412
+ },
413
+ {
414
+ key: 'kpUnresolved',
415
+ name: 'swingset_unresolved_kernel_promises',
416
+ description: 'Unresolved kernel promises',
417
+ },
418
+ {
419
+ key: 'kpFulfilled',
420
+ name: 'swingset_fulfilled_kernel_promises',
421
+ description: 'Fulfilled kernel promises',
422
+ },
423
+ {
424
+ key: 'kpRejected',
425
+ name: 'swingset_rejected_kernel_promises',
426
+ description: 'Rejected kernel promises',
427
+ },
428
+ {
429
+ key: 'runQueueLength',
430
+ name: 'swingset_run_queue_length',
431
+ consensus: true,
432
+ description: 'Length of the kernel run queue',
433
+ },
434
+ {
435
+ key: 'acceptanceQueueLength',
436
+ name: 'swingset_acceptance_queue_length',
437
+ consensus: true,
438
+ description: 'Length of the kernel acceptance queue',
439
+ },
440
+ {
441
+ key: 'promiseQueuesLength',
442
+ name: 'swingset_promise_queues_length',
443
+ consensus: true,
444
+ description: 'Combined length of all kernel promise queues',
445
+ },
446
+ {
447
+ key: 'clistEntries',
448
+ name: 'swingset_clist_entries',
449
+ description: 'Number of entries in the kernel c-list',
450
+ },
451
+ {
452
+ key: 'vats',
453
+ name: 'swingset_vats',
454
+ description: 'Number of active vats',
455
+ },
456
+ ];
457
+
458
+ const { Counter, Gauge } = MetricType;
459
+ /** @type {KernelMetricMeta[]} */
460
+ export const KERNEL_STATS_METRICS = harden([
461
+ ...KERNEL_STATS_SUM_METRICS.map(m => ({ ...m, metricType: Counter })),
462
+ ...KERNEL_STATS_UPDOWN_METRICS.map(m => ({ ...m, metricType: Gauge })),
463
+ ]);
464
+
465
+ // Ensure kernel stats key uniqueness.
466
+ const kernelStatsKeys = new Map();
467
+ for (const { key } of KERNEL_STATS_METRICS) {
468
+ kernelStatsKeys.set(key, (kernelStatsKeys.get(key) || 0) + 1);
469
+ }
470
+ const duplicateKernelStatsKeys = [...kernelStatsKeys.entries()].flatMap(
471
+ ([key, value]) => (value > 1 ? [key] : []),
472
+ );
473
+ if (duplicateKernelStatsKeys.length > 0) {
474
+ const msg = `Duplicate kernel stats keys ${JSON.stringify(duplicateKernelStatsKeys)}`;
475
+ throw Error(msg);
476
+ }
@@ -0,0 +1,2 @@
1
+ export function getSpecifier(fileUrl: string): Promise<string>;
2
+ //# sourceMappingURL=module-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module-utils.d.ts","sourceRoot":"","sources":["module-utils.js"],"names":[],"mappings":"AAaO,sCAHI,MAAM,GACJ,OAAO,CAAC,MAAM,CAAC,CAc3B"}
@@ -0,0 +1,27 @@
1
+ import { readFile } from 'node:fs/promises';
2
+ import { fileURLToPath } from 'node:url';
3
+ import { search } from '@endo/compartment-mapper';
4
+ import { Fail } from '@endo/errors';
5
+
6
+ /**
7
+ * Given a file URL, return a deep import specifier that starts with the
8
+ * specifier for its containing module (e.g., the deep import specifier for this
9
+ * file is expected to be "@agoric/internal/src/module-utils.js").
10
+ *
11
+ * @param {string} fileUrl
12
+ * @returns {Promise<string>}
13
+ */
14
+ export const getSpecifier = async fileUrl => {
15
+ // eslint-disable-next-line no-new
16
+ new URL(fileUrl); // validates fileUrl
17
+ const read = async location => {
18
+ const path = fileURLToPath(new URL(location, fileUrl));
19
+ return readFile(path);
20
+ };
21
+ const searchResult = await search(read, fileUrl);
22
+ const { packageDescriptorText, moduleSpecifier } = searchResult;
23
+ const { name } = JSON.parse(packageDescriptorText);
24
+ name || Fail`containing package must have a name`;
25
+ return `${name}/${moduleSpecifier.replace(/^\.\//, '')}`;
26
+ };
27
+ harden(getSpecifier);
@@ -0,0 +1,2 @@
1
+ export function naturalCompare(a: string, b: string): -1 | 0 | 1;
2
+ //# sourceMappingURL=natural-sort.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"natural-sort.d.ts","sourceRoot":"","sources":["natural-sort.js"],"names":[],"mappings":"AAqCO,kCAJI,MAAM,KACN,MAAM,GACJ,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAWtB"}
@@ -0,0 +1,48 @@
1
+ /**
2
+ * @param {string} a
3
+ * @param {string} b
4
+ * @returns {-1 | 0 | 1}
5
+ */
6
+ const compareNats = (a, b) => {
7
+ // Default to IEEE 754 number arithmetic for speed, but fall back on bigint
8
+ // arithmetic to resolve ties because big numbers can lose resolution
9
+ // (sometimes even becoming infinite) and then ultimately on length to resolve
10
+ // ties by ascending count of leading zeros.
11
+ const diff = +a - +b;
12
+ const finiteDiff =
13
+ (Number.isFinite(diff) && diff) ||
14
+ (a === b ? 0 : Number(BigInt(a) - BigInt(b)) || a.length - b.length);
15
+
16
+ // @ts-expect-error this call really does return -1 | 0 | 1
17
+ return Math.sign(finiteDiff);
18
+ };
19
+
20
+ // TODO: compareByCodePoints
21
+ // https://github.com/endojs/endo/pull/2008
22
+ // eslint-disable-next-line no-nested-ternary
23
+ const compareStrings = (a, b) => (a > b ? 1 : a < b ? -1 : 0);
24
+
25
+ const rPrefixedDigits = /^(\D*)(\d+)(\D.*|)/s;
26
+
27
+ /**
28
+ * Perform a single-level natural-sort comparison, finding the first decimal
29
+ * digit sequence in each operand and comparing first by the (possibly empty)
30
+ * preceding prefix as strings, then by the digits as integers, then by any
31
+ * following suffix (e.g., sorting 'ko42' before 'ko100' as ['ko', 42] vs.
32
+ * ['ko', 100]).
33
+ *
34
+ * @param {string} a
35
+ * @param {string} b
36
+ * @returns {-1 | 0 | 1}
37
+ */
38
+ export const naturalCompare = (a, b) => {
39
+ const [_a, aPrefix, aDigits, aSuffix] = rPrefixedDigits.exec(a) || [];
40
+ if (aPrefix !== undefined) {
41
+ const [_b, bPrefix, bDigits, bSuffix] = rPrefixedDigits.exec(b) || [];
42
+ if (bPrefix === aPrefix) {
43
+ return compareNats(aDigits, bDigits) || compareStrings(aSuffix, bSuffix);
44
+ }
45
+ }
46
+ return compareStrings(a, b);
47
+ };
48
+ harden(naturalCompare);
@@ -0,0 +1,24 @@
1
+ /**
2
+ * @param {Buffer} data
3
+ * @returns {Buffer} netstring-wrapped
4
+ */
5
+ export function encode(data: Buffer): Buffer;
6
+ export function netstringEncoderStream(): Transform;
7
+ /**
8
+ * @param {Buffer} data containing zero or more netstrings and maybe some
9
+ * leftover bytes
10
+ * @param {number} [optMaxChunkSize]
11
+ * @returns {{ leftover: Buffer; payloads: Buffer[] }} zero or more decoded
12
+ * Buffers, one per netstring,
13
+ */
14
+ export function decode(data: Buffer, optMaxChunkSize?: number): {
15
+ leftover: Buffer;
16
+ payloads: Buffer[];
17
+ };
18
+ /**
19
+ * @param {number} [optMaxChunkSize]
20
+ * @returns {Transform}
21
+ */
22
+ export function netstringDecoderStream(optMaxChunkSize?: number): Transform;
23
+ import { Transform } from 'stream';
24
+ //# sourceMappingURL=netstring.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"netstring.d.ts","sourceRoot":"","sources":["netstring.js"],"names":[],"mappings":"AASA;;;GAGG;AACH,6BAHW,MAAM,GACJ,MAAM,CAMlB;AAGD,oDAsBC;AAED;;;;;;GAMG;AACH,6BANW,MAAM,oBAEN,MAAM,GACJ;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,EAAE,CAAA;CAAE,CAmCpD;AAED;;;GAGG;AAEH,yDAJW,MAAM,GACJ,SAAS,CAqCrB;0BAxHyB,QAAQ"}