@ultimat3/cli 31.17.0 → 31.18.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.
- package/README.md +4 -1
- package/package.json +29 -29
- package/src/cmd-doctor.ts +3 -3
- package/src/cmd-generate-spec.ts +3 -3
- package/src/cmd-generate.ts +2 -2
- package/src/doctor-chart-alerts.ts +50 -22
- package/src/generate-chart-alerts.ts +99 -45
- package/src/generate-files.ts +4 -0
- package/src/generate-kinds.ts +2 -0
- package/src/messages.ts +2 -0
- package/src/templates/chart-dashboard.ts +245 -0
- package/src/templates/scaffold-helm-alert-rules.ts +160 -0
- package/src/templates/scaffold-helm-alerts.ts +22 -87
- package/src/templates/scaffold-helm-templates.ts +2 -0
- package/src/templates/scaffold-helm.ts +20 -4
- package/wiki/Admin-Dashboard.md +6 -2
- package/wiki/CLI-Reference.md +5 -2
- package/wiki/Observability.md +6 -1
- package/wiki/Testing.md +32 -0
- package/wiki/Upgrading.md +4 -0
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
// The one Grafana dashboard every Ultimate chart ships: requests, latency by route, statements,
|
|
2
|
+
// pool, jobs, realtime and the process, over the series the framework declares. One column of
|
|
3
|
+
// full-width panels, so a phone reads it as it is. The JSON and its ConfigMap are generated here;
|
|
4
|
+
// `docker/helm/` holds these bytes for the chart named `ultimate`.
|
|
5
|
+
import type { GeneratedFile, NameSet } from './naming';
|
|
6
|
+
|
|
7
|
+
export interface DashboardTarget {
|
|
8
|
+
readonly expr: string;
|
|
9
|
+
/** Grafana's legend template, `{{label}}` interpolated per series. */
|
|
10
|
+
readonly legend: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface DashboardPanel {
|
|
14
|
+
readonly title: string;
|
|
15
|
+
/** Grafana's unit id: `reqps`, `s`, `bytes`, `percentunit`, `short`. */
|
|
16
|
+
readonly unit: string;
|
|
17
|
+
readonly targets: readonly DashboardTarget[];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** One release in one namespace — the two labels the ServiceMonitor puts on every series. */
|
|
21
|
+
const SCOPE = 'namespace="$namespace",app_kubernetes_io_instance="$release"';
|
|
22
|
+
const RATE = '[$__rate_interval]';
|
|
23
|
+
|
|
24
|
+
const s = (name: string, extra?: string): string =>
|
|
25
|
+
`${name}{${extra === undefined ? SCOPE : `${SCOPE},${extra}`}}`;
|
|
26
|
+
|
|
27
|
+
const p = (q: number, name: string, by: string): string =>
|
|
28
|
+
`histogram_quantile(${String(q)}, sum by (${by}, le) (rate(${s(`${name}_bucket`)}${RATE})))`;
|
|
29
|
+
|
|
30
|
+
export const DASHBOARD_PANELS: readonly DashboardPanel[] = [
|
|
31
|
+
{
|
|
32
|
+
title: 'Requests per second, by status class',
|
|
33
|
+
unit: 'reqps',
|
|
34
|
+
targets: [
|
|
35
|
+
{ expr: `sum by (status) (rate(${s('http_requests_total')}${RATE}))`, legend: '{{status}}' },
|
|
36
|
+
],
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
title: 'Latency p95, by route',
|
|
40
|
+
unit: 's',
|
|
41
|
+
targets: [{ expr: p(0.95, 'http_request_duration_seconds', 'route'), legend: '{{route}}' }],
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
title: '5xx share of requests',
|
|
45
|
+
unit: 'percentunit',
|
|
46
|
+
targets: [
|
|
47
|
+
{
|
|
48
|
+
expr: `sum(rate(${s('http_requests_total', 'status="5xx"')}${RATE})) / sum(rate(${s('http_requests_total')}${RATE}))`,
|
|
49
|
+
legend: '5xx',
|
|
50
|
+
},
|
|
51
|
+
],
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
title: 'Statement p95, by operation',
|
|
55
|
+
unit: 's',
|
|
56
|
+
targets: [
|
|
57
|
+
{
|
|
58
|
+
expr: p(0.95, 'db_client_operation_duration_seconds', 'db_operation_name'),
|
|
59
|
+
legend: 'p95 {{db_operation_name}}',
|
|
60
|
+
},
|
|
61
|
+
],
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
title: 'Database pool, by pod',
|
|
65
|
+
unit: 'short',
|
|
66
|
+
targets: [
|
|
67
|
+
{ expr: `sum by (pod) (${s('db_pool_in_use')})`, legend: 'in use {{pod}}' },
|
|
68
|
+
{ expr: `sum by (pod) (${s('db_pool_waiting')})`, legend: 'waiting {{pod}}' },
|
|
69
|
+
{ expr: `sum by (pod) (${s('db_pool_max')})`, legend: 'max {{pod}}' },
|
|
70
|
+
],
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
title: 'Jobs per second, by queue and outcome',
|
|
74
|
+
unit: 'short',
|
|
75
|
+
targets: [
|
|
76
|
+
{
|
|
77
|
+
expr: `sum by (queue, outcome) (rate(${s('jobs_total')}${RATE}))`,
|
|
78
|
+
legend: '{{queue}} {{outcome}}',
|
|
79
|
+
},
|
|
80
|
+
],
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
title: 'Queue: oldest ready job and dead letters',
|
|
84
|
+
unit: 's',
|
|
85
|
+
targets: [
|
|
86
|
+
{ expr: `max by (queue) (${s('queue_oldest_ready_seconds')})`, legend: 'oldest {{queue}}' },
|
|
87
|
+
{ expr: `max by (queue) (${s('queue_dead_jobs')})`, legend: 'dead {{queue}}' },
|
|
88
|
+
],
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
title: 'Job duration p95, by queue',
|
|
92
|
+
unit: 's',
|
|
93
|
+
targets: [{ expr: p(0.95, 'job_duration_seconds', 'queue'), legend: '{{queue}}' }],
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
title: 'Realtime: connections and dropped frames',
|
|
97
|
+
unit: 'short',
|
|
98
|
+
targets: [
|
|
99
|
+
{ expr: `sum by (pod) (${s('connections')})`, legend: 'connections {{pod}}' },
|
|
100
|
+
{
|
|
101
|
+
expr: `sum(rate(${s('channel_frames_dropped_total')}${RATE}))`,
|
|
102
|
+
legend: 'frames dropped/s',
|
|
103
|
+
},
|
|
104
|
+
],
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
title: 'Memory: RSS over the container limit, by pod',
|
|
108
|
+
unit: 'percentunit',
|
|
109
|
+
targets: [
|
|
110
|
+
{
|
|
111
|
+
expr: `max by (pod) (${s('process_resident_memory_bytes')} / ${s('process_memory_limit_bytes')})`,
|
|
112
|
+
legend: '{{pod}}',
|
|
113
|
+
},
|
|
114
|
+
],
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
title: 'CPU seconds per second, by pod',
|
|
118
|
+
unit: 'short',
|
|
119
|
+
targets: [
|
|
120
|
+
{ expr: `sum by (pod) (rate(${s('process_cpu_seconds_total')}${RATE}))`, legend: '{{pod}}' },
|
|
121
|
+
],
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
title: 'Event-loop lag p99, by pod',
|
|
125
|
+
unit: 's',
|
|
126
|
+
targets: [{ expr: p(0.99, 'process_event_loop_lag_seconds', 'pod'), legend: '{{pod}}' }],
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
title: 'Restarts in the last hour, by role',
|
|
130
|
+
unit: 'short',
|
|
131
|
+
targets: [
|
|
132
|
+
{
|
|
133
|
+
expr: `sum by (app_kubernetes_io_component) (changes(${s('process_start_time_seconds')}[1h]))`,
|
|
134
|
+
legend: '{{app_kubernetes_io_component}}',
|
|
135
|
+
},
|
|
136
|
+
],
|
|
137
|
+
},
|
|
138
|
+
];
|
|
139
|
+
|
|
140
|
+
/** The stable uid a provisioned dashboard keeps across upgrades, so a bookmark survives. */
|
|
141
|
+
export const DASHBOARD_UID = 'ultimate-app';
|
|
142
|
+
export const DASHBOARD_FILE = 'docker/helm/dashboards/ultimate-app.json';
|
|
143
|
+
|
|
144
|
+
/** Every panel and variable reads the dashboard's own datasource variable. */
|
|
145
|
+
const DATASOURCE = { type: 'prometheus', uid: '$datasource' } as const;
|
|
146
|
+
|
|
147
|
+
const variable = (name: string, query: string) => ({
|
|
148
|
+
name,
|
|
149
|
+
type: 'query',
|
|
150
|
+
datasource: DATASOURCE,
|
|
151
|
+
query: { query, refId: name },
|
|
152
|
+
refresh: 2,
|
|
153
|
+
includeAll: false,
|
|
154
|
+
multi: false,
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
const PANEL_HEIGHT = 8;
|
|
158
|
+
|
|
159
|
+
/** The dashboard as Grafana's JSON model, two-space indented, one trailing newline. */
|
|
160
|
+
export function dashboardJson(): string {
|
|
161
|
+
const model = {
|
|
162
|
+
uid: DASHBOARD_UID,
|
|
163
|
+
title: 'Ultimate app',
|
|
164
|
+
tags: ['ultimate'],
|
|
165
|
+
timezone: 'utc',
|
|
166
|
+
schemaVersion: 39,
|
|
167
|
+
editable: true,
|
|
168
|
+
time: { from: 'now-6h', to: 'now' },
|
|
169
|
+
templating: {
|
|
170
|
+
list: [
|
|
171
|
+
{ name: 'datasource', type: 'datasource', query: 'prometheus' },
|
|
172
|
+
variable('namespace', 'label_values(process_info, namespace)'),
|
|
173
|
+
variable(
|
|
174
|
+
'release',
|
|
175
|
+
'label_values(process_info{namespace="$namespace"}, app_kubernetes_io_instance)',
|
|
176
|
+
),
|
|
177
|
+
],
|
|
178
|
+
},
|
|
179
|
+
panels: DASHBOARD_PANELS.map((panel, index) => ({
|
|
180
|
+
id: index + 1,
|
|
181
|
+
type: 'timeseries',
|
|
182
|
+
title: panel.title,
|
|
183
|
+
datasource: DATASOURCE,
|
|
184
|
+
// One full-width column: the grid is 24 wide, and a phone shows it unchanged.
|
|
185
|
+
gridPos: { x: 0, y: index * PANEL_HEIGHT, w: 24, h: PANEL_HEIGHT },
|
|
186
|
+
fieldConfig: { defaults: { unit: panel.unit }, overrides: [] },
|
|
187
|
+
targets: panel.targets.map((target, at) => ({
|
|
188
|
+
refId: String.fromCharCode(65 + at),
|
|
189
|
+
expr: target.expr,
|
|
190
|
+
legendFormat: target.legend,
|
|
191
|
+
})),
|
|
192
|
+
})),
|
|
193
|
+
};
|
|
194
|
+
return `${biomeJson(model)}\n`;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
const SCALAR = String.raw`(?:"(?:[^"\\\n]|\\.)*"|-?\d[\d.eE+-]*|true|false|null)`;
|
|
198
|
+
const SCALAR_ARRAY = new RegExp(String.raw`\[\n\s+(${SCALAR}(?:,\n\s+${SCALAR})*)\n\s*\]`, 'g');
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* `JSON.stringify` at two spaces, with an array of scalars on one line — how Biome formats JSON, so
|
|
202
|
+
* the file `x new` writes passes the app's own `biome check`. Objects stay expanded, as Biome keeps
|
|
203
|
+
* them.
|
|
204
|
+
*/
|
|
205
|
+
function biomeJson(value: unknown): string {
|
|
206
|
+
return JSON.stringify(value, null, 2).replace(
|
|
207
|
+
SCALAR_ARRAY,
|
|
208
|
+
(_all, items: string) => `[${items.split(/,\n\s+/).join(', ')}]`,
|
|
209
|
+
);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
const configMapTemplate = (chart: string): string => `{{/*
|
|
213
|
+
The chart's Grafana dashboard (dashboards/ultimate-app.json, written from @ultimat3/cli's panel
|
|
214
|
+
table), as a ConfigMap a Grafana sidecar provisions by label. Opt-in: dashboard.enabled. The JSON
|
|
215
|
+
is read with .Files.Get, never templated: its legends use Grafana's own double-brace syntax.
|
|
216
|
+
*/}}
|
|
217
|
+
{{- $cfg := .Values.dashboard | default dict }}
|
|
218
|
+
{{- if eq (toString $cfg.enabled) "true" }}
|
|
219
|
+
apiVersion: v1
|
|
220
|
+
kind: ConfigMap
|
|
221
|
+
metadata:
|
|
222
|
+
name: {{ include "${chart}.fullname" . }}-dashboard
|
|
223
|
+
labels:
|
|
224
|
+
{{- include "${chart}.labels" . | nindent 4 }}
|
|
225
|
+
{{- toYaml ($cfg.labels | default (dict "grafana_dashboard" "1")) | nindent 4 }}
|
|
226
|
+
{{- with $cfg.annotations }}
|
|
227
|
+
annotations:
|
|
228
|
+
{{- toYaml . | nindent 4 }}
|
|
229
|
+
{{- end }}
|
|
230
|
+
data:
|
|
231
|
+
ultimate-app.json: |-
|
|
232
|
+
{{ .Files.Get "dashboards/ultimate-app.json" | indent 4 }}
|
|
233
|
+
{{- end }}
|
|
234
|
+
`;
|
|
235
|
+
|
|
236
|
+
/** The dashboard and the template that ships it. */
|
|
237
|
+
export function helmDashboardFiles(app: NameSet): readonly GeneratedFile[] {
|
|
238
|
+
return [
|
|
239
|
+
{ path: DASHBOARD_FILE, contents: dashboardJson() },
|
|
240
|
+
{
|
|
241
|
+
path: 'docker/helm/templates/dashboard-configmap.yaml',
|
|
242
|
+
contents: configMapTemplate(app.kebab),
|
|
243
|
+
},
|
|
244
|
+
];
|
|
245
|
+
}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
// The rule table every Ultimate chart's alerts are written from, renderer-neutral. Only mechanism
|
|
2
|
+
// ships (axiom 8): a stalled queue, a dead letter, a lost lease, a dropped frame, error-budget burn,
|
|
3
|
+
// job failures, pool, loop and memory saturation, a dead target. A latency target is the app's.
|
|
4
|
+
|
|
5
|
+
/** How an expression names a series and groups its result, per renderer. */
|
|
6
|
+
export interface AlertScope {
|
|
7
|
+
/** `name{matchers}` — the scope's own matchers, then `extra`. */
|
|
8
|
+
readonly series: (name: string, extra?: string) => string;
|
|
9
|
+
/** The labels every rule groups by, so one release (or one job) fires one alert. */
|
|
10
|
+
readonly by: string;
|
|
11
|
+
/** The label naming a scrape target's role. */
|
|
12
|
+
readonly component: string;
|
|
13
|
+
/** The label naming one scrape target — a pod, or a plain `instance`. */
|
|
14
|
+
readonly target: string;
|
|
15
|
+
/** The rule's threshold, as the renderer spells it: a value lookup or the default. */
|
|
16
|
+
readonly threshold: (fallback: number) => string;
|
|
17
|
+
/** The error budget as a PromQL scalar: `(1 - <objective> / 100)`. */
|
|
18
|
+
readonly budget: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface ChartAlert {
|
|
22
|
+
readonly alert: string;
|
|
23
|
+
readonly expr: (scope: AlertScope) => string;
|
|
24
|
+
/** The default `alerts.rules.<alert>.threshold`, for a rule whose comparison is a number. */
|
|
25
|
+
readonly threshold?: number;
|
|
26
|
+
readonly for: string;
|
|
27
|
+
readonly severity: 'warning' | 'critical';
|
|
28
|
+
readonly summary: string;
|
|
29
|
+
/** The heading in `docs/ops/06-runbooks.md` the rule's `runbook_url` lands on. */
|
|
30
|
+
readonly anchor: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** `alerts.objective`'s default: the share of requests, in percent, answered without a 5xx. */
|
|
34
|
+
export const DEFAULT_OBJECTIVE = 99.9;
|
|
35
|
+
|
|
36
|
+
/** The PromQL error budget for an objective in percent. */
|
|
37
|
+
export const budgetOf = (objective: string): string => `(1 - ${objective} / 100)`;
|
|
38
|
+
|
|
39
|
+
const rule = (alert: Omit<ChartAlert, 'anchor'>): ChartAlert => ({
|
|
40
|
+
...alert,
|
|
41
|
+
anchor: alert.alert.toLowerCase(),
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
/** The share of requests answered 5xx over `window`, per release. */
|
|
45
|
+
const errorRatio = (s: AlertScope, window: string): string =>
|
|
46
|
+
`(sum by (${s.by}) (rate(${s.series('http_requests_total', 'status="5xx"')}[${window}])) / ` +
|
|
47
|
+
`sum by (${s.by}) (rate(${s.series('http_requests_total')}[${window}])))`;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Multi-window burn rate (the SRE workbook's): the long window says the budget is really going,
|
|
51
|
+
* the short one that it still is, so the alert resets minutes after the fault does.
|
|
52
|
+
*/
|
|
53
|
+
const burn = (s: AlertScope, long: string, short: string, factor: number): string =>
|
|
54
|
+
`${errorRatio(s, long)} > ${s.threshold(factor)} * ${s.budget} and ` +
|
|
55
|
+
`${errorRatio(s, short)} > ${s.threshold(factor)} * ${s.budget}`;
|
|
56
|
+
|
|
57
|
+
export const CHART_ALERTS: readonly ChartAlert[] = [
|
|
58
|
+
rule({
|
|
59
|
+
alert: 'UltimateQueueStalled',
|
|
60
|
+
threshold: 300,
|
|
61
|
+
expr: (s) =>
|
|
62
|
+
`max by (${s.by}, queue) (${s.series('queue_oldest_ready_seconds')}) > ${s.threshold(300)}`,
|
|
63
|
+
for: '5m',
|
|
64
|
+
severity: 'warning',
|
|
65
|
+
summary: 'A queue has a due job nothing has claimed for longer than the threshold',
|
|
66
|
+
}),
|
|
67
|
+
rule({
|
|
68
|
+
alert: 'UltimateDeadLetters',
|
|
69
|
+
expr: (s) => `max by (${s.by}, queue) (${s.series('queue_dead_jobs')}) > 0`,
|
|
70
|
+
for: '5m',
|
|
71
|
+
severity: 'warning',
|
|
72
|
+
summary: 'A queue holds dead-lettered jobs',
|
|
73
|
+
}),
|
|
74
|
+
rule({
|
|
75
|
+
alert: 'UltimateLeaseLost',
|
|
76
|
+
expr: (s) => `sum by (${s.by}, queue) (rate(${s.series('job_leases_lost_total')}[5m])) > 0`,
|
|
77
|
+
for: '5m',
|
|
78
|
+
severity: 'warning',
|
|
79
|
+
summary: 'Job leases are lapsing while their jobs still run, so jobs run twice',
|
|
80
|
+
}),
|
|
81
|
+
rule({
|
|
82
|
+
alert: 'UltimateFramesDropped',
|
|
83
|
+
expr: (s) => `sum by (${s.by}) (rate(${s.series('channel_frames_dropped_total')}[5m])) > 0`,
|
|
84
|
+
for: '5m',
|
|
85
|
+
severity: 'warning',
|
|
86
|
+
summary: 'Sync nodes are dropping channel frames to socket backpressure',
|
|
87
|
+
}),
|
|
88
|
+
rule({
|
|
89
|
+
alert: 'UltimateServerErrors',
|
|
90
|
+
threshold: 0.05,
|
|
91
|
+
expr: (s) =>
|
|
92
|
+
`sum by (${s.by}) (rate(${s.series('http_requests_total', 'status="5xx"')}[5m])) / ` +
|
|
93
|
+
`sum by (${s.by}) (rate(${s.series('http_requests_total')}[5m])) > ${s.threshold(0.05)}`,
|
|
94
|
+
for: '10m',
|
|
95
|
+
severity: 'critical',
|
|
96
|
+
summary: 'The share of requests answered 5xx is above the threshold',
|
|
97
|
+
}),
|
|
98
|
+
rule({
|
|
99
|
+
alert: 'UltimateErrorBudgetFastBurn',
|
|
100
|
+
threshold: 14.4,
|
|
101
|
+
expr: (s) => burn(s, '1h', '5m', 14.4),
|
|
102
|
+
for: '2m',
|
|
103
|
+
severity: 'critical',
|
|
104
|
+
summary: 'The error budget is burning fast enough to spend 2% of a 30-day budget in an hour',
|
|
105
|
+
}),
|
|
106
|
+
rule({
|
|
107
|
+
alert: 'UltimateErrorBudgetSlowBurn',
|
|
108
|
+
threshold: 6,
|
|
109
|
+
expr: (s) => burn(s, '6h', '30m', 6),
|
|
110
|
+
for: '15m',
|
|
111
|
+
severity: 'warning',
|
|
112
|
+
summary: 'The error budget is burning fast enough to spend 5% of a 30-day budget in six hours',
|
|
113
|
+
}),
|
|
114
|
+
rule({
|
|
115
|
+
alert: 'UltimateJobFailures',
|
|
116
|
+
threshold: 0.1,
|
|
117
|
+
expr: (s) =>
|
|
118
|
+
`sum by (${s.by}, queue) (rate(${s.series('jobs_total', 'outcome=~"failed|dead"')}[15m])) / ` +
|
|
119
|
+
`sum by (${s.by}, queue) (rate(${s.series('jobs_total')}[15m])) > ${s.threshold(0.1)}`,
|
|
120
|
+
for: '15m',
|
|
121
|
+
severity: 'warning',
|
|
122
|
+
summary: "The share of a queue's job runs that fail is above the threshold",
|
|
123
|
+
}),
|
|
124
|
+
rule({
|
|
125
|
+
alert: 'UltimatePoolSaturated',
|
|
126
|
+
threshold: 0,
|
|
127
|
+
expr: (s) =>
|
|
128
|
+
`max by (${s.by}, ${s.target}) (${s.series('db_pool_waiting')}) > ${s.threshold(0)}`,
|
|
129
|
+
for: '5m',
|
|
130
|
+
severity: 'warning',
|
|
131
|
+
summary: 'Statements are queuing for a database connection: the pool is at its ceiling',
|
|
132
|
+
}),
|
|
133
|
+
rule({
|
|
134
|
+
alert: 'UltimateEventLoopLag',
|
|
135
|
+
threshold: 0.5,
|
|
136
|
+
expr: (s) =>
|
|
137
|
+
`histogram_quantile(0.99, sum by (${s.by}, ${s.target}, le) ` +
|
|
138
|
+
`(rate(${s.series('process_event_loop_lag_seconds_bucket')}[5m]))) > ${s.threshold(0.5)}`,
|
|
139
|
+
for: '10m',
|
|
140
|
+
severity: 'warning',
|
|
141
|
+
summary: 'A process runs its timers late: the event loop is blocked or the pod is starved',
|
|
142
|
+
}),
|
|
143
|
+
rule({
|
|
144
|
+
alert: 'UltimateMemoryNearLimit',
|
|
145
|
+
threshold: 0.9,
|
|
146
|
+
expr: (s) =>
|
|
147
|
+
`max by (${s.by}, ${s.target}) (${s.series('process_resident_memory_bytes')} / ` +
|
|
148
|
+
`${s.series('process_memory_limit_bytes')}) > ${s.threshold(0.9)}`,
|
|
149
|
+
for: '10m',
|
|
150
|
+
severity: 'warning',
|
|
151
|
+
summary: "A process holds more of its container's memory limit than the threshold",
|
|
152
|
+
}),
|
|
153
|
+
rule({
|
|
154
|
+
alert: 'UltimateTargetDown',
|
|
155
|
+
expr: (s) => `count by (${s.by}, ${s.component}) (${s.series('up')} == 0) > 0`,
|
|
156
|
+
for: '5m',
|
|
157
|
+
severity: 'critical',
|
|
158
|
+
summary: 'A role has a scrape target that is down',
|
|
159
|
+
}),
|
|
160
|
+
];
|
|
@@ -1,87 +1,9 @@
|
|
|
1
1
|
// The monitoring objects every Ultimate chart ships: the scrape object and the alert rules. The
|
|
2
|
-
// rules are one table, rendered as the chart's PrometheusRule
|
|
3
|
-
//
|
|
4
|
-
// a dropped frame, a 5xx share, a dead target; a latency target is the app's (axiom 8).
|
|
2
|
+
// rules are one table (`scaffold-helm-alert-rules.ts`), rendered here as the chart's PrometheusRule
|
|
3
|
+
// template and as plain rule groups for a loader outside Kubernetes.
|
|
5
4
|
import type { GeneratedFile, NameSet } from './naming';
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export interface AlertScope {
|
|
9
|
-
/** `name{matchers}` — the scope's own matchers, then `extra`. */
|
|
10
|
-
readonly series: (name: string, extra?: string) => string;
|
|
11
|
-
/** The labels every rule groups by, so one release (or one job) fires one alert. */
|
|
12
|
-
readonly by: string;
|
|
13
|
-
/** The label naming a scrape target's role. */
|
|
14
|
-
readonly component: string;
|
|
15
|
-
/** The rule's threshold, as the renderer spells it: a value lookup or the default. */
|
|
16
|
-
readonly threshold: (fallback: number) => string;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export interface ChartAlert {
|
|
20
|
-
readonly alert: string;
|
|
21
|
-
readonly expr: (scope: AlertScope) => string;
|
|
22
|
-
/** The default `alerts.rules.<alert>.threshold`, for a rule whose comparison is a number. */
|
|
23
|
-
readonly threshold?: number;
|
|
24
|
-
readonly for: string;
|
|
25
|
-
readonly severity: 'warning' | 'critical';
|
|
26
|
-
readonly summary: string;
|
|
27
|
-
/** The heading in `docs/ops/06-runbooks.md` the rule's `runbook_url` lands on. */
|
|
28
|
-
readonly anchor: string;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const rule = (alert: Omit<ChartAlert, 'anchor'>): ChartAlert => ({
|
|
32
|
-
...alert,
|
|
33
|
-
anchor: alert.alert.toLowerCase(),
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
export const CHART_ALERTS: readonly ChartAlert[] = [
|
|
37
|
-
rule({
|
|
38
|
-
alert: 'UltimateQueueStalled',
|
|
39
|
-
threshold: 300,
|
|
40
|
-
expr: (s) =>
|
|
41
|
-
`max by (${s.by}, queue) (${s.series('queue_oldest_ready_seconds')}) > ${s.threshold(300)}`,
|
|
42
|
-
for: '5m',
|
|
43
|
-
severity: 'warning',
|
|
44
|
-
summary: 'A queue has a due job nothing has claimed for longer than the threshold',
|
|
45
|
-
}),
|
|
46
|
-
rule({
|
|
47
|
-
alert: 'UltimateDeadLetters',
|
|
48
|
-
expr: (s) => `max by (${s.by}, queue) (${s.series('queue_dead_jobs')}) > 0`,
|
|
49
|
-
for: '5m',
|
|
50
|
-
severity: 'warning',
|
|
51
|
-
summary: 'A queue holds dead-lettered jobs',
|
|
52
|
-
}),
|
|
53
|
-
rule({
|
|
54
|
-
alert: 'UltimateLeaseLost',
|
|
55
|
-
expr: (s) => `sum by (${s.by}, queue) (rate(${s.series('job_leases_lost_total')}[5m])) > 0`,
|
|
56
|
-
for: '5m',
|
|
57
|
-
severity: 'warning',
|
|
58
|
-
summary: 'Job leases are lapsing while their jobs still run, so jobs run twice',
|
|
59
|
-
}),
|
|
60
|
-
rule({
|
|
61
|
-
alert: 'UltimateFramesDropped',
|
|
62
|
-
expr: (s) => `sum by (${s.by}) (rate(${s.series('channel_frames_dropped_total')}[5m])) > 0`,
|
|
63
|
-
for: '5m',
|
|
64
|
-
severity: 'warning',
|
|
65
|
-
summary: 'Sync nodes are dropping channel frames to socket backpressure',
|
|
66
|
-
}),
|
|
67
|
-
rule({
|
|
68
|
-
alert: 'UltimateServerErrors',
|
|
69
|
-
threshold: 0.05,
|
|
70
|
-
expr: (s) =>
|
|
71
|
-
`sum by (${s.by}) (rate(${s.series('http_requests_total', 'status="5xx"')}[5m])) / ` +
|
|
72
|
-
`sum by (${s.by}) (rate(${s.series('http_requests_total')}[5m])) > ${s.threshold(0.05)}`,
|
|
73
|
-
for: '10m',
|
|
74
|
-
severity: 'critical',
|
|
75
|
-
summary: 'The share of requests answered 5xx is above the threshold',
|
|
76
|
-
}),
|
|
77
|
-
rule({
|
|
78
|
-
alert: 'UltimateTargetDown',
|
|
79
|
-
expr: (s) => `count by (${s.by}, ${s.component}) (${s.series('up')} == 0) > 0`,
|
|
80
|
-
for: '5m',
|
|
81
|
-
severity: 'critical',
|
|
82
|
-
summary: 'A role has a scrape target that is down',
|
|
83
|
-
}),
|
|
84
|
-
];
|
|
5
|
+
import type { AlertScope, ChartAlert } from './scaffold-helm-alert-rules';
|
|
6
|
+
import { budgetOf, CHART_ALERTS, DEFAULT_OBJECTIVE } from './scaffold-helm-alert-rules';
|
|
85
7
|
|
|
86
8
|
/** Where `runbook_url` points unless `alerts.runbookBase` says otherwise. */
|
|
87
9
|
export const RUNBOOK_BASE =
|
|
@@ -99,22 +21,30 @@ export const K8S_SCOPE: AlertScope = {
|
|
|
99
21
|
`${name}{${matchers('namespace="{{ $.Release.Namespace }}",app_kubernetes_io_instance="{{ $.Release.Name }}"', extra)}}`,
|
|
100
22
|
by: 'namespace, app_kubernetes_io_instance',
|
|
101
23
|
component: 'app_kubernetes_io_component',
|
|
24
|
+
// The operator's own target label: one pod, whichever role it runs.
|
|
25
|
+
target: 'pod',
|
|
102
26
|
threshold: (fallback) => `{{ ternary $r.threshold ${fallback} (hasKey $r "threshold") }}`,
|
|
27
|
+
budget: budgetOf('{{ $objective }}'),
|
|
103
28
|
};
|
|
104
29
|
|
|
105
|
-
const plainScope = (own: string): AlertScope => ({
|
|
30
|
+
const plainScope = (own: string, objective: number): AlertScope => ({
|
|
106
31
|
series: (name, extra) => {
|
|
107
32
|
const inner = matchers(own, extra);
|
|
108
33
|
return inner === '' ? name : `${name}{${inner}}`;
|
|
109
34
|
},
|
|
110
35
|
by: 'job',
|
|
111
36
|
component: 'instance',
|
|
37
|
+
target: 'instance',
|
|
112
38
|
threshold: (fallback) => String(fallback),
|
|
39
|
+
budget: budgetOf(String(objective)),
|
|
113
40
|
});
|
|
114
41
|
|
|
115
|
-
/**
|
|
116
|
-
|
|
117
|
-
|
|
42
|
+
/**
|
|
43
|
+
* The rules as one plain Prometheus rule group, defaults in place, scoped by `own` matchers, the
|
|
44
|
+
* burn-rate rules against `objective` (percent).
|
|
45
|
+
*/
|
|
46
|
+
export function alertRuleGroups(own = '', objective: number = DEFAULT_OBJECTIVE): string {
|
|
47
|
+
const scope = plainScope(own, objective);
|
|
118
48
|
const rules = CHART_ALERTS.map(
|
|
119
49
|
(a) => ` - alert: ${a.alert}
|
|
120
50
|
expr: >-
|
|
@@ -164,9 +94,14 @@ const operatorGate = (
|
|
|
164
94
|
const alertRulesTemplate = (chart: string): string => `{{/*
|
|
165
95
|
The alert rules for this release's own series, written from @ultimat3/cli's rule table. Each rule
|
|
166
96
|
reads alerts.rules.<alert> for threshold, for, severity and enabled; its runbook_url is
|
|
167
|
-
alerts.runbookBase plus the rule's anchor
|
|
97
|
+
alerts.runbookBase plus the rule's anchor; the burn-rate rules read alerts.objective (percent).
|
|
98
|
+
Rendered by capability, like servicemonitor.yaml.
|
|
168
99
|
*/}}
|
|
169
100
|
${operatorGate('alerts', 'PrometheusRule')}
|
|
101
|
+
{{- $objective := float64 (ternary $cfg.objective ${DEFAULT_OBJECTIVE} (hasKey $cfg "objective")) }}
|
|
102
|
+
{{- if not (and (gt $objective 0.0) (lt $objective 100.0)) }}
|
|
103
|
+
{{- fail (printf "alerts.objective is %v — set it to the percent of requests answered without a 5xx, above 0 and below 100, e.g. 99.9" $objective) }}
|
|
104
|
+
{{- end }}
|
|
170
105
|
{{- $rules := $cfg.rules | default dict }}
|
|
171
106
|
{{- $base := $cfg.runbookBase | default "${RUNBOOK_BASE}" }}
|
|
172
107
|
apiVersion: monitoring.coreos.com/v1
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// role, the release-phase Job, an optional ingress and an optional per-role autoscaler.
|
|
3
3
|
// Split from scaffold-helm.ts, which holds the chart's INPUTS (Chart.yaml, values.yaml).
|
|
4
4
|
|
|
5
|
+
import { helmDashboardFiles } from './chart-dashboard';
|
|
5
6
|
import type { GeneratedFile, NameSet } from './naming';
|
|
6
7
|
import { helmMonitoringFiles } from './scaffold-helm-alerts';
|
|
7
8
|
import { helmFenceFiles } from './scaffold-helm-fences';
|
|
@@ -471,5 +472,6 @@ export function helmTemplateFiles(app: NameSet): readonly GeneratedFile[] {
|
|
|
471
472
|
{ path: 'docker/helm/templates/hpa.yaml', contents: hpa(app) },
|
|
472
473
|
...helmFenceFiles(app),
|
|
473
474
|
...helmMonitoringFiles(app),
|
|
475
|
+
...helmDashboardFiles(app),
|
|
474
476
|
];
|
|
475
477
|
}
|
|
@@ -43,12 +43,24 @@ export const ALERTS_VALUES = `# Each rule's runbook_url is runbookBase#<alert, l
|
|
|
43
43
|
# threshold, for, severity, enabled — e.g. rules: { UltimateQueueStalled: { threshold: 600 } }.
|
|
44
44
|
alerts:
|
|
45
45
|
enabled: auto
|
|
46
|
+
objective: 99.9 # percent of requests answered without a 5xx; the burn-rate rules' budget
|
|
46
47
|
runbookBase: ${RUNBOOK_BASE}
|
|
47
48
|
labels: {} # what your operator's ruleSelector matches, if it uses one
|
|
48
49
|
rules: {}
|
|
49
50
|
|
|
50
51
|
`;
|
|
51
52
|
|
|
53
|
+
/** The dashboard's `values.yaml` block, beside the two monitoring ones. */
|
|
54
|
+
export const DASHBOARD_VALUES = `# The Grafana dashboard (dashboards/ultimate-app.json) as a ConfigMap, OFF by default: a Grafana
|
|
55
|
+
# sidecar provisions every ConfigMap carrying its label (kube-prometheus-stack's is the one below).
|
|
56
|
+
# Without a sidecar, import the JSON by hand; it picks namespace and release from process_info.
|
|
57
|
+
dashboard:
|
|
58
|
+
enabled: false
|
|
59
|
+
labels: { grafana_dashboard: "1" }
|
|
60
|
+
annotations: {} # e.g. the sidecar's grafana_folder: Ultimate
|
|
61
|
+
|
|
62
|
+
`;
|
|
63
|
+
|
|
52
64
|
/**
|
|
53
65
|
* `appVersion` is the default image tag (`image.tag: ""` below), so it must name a tag that can
|
|
54
66
|
* exist. `x deploy --image <ref>` overrides both keys, which is the path that actually ships.
|
|
@@ -143,7 +155,7 @@ networkPolicy:
|
|
|
143
155
|
# METRICS_PORT in the container; move one and the other follows.
|
|
144
156
|
metricsPort: 9090
|
|
145
157
|
|
|
146
|
-
${SERVICE_MONITOR_VALUES}${ALERTS_VALUES}# The image's \`bun\` user, the same uid as the Dockerfile's USER: move one and the other follows.
|
|
158
|
+
${SERVICE_MONITOR_VALUES}${ALERTS_VALUES}${DASHBOARD_VALUES}# The image's \`bun\` user, the same uid as the Dockerfile's USER: move one and the other follows.
|
|
147
159
|
podSecurityContext:
|
|
148
160
|
runAsNonRoot: true
|
|
149
161
|
runAsUser: ${RUNTIME_UID}
|
|
@@ -196,8 +208,10 @@ roles:
|
|
|
196
208
|
enabled: true
|
|
197
209
|
replicas: 2
|
|
198
210
|
port: 3000
|
|
211
|
+
# Requests are measured idle plus headroom, limits the ceiling: a web pod of the demo app idled
|
|
212
|
+
# at 73 Mi (plan 101 O6, 2026-11-11), so 128Mi; the limit is what an OOMKill reads.
|
|
199
213
|
resources:
|
|
200
|
-
requests: { cpu: 200m, memory:
|
|
214
|
+
requests: { cpu: 200m, memory: 128Mi }
|
|
201
215
|
limits: { memory: 512Mi }
|
|
202
216
|
autoscaling:
|
|
203
217
|
enabled: false
|
|
@@ -234,8 +248,9 @@ roles:
|
|
|
234
248
|
# exits at once, and a Terminating pod does not hold a rollout back. Added to this role's
|
|
235
249
|
# terminationGracePeriodSeconds, which the kubelet counts the preStop against.
|
|
236
250
|
retireSeconds: 3600
|
|
251
|
+
# 160Mi: ROLE=worker of the reference app idled at 138 MiB (Bun 1.4.4, 45 s, 2026-11-13).
|
|
237
252
|
resources:
|
|
238
|
-
requests: { cpu: 200m, memory:
|
|
253
|
+
requests: { cpu: 200m, memory: 160Mi }
|
|
239
254
|
limits: { memory: 1Gi }
|
|
240
255
|
autoscaling:
|
|
241
256
|
enabled: false
|
|
@@ -258,7 +273,8 @@ roles:
|
|
|
258
273
|
# when every role still built the app's islands first; at 256Mi the pod was OOMKilled on every
|
|
259
274
|
# boot. Only web builds islands now, so the peak is lower but unmeasured, and the limit stays.
|
|
260
275
|
resources:
|
|
261
|
-
|
|
276
|
+
# 160Mi: ROLE=scheduler of the reference app idled at 137 MiB (Bun 1.4.4, 45 s, 2026-11-13).
|
|
277
|
+
requests: { cpu: 50m, memory: 160Mi }
|
|
262
278
|
limits: { memory: 512Mi }
|
|
263
279
|
|
|
264
280
|
replicator:
|
package/wiki/Admin-Dashboard.md
CHANGED
|
@@ -30,7 +30,7 @@ export const admin = defineAdmin({ entities: adminEntitiesOf(db), db });
|
|
|
30
30
|
| `/admin/<entity>/<id>` | detail: sections, related lists, row actions, history (`?history=` pages older) | `POST _operation=action` (`input.<field>`) · `_operation=delete` (needs `confirmation`) |
|
|
31
31
|
| `/admin/<entity>/<id>?action=<name>` | an action's own form, when it declares an `input` schema | posts at the row |
|
|
32
32
|
| `/admin/<entity>/<id>/edit` | edit form | `POST` → 303 to the row, or 422 |
|
|
33
|
-
| `/admin/search?term=` · `/admin/audit` | built-in screens | — |
|
|
33
|
+
| `/admin/search?term=` · `/admin/audit` | built-in screens — search is case-insensitive, at most three text fields per resource, four resources read at a time | — |
|
|
34
34
|
| `/admin/jobs` · `/admin/jobs/runs` · `/queues` · `/tasks` · `/workers` | the jobs dashboard every admin carries — [below](#the-jobs-dashboard) | row actions and the batch bar, as any resource |
|
|
35
35
|
| `/admin/<page path>` | a `pages:` entry | — |
|
|
36
36
|
|
|
@@ -53,6 +53,8 @@ resources: { posts: { count: true } },
|
|
|
53
53
|
|
|
54
54
|
A count reads no row, so it is not audited. Upgrading from a release that counted every listable resource: add `count: true` to each resource whose tile you want back.
|
|
55
55
|
|
|
56
|
+
**`count: 'estimate'`** (`As of 2026-11`) reads the planner's figure (`AdminRepo.approximateCount()`, constant time) instead of a full count. It applies only when the resource declares no `rows` scope (the estimate is a whole-table figure) and the estimate is at least 10,000 rows (`ESTIMATE_COUNT_FLOOR`). The tile then reads `~1,200,000` (`admin.dashboard.records.approximate`). A small or never-analysed table, a row-scoped resource and a tenant-scoped or soft-deleting table the estimate refuses all show the exact `count()`.
|
|
57
|
+
|
|
56
58
|
## The list
|
|
57
59
|
|
|
58
60
|
`As of 2026-10`. Everything on a list page is derived from the entity or declared once on the resource.
|
|
@@ -65,6 +67,8 @@ A count reads no row, so it is not audited. Upgrading from a release that counte
|
|
|
65
67
|
| Computed columns | `columns: { age: { value, render } }` | `render`: `badge`, `relative-time`, `money`, `truncate`, `link`, `json`, or a component |
|
|
66
68
|
| Row scope | `rows: (actor) => AdminFilter[]` | applied by the list, the search, the detail read, the lookup, the labels and the MCP tools — one declaration, no second copy of the resource for a second audience |
|
|
67
69
|
|
|
70
|
+
**Case.** `As of 2026-11`. What an operator types ignores case: the search box, a `contains` filter and a lookup each use the entity's `contains`, a bound `ilike` that a `gin_trgm_ops` index on the column serves. What the app declares does not: a `contains` in `rows` or in a scope's `where` stays exact and case-sensitive (`like`, `caseSensitive: true` on the filter), on the read and on the write. A row scope is authorization, so it never widens. `rows: () => [{ field: 'company', op: 'contains', value: 'Acme' }]` admits `Acme Ltd` and never `acme corp`, however the operator spells a search.
|
|
71
|
+
|
|
68
72
|
| URL parameter | Means |
|
|
69
73
|
|---|---|
|
|
70
74
|
| `?f.<field>=<value>` | the field's default operator (`contains` for text, `eq` otherwise) |
|
|
@@ -162,7 +166,7 @@ export const admin = defineAdmin({
|
|
|
162
166
|
|
|
163
167
|
| URL | Shows | Actions (`job:manage`) |
|
|
164
168
|
|---|---|---|
|
|
165
|
-
| `/admin/jobs` | tiles: ready, running, delayed, suspended, dead, workers, oldest ready (one `stats()`); done vs failed over `?range=1h\|24h\|7d\|30d` from the settle counters; volume, failure rate and mean duration per job name. Re-read every 30 s by a declared `<meta http-equiv="refresh">` | — |
|
|
169
|
+
| `/admin/jobs` | tiles: ready, running, delayed, suspended, dead, workers, oldest ready (one `stats()`); done vs failed over `?range=1h\|24h\|7d\|30d` from the settle counters; volume, failure rate and mean duration per job name — every name's counters in one grouped read (`countersMany`), so the screen costs 4 statements at any number of names. Re-read every 30 s by a declared `<meta http-equiv="refresh">` | — |
|
|
166
170
|
| `/admin/jobs/runs` | one tab per state; the search box is an id prefix; filters by name, queue, state, tenant, created time | retry (dead rows), retry from a step, run now (waiting on its clock), cancel (live), remove |
|
|
167
171
|
| `/admin/jobs/runs/<id>` | input (redacted by `@ultimat3/jobs`), steps, error and stack, progress, tenant, trace, history | the row's own |
|
|
168
172
|
| `/admin/jobs/queues` | depth per state, paused, a link to the queue's jobs | pause, resume |
|