@zigordev/stack 0.0.0-stage → 1.0.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/dist/cli.js ADDED
@@ -0,0 +1,68 @@
1
+ import { join } from 'node:path';
2
+ export const files = ['compose.yaml', 'compose.local.yaml'];
3
+ export const resources = 'observability';
4
+ export const addresses = [
5
+ ['http://grafana.localhost', 'Grafana: the logs, traces and metrics of every app'],
6
+ ['http://mail.localhost', 'Mailpit: every email sent on this laptop'],
7
+ ['http://traefik.localhost', 'Traefik: the routes it knows'],
8
+ ['http://alloy.localhost', 'Alloy: what it receives and where it sends it'],
9
+ ];
10
+ const usage = [
11
+ 'Usage: zigordev-stack up',
12
+ ' zigordev-stack down',
13
+ ' zigordev-stack reset',
14
+ '',
15
+ 'up Starts the shared services and waits until each one is healthy.',
16
+ ' It then pushes the dashboards and the alert rules to the local Grafana.',
17
+ ' When the services are running already, it changes nothing.',
18
+ 'down Stops them and keeps their data.',
19
+ 'reset Stops them, deletes their data and starts them again.',
20
+ '',
21
+ ].join('\n');
22
+ function compose(io, ...args) {
23
+ return io.interact('docker', ['compose', ...files.flatMap((file) => ['--file', file]), ...args], io.folder);
24
+ }
25
+ function up(io) {
26
+ if (!io.has(join(io.folder, resources, 'folder.json'))) {
27
+ io.write(`zigordev-stack: the dashboard files are missing from ${join(io.folder, resources)}. In the platform repo, \`pnpm build\` writes them\n`);
28
+ return 1;
29
+ }
30
+ const started = compose(io, 'up', '--detach', '--wait', '--wait-timeout', '300');
31
+ if (started !== 0) {
32
+ io.write('zigordev-stack: not every shared service became healthy. The lines above name the one that did not\n');
33
+ return started;
34
+ }
35
+ const pushed = compose(io, 'run', '--rm', 'gcx');
36
+ if (pushed !== 0) {
37
+ io.write('zigordev-stack: the services are up, but the dashboards and the alert rules could not be pushed. The lines above say why\n');
38
+ return pushed;
39
+ }
40
+ const width = Math.max(...addresses.map(([address]) => address.length)) + 2;
41
+ io.write([
42
+ 'The shared services are up:',
43
+ ...addresses.map(([address, what]) => ` ${address.padEnd(width)}${what}`),
44
+ '',
45
+ ].join('\n'));
46
+ return 0;
47
+ }
48
+ function reset(io) {
49
+ const code = compose(io, 'down', '--volumes');
50
+ return code === 0 ? up(io) : code;
51
+ }
52
+ export function main(args, io) {
53
+ const [command, ...rest] = args;
54
+ if (rest.length === 0) {
55
+ if (command === 'up') {
56
+ return up(io);
57
+ }
58
+ if (command === 'down') {
59
+ return compose(io, 'down');
60
+ }
61
+ if (command === 'reset') {
62
+ return reset(io);
63
+ }
64
+ }
65
+ io.write(usage);
66
+ return 2;
67
+ }
68
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAWjC,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,cAAc,EAAE,oBAAoB,CAAU,CAAC;AACrE,MAAM,CAAC,MAAM,SAAS,GAAG,eAAe,CAAC;AAEzC,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB,CAAC,0BAA0B,EAAE,oDAAoD,CAAC;IAClF,CAAC,uBAAuB,EAAE,0CAA0C,CAAC;IACrE,CAAC,0BAA0B,EAAE,8BAA8B,CAAC;IAC5D,CAAC,wBAAwB,EAAE,+CAA+C,CAAC;CACnE,CAAC;AAEX,MAAM,KAAK,GAAG;IACZ,0BAA0B;IAC1B,4BAA4B;IAC5B,6BAA6B;IAC7B,EAAE;IACF,wEAAwE;IACxE,gFAAgF;IAChF,mEAAmE;IACnE,yCAAyC;IACzC,8DAA8D;IAC9D,EAAE;CACH,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAEb,SAAS,OAAO,CAAC,EAAM,EAAE,GAAG,IAAuB;IACjD,OAAO,EAAE,CAAC,QAAQ,CAChB,QAAQ,EACR,CAAC,SAAS,EAAE,GAAG,KAAK,CAAC,OAAO,CAAC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GAAG,IAAI,EAAE,CAAC;QAC1E,EAAE;KACH,CAAC,IAAI,CAAC,IAAI,CAAC,CACb,CAAC;IACF,OAAO,CAAC,CAAC;AACX,CAAC;AAED,SAAS,KAAK,CAAC,EAAM;IACnB,MAAM,IAAI,GAAG,OAAO,CAAC,EAAE,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;IAC9C,OAAO,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AACpC,CAAC;AAED,MAAM,UAAU,IAAI,CAAC,IAAuB,EAAE,EAAM;IAClD,MAAM,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC;IAChC,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACtB,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;YACrB,OAAO,EAAE,CAAC,EAAE,CAAC,CAAC;QAChB,CAAC;QACD,IAAI,OAAO,KAAK,MAAM,EAAE,CAAC;YACvB,OAAO,OAAO,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;QAC7B,CAAC;QACD,IAAI,OAAO,KAAK,OAAO,EAAE,CAAC;YACxB,OAAO,KAAK,CAAC,EAAE,CAAC,CAAC;QACnB,CAAC;IACH,CAAC;IACD,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAChB,OAAO,CAAC,CAAC;AACX,CAAC"}
@@ -0,0 +1,60 @@
1
+ {
2
+ "apiVersion": "rules.alerting.grafana.app/v1beta1",
3
+ "kind": "AlertRule",
4
+ "metadata": {
5
+ "name": "app-answers-with-errors",
6
+ "annotations": {
7
+ "grafana.app/folder": "zigordev"
8
+ }
9
+ },
10
+ "spec": {
11
+ "title": "An app answers with errors",
12
+ "trigger": {
13
+ "interval": "1m"
14
+ },
15
+ "for": "5m",
16
+ "noDataState": "Ok",
17
+ "execErrState": "Error",
18
+ "labels": {
19
+ "severity": "phone"
20
+ },
21
+ "annotations": {
22
+ "summary": "More than 5% of the requests to {{ $labels.service_name }} have failed with a server error for 5 minutes",
23
+ "runbook_url": "https://github.com/zigordev/platform/blob/main/docs/runbooks/app-answers-with-errors.md",
24
+ "__dashboardUid__": "app",
25
+ "__panelId__": "4"
26
+ },
27
+ "expressions": {
28
+ "A": {
29
+ "datasourceUID": "prometheus",
30
+ "relativeTimeRange": {
31
+ "from": "10m",
32
+ "to": "0s"
33
+ },
34
+ "model": {
35
+ "refId": "A",
36
+ "expr": "(sum by (service_name) (rate(http_server_request_duration_seconds_count{service_name!=\"traefik\", http_response_status_code=~\"5..\"}[5m])) / sum by (service_name) (rate(http_server_request_duration_seconds_count{service_name!=\"traefik\"}[5m]))) > 0.05",
37
+ "instant": true
38
+ }
39
+ },
40
+ "B": {
41
+ "source": true,
42
+ "model": {
43
+ "refId": "B",
44
+ "type": "threshold",
45
+ "expression": "A",
46
+ "conditions": [
47
+ {
48
+ "evaluator": {
49
+ "type": "gt",
50
+ "params": [
51
+ 0
52
+ ]
53
+ }
54
+ }
55
+ ]
56
+ }
57
+ }
58
+ }
59
+ }
60
+ }
@@ -0,0 +1,60 @@
1
+ {
2
+ "apiVersion": "rules.alerting.grafana.app/v1beta1",
3
+ "kind": "AlertRule",
4
+ "metadata": {
5
+ "name": "app-is-slow",
6
+ "annotations": {
7
+ "grafana.app/folder": "zigordev"
8
+ }
9
+ },
10
+ "spec": {
11
+ "title": "An app is slow",
12
+ "trigger": {
13
+ "interval": "1m"
14
+ },
15
+ "for": "10m",
16
+ "noDataState": "Ok",
17
+ "execErrState": "Error",
18
+ "labels": {
19
+ "severity": "phone"
20
+ },
21
+ "annotations": {
22
+ "summary": "The slowest 5% of the requests to {{ $labels.service_name }} have taken longer than 1 second for 10 minutes",
23
+ "runbook_url": "https://github.com/zigordev/platform/blob/main/docs/runbooks/app-is-slow.md",
24
+ "__dashboardUid__": "app",
25
+ "__panelId__": "5"
26
+ },
27
+ "expressions": {
28
+ "A": {
29
+ "datasourceUID": "prometheus",
30
+ "relativeTimeRange": {
31
+ "from": "10m",
32
+ "to": "0s"
33
+ },
34
+ "model": {
35
+ "refId": "A",
36
+ "expr": "histogram_quantile(0.95, sum by (service_name, le) (rate(http_server_request_duration_seconds_bucket{service_name!=\"traefik\"}[5m]))) > 1",
37
+ "instant": true
38
+ }
39
+ },
40
+ "B": {
41
+ "source": true,
42
+ "model": {
43
+ "refId": "B",
44
+ "type": "threshold",
45
+ "expression": "A",
46
+ "conditions": [
47
+ {
48
+ "evaluator": {
49
+ "type": "gt",
50
+ "params": [
51
+ 0
52
+ ]
53
+ }
54
+ }
55
+ ]
56
+ }
57
+ }
58
+ }
59
+ }
60
+ }
@@ -0,0 +1,60 @@
1
+ {
2
+ "apiVersion": "rules.alerting.grafana.app/v1beta1",
3
+ "kind": "AlertRule",
4
+ "metadata": {
5
+ "name": "host-is-filling-up",
6
+ "annotations": {
7
+ "grafana.app/folder": "zigordev"
8
+ }
9
+ },
10
+ "spec": {
11
+ "title": "The host is filling up",
12
+ "trigger": {
13
+ "interval": "1m"
14
+ },
15
+ "for": "5m",
16
+ "noDataState": "Ok",
17
+ "execErrState": "Error",
18
+ "labels": {
19
+ "severity": "phone"
20
+ },
21
+ "annotations": {
22
+ "summary": "The memory of the host is more than 85% in use, or one of its disks more than 80%",
23
+ "runbook_url": "https://github.com/zigordev/platform/blob/main/docs/runbooks/host-is-filling-up.md",
24
+ "__dashboardUid__": "platform",
25
+ "__panelId__": "5"
26
+ },
27
+ "expressions": {
28
+ "A": {
29
+ "datasourceUID": "prometheus",
30
+ "relativeTimeRange": {
31
+ "from": "10m",
32
+ "to": "0s"
33
+ },
34
+ "model": {
35
+ "refId": "A",
36
+ "expr": "(1 - sum(node_memory_MemAvailable_bytes) / sum(node_memory_MemTotal_bytes)) > 0.85 or (1 - max by (device) (node_filesystem_avail_bytes) / max by (device) (node_filesystem_size_bytes)) > 0.8",
37
+ "instant": true
38
+ }
39
+ },
40
+ "B": {
41
+ "source": true,
42
+ "model": {
43
+ "refId": "B",
44
+ "type": "threshold",
45
+ "expression": "A",
46
+ "conditions": [
47
+ {
48
+ "evaluator": {
49
+ "type": "gt",
50
+ "params": [
51
+ 0
52
+ ]
53
+ }
54
+ }
55
+ ]
56
+ }
57
+ }
58
+ }
59
+ }
60
+ }
@@ -0,0 +1,60 @@
1
+ {
2
+ "apiVersion": "rules.alerting.grafana.app/v1beta1",
3
+ "kind": "AlertRule",
4
+ "metadata": {
5
+ "name": "telemetry-went-silent",
6
+ "annotations": {
7
+ "grafana.app/folder": "zigordev"
8
+ }
9
+ },
10
+ "spec": {
11
+ "title": "Telemetry went silent",
12
+ "trigger": {
13
+ "interval": "1m"
14
+ },
15
+ "for": "0s",
16
+ "noDataState": "Ok",
17
+ "execErrState": "Error",
18
+ "labels": {
19
+ "severity": "phone"
20
+ },
21
+ "annotations": {
22
+ "summary": "The telemetry agent has reported nothing for 10 minutes, so nothing else is known either",
23
+ "runbook_url": "https://github.com/zigordev/platform/blob/main/docs/runbooks/telemetry-went-silent.md",
24
+ "__dashboardUid__": "platform",
25
+ "__panelId__": "4"
26
+ },
27
+ "expressions": {
28
+ "A": {
29
+ "datasourceUID": "prometheus",
30
+ "relativeTimeRange": {
31
+ "from": "10m",
32
+ "to": "0s"
33
+ },
34
+ "model": {
35
+ "refId": "A",
36
+ "expr": "absent_over_time(alloy_build_info[10m])",
37
+ "instant": true
38
+ }
39
+ },
40
+ "B": {
41
+ "source": true,
42
+ "model": {
43
+ "refId": "B",
44
+ "type": "threshold",
45
+ "expression": "A",
46
+ "conditions": [
47
+ {
48
+ "evaluator": {
49
+ "type": "gt",
50
+ "params": [
51
+ 0
52
+ ]
53
+ }
54
+ }
55
+ ]
56
+ }
57
+ }
58
+ }
59
+ }
60
+ }