@mark1russell7/kind 0.14.1 → 0.14.3

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.
@@ -1,8 +1,9 @@
1
1
  import { format, valueIn } from "@mark1russell7/quantity";
2
2
  import { median, medianInterval, quantileSorted } from "@mark1russell7/rigor-statistics";
3
+ import { backoffDelay } from "@mark1russell7/service/backoff";
3
4
  import { extentSchema, quantitySchema } from "@mark1russell7/quantity/schema";
4
5
  import { z } from "zod";
5
- //#region src/bands.ts
6
+ // src/bands.ts
6
7
  /** This module makes and prints the bands of the predictions. It imports only the amounts. */
7
8
  /** This function gives a time in seconds as a quantity. */
8
9
  const seconds = (value) => ({
@@ -108,8 +109,7 @@ const requestBand = (term, span, mean, connections, sessions) => {
108
109
  hi: sessions * (Math.ceil(each) + 1 + term.requests.hi + drained.hi)
109
110
  };
110
111
  };
111
- //#endregion
112
- //#region src/names.ts
112
+ // src/names.ts
113
113
  /** These are the ports of the app: its server, and its health server for the probes. */
114
114
  const PORT = 8080;
115
115
  const HEALTH_PORT = 9e3;
@@ -125,8 +125,7 @@ const LB_CLASS = "kube-vip.io/kube-vip-class";
125
125
  const VIP_ANNOTATION = "kube-vip.io/loadbalancerIPs";
126
126
  /** This is the name of the node of each client outside the cluster, in its lines (`KindCell.vip`). */
127
127
  const OUTSIDE = "outside";
128
- //#endregion
129
- //#region src/stats.ts
128
+ // src/stats.ts
130
129
  /** This fraction, δ_rel, is how far the median of a cell can be outside its band and stay equivalent. */
131
130
  const RELATIVE = .05;
132
131
  /**
@@ -149,8 +148,7 @@ const medianInterval$1 = (sorted) => {
149
148
  const interval = medianInterval(sorted, .95);
150
149
  return [interval.low, interval.high];
151
150
  };
152
- //#endregion
153
- //#region src/observe.ts
151
+ // src/observe.ts
154
152
  /**
155
153
  * This module reads a run from its lines. Each time is in milliseconds on CLOCK_MONOTONIC. All the
156
154
  * containers of the VM share that clock: the clients, the service, the agents, the injector, the
@@ -355,8 +353,16 @@ const restartsAt = (lines, at) => {
355
353
  for (const [name, pod] of podsAt(lines, at)) out.set(name, pod.cs.reduce((sum, status) => sum + status.rc, 0));
356
354
  return out;
357
355
  };
358
- //#endregion
359
- //#region src/reconnects.ts
356
+ // src/reconnects.ts
357
+ /**
358
+ * This function gives the delay of the call `index`, from 0, before the floor, the stop and the
359
+ * jitter. It is the backoff of the service, with a factor of 2 and a cap of the most.
360
+ */
361
+ const nominalOf = (delays, index) => backoffDelay({
362
+ base: delays.initial,
363
+ factor: 2,
364
+ cap: delays.max
365
+ }, index + 1);
360
366
  const delaysOf = (backoff) => ({
361
367
  initial: valueIn(backoff.initial, "ms"),
362
368
  max: valueIn(backoff.max, "ms"),
@@ -369,12 +375,10 @@ const delaysOf = (backoff) => ({
369
375
  */
370
376
  const pathOf = (delays, share, latency, until) => {
371
377
  const tries = [];
372
- let next = delays.initial;
373
378
  let call = 0;
374
379
  let made = false;
375
380
  for (let count = 0; count < 1e3; count += 1) {
376
- let current = next;
377
- next = Math.min(2 * next, delays.max);
381
+ let current = nominalOf(delays, count);
378
382
  if (!made && call + current > delays.stop) {
379
383
  current = Math.max(delays.initial, delays.stop - call);
380
384
  made = true;
@@ -418,7 +422,7 @@ const latestReturn = (prediction) => {
418
422
  };
419
423
  /** This function gives the delay of each call of a backoff, as an interval, with `elapsed` from the first call to this one. */
420
424
  const delayBand = (delays, index, elapsed, made, noise) => {
421
- const nominal = Math.min(delays.initial * 2 ** index, delays.max);
425
+ const nominal = nominalOf(delays, index);
422
426
  const band = (current) => ({
423
427
  lo: Math.max(delays.initial, current * (1 - delays.jitter)),
424
428
  hi: Math.max(delays.initial, current)
@@ -539,7 +543,7 @@ const judgeReconnects = (prediction, run, sends, noise) => {
539
543
  for (const [index, schedule] of schedules.entries()) {
540
544
  const band = delayBand(delays, index, schedule.t - first.t, made, noise);
541
545
  if (schedule.delay < band.lo - 1 || schedule.delay > band.hi + 1) return no(`the delay ${index + 1} is ${schedule.delay} ms, not in ${band.lo.toFixed(0)}–${band.hi.toFixed(0)} ms of the backoff`);
542
- made = band.either ? schedule.delay < Math.min(delays.initial * 2 ** index, delays.max) * (1 - delays.jitter) - 1 : band.made;
546
+ made = band.either ? schedule.delay < nominalOf(delays, index) * (1 - delays.jitter) - 1 : band.made;
543
547
  }
544
548
  const tries = schedules.map((schedule) => schedule.t + schedule.delay);
545
549
  const last = tries.at(-1);
@@ -585,8 +589,7 @@ const judgeReconnects = (prediction, run, sends, noise) => {
585
589
  }
586
590
  return done(true, `${flip === null ? "the stopped broker owns the topic again" : `another owner ${flip.toFixed(0)} ms after the fault`}; ${returns.map((each) => `${each.pod} back at try ${each.tries}`).join(", ")}`);
587
591
  };
588
- //#endregion
589
- //#region src/verdict.ts
592
+ // src/verdict.ts
590
593
  /**
591
594
  * This time is δ for kind: each time of a run lands in its band ± δ. Its parts are the interval of
592
595
  * the poll of the rules (50 ms) and the delay of the watcher. The watcher receives each change after
@@ -1511,8 +1514,7 @@ const judgeKind = (cell, runs) => {
1511
1514
  checks
1512
1515
  };
1513
1516
  };
1514
- //#endregion
1515
- //#region src/record.ts
1517
+ // src/record.ts
1516
1518
  /**
1517
1519
  * This module is the raw record of a kind cell: its formats, and the upgrade from the format `/1`
1518
1520
  * to the format `/2`. The lab writes `/2`, and it does not write `/1` again. A reader reads a record
@@ -1728,8 +1730,7 @@ const judge = (record) => {
1728
1730
  const current = upgrade(record);
1729
1731
  return judgeKind(current.cell, current.runs);
1730
1732
  };
1731
- //#endregion
1732
- //#region src/report.ts
1733
+ // src/report.ts
1733
1734
  /** This function gives the spread of a set of times, or null for none. The percentile is by nearest rank. */
1734
1735
  const timeSpread = (times) => {
1735
1736
  if (times.length === 0) return null;
@@ -1832,8 +1833,7 @@ const calibrationOf = (judged) => {
1832
1833
  intake: timeSpread(intake)
1833
1834
  };
1834
1835
  };
1835
- //#endregion
1836
- //#region src/schema.ts
1836
+ // src/schema.ts
1837
1837
  /**
1838
1838
  * This module holds the zod schemas of a kind cell record, in the formats `/1` and `/2`. It names
1839
1839
  * the stages of the shutdown itself, thus it does not load the service. A test holds the names to
@@ -2373,7 +2373,6 @@ const readRecord = (data) => {
2373
2373
  if (format === "systems.kind-cell-record/2") return kindCellRecordSchema.parse(data);
2374
2374
  throw new Error(`a kind cell record has the format ${FORMAT} or ${FORMAT_V1}, not ${String(format)}`);
2375
2375
  };
2376
- //#endregion
2377
2376
  export { rulesOf as $, judgeReconnects as A, overshootBand as At, emptyOf as B, observationEnd as C, PORT as Ct, reusesReset as D, backlogEnd as Dt, referenceOf as E, VIP_ANNOTATION as Et, backendsAt as F, outcomesOf as G, intakeOf as H, byClients as I, podsOf as J, periodOf as K, byNode as L, triesOf as M, seconds as Mt, HBONE_PORT as N, secondsOf as Nt, unitOf as O, bandOf as Ot, TCP_STATE as P, showBand as Pt, restartsAt as Q, deletionOf as R, observationAfter as S, OUTSIDE as St, propagationSource as T, SERVER as Tt, isTunnelState as U, failuresOf as V, kernelCounts as W, requestsOf as X, recordsOf as Y, restartOf as Z, checkRun as _, quantileOf as _t, calibrationOf as a, sliceReadyAt as at, factsOf as b, LB_CLASS as bt, predictionText as c, socketsOf as ct, FORMAT_V1 as d, tunnelsOf as dt, sessionsAt as et, judge as f, ztunnelPodsOf as ft, LAST_SLACK as g, middle as gt, KIND_NOISE as h, medianInterval$1 as ht, readRecord as i, sliceEmptyOf as it, latestReturn as j, requestBand as jt, updatesOf as k, drainBand as kt, timeSpread as l, stoppingOf as lt, upgradeCell as m, RELATIVE as mt, kindCellRecordSchema as n, signalsOf as nt, cellsTable as o, sliceReadyOf as ot, upgrade as p, ztunnelReplaced as pt, podsAt as q, kindCellRecordV1Schema as r, sliceDropOf as rt, medianText as s, slicesOf as st, STAGES as t, signalOf as tt, FORMAT as u, transitionOf as ut, cyclesOf as v, CLIENT as vt, propagationOf as w, REDIS as wt, judgeKind as x, LOG_LABEL as xt, deletionsOf as y, HEALTH_PORT as yt, dropOf as z };
2378
2377
 
2379
- //# sourceMappingURL=judge-DjtNaAVO.js.map
2378
+ //# sourceMappingURL=judge-BvytGtrG.js.map