@ultimat3/cli 31.17.0 → 31.18.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/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
package/README.md
CHANGED
|
@@ -249,6 +249,7 @@ apps/web/app/auth/{sign-in,actions,…} # x g sign-in --password | --
|
|
|
249
249
|
apps/web/runtime.ts # …and the boot guard it calls (x new writes the
|
|
250
250
|
# port-commented one; replaced only while untouched)
|
|
251
251
|
docker/helm/templates/{servicemonitor,alert-rules}.yaml # x g chart-alerts [--print]
|
|
252
|
+
docker/helm/{dashboards/ultimate-app.json,templates/dashboard-configmap.yaml} # x g chart-dashboard [--print]
|
|
252
253
|
```
|
|
253
254
|
|
|
254
255
|
Every emitted source has a `<file>.test.ts` beside it that passes on the first run.
|
|
@@ -256,7 +257,9 @@ Every emitted source has a `<file>.test.ts` beside it that passes on the first r
|
|
|
256
257
|
`x g chart-alerts` takes no `<name>` either — `docker/helm/Chart.yaml` names the chart — and writes
|
|
257
258
|
only the monitoring templates and `values.yaml` blocks an older app chart lacks
|
|
258
259
|
(`generate-chart-alerts.ts`); `x doctor` lists them (`doctor-chart-alerts.ts`). `--print` is the
|
|
259
|
-
same rule table as plain Prometheus rule groups, for a loader outside Kubernetes.
|
|
260
|
+
same rule table as plain Prometheus rule groups, for a loader outside Kubernetes. `x g
|
|
261
|
+
chart-dashboard` is the same backfill for the Grafana dashboard JSON, its ConfigMap and the
|
|
262
|
+
`dashboard:` values block; its `--print` is the JSON, for a Grafana outside Kubernetes.
|
|
260
263
|
|
|
261
264
|
`x g sign-in` takes no `<name>` — an app has one sign-in — and exactly one of `--password` or
|
|
262
265
|
`--oidc <provider>` (`generate-sign-in-mode.ts`). It writes through `writeFiles` like every
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ultimat3/cli",
|
|
3
|
-
"version": "31.
|
|
3
|
+
"version": "31.18.1",
|
|
4
4
|
"description": "The `x` binary: new, dev, build, verify, generate, db, mcp, doctor, deploy",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ultimate",
|
|
@@ -53,34 +53,34 @@
|
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
55
|
"@babel/core": "^8.0.9",
|
|
56
|
-
"@ultimat3/action": "31.
|
|
57
|
-
"@ultimat3/admin": "31.
|
|
58
|
-
"@ultimat3/ai": "31.
|
|
59
|
-
"@ultimat3/auth": "31.
|
|
60
|
-
"@ultimat3/cache": "31.
|
|
61
|
-
"@ultimat3/core": "31.
|
|
62
|
-
"@ultimat3/db": "31.
|
|
63
|
-
"@ultimat3/entity": "31.
|
|
64
|
-
"@ultimat3/flags": "31.
|
|
65
|
-
"@ultimat3/http": "31.
|
|
66
|
-
"@ultimat3/i18n": "31.
|
|
67
|
-
"@ultimat3/jobs": "31.
|
|
68
|
-
"@ultimat3/mail": "31.
|
|
69
|
-
"@ultimat3/manifest": "31.
|
|
70
|
-
"@ultimat3/mcp": "31.
|
|
71
|
-
"@ultimat3/money": "31.
|
|
72
|
-
"@ultimat3/notify": "31.
|
|
73
|
-
"@ultimat3/policy": "31.
|
|
74
|
-
"@ultimat3/pwa": "31.
|
|
75
|
-
"@ultimat3/query": "31.
|
|
76
|
-
"@ultimat3/realtime": "31.
|
|
77
|
-
"@ultimat3/render": "31.
|
|
78
|
-
"@ultimat3/schema": "31.
|
|
79
|
-
"@ultimat3/scraping": "31.
|
|
80
|
-
"@ultimat3/seo": "31.
|
|
81
|
-
"@ultimat3/storage": "31.
|
|
82
|
-
"@ultimat3/testing": "31.
|
|
83
|
-
"@ultimat3/time": "31.
|
|
56
|
+
"@ultimat3/action": "31.18.1",
|
|
57
|
+
"@ultimat3/admin": "31.18.1",
|
|
58
|
+
"@ultimat3/ai": "31.18.1",
|
|
59
|
+
"@ultimat3/auth": "31.18.1",
|
|
60
|
+
"@ultimat3/cache": "31.18.1",
|
|
61
|
+
"@ultimat3/core": "31.18.1",
|
|
62
|
+
"@ultimat3/db": "31.18.1",
|
|
63
|
+
"@ultimat3/entity": "31.18.1",
|
|
64
|
+
"@ultimat3/flags": "31.18.1",
|
|
65
|
+
"@ultimat3/http": "31.18.1",
|
|
66
|
+
"@ultimat3/i18n": "31.18.1",
|
|
67
|
+
"@ultimat3/jobs": "31.18.1",
|
|
68
|
+
"@ultimat3/mail": "31.18.1",
|
|
69
|
+
"@ultimat3/manifest": "31.18.1",
|
|
70
|
+
"@ultimat3/mcp": "31.18.1",
|
|
71
|
+
"@ultimat3/money": "31.18.1",
|
|
72
|
+
"@ultimat3/notify": "31.18.1",
|
|
73
|
+
"@ultimat3/policy": "31.18.1",
|
|
74
|
+
"@ultimat3/pwa": "31.18.1",
|
|
75
|
+
"@ultimat3/query": "31.18.1",
|
|
76
|
+
"@ultimat3/realtime": "31.18.1",
|
|
77
|
+
"@ultimat3/render": "31.18.1",
|
|
78
|
+
"@ultimat3/schema": "31.18.1",
|
|
79
|
+
"@ultimat3/scraping": "31.18.1",
|
|
80
|
+
"@ultimat3/seo": "31.18.1",
|
|
81
|
+
"@ultimat3/storage": "31.18.1",
|
|
82
|
+
"@ultimat3/testing": "31.18.1",
|
|
83
|
+
"@ultimat3/time": "31.18.1",
|
|
84
84
|
"babel-preset-solid": "^1.9.16"
|
|
85
85
|
}
|
|
86
86
|
}
|
package/src/cmd-doctor.ts
CHANGED
|
@@ -8,7 +8,7 @@ import { doctorSpec } from './cmd-doctor-spec';
|
|
|
8
8
|
import type { CliCommand, CommandContext } from './command';
|
|
9
9
|
import { appUrlFindings } from './doctor-app-url';
|
|
10
10
|
import { authStorageFindings } from './doctor-auth';
|
|
11
|
-
import { chartAlertsProbe, withChartAlertsListing } from './doctor-chart-alerts';
|
|
11
|
+
import { chartAlertsProbe, NOTHING_MISSING, withChartAlertsListing } from './doctor-chart-alerts';
|
|
12
12
|
import { coverageExcludesProbe, withCoverageExcludes } from './doctor-coverage';
|
|
13
13
|
import { embeddedDatabaseFinding } from './doctor-database';
|
|
14
14
|
import { shippedGuardsProbe, withGuardListing } from './doctor-guards';
|
|
@@ -162,10 +162,10 @@ export async function reportDoctor(probe: DoctorProbe): Promise<CommandResult> {
|
|
|
162
162
|
listed,
|
|
163
163
|
probe.root === undefined ? [] : await coverageExcludesProbe(probe.root),
|
|
164
164
|
);
|
|
165
|
-
// The third: the monitoring templates the
|
|
165
|
+
// The third: the monitoring templates and dashboard the chart predates (`doctor-chart-alerts.ts`).
|
|
166
166
|
const charted = withChartAlertsListing(
|
|
167
167
|
covered,
|
|
168
|
-
probe.root === undefined ?
|
|
168
|
+
probe.root === undefined ? NOTHING_MISSING : chartAlertsProbe(probe.root),
|
|
169
169
|
);
|
|
170
170
|
// A reminder, not a finding: the rolling rail is off until this is set (`doctor-rolling.ts`).
|
|
171
171
|
const reminded = withPoolerReport(
|
package/src/cmd-generate-spec.ts
CHANGED
|
@@ -11,8 +11,8 @@ export const generateSpec: CommandSpec = {
|
|
|
11
11
|
// Projected from `GENERATORS`, never restated: the literal that used to live here had already
|
|
12
12
|
// drifted — it omitted `backfill` — and a usage line that can disagree with the list it
|
|
13
13
|
// describes is exactly the second source of truth axiom 2 forbids.
|
|
14
|
-
// `sign-in` and
|
|
15
|
-
usage: `x g ${GENERATORS.filter((kind) => kind !== 'sign-in' && kind
|
|
14
|
+
// `sign-in` and the two chart generators take no `<name>`, so each is spelled in its own clause.
|
|
15
|
+
usage: `x g ${GENERATORS.filter((kind) => kind !== 'sign-in' && !kind.startsWith('chart-')).join('|')} <name> [--feature f] · x g sign-in --password|--oidc <provider> · x g chart-alerts|chart-dashboard [--print]`,
|
|
16
16
|
// Declared from the SAME constant `readKind` validates against: without it `fix-command.ts`
|
|
17
17
|
// has no set to judge the word after `x g`, and two shipped `@ultimat3/admin` fix lines said
|
|
18
18
|
// `x g migration` — a generator that has never existed — straight through the `errors` gate.
|
|
@@ -37,7 +37,7 @@ export const generateSpec: CommandSpec = {
|
|
|
37
37
|
{
|
|
38
38
|
name: 'print',
|
|
39
39
|
type: 'boolean',
|
|
40
|
-
summary: 'chart-alerts: print
|
|
40
|
+
summary: 'chart-alerts, chart-dashboard: print rule groups / dashboard JSON, write nothing',
|
|
41
41
|
},
|
|
42
42
|
{ name: 'force', type: 'boolean', summary: 'overwrite existing files' },
|
|
43
43
|
{ name: 'dry-run', type: 'boolean', summary: 'print the file list, write nothing' },
|
package/src/cmd-generate.ts
CHANGED
|
@@ -12,7 +12,7 @@ import { generateSpec } from './cmd-generate-spec';
|
|
|
12
12
|
import type { CliCommand, CommandContext } from './command';
|
|
13
13
|
import { invocationOf } from './command';
|
|
14
14
|
import { localiseCatalogs, namedOrAppLocales } from './generate-catalog-locales';
|
|
15
|
-
import { refuseChartAlertsFlags, runChartAlerts } from './generate-chart-alerts';
|
|
15
|
+
import { isChartGenerator, refuseChartAlertsFlags, runChartAlerts } from './generate-chart-alerts';
|
|
16
16
|
import { appDisk, plannedDisk } from './generate-disk';
|
|
17
17
|
import { writtenExercises } from './generate-exercise';
|
|
18
18
|
import { assertFeatureExists } from './generate-feature';
|
|
@@ -80,7 +80,7 @@ export const generateCommand: CliCommand = {
|
|
|
80
80
|
// One sign-in per app, named by a flag rather than a `<name>`, and edits no other kind makes.
|
|
81
81
|
if (kind === 'sign-in') return await runSignIn(ctx, root);
|
|
82
82
|
// One chart per app, named by its `Chart.yaml`: the same shape, for the same reason.
|
|
83
|
-
if (kind
|
|
83
|
+
if (isChartGenerator(kind)) return await runChartAlerts(ctx, root, kind);
|
|
84
84
|
// A workspace, not a slice: no feature, no surface, no follow-up edit (`generate-workspace.ts`).
|
|
85
85
|
if (isWorkspaceKind(kind)) return await runWorkspace(ctx, root, kind);
|
|
86
86
|
const name = readName(ctx.args.positionals[1], kind);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
// `x doctor`'s chart listing: the monitoring templates an app's Helm chart
|
|
2
|
-
// command that writes
|
|
1
|
+
// `x doctor`'s chart listing: the monitoring templates and the dashboard an app's Helm chart
|
|
2
|
+
// predates, each with the one command that writes it. A LISTING, never a finding: the chart is the app's, and a chart that
|
|
3
3
|
// declines the operator's objects (or keeps its own) is a decision `x doctor` must not overrule.
|
|
4
4
|
|
|
5
5
|
// why: a synchronous exists check; Bun.file().exists() is async and the probe is not.
|
|
@@ -9,47 +9,75 @@ import { join } from 'node:path';
|
|
|
9
9
|
import { CHART_FILE } from './generate-chart-alerts';
|
|
10
10
|
import { msg } from './messages';
|
|
11
11
|
import type { CommandResult, JsonValue } from './output';
|
|
12
|
+
import type { GeneratedFile, NameSet } from './templates';
|
|
12
13
|
import { names } from './templates';
|
|
14
|
+
import { helmDashboardFiles } from './templates/chart-dashboard';
|
|
13
15
|
import { helmMonitoringFiles } from './templates/scaffold-helm-alerts';
|
|
14
16
|
|
|
15
17
|
/** The command every row names: it writes only the files the chart lacks. */
|
|
16
18
|
export const CHART_ALERTS_ADD = 'x g chart-alerts';
|
|
19
|
+
export const CHART_DASHBOARD_ADD = 'x g chart-dashboard';
|
|
20
|
+
|
|
21
|
+
const absentOf =
|
|
22
|
+
(files: (app: NameSet) => readonly GeneratedFile[]) =>
|
|
23
|
+
(hasChart: boolean, exists: (path: string) => boolean): readonly string[] =>
|
|
24
|
+
// The paths only — they do not depend on the chart's name.
|
|
25
|
+
hasChart
|
|
26
|
+
? files(names('app'))
|
|
27
|
+
.map((file) => file.path)
|
|
28
|
+
.filter((path) => !exists(path))
|
|
29
|
+
: [];
|
|
30
|
+
|
|
31
|
+
/** The dashboard's half of the rule: its JSON and its ConfigMap, absent from a chart that exists. */
|
|
32
|
+
export const missingDashboardTemplates = absentOf(helmDashboardFiles);
|
|
17
33
|
|
|
18
34
|
/** The rule, pure: which monitoring templates are absent from a chart that exists. */
|
|
19
|
-
export
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
.filter((path) => !exists(path));
|
|
35
|
+
export const missingMonitoringTemplates = absentOf(helmMonitoringFiles);
|
|
36
|
+
|
|
37
|
+
/** What a chart lacks, per command. An app with no chart lacks nothing. */
|
|
38
|
+
export const NOTHING_MISSING: ChartListing = { alerts: [], dashboard: [] };
|
|
39
|
+
|
|
40
|
+
export interface ChartListing {
|
|
41
|
+
readonly alerts: readonly string[];
|
|
42
|
+
readonly dashboard: readonly string[];
|
|
28
43
|
}
|
|
29
44
|
|
|
30
45
|
/** The I/O half. An app with no chart deploys some other way, and is listed nothing. */
|
|
31
|
-
export function chartAlertsProbe(root: string):
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
46
|
+
export function chartAlertsProbe(root: string): ChartListing {
|
|
47
|
+
const hasChart = existsSync(join(root, CHART_FILE));
|
|
48
|
+
const exists = (path: string) => existsSync(join(root, path));
|
|
49
|
+
return {
|
|
50
|
+
alerts: missingMonitoringTemplates(hasChart, exists),
|
|
51
|
+
dashboard: missingDashboardTemplates(hasChart, exists),
|
|
52
|
+
};
|
|
35
53
|
}
|
|
36
54
|
|
|
37
55
|
/** The listing, on a result `x doctor` already decided: `ok` and the findings stay as they came. */
|
|
38
56
|
export function withChartAlertsListing(
|
|
39
57
|
result: CommandResult,
|
|
40
|
-
|
|
58
|
+
{ alerts, dashboard }: ChartListing,
|
|
41
59
|
): CommandResult {
|
|
42
|
-
if (
|
|
60
|
+
if (alerts.length === 0 && dashboard.length === 0) return result;
|
|
43
61
|
const data = typeof result.data === 'object' && result.data !== null ? result.data : {};
|
|
44
|
-
const
|
|
62
|
+
const rows = (missing: readonly string[], key: string, add: string): readonly string[] =>
|
|
63
|
+
missing.length === 0
|
|
64
|
+
? []
|
|
65
|
+
: [msg(key, { count: missing.length }), ...missing.map((path) => ` ${path}`), ` ${add}`];
|
|
45
66
|
return {
|
|
46
67
|
...result,
|
|
47
|
-
data: {
|
|
68
|
+
data: {
|
|
69
|
+
...(data as Record<string, JsonValue>),
|
|
70
|
+
...(alerts.length === 0
|
|
71
|
+
? {}
|
|
72
|
+
: { chartAlerts: { missing: [...alerts], add: CHART_ALERTS_ADD } }),
|
|
73
|
+
...(dashboard.length === 0
|
|
74
|
+
? {}
|
|
75
|
+
: { chartDashboard: { missing: [...dashboard], add: CHART_DASHBOARD_ADD } }),
|
|
76
|
+
},
|
|
48
77
|
lines: [
|
|
49
78
|
...(result.lines ?? []),
|
|
50
|
-
|
|
51
|
-
...
|
|
52
|
-
` ${CHART_ALERTS_ADD}`,
|
|
79
|
+
...rows(alerts, 'cli.doctor.chartAlerts', CHART_ALERTS_ADD),
|
|
80
|
+
...rows(dashboard, 'cli.doctor.chartDashboard', CHART_DASHBOARD_ADD),
|
|
53
81
|
],
|
|
54
82
|
};
|
|
55
83
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
// `x g chart-alerts`: the chart's
|
|
2
|
-
// them, plus the `values.yaml` blocks it lacks
|
|
3
|
-
// `enabled: false` stays. `--print` is the same
|
|
4
|
-
//
|
|
1
|
+
// `x g chart-alerts` / `x g chart-dashboard`: the chart's monitoring templates (or its Grafana
|
|
2
|
+
// dashboard) written into an app whose chart predates them, plus the `values.yaml` blocks it lacks
|
|
3
|
+
// — appended, never rewritten, so a deliberate `enabled: false` stays. `--print` is the same table
|
|
4
|
+
// for a loader outside Kubernetes. No `<name>`: an app has one chart, and `Chart.yaml` names it.
|
|
5
5
|
|
|
6
6
|
import { stringField, UltimateError } from '@ultimat3/core';
|
|
7
7
|
import { generateSpec } from './cmd-generate-spec';
|
|
@@ -12,30 +12,41 @@ import { generate } from './generate-files';
|
|
|
12
12
|
import type { Generator } from './generate-kinds';
|
|
13
13
|
import { containedPath, planWrites, writeFiles } from './generate-write';
|
|
14
14
|
import { msg } from './messages';
|
|
15
|
-
import type { CommandResult } from './output';
|
|
15
|
+
import type { CommandResult, JsonValue } from './output';
|
|
16
16
|
import type { ParsedArgs } from './parse';
|
|
17
17
|
import { flagBool } from './parse';
|
|
18
18
|
import type { GeneratedFile } from './templates';
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
19
|
+
import { dashboardJson } from './templates/chart-dashboard';
|
|
20
|
+
import { ALERTS_VALUES, DASHBOARD_VALUES, SERVICE_MONITOR_VALUES } from './templates/scaffold-helm';
|
|
21
|
+
import { CHART_ALERTS } from './templates/scaffold-helm-alert-rules';
|
|
22
|
+
import { alertRuleGroups } from './templates/scaffold-helm-alerts';
|
|
21
23
|
|
|
22
24
|
export const CHART_FILE = 'docker/helm/Chart.yaml';
|
|
23
25
|
export const VALUES_FILE = 'docker/helm/values.yaml';
|
|
24
26
|
|
|
27
|
+
/** The two generators that write into the app's one chart, and only into it. */
|
|
28
|
+
export type ChartGenerator = 'chart-alerts' | 'chart-dashboard';
|
|
29
|
+
|
|
25
30
|
/** A chart is not there to write into. Its fix is the half that needs none. */
|
|
26
31
|
export class ChartMissingError extends UltimateError {
|
|
27
|
-
constructor(reason: string) {
|
|
32
|
+
constructor(reason: string, kind: ChartGenerator = 'chart-alerts') {
|
|
28
33
|
super({
|
|
29
34
|
code: 'X_CHART_MISSING',
|
|
30
|
-
cause: `${CHART_FILE} ${reason}, so there is no chart for the monitoring templates to join`,
|
|
31
|
-
fix:
|
|
35
|
+
cause: `${CHART_FILE} ${reason}, so there is no chart for the ${kind === 'chart-alerts' ? 'monitoring templates' : 'dashboard'} to join`,
|
|
36
|
+
fix:
|
|
37
|
+
kind === 'chart-alerts'
|
|
38
|
+
? 'x g chart-alerts --print --json'
|
|
39
|
+
: 'x g chart-dashboard --print --json',
|
|
32
40
|
});
|
|
33
41
|
}
|
|
34
42
|
}
|
|
35
43
|
|
|
36
|
-
|
|
44
|
+
export const isChartGenerator = (kind: Generator): kind is ChartGenerator =>
|
|
45
|
+
kind === 'chart-alerts' || kind === 'chart-dashboard';
|
|
46
|
+
|
|
47
|
+
/** `--print` is the chart generators', and on any other one it would be a flag accepted and ignored. */
|
|
37
48
|
export function refuseChartAlertsFlags(kind: Generator, args: ParsedArgs): void {
|
|
38
|
-
if (kind
|
|
49
|
+
if (isChartGenerator(kind) || !args.flags.has('print')) return;
|
|
39
50
|
throw new BadFlagError({
|
|
40
51
|
flag: 'print',
|
|
41
52
|
command: `g ${kind}`,
|
|
@@ -47,14 +58,21 @@ export function refuseChartAlertsFlags(kind: Generator, args: ParsedArgs): void
|
|
|
47
58
|
/** The flags this generator reads; any other set to something but its default is refused. */
|
|
48
59
|
const READS = new Set(['print', 'force', 'dry-run']);
|
|
49
60
|
|
|
50
|
-
|
|
61
|
+
/** Each generator's own bare run: a literal per kind, so a fix line splices no value. */
|
|
62
|
+
const BARE_RUN: ReadonlyMap<ChartGenerator, string> = new Map([
|
|
63
|
+
['chart-alerts', 'x g chart-alerts'],
|
|
64
|
+
['chart-dashboard', 'x g chart-dashboard'],
|
|
65
|
+
]);
|
|
66
|
+
|
|
67
|
+
function refuseUnreadFlags(args: ParsedArgs, kind: ChartGenerator): void {
|
|
68
|
+
const fix = BARE_RUN.get(kind) ?? 'x g chart-alerts';
|
|
51
69
|
const named = args.positionals[1];
|
|
52
70
|
if (named !== undefined) {
|
|
53
71
|
throw new BadFlagError({
|
|
54
72
|
flag: 'name',
|
|
55
|
-
command:
|
|
73
|
+
command: `g ${kind}`,
|
|
56
74
|
reason: `takes no <name> and got "${named}": an app has one chart, and Chart.yaml names it`,
|
|
57
|
-
fix
|
|
75
|
+
fix,
|
|
58
76
|
});
|
|
59
77
|
}
|
|
60
78
|
for (const flag of generateSpec.flags ?? []) {
|
|
@@ -63,63 +81,99 @@ function refuseUnreadFlags(args: ParsedArgs): void {
|
|
|
63
81
|
if (value === undefined || value === flag.default) continue;
|
|
64
82
|
throw new BadFlagError({
|
|
65
83
|
flag: flag.name,
|
|
66
|
-
command:
|
|
67
|
-
reason: `the
|
|
68
|
-
fix
|
|
84
|
+
command: `g ${kind}`,
|
|
85
|
+
reason: `the ${kind} generator does not read --${flag.name}, so it would change nothing`,
|
|
86
|
+
fix,
|
|
69
87
|
});
|
|
70
88
|
}
|
|
71
89
|
}
|
|
72
90
|
|
|
73
91
|
/** The chart's `name`, which its helpers (`<name>.fullname`, `<name>.labels`) are named after. */
|
|
74
|
-
export async function chartName(
|
|
92
|
+
export async function chartName(
|
|
93
|
+
root: string,
|
|
94
|
+
kind: ChartGenerator = 'chart-alerts',
|
|
95
|
+
): Promise<string> {
|
|
75
96
|
const file = Bun.file(containedPath(root, CHART_FILE));
|
|
76
|
-
if (!(await file.exists())) throw new ChartMissingError('does not exist');
|
|
97
|
+
if (!(await file.exists())) throw new ChartMissingError('does not exist', kind);
|
|
77
98
|
let parsed: unknown;
|
|
78
99
|
try {
|
|
79
100
|
parsed = Bun.YAML.parse(await file.text());
|
|
80
101
|
} catch {
|
|
81
|
-
throw new ChartMissingError('does not parse as YAML');
|
|
102
|
+
throw new ChartMissingError('does not parse as YAML', kind);
|
|
82
103
|
}
|
|
83
104
|
const name = stringField(parsed, 'name');
|
|
84
105
|
if (name === undefined || !/^[a-z0-9][a-z0-9-]*$/.test(name)) {
|
|
85
|
-
throw new ChartMissingError(
|
|
106
|
+
throw new ChartMissingError(
|
|
107
|
+
'declares no chart name of lowercase letters, digits and hyphens',
|
|
108
|
+
kind,
|
|
109
|
+
);
|
|
86
110
|
}
|
|
87
111
|
return name;
|
|
88
112
|
}
|
|
89
113
|
|
|
114
|
+
/** Each generator's `values.yaml` blocks, by the top-level key each declares. */
|
|
115
|
+
const VALUE_BLOCKS: ReadonlyMap<ChartGenerator, readonly (readonly [string, string])[]> = new Map([
|
|
116
|
+
[
|
|
117
|
+
'chart-alerts',
|
|
118
|
+
[
|
|
119
|
+
['serviceMonitor', SERVICE_MONITOR_VALUES],
|
|
120
|
+
['alerts', ALERTS_VALUES],
|
|
121
|
+
],
|
|
122
|
+
],
|
|
123
|
+
['chart-dashboard', [['dashboard', DASHBOARD_VALUES]]],
|
|
124
|
+
]);
|
|
125
|
+
|
|
90
126
|
/**
|
|
91
127
|
* The blocks `values.yaml` lacks, by top-level key. A key already there is the app's — whatever it
|
|
92
|
-
* says — and the templates read a missing one as
|
|
128
|
+
* says — and the templates read a missing one as their default, so a values file this never
|
|
129
|
+
* touches works.
|
|
93
130
|
*/
|
|
94
|
-
export function missingValueBlocks(values: string): string {
|
|
131
|
+
export function missingValueBlocks(values: string, kind: ChartGenerator = 'chart-alerts'): string {
|
|
95
132
|
const has = (key: string) => new RegExp(`^${key}\\s*:`, 'm').test(values);
|
|
96
|
-
return [
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
133
|
+
return (VALUE_BLOCKS.get(kind) ?? [])
|
|
134
|
+
.filter(([key]) => !has(key))
|
|
135
|
+
.map(([, block]) => block)
|
|
136
|
+
.join('');
|
|
100
137
|
}
|
|
101
138
|
|
|
102
|
-
/**
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
export async function runChartAlerts(ctx: CommandContext, root: string): Promise<CommandResult> {
|
|
107
|
-
refuseUnreadFlags(ctx.args);
|
|
108
|
-
if (flagBool(ctx.args, 'print')) {
|
|
109
|
-
const rules = alertRuleGroups();
|
|
139
|
+
/** `--print`: what a loader outside Kubernetes takes — rule groups, or the dashboard's JSON. */
|
|
140
|
+
function printed(kind: ChartGenerator): CommandResult {
|
|
141
|
+
if (kind === 'chart-dashboard') {
|
|
142
|
+
const json = dashboardJson();
|
|
110
143
|
return {
|
|
111
144
|
ok: true,
|
|
112
145
|
command: 'g',
|
|
113
|
-
summary: msg('cli.generate.
|
|
114
|
-
data: {
|
|
115
|
-
lines:
|
|
146
|
+
summary: msg('cli.generate.chartDashboardPrinted'),
|
|
147
|
+
data: { dashboard: JSON.parse(json) as JsonValue },
|
|
148
|
+
lines: json.trimEnd().split('\n'),
|
|
116
149
|
};
|
|
117
150
|
}
|
|
118
|
-
const
|
|
151
|
+
const rules = alertRuleGroups();
|
|
152
|
+
return {
|
|
153
|
+
ok: true,
|
|
154
|
+
command: 'g',
|
|
155
|
+
summary: msg('cli.generate.chartAlertsPrinted', { count: CHART_ALERTS.length }),
|
|
156
|
+
data: { rules },
|
|
157
|
+
lines: rules.trimEnd().split('\n'),
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/** `values` with `blocks` appended after one blank line. */
|
|
162
|
+
const appended = (values: string, blocks: string): string =>
|
|
163
|
+
`${values.trimEnd()}\n\n${blocks.trimEnd()}\n`;
|
|
164
|
+
|
|
165
|
+
export async function runChartAlerts(
|
|
166
|
+
ctx: CommandContext,
|
|
167
|
+
root: string,
|
|
168
|
+
kind: ChartGenerator = 'chart-alerts',
|
|
169
|
+
): Promise<CommandResult> {
|
|
170
|
+
refuseUnreadFlags(ctx.args, kind);
|
|
171
|
+
if (flagBool(ctx.args, 'print')) return printed(kind);
|
|
172
|
+
const name = await chartName(root, kind);
|
|
119
173
|
const force = flagBool(ctx.args, 'force');
|
|
120
174
|
// Without --force a template already there is kept, never a conflict: it is the app's, and this
|
|
121
|
-
// run's job is the files the chart lacks. --force rewrites
|
|
122
|
-
const files = generate({ kind
|
|
175
|
+
// run's job is the files the chart lacks. --force rewrites them from the current table.
|
|
176
|
+
const files = generate({ kind, name }).map(
|
|
123
177
|
(file): GeneratedFile =>
|
|
124
178
|
force || typeof file.contents !== 'string'
|
|
125
179
|
? file
|
|
@@ -128,9 +182,9 @@ export async function runChartAlerts(ctx: CommandContext, root: string): Promise
|
|
|
128
182
|
const valuesPath = containedPath(root, VALUES_FILE);
|
|
129
183
|
const valuesFile = Bun.file(valuesPath);
|
|
130
184
|
const values = (await valuesFile.exists()) ? await valuesFile.text() : undefined;
|
|
131
|
-
const blocks = values === undefined ? '' : missingValueBlocks(values);
|
|
185
|
+
const blocks = values === undefined ? '' : missingValueBlocks(values, kind);
|
|
132
186
|
const edited = blocks === '' ? [] : [VALUES_FILE];
|
|
133
|
-
const invocation = `${invocationOf(ctx, 'g')}
|
|
187
|
+
const invocation = `${invocationOf(ctx, 'g')} ${kind}`;
|
|
134
188
|
const dryRun = flagBool(ctx.args, 'dry-run');
|
|
135
189
|
const report = dryRun
|
|
136
190
|
? await planWrites(root, files, force, invocation)
|
|
@@ -142,7 +196,7 @@ export async function runChartAlerts(ctx: CommandContext, root: string): Promise
|
|
|
142
196
|
// Zero files is a run like any other: a chart that holds both templates and both values blocks.
|
|
143
197
|
const summary = msg(dryRun ? 'cli.generate.planned' : 'cli.generate.wrote', {
|
|
144
198
|
count: touched.length,
|
|
145
|
-
kind
|
|
199
|
+
kind,
|
|
146
200
|
name,
|
|
147
201
|
});
|
|
148
202
|
return {
|
package/src/generate-files.ts
CHANGED
|
@@ -28,6 +28,7 @@ import {
|
|
|
28
28
|
taskFiles,
|
|
29
29
|
} from './templates';
|
|
30
30
|
import { adminCatalogFiles } from './templates/admin-catalog';
|
|
31
|
+
import { helmDashboardFiles } from './templates/chart-dashboard';
|
|
31
32
|
import { cronJobFiles } from './templates/generate-cron-job';
|
|
32
33
|
import { purgeFiles } from './templates/generate-purge';
|
|
33
34
|
import { webhookReceiverFiles } from './templates/generate-webhook-receiver';
|
|
@@ -288,6 +289,9 @@ export function generate(options: GenerateOptions): readonly GeneratedFile[] {
|
|
|
288
289
|
// `name` is the chart's own (`Chart.yaml`), which its helpers are named after. The values
|
|
289
290
|
// blocks are an edit to a file the app owns, so `generate-chart-alerts.ts` makes it.
|
|
290
291
|
return helmMonitoringFiles(names(options.name));
|
|
292
|
+
case 'chart-dashboard':
|
|
293
|
+
// The same chart, the same name: the dashboard JSON and the ConfigMap that ships it.
|
|
294
|
+
return helmDashboardFiles(names(options.name));
|
|
291
295
|
case 'route':
|
|
292
296
|
// `--locales` reaches the route generator too: its catalog entry is the route's title and
|
|
293
297
|
// description, and a locale asked for on the command line is a locale that gets a file.
|
package/src/generate-kinds.ts
CHANGED
|
@@ -35,6 +35,7 @@ export const GENERATORS = [
|
|
|
35
35
|
'guard',
|
|
36
36
|
'sign-in',
|
|
37
37
|
'chart-alerts',
|
|
38
|
+
'chart-dashboard',
|
|
38
39
|
'app',
|
|
39
40
|
'package',
|
|
40
41
|
] as const;
|
|
@@ -301,6 +302,7 @@ const EXAMPLE_NAME: Readonly<Record<Generator, string>> = {
|
|
|
301
302
|
'sign-in': '--password',
|
|
302
303
|
// No name either: an app has one chart. `--print` runs with or without one.
|
|
303
304
|
'chart-alerts': '--print',
|
|
305
|
+
'chart-dashboard': '--print',
|
|
304
306
|
// A workspace: `apps/admin`, `packages/domain`.
|
|
305
307
|
app: 'admin',
|
|
306
308
|
package: 'domain',
|
package/src/messages.ts
CHANGED
|
@@ -102,6 +102,7 @@ const CATALOG = {
|
|
|
102
102
|
'cli.doctor.coverageExclude':
|
|
103
103
|
'{count} path(s) x.verify.json excludes from the coverage floor — each with the reason it gives:',
|
|
104
104
|
'cli.doctor.chartAlerts': '{count} monitoring template(s) missing from the chart:',
|
|
105
|
+
'cli.doctor.chartDashboard': '{count} dashboard file(s) missing from the chart:',
|
|
105
106
|
// `x doctor`'s reminder: the rolling rail is off until this key is set (`doctor-rolling.ts`).
|
|
106
107
|
'cli.doctor.rollingSince':
|
|
107
108
|
'the rolling-deploy rail is off: set "rollingSince": "{newest}" in x.verify.json to judge every migration after your newest',
|
|
@@ -146,6 +147,7 @@ const CATALOG = {
|
|
|
146
147
|
// believed the files were on disk.
|
|
147
148
|
'cli.generate.planned': 'would write {count} file(s) for {kind} {name} — nothing written',
|
|
148
149
|
'cli.generate.chartAlertsPrinted': '{count} alert rule(s), as Prometheus rule groups',
|
|
150
|
+
'cli.generate.chartDashboardPrinted': 'the Grafana dashboard, as JSON to import',
|
|
149
151
|
'cli.i18n.added': 'added {locale} — {keys} key(s) seeded from {from}',
|
|
150
152
|
'cli.i18n.dynamic': '{count} dynamic t() call(s) the extractor cannot verify:',
|
|
151
153
|
'cli.i18n.gaps': '{missing} missing key(s) across {locales} locale(s)',
|