@mark1russell7/capacity 0.0.0-bootstrap.0 → 0.1.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.
Files changed (45) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1107 -1
  3. package/build/index.d.ts +858 -0
  4. package/build/index.d.ts.map +1 -0
  5. package/build/index.js +1713 -0
  6. package/build/index.js.map +1 -0
  7. package/build/instance-0n6WhJzF.d.ts +782 -0
  8. package/build/instance-0n6WhJzF.d.ts.map +1 -0
  9. package/build/instance-check-CAuD9L4Z.js +1711 -0
  10. package/build/instance-check-CAuD9L4Z.js.map +1 -0
  11. package/build/schema.d.ts +69 -0
  12. package/build/schema.d.ts.map +1 -0
  13. package/build/schema.js +315 -0
  14. package/build/schema.js.map +1 -0
  15. package/limits/alerts-routes.line.json +78 -0
  16. package/limits/alerts-scale.limits.json +10 -0
  17. package/limits/alerts-start-gate.limits.json +1149 -0
  18. package/limits/alerts-start-routes-limit-home.bracket.json +543 -0
  19. package/limits/alerts-start-routes-limit-mid.bracket.json +464 -0
  20. package/limits/alerts-start-routes-limit.bracket.json +579 -0
  21. package/limits/alerts-tail-gate.limits.json +610 -0
  22. package/package.json +79 -4
  23. package/src/app-check.ts +477 -0
  24. package/src/app-metrics.ts +105 -0
  25. package/src/app.ts +239 -0
  26. package/src/check.ts +228 -0
  27. package/src/composition.ts +680 -0
  28. package/src/demand.ts +312 -0
  29. package/src/fit.ts +153 -0
  30. package/src/forms.ts +358 -0
  31. package/src/gate.ts +237 -0
  32. package/src/index.ts +142 -0
  33. package/src/instance-check.ts +122 -0
  34. package/src/instance.ts +84 -0
  35. package/src/knee.ts +606 -0
  36. package/src/law.ts +215 -0
  37. package/src/limit.ts +112 -0
  38. package/src/names.ts +19 -0
  39. package/src/observe.ts +74 -0
  40. package/src/program.ts +74 -0
  41. package/src/scale.ts +617 -0
  42. package/src/schema.ts +260 -0
  43. package/src/value.ts +206 -0
  44. package/src/workload-check.ts +130 -0
  45. package/src/workload.ts +88 -0
