@mark1russell7/capacity 0.0.0-stage → 0.1.1
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.
- package/LICENSE +21 -0
- package/README.md +1110 -2
- package/build/index.d.ts +858 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +1713 -0
- package/build/index.js.map +1 -0
- package/build/instance-check-Bt-SI8va.js +1732 -0
- package/build/instance-check-Bt-SI8va.js.map +1 -0
- package/build/instance-sZmVOOvz.d.ts +801 -0
- package/build/instance-sZmVOOvz.d.ts.map +1 -0
- package/build/schema.d.ts +69 -0
- package/build/schema.d.ts.map +1 -0
- package/build/schema.js +325 -0
- package/build/schema.js.map +1 -0
- package/limits/alerts-routes.line.json +78 -0
- package/limits/alerts-scale.limits.json +10 -0
- package/limits/alerts-start-gate.limits.json +1149 -0
- package/limits/alerts-start-routes-limit-home.bracket.json +543 -0
- package/limits/alerts-start-routes-limit-mid.bracket.json +464 -0
- package/limits/alerts-start-routes-limit.bracket.json +579 -0
- package/limits/alerts-tail-gate.limits.json +610 -0
- package/package.json +85 -3
- package/src/app-check.ts +477 -0
- package/src/app-metrics.ts +105 -0
- package/src/app.ts +239 -0
- package/src/check.ts +253 -0
- package/src/composition.ts +680 -0
- package/src/demand.ts +312 -0
- package/src/fit.ts +153 -0
- package/src/forms.ts +358 -0
- package/src/gate.ts +237 -0
- package/src/index.ts +143 -0
- package/src/instance-check.ts +122 -0
- package/src/instance.ts +84 -0
- package/src/knee.ts +606 -0
- package/src/law.ts +236 -0
- package/src/limit.ts +112 -0
- package/src/names.ts +19 -0
- package/src/observe.ts +74 -0
- package/src/program.ts +74 -0
- package/src/scale.ts +617 -0
- package/src/schema.ts +263 -0
- package/src/value.ts +206 -0
- package/src/workload-check.ts +130 -0
- package/src/workload.ts +88 -0
package/src/index.ts
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Performance and capacity models. A law gives one measure of a subject, for example the CPU time
|
|
3
|
+
* of one request, as a function of its load variables. A workload gives the load: the classes of
|
|
4
|
+
* requests with their rates. The package examines a law and a workload, and it gives the value of
|
|
5
|
+
* a law at a load point, with an interval. The catalog of forms gives the math of a law as data,
|
|
6
|
+
* with its slope and the start values of its fit. The knee of a law is the first load where its
|
|
7
|
+
* cost starts to grow fast. Its edge is the first load with no value. The gate of some laws tells if new
|
|
8
|
+
* measured values stay in the run ranges of their laws.
|
|
9
|
+
*
|
|
10
|
+
* The contract of an app gives its load variables, its classes of requests, its start with fakes of its
|
|
11
|
+
* outside services, and its live metrics. Each app gives the same contract.
|
|
12
|
+
*
|
|
13
|
+
* An instance type gives the resources of one copy of a service. A limit is a ceiling on one
|
|
14
|
+
* measure, with headroom. The package gives the share of each limit that a value takes.
|
|
15
|
+
*
|
|
16
|
+
* @packageDocumentation
|
|
17
|
+
*/
|
|
18
|
+
export type {
|
|
19
|
+
ConditionValue,
|
|
20
|
+
Constant,
|
|
21
|
+
Evidence,
|
|
22
|
+
Fit,
|
|
23
|
+
FitError,
|
|
24
|
+
Form,
|
|
25
|
+
Law,
|
|
26
|
+
LawIdle,
|
|
27
|
+
LawProblem,
|
|
28
|
+
Loser,
|
|
29
|
+
Measure,
|
|
30
|
+
Noise,
|
|
31
|
+
Problem,
|
|
32
|
+
ProblemCode,
|
|
33
|
+
ResidualKind,
|
|
34
|
+
Run,
|
|
35
|
+
RunPoint,
|
|
36
|
+
Scale,
|
|
37
|
+
Variable,
|
|
38
|
+
} from "./law.ts";
|
|
39
|
+
export { DEFAULT_LEVEL, LAW_FORMAT, MAX_VARIABLES, bootstrapDraws, leastCount, leastGroups } from "./law.ts";
|
|
40
|
+
export { NAME, SLUG } from "./names.ts";
|
|
41
|
+
export { checkLaw } from "./check.ts";
|
|
42
|
+
export type { Binding, Bounds, CatalogForm, Grid, Points, Shape, Start, Term } from "./forms.ts";
|
|
43
|
+
export {
|
|
44
|
+
FORMS,
|
|
45
|
+
FORM_VARIABLE,
|
|
46
|
+
catalogForm,
|
|
47
|
+
constantIdsOf,
|
|
48
|
+
formOf,
|
|
49
|
+
formSlopes,
|
|
50
|
+
formValues,
|
|
51
|
+
gridOf,
|
|
52
|
+
programOf,
|
|
53
|
+
separableOf,
|
|
54
|
+
slopeOf,
|
|
55
|
+
startOf,
|
|
56
|
+
} from "./forms.ts";
|
|
57
|
+
export type { FormRank, LawFit, LawFitOptions } from "./fit.ts";
|
|
58
|
+
export { fitLaw } from "./fit.ts";
|
|
59
|
+
export type { ConstantInterval, LawValue, LevelOptions, LoadPoint, Range } from "./value.ts";
|
|
60
|
+
export { constantIntervals, lawValue } from "./value.ts";
|
|
61
|
+
export type { Crossing, Floor, Knee, KneeOptions, KneeRule, OpenRange, OpenValue, Reach } from "./knee.ts";
|
|
62
|
+
export { KNEE_STEPS, kneeRuleProblem, lawKnee, lawReach } from "./knee.ts";
|
|
63
|
+
export type { GateCase, GateJob, GateRead, JobCount, LawGate, LawGateCase, LawGateOptions, LawRead, NoReadJob, ReadSide, SideTest } from "./gate.ts";
|
|
64
|
+
export { GATE_ALPHA, GATE_JOBS, lawGate, lawRead } from "./gate.ts";
|
|
65
|
+
export type {
|
|
66
|
+
Amounts,
|
|
67
|
+
Demand,
|
|
68
|
+
MetricsSource,
|
|
69
|
+
PlanSource,
|
|
70
|
+
Workload,
|
|
71
|
+
WorkloadClass,
|
|
72
|
+
WorkloadProblem,
|
|
73
|
+
WorkloadProblemCode,
|
|
74
|
+
WorkloadSource,
|
|
75
|
+
} from "./workload.ts";
|
|
76
|
+
export { NO_DEMAND, RATE, WORKLOAD_FORMAT } from "./workload.ts";
|
|
77
|
+
export { checkWorkload, demandProblems } from "./workload-check.ts";
|
|
78
|
+
export type {
|
|
79
|
+
AppClass,
|
|
80
|
+
AppCommand,
|
|
81
|
+
AppContract,
|
|
82
|
+
AppEntry,
|
|
83
|
+
AppLine,
|
|
84
|
+
AppLineKind,
|
|
85
|
+
AppProblem,
|
|
86
|
+
AppProblemCode,
|
|
87
|
+
AppProcess,
|
|
88
|
+
AppRange,
|
|
89
|
+
AppReady,
|
|
90
|
+
AppRun,
|
|
91
|
+
AppSeries,
|
|
92
|
+
AppService,
|
|
93
|
+
AppStart,
|
|
94
|
+
AppVariable,
|
|
95
|
+
HttpEntry,
|
|
96
|
+
MetricsGap,
|
|
97
|
+
SeriesTarget,
|
|
98
|
+
ServiceEntry,
|
|
99
|
+
VariableKind,
|
|
100
|
+
} from "./app.ts";
|
|
101
|
+
export { APP_FILE, APP_FORMAT, APP_LINE_KINDS } from "./app.ts";
|
|
102
|
+
export { appWorkloadProblems, checkApp, fillPlaceholders, isHttps, metricsGaps, placeholdersOf, requestPath } from "./app-check.ts";
|
|
103
|
+
export type { MetricsWindow, SeriesReading } from "./app-metrics.ts";
|
|
104
|
+
export { counterIncrease, observationOf } from "./app-metrics.ts";
|
|
105
|
+
export type { Load, PointLaw, PointOptions, ShareOptions } from "./demand.ts";
|
|
106
|
+
export { instancePointOf, loadPointOf, mergeDemands, scaleDemand, shareOf, totalRate } from "./demand.ts";
|
|
107
|
+
export type {
|
|
108
|
+
Catalog,
|
|
109
|
+
Composition,
|
|
110
|
+
CompositionOptions,
|
|
111
|
+
CompositionProblem,
|
|
112
|
+
CompositionProblemCode,
|
|
113
|
+
CompositionTerm,
|
|
114
|
+
CompositionValue,
|
|
115
|
+
LawPart,
|
|
116
|
+
LawTerm,
|
|
117
|
+
NestedPart,
|
|
118
|
+
NestedTerm,
|
|
119
|
+
Over,
|
|
120
|
+
PartValue,
|
|
121
|
+
} from "./composition.ts";
|
|
122
|
+
export { COMPOSITION_FORMAT, checkComposition, compositionValue, isLawTerm } from "./composition.ts";
|
|
123
|
+
export type { Observation, ObservedClass, WorkloadName } from "./observe.ts";
|
|
124
|
+
export { observedWorkload } from "./observe.ts";
|
|
125
|
+
export type {
|
|
126
|
+
AmountCeiling,
|
|
127
|
+
Ceiling,
|
|
128
|
+
Instance,
|
|
129
|
+
InstanceProblem,
|
|
130
|
+
InstanceProblemCode,
|
|
131
|
+
InstanceType,
|
|
132
|
+
Limit,
|
|
133
|
+
LimitProblem,
|
|
134
|
+
LimitProblemCode,
|
|
135
|
+
LimitSet,
|
|
136
|
+
ResourceCeiling,
|
|
137
|
+
} from "./instance.ts";
|
|
138
|
+
export { INSTANCE_FORMAT, LIMITS_FORMAT, RESOURCE_UNITS } from "./instance.ts";
|
|
139
|
+
export { checkInstance, checkLimits, instanceProblems, limitProblems } from "./instance-check.ts";
|
|
140
|
+
export type { LimitUse } from "./limit.ts";
|
|
141
|
+
export { limitAmount, limitUse, limitUses } from "./limit.ts";
|
|
142
|
+
export type { CountReach, LimitCount, LimitLadder, LimitReach, ScaleLadder, ScaleModel, ScaleOptions, ScaleProblem, ScaleProblemCode, ScaleRule } from "./scale.ts";
|
|
143
|
+
export { SCALE_MOST, SCALE_STEPS, countReach, scaleLadder, scaleRule } from "./scale.ts";
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { convertible, isQuantity } from "@mark1russell7/quantity";
|
|
2
|
+
import {
|
|
3
|
+
INSTANCE_FORMAT,
|
|
4
|
+
LIMITS_FORMAT,
|
|
5
|
+
RESOURCE_UNITS,
|
|
6
|
+
type Instance,
|
|
7
|
+
type InstanceProblem,
|
|
8
|
+
type InstanceType,
|
|
9
|
+
type Limit,
|
|
10
|
+
type LimitProblem,
|
|
11
|
+
type LimitSet,
|
|
12
|
+
} from "./instance.ts";
|
|
13
|
+
import { NAME, SLUG, finite, repeated } from "./names.ts";
|
|
14
|
+
|
|
15
|
+
/** This function makes a problem of an instance. */
|
|
16
|
+
export const instanceProblem = (code: InstanceProblem["code"], path: string, message: string): InstanceProblem => ({
|
|
17
|
+
code,
|
|
18
|
+
path,
|
|
19
|
+
message,
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
/** This function makes a problem of a limit. */
|
|
23
|
+
export const limitProblem = (code: LimitProblem["code"], path: string, message: string): LimitProblem => ({ code, path, message });
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* This function examines the resources of an instance and gives each problem that it finds. An
|
|
27
|
+
* instance with no problem gives an empty list.
|
|
28
|
+
*
|
|
29
|
+
* It examines that the instance has a resource. It examines the name and the amount of each
|
|
30
|
+
* resource. It examines the unit of each resource of `RESOURCE_UNITS`.
|
|
31
|
+
*/
|
|
32
|
+
export const instanceProblems = (instance: Instance): readonly InstanceProblem[] => {
|
|
33
|
+
const problems: InstanceProblem[] = [];
|
|
34
|
+
const entries = Object.entries(instance.resources);
|
|
35
|
+
if (entries.length === 0) problems.push(instanceProblem("resource", "resources", "The instance has no resource."));
|
|
36
|
+
for (const [name, amount] of entries) {
|
|
37
|
+
const at = `resources.${name}`;
|
|
38
|
+
if (!NAME.test(name)) {
|
|
39
|
+
problems.push(instanceProblem("id", at, `The name "${name}" is not letters and digits that start with a lower-case letter.`));
|
|
40
|
+
}
|
|
41
|
+
if (!isQuantity(amount)) {
|
|
42
|
+
problems.push(instanceProblem("amount", at, `"${name}" is not a finite amount in a canonical unit.`));
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
if (!(amount.value > 0)) problems.push(instanceProblem("amount", at, `The resource "${name}" is not above 0.`));
|
|
46
|
+
const unit = Object.hasOwn(RESOURCE_UNITS, name) ? RESOURCE_UNITS[name] : undefined;
|
|
47
|
+
if (unit !== undefined && !convertible(amount.unit, unit)) {
|
|
48
|
+
problems.push(instanceProblem("unit", at, `The resource "${name}" is in "${amount.unit}". Its unit converts to "${unit}".`));
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return problems;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* This function examines an instance type and gives each problem that it finds. An instance type
|
|
56
|
+
* with no problem gives an empty list.
|
|
57
|
+
*
|
|
58
|
+
* It examines the format, the id and the title. It examines the resources with `instanceProblems`.
|
|
59
|
+
*/
|
|
60
|
+
export const checkInstance = (type: InstanceType): readonly InstanceProblem[] => {
|
|
61
|
+
const problems: InstanceProblem[] = [];
|
|
62
|
+
if (type.format !== INSTANCE_FORMAT) {
|
|
63
|
+
problems.push(instanceProblem("format", "format", `The format is "${String(type.format)}", not "${INSTANCE_FORMAT}".`));
|
|
64
|
+
}
|
|
65
|
+
if (!SLUG.test(type.id)) {
|
|
66
|
+
problems.push(instanceProblem("id", "id", `The id "${type.id}" is not lower-case words joined by ".", "-" or "/".`));
|
|
67
|
+
}
|
|
68
|
+
if (type.title.trim() === "") problems.push(instanceProblem("id", "title", "The title is empty."));
|
|
69
|
+
problems.push(...instanceProblems(type));
|
|
70
|
+
return problems;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* This function examines one limit and gives each problem that it finds. The text `path` is the
|
|
75
|
+
* path of the limit, and it goes before the path of each problem.
|
|
76
|
+
*/
|
|
77
|
+
export const limitProblems = (limit: Limit, path = ""): readonly LimitProblem[] => {
|
|
78
|
+
const problems: LimitProblem[] = [];
|
|
79
|
+
const at = (field: string): string => (path === "" ? field : `${path}.${field}`);
|
|
80
|
+
if (!SLUG.test(limit.id)) {
|
|
81
|
+
problems.push(limitProblem("id", at("id"), `The id "${limit.id}" is not lower-case words joined by ".", "-" or "/".`));
|
|
82
|
+
}
|
|
83
|
+
if (!SLUG.test(limit.measure)) {
|
|
84
|
+
problems.push(limitProblem("measure", at("measure"), `The measure "${limit.measure}" is not lower-case words joined by ".", "-" or "/".`));
|
|
85
|
+
}
|
|
86
|
+
if (!finite(limit.headroom) || limit.headroom < 0 || limit.headroom >= 1) {
|
|
87
|
+
problems.push(limitProblem("headroom", at("headroom"), `The headroom ${limit.headroom} is not a number from 0 to below 1.`));
|
|
88
|
+
}
|
|
89
|
+
const ceiling = limit.ceiling;
|
|
90
|
+
if (ceiling.kind === "resource") {
|
|
91
|
+
if (!NAME.test(ceiling.resource)) {
|
|
92
|
+
problems.push(
|
|
93
|
+
limitProblem("resource", at("ceiling.resource"), `The name "${ceiling.resource}" is not letters and digits that start with a lower-case letter.`),
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
} else if (!isQuantity(ceiling.amount)) {
|
|
97
|
+
problems.push(limitProblem("amount", at("ceiling.amount"), "The ceiling is not a finite amount in a canonical unit."));
|
|
98
|
+
} else if (!(ceiling.amount.value > 0)) {
|
|
99
|
+
problems.push(limitProblem("amount", at("ceiling.amount"), "The ceiling is not above 0."));
|
|
100
|
+
}
|
|
101
|
+
return problems;
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* This function examines a limit set and gives each problem that it finds. A limit set with no
|
|
106
|
+
* problem gives an empty list.
|
|
107
|
+
*
|
|
108
|
+
* It examines the format, the id and the title. It examines each limit with `limitProblems`. It
|
|
109
|
+
* examines that two limits do not have one id.
|
|
110
|
+
*/
|
|
111
|
+
export const checkLimits = (set: LimitSet): readonly LimitProblem[] => {
|
|
112
|
+
const problems: LimitProblem[] = [];
|
|
113
|
+
if (set.format !== LIMITS_FORMAT) {
|
|
114
|
+
problems.push(limitProblem("format", "format", `The format is "${String(set.format)}", not "${LIMITS_FORMAT}".`));
|
|
115
|
+
}
|
|
116
|
+
if (!SLUG.test(set.id)) problems.push(limitProblem("id", "id", `The id "${set.id}" is not lower-case words joined by ".", "-" or "/".`));
|
|
117
|
+
if (set.title.trim() === "") problems.push(limitProblem("id", "title", "The title is empty."));
|
|
118
|
+
set.limits.forEach((limit, index) => problems.push(...limitProblems(limit, `limits[${index}]`)));
|
|
119
|
+
const twice = repeated(set.limits.map((limit) => limit.id));
|
|
120
|
+
if (twice !== undefined) problems.push(limitProblem("id", "limits", `Two limits have the id "${twice}".`));
|
|
121
|
+
return problems;
|
|
122
|
+
};
|
package/src/instance.ts
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type { Quantity } from "@mark1russell7/quantity";
|
|
2
|
+
import type { Problem } from "./law.ts";
|
|
3
|
+
import type { Amounts } from "./workload.ts";
|
|
4
|
+
|
|
5
|
+
/** This text is the format of an instance file. */
|
|
6
|
+
export const INSTANCE_FORMAT = "capacity-instance/1";
|
|
7
|
+
|
|
8
|
+
/** This text is the format of a limits file. */
|
|
9
|
+
export const LIMITS_FORMAT = "capacity-limits/1";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* These units are the unit of each resource that has one meaning in each instance. A resource with
|
|
13
|
+
* one of these names is in a unit that converts to the unit here.
|
|
14
|
+
*
|
|
15
|
+
* - `cpu` is the CPU time that the instance gives in a unit of time, in cores.
|
|
16
|
+
* - `memory` is the memory of the instance.
|
|
17
|
+
* - `network` is the rate of the network of the instance.
|
|
18
|
+
*/
|
|
19
|
+
export const RESOURCE_UNITS: Readonly<Record<string, string>> = { cpu: "{core}", memory: "B", network: "bit/s" };
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* An instance is the resources of one copy of a service: the amount of each resource, by its
|
|
23
|
+
* name. Each amount is above 0. An instance that does not have a resource does not name it.
|
|
24
|
+
*/
|
|
25
|
+
export interface Instance {
|
|
26
|
+
readonly resources: Amounts;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* An instance type is one size of a machine or a container, with a name. An instance file is this
|
|
31
|
+
* record as JSON. Each copy of a service on one instance type has equal resources.
|
|
32
|
+
*/
|
|
33
|
+
export interface InstanceType extends Instance {
|
|
34
|
+
readonly format: typeof INSTANCE_FORMAT;
|
|
35
|
+
readonly id: string;
|
|
36
|
+
readonly title: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** An amount ceiling is a fixed amount, for example a latency of 200 ms. It is equal on each instance. */
|
|
40
|
+
export interface AmountCeiling {
|
|
41
|
+
readonly kind: "amount";
|
|
42
|
+
readonly amount: Quantity;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** A resource ceiling is the whole of one resource of the instance, for example its memory. It grows with the instance. */
|
|
46
|
+
export interface ResourceCeiling {
|
|
47
|
+
readonly kind: "resource";
|
|
48
|
+
readonly resource: string;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** A ceiling is the largest amount of a measure: a fixed amount, or a resource of the instance. */
|
|
52
|
+
export type Ceiling = AmountCeiling | ResourceCeiling;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* A limit is a ceiling on one measure of an instance, with headroom. The `headroom` is the share of
|
|
56
|
+
* the ceiling that stays free, from 0 to below 1. The measure stays at or below the remainder.
|
|
57
|
+
*/
|
|
58
|
+
export interface Limit {
|
|
59
|
+
readonly id: string;
|
|
60
|
+
/** This id is the measure that the limit holds, for example `cpu` or `latency.p99`. */
|
|
61
|
+
readonly measure: string;
|
|
62
|
+
readonly ceiling: Ceiling;
|
|
63
|
+
readonly headroom: number;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** A limit set is the limits of a service, with a name. A limits file is this record as JSON. */
|
|
67
|
+
export interface LimitSet {
|
|
68
|
+
readonly format: typeof LIMITS_FORMAT;
|
|
69
|
+
readonly id: string;
|
|
70
|
+
readonly title: string;
|
|
71
|
+
readonly limits: readonly Limit[];
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** An instance problem code names the part of an instance that is not correct. */
|
|
75
|
+
export type InstanceProblemCode = "shape" | "format" | "id" | "amount" | "unit" | "resource";
|
|
76
|
+
|
|
77
|
+
/** An instance problem tells what is not correct, and where: `path` is the path of the field in the instance. */
|
|
78
|
+
export type InstanceProblem = Problem<InstanceProblemCode>;
|
|
79
|
+
|
|
80
|
+
/** A limit problem code names the part of a limit, or of a query of a limit, that is not correct. */
|
|
81
|
+
export type LimitProblemCode = "shape" | "format" | "id" | "measure" | "amount" | "unit" | "resource" | "headroom";
|
|
82
|
+
|
|
83
|
+
/** A limit problem tells what is not correct, and where: `path` is the path of the field in the limit or in the query. */
|
|
84
|
+
export type LimitProblem = Problem<LimitProblemCode>;
|