@mark1russell7/service 0.0.0-stage → 0.2.0

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,168 @@
1
+ import { $ as FailsBy, A as StartOptions, B as Check, C as ProcessPort, D as HealthVerdict, E as Health, F as MachineName, G as Gate, H as Coupling, I as Recorder, J as Step, K as Phase, L as Cancel, M as Outcome, N as Result, O as ProbeAnswer, P as LifecycleEvent, Q as mayReissue, R as Clock, S as ExitSignal, T as CheckVerdict, U as Dependency, V as Controller, W as FORMAT, X as Idempotency, Y as Transport, Z as Operation, _ as cooperativeAbortAt, a as WatchdogSpec, at as failSpan, b as RequestOutcome, c as HealthServer, d as PhaseContext, et as Poll, f as PhaseWork, g as TransportImpl, h as Stage, i as Watchdog, it as asWindow, j as CheckFn, k as ProbeKind, l as Lifecycle, m as STAGES, n as ServiceBuilder, nt as Timing, o as watchdog, ot as recoverSpan, p as RunOptions, q as ServiceDescription, r as service, rt as asDebounce, s as DependencyHandle, t as ControllerBuilder, tt as Span, u as LifecycleState, v as stageRank, w as nodeProcess, x as EXIT_SIGNALS, y as RequestFn, z as realClock } from "./builder-BFxOuULH.js";
2
+ import { Extent, Quantity } from "@mark1russell7/quantity";
3
+ import { Machine } from "@mark1russell7/algebra";
4
+ //#region src/law.d.ts
5
+ /**
6
+ * This module is the evaluator of the timer-ordering law. Its decisions are the same as the
7
+ * decisions of the research evaluator. The rules are data, and the caller gives them. Each rule
8
+ * is one or more linear inequalities over symbols at a hop (`readiness_detection_window@pod`),
9
+ * with a margin. A binding maps `symbol@hop` to seconds, or to "inf" for a timer that is absent.
10
+ */
11
+ /** A term is a coefficient times one symbol, at a hop when it has one. */
12
+ interface Term {
13
+ readonly knob: string;
14
+ readonly coef: number;
15
+ readonly at?: string | undefined;
16
+ }
17
+ /** A side is a sum of terms, plus a constant. */
18
+ interface Side {
19
+ readonly terms: readonly Term[];
20
+ readonly const?: number | undefined;
21
+ }
22
+ /** An inequality compares two sides, with a margin. */
23
+ interface Inequality {
24
+ readonly lhs: Side;
25
+ readonly op: "<" | "<=" | ">" | ">=";
26
+ readonly rhs: Side;
27
+ /** The margin is in seconds, or it is words for a margin that no binding gives ("a factor of several"). Words count as 0. */
28
+ readonly margin?: number | string | undefined;
29
+ }
30
+ /** A rule is one or more inequalities, with their statement in words. */
31
+ interface Rule {
32
+ readonly id: string;
33
+ /** This text is the rule in words. */
34
+ readonly rule: string;
35
+ /** This text is the window that a violation opens. */
36
+ readonly window?: string | undefined;
37
+ readonly expr: Inequality;
38
+ readonly expr_more?: readonly Inequality[] | undefined;
39
+ }
40
+ /** A bound is in seconds, or it is "inf" for an absent timer, or "off" for a disabled feature. The last two have no limit. */
41
+ type Bound = number | "inf" | "off";
42
+ /**
43
+ * A binding maps `symbol@hop` to its bound. Its "margin" replaces the margin of each inequality.
44
+ * Its "margins" replace them one by one, in sequence, as the binding of a chain can.
45
+ */
46
+ type Binding = Readonly<Record<string, Bound | readonly number[] | undefined>> & {
47
+ readonly margin?: number | undefined;
48
+ readonly margins?: readonly number[] | undefined;
49
+ };
50
+ /** A verdict is "holds", "violated", "unbounded" (it holds only because a timer is absent) or "depends" (nothing is bound). */
51
+ type Verdict = "holds" | "violated" | "unbounded" | "depends";
52
+ /** An evaluation is the value of each side of one inequality, its margin, and if it holds. */
53
+ interface Evaluated {
54
+ readonly lhs: number | null;
55
+ readonly rhs: number | null;
56
+ readonly margin: number;
57
+ readonly holds: boolean | null;
58
+ }
59
+ /** This function gives the inequalities of a rule: its expr, then the others. */
60
+ export declare const inequalities: (rule: Rule) => readonly Inequality[];
61
+ /** This function gives the symbols that a rule reads, as `symbol@hop`. */
62
+ export declare const symbolsOf: (rule: Rule) => string[];
63
+ /**
64
+ * This function evaluates each inequality on one binding. "<" holds when lhs + margin < rhs, and
65
+ * ">" holds when lhs > rhs + margin. Only the inequalities with all their symbols bound apply.
66
+ * The others are null.
67
+ */
68
+ export declare const evaluate: (rule: Rule, bind: Binding) => Evaluated[];
69
+ /**
70
+ * This function gives the verdict of an evaluation. When an applicable inequality fails, the
71
+ * verdict is "violated". When all hold only because a timer is absent, the verdict is "unbounded",
72
+ * because nothing then limits the window. Otherwise the verdict is "holds". When no inequality
73
+ * applies, the arithmetic cannot decide, and the verdict is "depends".
74
+ */
75
+ export declare const verdictOf: (rule: Rule, bind: Binding, evaluated: readonly Evaluated[]) => Verdict;
76
+ //#endregion
77
+ //#region src/lint.d.ts
78
+ /**
79
+ * This module applies the ordering law to a declaration. The declaration binds the symbols of the
80
+ * service, from its primitives: the polls of its checks, the windows of its policies, its drain.
81
+ * The scenario binds the symbols of the platform (preStop, grace, the probes of the kubelet,
82
+ * propagation) and of each dependency (its failover time, the idle close of its server). Thus the
83
+ * service gives the inequalities, and the scenario gives the values. A rule about a client
84
+ * applies one time for each dependency.
85
+ */
86
+ /** A scenario gives the values of the platform and of each dependency, by the `symbol@hop` of the law. */
87
+ interface Scenario {
88
+ /** These are the values of the platform: prestop_sleep@pod, termination_grace@pod, probe_period@pod, propagation_bound@cluster. */
89
+ readonly platform: Readonly<Record<string, Extent>>;
90
+ /**
91
+ * These are the probe windows of the kubelet, period × failure threshold. They add to the
92
+ * windows of the declaration. A probe reads the cached verdict, thus detection is the latch,
93
+ * then the probe.
94
+ */
95
+ readonly probes: {
96
+ readonly readiness: Quantity;
97
+ readonly liveness: Quantity;
98
+ };
99
+ /** These are the values of each dependency, by its name: failover_time@dependency, server_idle_close@server. */
100
+ readonly dependencies?: Readonly<Record<string, Readonly<Record<string, Extent>>>> | undefined;
101
+ }
102
+ /** A finding is the verdict of one rule for one scope: the service, or the client of a dependency. */
103
+ interface Finding {
104
+ readonly rule: string;
105
+ readonly scope: string;
106
+ readonly verdict: Verdict;
107
+ readonly statement: string;
108
+ readonly window?: string | undefined;
109
+ readonly evaluated: readonly Evaluated[];
110
+ /** These are the symbols that have no bound. A "depends" verdict waits for them. */
111
+ readonly unbound: readonly string[];
112
+ }
113
+ /** These are the identifiers of the rules that each declaration gets. */
114
+ export declare const SERVICE_RULES: readonly string[];
115
+ /** This function gives what the declaration tells about the service, as symbols of the law, and the source of each. */
116
+ export declare const serviceBindings: (svc: ServiceDescription, scenario: Scenario) => {
117
+ readonly bind: Record<string, Bound>;
118
+ readonly from: Record<string, string>;
119
+ };
120
+ /** This function applies each service rule to a declaration and a scenario: one time for the service, and one time for each client. */
121
+ export declare const lint: (svc: ServiceDescription, scenario: Scenario, rules: readonly Rule[]) => Finding[];
122
+ //#endregion
123
+ //#region src/machines.d.ts
124
+ /**
125
+ * The startup gate opens one time. The lifecycle moves it from `closed` to `starting` while its
126
+ * components start. Then one warm-up sweep of each check opens it. A component that does not start
127
+ * fails it for good.
128
+ */
129
+ export declare const GATE_MACHINE: Machine;
130
+ /** A debounce latch counts the polls of its check in sequence. A readiness latch starts tripped. */
131
+ export declare const LATCH_MACHINE: Machine;
132
+ /**
133
+ * A window latch measures time on the monotonic clock from the first failure of a sequence, and
134
+ * from the first pass after a trip.
135
+ */
136
+ export declare const WINDOW_MACHINE: Machine;
137
+ /**
138
+ * A poller starts one check on a jittered loop with a fixed delay. A call that outlives its timeout
139
+ * stays pending (`hung`), and the poller does not start the check again until the call settles.
140
+ */
141
+ export declare const POLLER_MACHINE: Machine;
142
+ /**
143
+ * The exit manager is the only part that ends the process. The first exit request starts the
144
+ * shutdown, and a later one has no effect. An error makes the exit code 1.
145
+ */
146
+ export declare const EXIT_MACHINE: Machine;
147
+ /** A watchdog measures how late its own tick comes, and a late tick shows a blocked event loop. */
148
+ export declare const WATCHDOG_MACHINE: Machine;
149
+ /** This function gives the name of a knob for the cap of a phase: `drain` gives `drain_cap`. */
150
+ export declare const capKnob: (phase: string) => string;
151
+ /**
152
+ * This function gives the drain of a declaration as a machine. It has one state for each declared
153
+ * phase, in its sequence, and each state has a timer at its cap. The drain also has the cooperative abort: the
154
+ * cap of the drain less the cooperative window, and half that cap at the least.
155
+ */
156
+ export declare const drainMachine: (description: ServiceDescription) => Machine;
157
+ /** These are the static machines of the runtime, by the name that their events carry. */
158
+ export declare const MACHINES: Readonly<Record<Exclude<MachineName, "drain" | "client">, Machine>>;
159
+ /**
160
+ * This function replays the transitions of one machine of the runtime against its document. Each
161
+ * instance starts in the state that its first transition leaves. Each transition must leave the
162
+ * state where the replay is. The document must have a transition from that state, on that event,
163
+ * to that state. The function gives each disagreement.
164
+ */
165
+ export declare const replay: (doc: Machine, events: readonly LifecycleEvent[]) => string[];
166
+ //#endregion
167
+ export { type Binding, type Bound, type Cancel, type Check, type CheckFn, type CheckVerdict, type Clock, type Controller, type ControllerBuilder, type Coupling, type Dependency, type DependencyHandle, EXIT_SIGNALS, type Evaluated, type ExitSignal, FORMAT, type FailsBy, type Finding, type Gate, type Health, type HealthServer, type HealthVerdict, type Idempotency, type Inequality, type Lifecycle, type LifecycleEvent, type LifecycleState, type MachineName, type Operation, type Outcome, type Phase, type PhaseContext, type PhaseWork, type Poll, type ProbeAnswer, type ProbeKind, type ProcessPort, type Recorder, type RequestFn, type RequestOutcome, type Result, type Rule, type RunOptions, STAGES, type Scenario, type ServiceBuilder, type ServiceDescription, type Side, type Span, type Stage, type StartOptions, type Step, type Term, type Timing, type Transport, type TransportImpl, type Verdict, type Watchdog, type WatchdogSpec, asDebounce, asWindow, cooperativeAbortAt, failSpan, mayReissue, nodeProcess, realClock, recoverSpan, service, stageRank, watchdog };
168
+ //# sourceMappingURL=index.d.ts.map