@@ -0,0 +1,782 @@
1
+ import { Quantity } from "@mark1russell7/quantity";
2
+ import { Expr } from "@mark1russell7/vex";
3
+ import { Result } from "@mark1russell7/optional";
4
+ /** This text is the format of a law file. */
5
+ declare const LAW_FORMAT = "capacity-law/1";
6
+ /** This number is the most variables that a law can have. The check reads each corner of their ranges. */
7
+ declare const MAX_VARIABLES = 8;
8
+ /** A scale tells how a variable moves through its range: in equal steps or in equal ratios. */
9
+ type Scale = "linear" | "log";
10
+ /**
11
+ * A measure is the quantity that a law gives. Its unit is a canonical unit of
12
+ * `@mark1russell7/quantity`, for example `{core}·ms/{request}` or `MiB`.
13
+ *
14
+ * CPU time is in core-seconds. Thus a request rate times a CPU cost of one request converts to
15
+ * `{core}`. That unit is the unit of the CPU of an instance.
16
+ */
17
+ interface Measure {
18
+ readonly id: string;
19
+ readonly unit: string;
20
+ }
21
+ /**
22
+ * A variable is one load variable of a law. The law holds from `min` to `max`, in the unit of the
23
+ * variable. A value outside this range is an extrapolation.
24
+ */
25
+ interface Variable {
26
+ readonly id: string;
27
+ readonly unit: string;
28
+ readonly min: number;
29
+ readonly max: number;
30
+ readonly scale: Scale;
31
+ }
32
+ /** A constant is one fitted number of a law. The program of the form reads it by its `id`. */
33
+ interface Constant {
34
+ readonly id: string;
35
+ readonly value: number;
36
+ }
37
+ /**
38
+ * A form is the math of a law. Its program is a Vex expression that reads each variable and each
39
+ * constant by its id. Its `id` names the form, for example `hinge`.
40
+ */
41
+ interface Form {
42
+ readonly id: string;
43
+ readonly program: Expr;
44
+ }
45
+ /** A condition value is a fact that a law holds constant: a name, a number, a flag or an amount with a unit. */
46
+ type ConditionValue = string | number | boolean | Quantity;
47
+ /**
48
+ * A residual kind tells how a fit compares a measured value with a law. An absolute residual is
49
+ * their difference. A relative residual is their ratio less 1.
50
+ */
51
+ type ResidualKind = "absolute" | "relative";
52
+ /** A fit error sums the residuals of a form: the mean of their sizes, and the root of the mean of their squares. */
53
+ interface FitError {
54
+ readonly mae: number;
55
+ readonly rmse: number;
56
+ }
57
+ /** A loser is a form that the fit also tried and did not keep, with its error. */
58
+ interface Loser {
59
+ readonly form: string;
60
+ readonly error: FitError;
61
+ }
62
+ /**
63
+ * A fit tells how well a law agrees with its points. Each residual compares one measured point
64
+ * with a fit that did not use that point. The list `losers` keeps each form that lost.
65
+ */
66
+ interface Fit {
67
+ readonly method: string;
68
+ readonly residual: ResidualKind;
69
+ readonly residuals: readonly number[];
70
+ readonly losers: readonly Loser[];
71
+ }
72
+ /** A run is one CI run that measured points of a law: its address, its commit and its time. */
73
+ interface Run {
74
+ readonly url: string;
75
+ readonly commit: string;
76
+ readonly date: string;
77
+ }
78
+ /**
79
+ * A run point is one point of the fit of a law. Its load gives the value of each variable of the law, in the unit of the
80
+ * variable. Its value is the value of the measure, in the unit of the measure.
81
+ */
82
+ interface RunPoint {
83
+ readonly load: Readonly<Record<string, number>>;
84
+ readonly value: number;
85
+ /** This number is the index of the run of the point in `evidence.runs`. */
86
+ readonly run: number;
87
+ /** This text is the start time of the job of the point, as an ISO 8601 time. A run can have more than one job. */
88
+ readonly job: string;
89
+ }
90
+ /** The evidence of a law is the list of the runs that measured its points. */
91
+ interface Evidence {
92
+ readonly runs: readonly Run[];
93
+ }
94
+ /**
95
+ * The noise of a law is the noise floor of its measure on one CPU model. A difference of two
96
+ * measurements below the floor is not a result. Thus a gate does not read it as a change.
97
+ */
98
+ interface Noise {
99
+ /**
100
+ * This amount is the noise floor, in the unit of the measure. It is two standard deviations of
101
+ * the differences of A/A pairs: two equal cases, each in its own container.
102
+ */
103
+ readonly floor: number;
104
+ /** This name is the CPU model of the runs that measured the floor. */
105
+ readonly cpu: string;
106
+ /** These runs measured the floor. They are not always the runs of the evidence. */
107
+ readonly runs: readonly Run[];
108
+ }
109
+ /**
110
+ * A law gives one measure of a subject as a function of its load variables. It holds for the
111
+ * ranges of its variables and for its conditions.
112
+ *
113
+ * Each row of `replicates` is one more fit of the constants, in the order of `constants`. The rows
114
+ * come from resamples of the points. Thus the spread of the rows is the doubt of the constants
115
+ * together, and each query gets its interval from them. `noise` is the noise of one measurement.
116
+ *
117
+ * The list `points` keeps each point that the fit used, in the order of `fit.residuals`. A law file from before the
118
+ * points has no list.
119
+ */
120
+ interface Law {
121
+ readonly format: typeof LAW_FORMAT;
122
+ readonly id: string;
123
+ readonly title: string;
124
+ readonly subject: string;
125
+ readonly measure: Measure;
126
+ readonly variables: readonly Variable[];
127
+ readonly conditions: Readonly<Record<string, ConditionValue>>;
128
+ readonly form: Form;
129
+ readonly constants: readonly Constant[];
130
+ readonly replicates: readonly (readonly number[])[];
131
+ readonly fit: Fit;
132
+ readonly points?: readonly RunPoint[];
133
+ readonly evidence: Evidence;
134
+ readonly noise: Noise;
135
+ }
136
+ /** A problem code names the part of a law, or of a query, that is not correct. */
137
+ type ProblemCode = "shape" | "format" | "id" | "unit" | "range" | "condition" | "program" | "read" | "constant" | "replicates" | "flat" | "value" | "fit" | "evidence" | "noise" | "point" | "level" | "knee";
138
+ /** A problem tells what is not correct, and where: `path` is the path of the field in the record. */
139
+ interface Problem<Code extends string> {
140
+ readonly code: Code;
141
+ readonly path: string;
142
+ readonly message: string;
143
+ }
144
+ /** A law problem tells what is not correct in a law, or in a query of a law. */
145
+ type LawProblem = Problem<ProblemCode>;
146
+ /** This number is the level of an interval when a query gives none. */
147
+ declare const DEFAULT_LEVEL = .95;
148
+ /**
149
+ * This function gives the least count of values that can show an interval of a level. An end of
150
+ * the interval needs one value beyond it. Thus the level 0.95 needs 40 values.
151
+ */
152
+ declare const leastCount: (level: number) => number;
153
+ /**
154
+ * This function gives the number of different draws of a bootstrap of `groups` whole groups. A run draws as many
155
+ * groups as the data has, with replacement, and a fit does not see their order. Thus the number is `C(2g - 1, g)`.
156
+ */
157
+ declare const bootstrapDraws: (groups: number) => number;
158
+ /**
159
+ * This function gives the least count of groups that a bootstrap of whole groups needs for an interval of a level.
160
+ * A run draws `g` groups from `g` groups with replacement, and a fit does not see their order. Thus `g` groups give
161
+ * `C(2g - 1, g)` different draws (`bootstrapDraws`). Each different draw gives at most one different value, and the
162
+ * interval needs `leastCount(level)` values. Thus the level 0.95 needs 5 groups: 4 groups give only 35 different draws.
163
+ */
164
+ declare const leastGroups: (level: number) => number;
165
+ /** A load point gives one value for each variable of a law, in the unit of the variable. */
166
+ type LoadPoint = Readonly<Record<string, number>>;
167
+ /** A range goes from `low` to `high`. */
168
+ interface Range {
169
+ readonly low: number;
170
+ readonly high: number;
171
+ }
172
+ /** These options set the level of the intervals of a query. The level is 0.95 when a query gives none. */
173
+ interface LevelOptions {
174
+ readonly level?: number;
175
+ }
176
+ /**
177
+ * A law value is the answer of a law at one load point, in the unit of the measure.
178
+ *
179
+ * The `interval` is the doubt of the law: the spread of its replicates at the point. It always
180
+ * holds the value. The range `run` is where one measured run falls: the interval, made wider by
181
+ * the residuals of the fit. The list `outside` names each variable whose value is outside its
182
+ * range. With a name in this list, the value is an extrapolation.
183
+ */
184
+ interface LawValue {
185
+ readonly value: number;
186
+ readonly unit: string;
187
+ readonly level: number;
188
+ readonly interval: Range;
189
+ readonly run: Range;
190
+ readonly outside: readonly string[];
191
+ }
192
+ /** A constant interval is the value of one constant of a law and the interval of its replicates. */
193
+ interface ConstantInterval {
194
+ readonly id: string;
195
+ readonly value: number;
196
+ readonly level: number;
197
+ readonly interval: Range;
198
+ }
199
+ /**
200
+ * This function gives the value of a law at a load point, with its interval. The point gives each
201
+ * variable of the law, and no other name.
202
+ *
203
+ * The function evaluates the program with the constants, then with each replicate. The interval is
204
+ * the share `level` of the values of the replicates, made wider to hold the value.
205
+ *
206
+ * The function gives a problem for a point that the law cannot read. It also gives a problem for a
207
+ * level that the law cannot show, and for a value that is not finite.
208
+ */
209
+ declare const lawValue: (law: Law, point: LoadPoint, options?: LevelOptions) => Result<LawValue, LawProblem>;
210
+ /**
211
+ * This function gives each constant of a law with the interval of its replicates. It gives a
212
+ * problem for a level that the law cannot show.
213
+ */
214
+ declare const constantIntervals: (law: Law, options?: LevelOptions) => Result<readonly ConstantInterval[], LawProblem>;
215
+ /** This text is the format of a workload file. */
216
+ declare const WORKLOAD_FORMAT = "capacity-workload/1";
217
+ /** This name is the variable that gives the rate of a class. A class and a level cannot use it for a different amount. */
218
+ declare const RATE = "rate";
219
+ /** Amounts are amounts with names. Each amount is in a canonical unit of `@mark1russell7/quantity`. */
220
+ type Amounts = Readonly<Record<string, Quantity>>;
221
+ /**
222
+ * A workload class is one kind of request. Its `rate` tells how many requests arrive in a unit of
223
+ * time, for example in `{request}/s`. Its `request` gives each variable of one request, for example
224
+ * the size of its body and its duration.
225
+ *
226
+ * A class is one point. Requests of two sizes are two classes, each with its own rate.
227
+ *
228
+ * The field `of` names the class of the contract of the app that the class is a point of. A class
229
+ * with no `of` is a point of the class of the app with its own id.
230
+ */
231
+ interface WorkloadClass {
232
+ readonly id: string;
233
+ readonly of?: string | undefined;
234
+ readonly rate: Quantity;
235
+ readonly request: Amounts;
236
+ }
237
+ /**
238
+ * A demand is the load that clients put on a service: its classes and its levels. A level is an
239
+ * amount that stays in the service and does not come with each request, for example the open
240
+ * connections.
241
+ *
242
+ * A demand is extensive. The rates and the levels of two demands add, and they divide between the
243
+ * instances of a service. The variables of one request do not.
244
+ */
245
+ interface Demand {
246
+ readonly classes: readonly WorkloadClass[];
247
+ readonly levels: Amounts;
248
+ }
249
+ /** A plan is a workload that a person wrote. Its `note` tells where its numbers come from. */
250
+ interface PlanSource {
251
+ readonly kind: "plan";
252
+ readonly note: string;
253
+ }
254
+ /**
255
+ * A metrics source is a workload from the live metrics of an app. Its `origin` names the place of
256
+ * the metrics. The window goes from `from` to `to`, and each is a UTC time.
257
+ */
258
+ interface MetricsSource {
259
+ readonly kind: "metrics";
260
+ readonly origin: string;
261
+ readonly from: string;
262
+ readonly to: string;
263
+ }
264
+ /** A workload source tells where the numbers of a workload come from: a plan or the live metrics. */
265
+ type WorkloadSource = PlanSource | MetricsSource;
266
+ /** A workload is a demand with a name and a source. A workload file is this record as JSON. */
267
+ interface Workload extends Demand {
268
+ readonly format: typeof WORKLOAD_FORMAT;
269
+ readonly id: string;
270
+ readonly title: string;
271
+ readonly source: WorkloadSource;
272
+ }
273
+ /** A workload problem code names the part of a workload, or of a query, that is not correct. */
274
+ type WorkloadProblemCode = "shape" | "format" | "id" | "rate" | "amount" | "unit" | "class" | "source" | "factor" | "variable";
275
+ /** A workload problem tells what is not correct, and where: `path` is the path of the field in the workload. */
276
+ type WorkloadProblem = Problem<WorkloadProblemCode>;
277
+ /** This demand has no class and no level. It is the zero of the sum of demands. */
278
+ declare const NO_DEMAND: Demand;
279
+ /** This text is the format of the contract file of an app. */
280
+ declare const APP_FORMAT = "capacity-app/1";
281
+ /** This name is the contract file of an app, at the root of its repository. */
282
+ declare const APP_FILE = "capacity-app.json";
283
+ /**
284
+ * The kind of a load variable tells where the amount is.
285
+ *
286
+ * - `request`: an amount of one request of a class, for example the bytes of its body.
287
+ * - `level`: an amount that stays in the app and does not come with each request, for example the open incidents.
288
+ * - `store`: an amount of a store at the start of the app, for example the bytes of its log.
289
+ * - `run`: an amount that the run of the app gives in its line `amounts`, for example the routes that its configuration makes.
290
+ * No workload and no start case sets it. A start law can read it as its variable.
291
+ */
292
+ type VariableKind = "request" | "level" | "store" | "run";
293
+ /**
294
+ * A range tells the amounts of a variable that the app accepts and that a run can measure. The unit
295
+ * is a canonical unit of `@mark1russell7/quantity`. A range on the scale `log` starts above 0.
296
+ */
297
+ interface AppRange {
298
+ readonly unit: string;
299
+ readonly min: number;
300
+ readonly max: number;
301
+ readonly scale: Scale;
302
+ }
303
+ /** A load variable of an app is one amount that a workload or a start case sets, or that the run gives. A program of a law reads it by its id. */
304
+ interface AppVariable extends AppRange {
305
+ readonly id: string;
306
+ readonly title: string;
307
+ readonly kind: VariableKind;
308
+ }
309
+ /**
310
+ * A request of HTTP comes from a client of the app. The path is a template: each `{id}` in it is a request
311
+ * variable of the class. The variable `body`, when it is there, gives the bytes of the body of the request.
312
+ */
313
+ interface HttpEntry {
314
+ readonly kind: "http";
315
+ readonly method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
316
+ readonly path: string;
317
+ readonly body?: string | undefined;
318
+ }
319
+ /**
320
+ * A service entry tells that the load of a class comes from an outside service that the app calls. The
321
+ * fake of the service reads the workload, and it gives the app the requests of the class at their rates.
322
+ */
323
+ interface ServiceEntry {
324
+ readonly kind: "service";
325
+ readonly service: string;
326
+ }
327
+ /** An entry tells how the requests of a class get to the app: from a client of HTTP, or from an outside service. */
328
+ type AppEntry = HttpEntry | ServiceEntry;
329
+ /**
330
+ * A class of an app is one kind of request. `rate` is the range of its rate, in a count in a unit of
331
+ * time. `request` names the request variables of one request, by their ids.
332
+ */
333
+ interface AppClass {
334
+ readonly id: string;
335
+ readonly title: string;
336
+ readonly rate: AppRange;
337
+ readonly request: readonly string[];
338
+ readonly entry: AppEntry;
339
+ }
340
+ /**
341
+ * A command is a program and its arguments, with no shell. `cwd` is the folder of the command, relative to
342
+ * the root of the repository. `env` gives the environment variables that the command adds.
343
+ *
344
+ * Each text of `argv` and of `env` can hold placeholders. The lab puts in their values before the start:
345
+ *
346
+ * - `{port}`: the port of the listener of the process.
347
+ * - `{store}`: the folder of the store of the app.
348
+ * - `{workload}`: the path of the workload file of the run.
349
+ * - `{service.<id>}`: the base URL of the fake of the service `<id>`.
350
+ * - `{variable.<id>}`: the amount of the store or level variable `<id>` at the point, in the unit of the variable.
351
+ *
352
+ * The run holds `{port}` when a class comes from HTTP or the ready signal is `http`. The seed and the run hold
353
+ * `{store}` when the app has a store variable. The seed can hold `{variable.<id>}` of a store or a level variable,
354
+ * for example the routes of a configuration. The fake of each service holds `{port}`, and `{workload}` when a class comes from the service.
355
+ */
356
+ interface AppCommand {
357
+ readonly argv: readonly string[];
358
+ readonly cwd: string;
359
+ readonly env: Readonly<Record<string, string>>;
360
+ }
361
+ /**
362
+ * The ready signal tells that a process serves. `line` is a text in a line of the output of the process.
363
+ * `http` is a path of the process that gives a status of 200.
364
+ */
365
+ type AppReady = {
366
+ readonly kind: "line";
367
+ readonly text: string;
368
+ } | {
369
+ readonly kind: "http";
370
+ readonly path: string;
371
+ };
372
+ /** A process is a command that runs until the lab stops it, and its ready signal. */
373
+ interface AppProcess extends AppCommand {
374
+ readonly ready: AppReady;
375
+ }
376
+ /** The kinds of the lines of a run that the lab records. The lab knows the fields of each kind. */
377
+ declare const APP_LINE_KINDS: readonly ["pass", "write", "readings", "amounts"];
378
+ /**
379
+ * The kind of a line of a run.
380
+ *
381
+ * - `pass`: the end of one pass of the loop of the app. The lab counts the passes in the watch after ready.
382
+ * - `write`: one write of the snapshot of the start. The fields `longestMs`, `writeMs`, `rowsMs`, `wallMs` and `cpuMs`
383
+ * give its times in milliseconds. The lab keeps the longest value of each time.
384
+ * - `readings`: one collection of the live metrics of the app. The field `readings` is a list of `SeriesReading`. The
385
+ * lab keeps each collection with its time, so the record of a start has the series of the metrics of the app.
386
+ * - `amounts`: the amounts of the run variables. The field `amounts` gives the amount of each run variable by its id, in the
387
+ * unit of the variable. The lab keeps the last line up to the end of the watch.
388
+ */
389
+ type AppLineKind = (typeof APP_LINE_KINDS)[number];
390
+ /**
391
+ * A line of a run is a JSON line of the output of the run that the lab records. The line is a JSON object, and its
392
+ * field `ev` has the text `ev`. `kind` tells what the lab reads from it.
393
+ */
394
+ interface AppLine {
395
+ readonly kind: AppLineKind;
396
+ readonly ev: string;
397
+ readonly title: string;
398
+ }
399
+ /** The run of an app is its process, and the lines of its output that the lab records. A run with no `lines` gives no pass and no write. */
400
+ interface AppRun extends AppProcess {
401
+ readonly lines?: readonly AppLine[] | undefined;
402
+ }
403
+ /**
404
+ * The start of an app tells how to make it run in a tree of its repository.
405
+ *
406
+ * - `install` installs the dependencies of the tree. An app with no dependencies has no install.
407
+ * - `check` examines the tree after the install, for example with a typecheck.
408
+ * - `seed` writes the store of a start case at the amounts of the store variables. An app with no store variable has no seed.
409
+ * The last line of the output of the seed is a JSON record. Its field `amounts` gives the amount of each store variable
410
+ * that the seed wrote, by its id, in the unit of the variable.
411
+ * - `run` is the process of the app, and the lines of its output that the lab records.
412
+ */
413
+ interface AppStart {
414
+ readonly install?: AppCommand | undefined;
415
+ readonly check?: AppCommand | undefined;
416
+ readonly seed?: AppCommand | undefined;
417
+ readonly run: AppRun;
418
+ }
419
+ /**
420
+ * An outside service of an app is a service of others that the app calls, for example a feed or a channel
421
+ * of messages. The lab starts the fake of the service in place of the service, and the app gets its URL.
422
+ */
423
+ interface AppService {
424
+ readonly id: string;
425
+ readonly title: string;
426
+ readonly fake: AppProcess;
427
+ }
428
+ /**
429
+ * The target of a series tells what the series measures.
430
+ *
431
+ * - `rate`: a counter of the requests of a class. Its rate is the rate of the class.
432
+ * - `level`: a gauge of a level variable.
433
+ * - `total`: a counter of the sum of a request variable over the requests of a class. Its increase over
434
+ * the increase of the counter of the class is the mean of the variable.
435
+ * - `measure`: a counter or a gauge of a measure of the laws of the app, for example its CPU time.
436
+ */
437
+ type SeriesTarget = {
438
+ readonly rate: string;
439
+ } | {
440
+ readonly level: string;
441
+ } | {
442
+ readonly total: string;
443
+ readonly class: string;
444
+ } | {
445
+ readonly measure: string;
446
+ };
447
+ /**
448
+ * A series is one live metric of an app. Its `id` is the name of the metric in the readings of the app.
449
+ * A counter only goes up, until the process starts again. A gauge is an amount at the time of its reading.
450
+ */
451
+ interface AppSeries {
452
+ readonly id: string;
453
+ readonly kind: "counter" | "gauge";
454
+ readonly unit: string;
455
+ readonly of: SeriesTarget;
456
+ }
457
+ /**
458
+ * The contract of an app is the record that each app gives to the lab and to the models. A contract file
459
+ * is this record as JSON. The `id` is the subject of the laws of the app.
460
+ */
461
+ interface AppContract {
462
+ readonly format: typeof APP_FORMAT;
463
+ readonly id: string;
464
+ readonly title: string;
465
+ /** This URL is the public HTTPS URL of the repository of the app. */
466
+ readonly repository: string;
467
+ readonly variables: readonly AppVariable[];
468
+ readonly classes: readonly AppClass[];
469
+ readonly start: AppStart;
470
+ readonly services: readonly AppService[];
471
+ readonly metrics: readonly AppSeries[];
472
+ }
473
+ /** An app problem code names the part of a contract, or of a workload against a contract, that is not correct. */
474
+ type AppProblemCode = "shape" | "format" | "id" | "range" | "unit" | "variable" | "class" | "entry" | "command" | "placeholder" | "service" | "series" | "workload";
475
+ /** An app problem tells what is not correct, and where: `path` is the path of the field in the contract or in the workload. */
476
+ type AppProblem = Problem<AppProblemCode>;
477
+ /**
478
+ * A gap is one part of the demand of an app that its live metrics cannot give. `need` names the series that
479
+ * is not there. It is the counter of a class, the gauge of a level, or the counter of a total.
480
+ */
481
+ interface MetricsGap {
482
+ readonly need: "rate" | "level" | "total";
483
+ readonly class?: string | undefined;
484
+ readonly variable?: string | undefined;
485
+ readonly message: string;
486
+ }
487
+ /**
488
+ * This function gives a demand that is `by` times as large: each rate and each level, times `by`.
489
+ * The variables of the requests stay, because more clients do not make a request larger.
490
+ *
491
+ * It gives a problem for a demand that is not correct, and for a factor that is not a finite number
492
+ * of 0 or more.
493
+ */
494
+ declare const scaleDemand: (demand: Demand, by: number) => Result<Demand, WorkloadProblem>;
495
+ /** These options name the levels that do not divide between instances. Each instance has the whole of such a level. */
496
+ interface ShareOptions {
497
+ readonly whole?: readonly string[];
498
+ }
499
+ /**
500
+ * This function gives the demand on one instance when `instances` equal instances serve a demand:
501
+ * each rate and each level, divided by the count. The variables of the requests stay.
502
+ *
503
+ * A level in `options.whole` does not divide. For example, each instance of an app that keeps all
504
+ * open incidents in memory has the whole level.
505
+ *
506
+ * It gives a problem for a demand that is not correct. It gives a problem for a count that is not
507
+ * a whole number of 1 or more. It gives a problem for a name in `options.whole` that is not a level.
508
+ */
509
+ declare const shareOf: (demand: Demand, instances: number, options?: ShareOptions) => Result<Demand, WorkloadProblem>;
510
+ /**
511
+ * This function gives the sum of two demands. A class of one demand stays. A class of the two
512
+ * demands has the sum of its rates, and its request must be equal in the two. The levels add, and a
513
+ * level of one demand stays. The classes and the levels of the sum are in the order of their names.
514
+ *
515
+ * The sum has the laws of addition: the order of the demands does not change it, and `NO_DEMAND`
516
+ * is its zero. An amount of the sum is in the unit of the first demand that gives it. Thus the
517
+ * order can change the unit of an amount, and not the amount.
518
+ *
519
+ * It gives a problem for a demand that is not correct, and for amounts that do not add. A path of
520
+ * a problem starts with `first` or `second`, or with neither for a problem of the sum.
521
+ */
522
+ declare const mergeDemands: (first: Demand, second: Demand) => Result<Demand, WorkloadProblem>;
523
+ /**
524
+ * This function gives the sum of the rates of the classes of a demand, in `unit`. A demand with no
525
+ * class has a rate of 0.
526
+ *
527
+ * It gives a problem for a demand that is not correct, and for a unit that is not a unit of a
528
+ * rate. It gives a problem for a class whose rate counts a different thing, for example events.
529
+ */
530
+ declare const totalRate: (demand: Demand, unit: string) => Result<Quantity, WorkloadProblem>;
531
+ /**
532
+ * A load tells which rate the variable `rate` of a law reads. The load `class` is the rate of one
533
+ * class. The load `total` is the sum of the rates of all classes, the load of the whole instance.
534
+ */
535
+ type Load = "class" | "total";
536
+ /** These options tell which rate the variable `rate` of a law reads. The load is `class` when the options give none. */
537
+ interface PointOptions {
538
+ readonly load?: Load;
539
+ }
540
+ /**
541
+ * A point law is the part of a law that a load point reads: its id, and the id and the unit of each
542
+ * variable. Thus a caller can get the points of a law before the fit of the law.
543
+ */
544
+ interface PointLaw extends Pick<Law, "id"> {
545
+ readonly variables: readonly Pick<Variable, "id" | "unit">[];
546
+ }
547
+ /**
548
+ * This function gives the load point of one class of a demand for a law. The point has one number
549
+ * for each variable of the law, in the unit of that variable.
550
+ *
551
+ * The variable `rate` is the rate of the class, or the total rate with the load `total`. Each other
552
+ * variable is a variable of the request of the class, a level of the demand, or an amount of
553
+ * `given`. The amounts of `given` are the state of an instance, for example the size of its heap
554
+ * and its age. No workload gives that state.
555
+ *
556
+ * It gives a problem for a demand that is not correct and for a class that the demand does not
557
+ * have. It gives a problem for a variable with no amount or with two amounts. It gives a problem
558
+ * for an amount that does not convert to the unit of the variable.
559
+ */
560
+ declare const loadPointOf: (demand: Demand, id: string, law: PointLaw, given?: Amounts, options?: PointOptions) => Result<LoadPoint, WorkloadProblem>;
561
+ /**
562
+ * This function gives the load point of a whole instance for a law: a point with no class. The
563
+ * variable `rate` is the total rate of the demand. Each other variable is a level of the demand or
564
+ * an amount of `given`. A variable of a request has no amount here.
565
+ *
566
+ * It gives the problems of `loadPointOf`, with no problem of a class.
567
+ */
568
+ declare const instancePointOf: (demand: Demand, law: PointLaw, given?: Amounts) => Result<LoadPoint, WorkloadProblem>;
569
+ /** This text is the format of a composition file. */
570
+ declare const COMPOSITION_FORMAT = "capacity-composition/1";
571
+ /**
572
+ * The scope of a law term tells where the law applies. The scope `instance` gives one part with no
573
+ * class. The scope `each` gives one part for each class of the demand. A list of class ids gives
574
+ * one part for each class in the list.
575
+ */
576
+ type Over = "instance" | "each" | readonly string[];
577
+ /**
578
+ * A law term adds a law to a composition, times `factor` (1 when the term gives none). The field
579
+ * `load` tells which rate the variable `rate` of the law reads. A term over the instance always
580
+ * reads the total rate.
581
+ *
582
+ * A term with a `base` gives the change of its law from the base point. The change is the value at
583
+ * the load point less the value at the base point. The base point is the load point, with the
584
+ * amount of `base` for each variable that `base` names. Use it for a law of a ladder of one level.
585
+ * That ladder holds the other levels at a base point. A demand with no amount for a variable of
586
+ * `base` stays at the base point, thus the change is 0.
587
+ */
588
+ interface LawTerm {
589
+ readonly law: string;
590
+ readonly over: Over;
591
+ readonly load?: Load | undefined;
592
+ readonly factor?: number | undefined;
593
+ readonly base?: Amounts | undefined;
594
+ }
595
+ /**
596
+ * A nested term adds the value of a different composition over the same demand, times `factor`.
597
+ * Thus layer 3 of an app names layer 2, and layer 2 names layer 1. No layer copies the terms of
598
+ * an other layer.
599
+ */
600
+ interface NestedTerm {
601
+ readonly composition: string;
602
+ readonly factor?: number | undefined;
603
+ }
604
+ /** A composition term is a law term or a nested term. */
605
+ type CompositionTerm = LawTerm | NestedTerm;
606
+ /**
607
+ * A composition gives one measure of a subject as a sum of laws over a demand. Each term gives
608
+ * parts, and the value is the sum of the parts in the unit of the measure.
609
+ *
610
+ * The units of a law term tell if a part is the value of the law times a rate. A law of the CPU
611
+ * time of one request, in `{core}·ms/{request}`, gives `{core}` times the rate of its class. A law
612
+ * of the memory of an instance, in `MiB`, gives `MiB` with no rate.
613
+ */
614
+ interface Composition {
615
+ readonly format: typeof COMPOSITION_FORMAT;
616
+ readonly id: string;
617
+ readonly title: string;
618
+ readonly subject: string;
619
+ readonly measure: Measure;
620
+ readonly terms: readonly CompositionTerm[];
621
+ }
622
+ /** A catalog holds the laws and the compositions that the terms of a composition can name. */
623
+ interface Catalog {
624
+ readonly laws: readonly Law[];
625
+ readonly compositions?: readonly Composition[];
626
+ }
627
+ /** These options set the level of the intervals and the state of the instance: its heap and its age, for example. */
628
+ interface CompositionOptions extends LevelOptions {
629
+ readonly given?: Amounts;
630
+ }
631
+ /** A composition problem code names the part of a composition, or of a query, that is not correct. */
632
+ type CompositionProblemCode = ProblemCode | WorkloadProblemCode | "term" | "law" | "composition";
633
+ /** A composition problem tells what is not correct, and where. */
634
+ type CompositionProblem = Problem<CompositionProblemCode>;
635
+ /**
636
+ * A part value is one part of a composition value, in the unit of the composition. The `weight`
637
+ * is the number that multiplies the value of the law or of the nested composition. The ends of a
638
+ * range change places when the weight is less than 0.
639
+ */
640
+ interface PartBase {
641
+ readonly term: number;
642
+ readonly weight: number;
643
+ readonly value: number;
644
+ readonly interval: Range;
645
+ readonly run: Range;
646
+ }
647
+ /**
648
+ * A law part is the value of a law at the point of one class. When `class` is null, it is the
649
+ * value at the point of the instance. A term with a base gives two parts. The first part is at the load point.
650
+ * The second part is at the base point, with `base` true and the weight times -1.
651
+ */
652
+ interface LawPart extends PartBase {
653
+ readonly kind: "law";
654
+ readonly law: string;
655
+ readonly class: string | null;
656
+ readonly base: boolean;
657
+ readonly outside: readonly string[];
658
+ }
659
+ /** A nested part is the value of a nested composition, with its own parts. */
660
+ interface NestedPart extends PartBase {
661
+ readonly kind: "composition";
662
+ readonly composition: string;
663
+ readonly parts: readonly PartValue[];
664
+ }
665
+ /** A part value is a law part or a nested part. */
666
+ type PartValue = LawPart | NestedPart;
667
+ /**
668
+ * A composition value is the answer of a composition over a demand, in the unit of its measure.
669
+ *
670
+ * Replicate `i` is the sum of row `i` of each law, each times its weight. The `interval` is the
671
+ * share `level` of the replicates, made wider to hold the value. The range `run` is where one
672
+ * measured run falls. The value is an extrapolation when `extrapolated` is true: a part reads a
673
+ * variable outside its range.
674
+ */
675
+ interface CompositionValue {
676
+ readonly value: number;
677
+ readonly unit: string;
678
+ readonly level: number;
679
+ readonly interval: Range;
680
+ readonly run: Range;
681
+ readonly replicates: readonly number[];
682
+ readonly parts: readonly PartValue[];
683
+ readonly extrapolated: boolean;
684
+ }
685
+ /** This function tells if a term names a law. */
686
+ declare const isLawTerm: (term: CompositionTerm) => term is LawTerm;
687
+ /**
688
+ * This function examines a composition and gives each problem that it finds. A composition with no
689
+ * problem gives an empty list.
690
+ *
691
+ * It examines the format, the ids, the title and the unit of the measure. It examines that each
692
+ * term names a law or a composition and has a correct scope. It examines that each factor is a
693
+ * finite number other than 0. It does not look for the laws: `compositionValue` does that.
694
+ */
695
+ declare const checkComposition: (composition: Composition) => readonly CompositionProblem[];
696
+ /**
697
+ * This function gives the value of a composition over a demand, with its interval. The catalog
698
+ * gives each law and each nested composition that a term names. It can hold more.
699
+ *
700
+ * Each part pairs its replicates by row. Row `i` of each law is one draw of the doubt of that law.
701
+ * Laws from separate fits have independent rows. Two laws that share points share their doubt
702
+ * only when their fits use the same resample for row `i`. The count of rows is the least count of
703
+ * the laws that the composition reads.
704
+ *
705
+ * The range `run` adds the change from the interval to the run of each part. That sum is exact
706
+ * when the noise of each part moves with the noise of each other part. For independent noise, the
707
+ * sum is wider than the true range. Thus the range is on the safe side for a limit.
708
+ *
709
+ * The function gives a problem for a composition that is not correct, for a missing law or
710
+ * composition, and for a cycle of compositions. It gives the problems of `loadPointOf` and of
711
+ * `lawValue` for each part, with the path of the term in front.
712
+ */
713
+ declare const compositionValue: (composition: Composition, catalog: Catalog, demand: Demand, options?: CompositionOptions) => Result<CompositionValue, CompositionProblem>;
714
+ /** This text is the format of an instance file. */
715
+ declare const INSTANCE_FORMAT = "capacity-instance/1";
716
+ /** This text is the format of a limits file. */
717
+ declare const LIMITS_FORMAT = "capacity-limits/1";
718
+ /**
719
+ * These units are the unit of each resource that has one meaning in each instance. A resource with
720
+ * one of these names is in a unit that converts to the unit here.
721
+ *
722
+ * - `cpu` is the CPU time that the instance gives in a unit of time, in cores.
723
+ * - `memory` is the memory of the instance.
724
+ * - `network` is the rate of the network of the instance.
725
+ */
726
+ declare const RESOURCE_UNITS: Readonly<Record<string, string>>;
727
+ /**
728
+ * An instance is the resources of one copy of a service: the amount of each resource, by its
729
+ * name. Each amount is above 0. An instance that does not have a resource does not name it.
730
+ */
731
+ interface Instance {
732
+ readonly resources: Amounts;
733
+ }
734
+ /**
735
+ * An instance type is one size of a machine or a container, with a name. An instance file is this
736
+ * record as JSON. Each copy of a service on one instance type has equal resources.
737
+ */
738
+ interface InstanceType extends Instance {
739
+ readonly format: typeof INSTANCE_FORMAT;
740
+ readonly id: string;
741
+ readonly title: string;
742
+ }
743
+ /** An amount ceiling is a fixed amount, for example a latency of 200 ms. It is equal on each instance. */
744
+ interface AmountCeiling {
745
+ readonly kind: "amount";
746
+ readonly amount: Quantity;
747
+ }
748
+ /** A resource ceiling is the whole of one resource of the instance, for example its memory. It grows with the instance. */
749
+ interface ResourceCeiling {
750
+ readonly kind: "resource";
751
+ readonly resource: string;
752
+ }
753
+ /** A ceiling is the largest amount of a measure: a fixed amount, or a resource of the instance. */
754
+ type Ceiling = AmountCeiling | ResourceCeiling;
755
+ /**
756
+ * A limit is a ceiling on one measure of an instance, with headroom. The `headroom` is the share of
757
+ * the ceiling that stays free, from 0 to below 1. The measure stays at or below the remainder.
758
+ */
759
+ interface Limit {
760
+ readonly id: string;
761
+ /** This id is the measure that the limit holds, for example `cpu` or `latency.p99`. */
762
+ readonly measure: string;
763
+ readonly ceiling: Ceiling;
764
+ readonly headroom: number;
765
+ }
766
+ /** A limit set is the limits of a service, with a name. A limits file is this record as JSON. */
767
+ interface LimitSet {
768
+ readonly format: typeof LIMITS_FORMAT;
769
+ readonly id: string;
770
+ readonly title: string;
771
+ readonly limits: readonly Limit[];
772
+ }
773
+ /** An instance problem code names the part of an instance that is not correct. */
774
+ type InstanceProblemCode = "shape" | "format" | "id" | "amount" | "unit" | "resource";
775
+ /** An instance problem tells what is not correct, and where: `path` is the path of the field in the instance. */
776
+ type InstanceProblem = Problem<InstanceProblemCode>;
777
+ /** A limit problem code names the part of a limit, or of a query of a limit, that is not correct. */
778
+ type LimitProblemCode = "shape" | "format" | "id" | "measure" | "amount" | "unit" | "resource" | "headroom";
779
+ /** A limit problem tells what is not correct, and where: `path` is the path of the field in the limit or in the query. */
780
+ type LimitProblem = Problem<LimitProblemCode>;
781
+ export { AppProcess as $, leastCount as $t, compositionValue as A, lawValue as At, shareOf as B, LawProblem as Bt, LawPart as C, WorkloadSource as Ct, Over as D, LoadPoint as Dt, NestedTerm as E, LevelOptions as Et, ShareOptions as F, Fit as Ft, AppClass as G, Problem as Gt, APP_FILE as H, MAX_VARIABLES as Ht, instancePointOf as I, FitError as It, AppEntry as J, Run as Jt, AppCommand as K, ProblemCode as Kt, loadPointOf as L, Form as Lt, Load as M, Constant as Mt, PointLaw as N, DEFAULT_LEVEL as Nt, PartValue as O, Range as Ot, PointOptions as P, Evidence as Pt, AppProblemCode as Q, bootstrapDraws as Qt, mergeDemands as R, LAW_FORMAT as Rt, CompositionValue as S, WorkloadProblemCode as St, NestedPart as T, LawValue as Tt, APP_FORMAT as U, Measure as Ut, totalRate as V, Loser as Vt, APP_LINE_KINDS as W, Noise as Wt, AppLineKind as X, Scale as Xt, AppLine as Y, RunPoint as Yt, AppProblem as Z, Variable as Zt, Composition as _, RATE as _t, InstanceProblem as a, AppStart as at, CompositionProblemCode as b, WorkloadClass as bt, LIMITS_FORMAT as c, MetricsGap as ct, LimitProblemCode as d, VariableKind as dt, leastGroups as en, AppRange as et, LimitSet as f, Amounts as ft, Catalog as g, PlanSource as gt, COMPOSITION_FORMAT as h, NO_DEMAND as ht, Instance as i, AppService as it, isLawTerm as j, ConditionValue as jt, checkComposition as k, constantIntervals as kt, Limit as l, SeriesTarget as lt, ResourceCeiling as m, MetricsSource as mt, Ceiling as n, AppRun as nt, InstanceProblemCode as o, AppVariable as ot, RESOURCE_UNITS as p, Demand as pt, AppContract as q, ResidualKind as qt, INSTANCE_FORMAT as r, AppSeries as rt, InstanceType as s, HttpEntry as st, AmountCeiling as t, AppReady as tt, LimitProblem as u, ServiceEntry as ut, CompositionOptions as v, WORKLOAD_FORMAT as vt, LawTerm as w, ConstantInterval as wt, CompositionTerm as x, WorkloadProblem as xt, CompositionProblem as y, Workload as yt, scaleDemand as z, Law as zt };
782
+ //# sourceMappingURL=instance-0n6WhJzF.d.ts.map