@zigordev/stack 0.0.0 → 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/README.md +237 -1
- package/bin/zigordev-stack.js +19 -0
- package/compose.local.yaml +107 -0
- package/compose.yaml +263 -0
- package/dist/cli.d.ts +12 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +68 -0
- package/dist/cli.js.map +1 -0
- package/observability/alert-app-answers-with-errors.json +60 -0
- package/observability/alert-app-is-slow.json +60 -0
- package/observability/alert-host-is-filling-up.json +60 -0
- package/observability/alert-telemetry-went-silent.json +60 -0
- package/observability/dashboard-app.json +623 -0
- package/observability/dashboard-platform.json +552 -0
- package/observability/folder.json +10 -0
- package/package.json +31 -4
package/README.md
CHANGED
|
@@ -1,3 +1,239 @@
|
|
|
1
1
|
# @zigordev/stack
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The shared services of the zigordev platform for a laptop: the ingress, the telemetry agent, a local Grafana and a mail catcher. They are two compose files, the standard dashboards and alert rules, and one command that starts it all.
|
|
4
|
+
|
|
5
|
+
## What it is
|
|
6
|
+
|
|
7
|
+
Five containers that every product on the laptop shares. Three of them run in production too, from the same file.
|
|
8
|
+
|
|
9
|
+
| Service | Image | What it does | Runs |
|
|
10
|
+
| -------------- | ---------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------- |
|
|
11
|
+
| `traefik` | Traefik 3.7 | The ingress. It sends each address to its container, from the labels that the container carries | Everywhere |
|
|
12
|
+
| `docker-proxy` | wollomatic/socket-proxy 1.14 | A filtered door to Docker. It lets the ingress and the agent read which containers exist, and nothing else | Everywhere |
|
|
13
|
+
| `alloy` | Grafana Alloy 1.22 | The telemetry agent. It receives traces and metrics from every app, reads every container's log lines and the machine's own numbers, and forwards all of it | Everywhere |
|
|
14
|
+
| `lgtm` | grafana/otel-lgtm 0.41 | The local Grafana, with its stores for logs, traces and metrics in the same container | Laptop only |
|
|
15
|
+
| `mailpit` | Mailpit 1.34 | The mail catcher. It receives every email an app sends on the laptop, and shows it on a page | Laptop only |
|
|
16
|
+
| `gcx` | Grafana gcx 1.8 | Not a service but a job: it pushes the dashboards and the alert rules to the local Grafana, and ends | Laptop only, on each `up` |
|
|
17
|
+
|
|
18
|
+
| File | What it holds |
|
|
19
|
+
| -------------------- | -------------------------------------------------------------------------------------------------------------------------- |
|
|
20
|
+
| `compose.yaml` | The three services that run everywhere, with the agent's config inside |
|
|
21
|
+
| `compose.local.yaml` | What only the laptop has: the two other services, the local addresses, the published port and the settings |
|
|
22
|
+
| `observability/` | The dashboards and the alert rules as files, which `pnpm build` writes from the code in the repo's `observability/` folder |
|
|
23
|
+
| `bin/` and `src/` | The command `zigordev-stack`, which starts and stops them |
|
|
24
|
+
|
|
25
|
+
```mermaid
|
|
26
|
+
flowchart LR
|
|
27
|
+
browser["Browser"] -->|"http://name.localhost"| traefik
|
|
28
|
+
traefik --> app["An app's container"]
|
|
29
|
+
traefik --> lgtm["lgtm: Grafana"]
|
|
30
|
+
traefik --> mailpit
|
|
31
|
+
app -->|traces and metrics| alloy
|
|
32
|
+
app -->|email| mailpit
|
|
33
|
+
alloy -->|logs, traces, metrics| lgtm
|
|
34
|
+
traefik -.->|which containers exist| proxy["docker-proxy"]
|
|
35
|
+
alloy -.->|which containers exist, and their log lines| proxy
|
|
36
|
+
proxy -.-> docker["Docker"]
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Why we have it, and what we would lose without it
|
|
40
|
+
|
|
41
|
+
Every product needs an ingress, somewhere to send its telemetry and somewhere to send its mail. Without this package each product would bring its own, and two products could not run side by side on one laptop: both would want port 80, and their logs would land in two places.
|
|
42
|
+
|
|
43
|
+
Because the same three services run in production from the same file, a route or a log line that works on the laptop works there too. What differs is a short list of settings, and it is written down below.
|
|
44
|
+
|
|
45
|
+
Without the Docker proxy, the ingress and the agent would hold Docker's socket itself, which is the right to start any container with any privilege. A flaw in either would then be a flaw in the whole machine.
|
|
46
|
+
|
|
47
|
+
## How it works here, on the laptop and in production
|
|
48
|
+
|
|
49
|
+
### One project, one network, fixed names
|
|
50
|
+
|
|
51
|
+
The five containers form one Compose project named `platform`, whichever folder the files are started from. A product starts the same project from its own copy of this package, so a second start changes nothing, and two products share one set of services.
|
|
52
|
+
|
|
53
|
+
| Name | What it is |
|
|
54
|
+
| ----------------- | ------------------------------------------------------------------------------------------------ |
|
|
55
|
+
| `zigordev` | The network that every app joins. On it, the services answer to their own names |
|
|
56
|
+
| `alloy:4318` | Where an app sends its traces and metrics, over OTLP on HTTP. Port 4317 takes the same over gRPC |
|
|
57
|
+
| `mailpit:1025` | Where an app sends its mail on the laptop, over SMTP |
|
|
58
|
+
| `zigordev-docker` | A second network with no way out. Only the Docker proxy, the ingress and the agent are on it |
|
|
59
|
+
|
|
60
|
+
Nothing in the files points at a file on disk. That is on purpose: Compose recreates a container when the path of a mounted file changes, and each product has this package in a folder of its own. So the ingress and the proxy take their settings as variables and flags, and the agent's config travels inside `compose.yaml`, as the variable `ALLOY_CONFIG`. One line of shell writes it to a file in memory before Alloy starts, and Alloy then replaces that shell. A change to the config therefore recreates the agent and nothing else.
|
|
61
|
+
|
|
62
|
+
### What an app does to be served
|
|
63
|
+
|
|
64
|
+
An app joins the network and says three things about itself, in its own compose file:
|
|
65
|
+
|
|
66
|
+
| The app says | With | What it gets |
|
|
67
|
+
| ---------------------------------- | -------------------------------------------------------- | ------------------------------------------------------- |
|
|
68
|
+
| "Route this address to me" | The labels `traefik.enable`, a router rule and its port | Requests for that address, once its health check passes |
|
|
69
|
+
| "This is my name" | Its service name in Compose, which is `<product>-<part>` | Its log lines in Grafana under that name, with no setup |
|
|
70
|
+
| "Send my traces and metrics there" | `OTEL_EXPORTER_OTLP_ENDPOINT: http://alloy:4318` | Its traces and metrics in Grafana |
|
|
71
|
+
|
|
72
|
+
The ingress routes only to a container that asked for it and whose health check passes. A container that is still starting, or that turned unhealthy, gets no request.
|
|
73
|
+
|
|
74
|
+
The agent reads the log lines of every container on the two networks, through the proxy, and of no other container on the machine. When a line is JSON and carries a `traceId`, the agent stores that id beside the line. In Grafana the line then has a link named Trace, which opens the whole request, and a trace lists its own log lines. It looks for new containers every 5 seconds, so a job that runs for a few seconds is not missed.
|
|
75
|
+
|
|
76
|
+
### What the agent reports by itself
|
|
77
|
+
|
|
78
|
+
| What | From | Kept |
|
|
79
|
+
| ---------------------------------------------------------------- | -------------------------------------------------------------- | ---------------------------------------------------------------------- |
|
|
80
|
+
| Its own heartbeat, under the name `alloy` | Itself | One series. An alert fires when it has been missing for 10 minutes |
|
|
81
|
+
| The machine's processor, memory and disks, under the name `host` | Three read-only mounts of the machine: `/proc`, `/sys` and `/` | Only the series that a dashboard or an alert uses, and only real disks |
|
|
82
|
+
|
|
83
|
+
The three mounts let the agent read the machine's numbers. It runs as a user that is not root, so it reads only what every user of the machine may read. On the laptop "the machine" is the small Linux machine inside Docker Desktop.
|
|
84
|
+
|
|
85
|
+
### Dashboards and alert rules
|
|
86
|
+
|
|
87
|
+
`zigordev-stack up` ends by pushing seven files to the local Grafana, with gcx: one folder, two dashboards and four alert rules. A second push changes nothing.
|
|
88
|
+
|
|
89
|
+
| In Grafana | What it shows |
|
|
90
|
+
| --------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
91
|
+
| Dashboards, folder `zigordev`, App | One app, picked from a list: whether it reports, its version, its requests, the share that fail, its response times, its events and its errors |
|
|
92
|
+
| Dashboards, folder `zigordev`, Platform | The machine's processor, memory and disks, the requests at the ingress, and who is reporting |
|
|
93
|
+
| Alerting, four rules | [The runbooks](../docs/runbooks/README.md) list them. On the laptop they show in Grafana and notify nobody |
|
|
94
|
+
|
|
95
|
+
A new app needs no entry anywhere. It appears in the list of the App dashboard with its first request, and every rule covers it.
|
|
96
|
+
|
|
97
|
+
### Each container is boxed in
|
|
98
|
+
|
|
99
|
+
| Rule | Why |
|
|
100
|
+
| ------------------------------------------------------------------------------- | -------------------------------------------------------------- |
|
|
101
|
+
| An exact image version | The same bytes on every laptop, and Renovate proposes the next |
|
|
102
|
+
| A health check | `up` can wait for it, and the ingress can trust it |
|
|
103
|
+
| A memory limit and a CPU limit | One service cannot starve the others |
|
|
104
|
+
| An init process, no new privileges, no capabilities, at most 30 seconds to stop | A broken service stays inside its box and stops cleanly |
|
|
105
|
+
| A user that is not root, and a read-only file system | A flaw in the service cannot change the service |
|
|
106
|
+
| No published port, except port 80 of the ingress, on this laptop itself | Nothing is reachable from the network the laptop is on |
|
|
107
|
+
|
|
108
|
+
`src/compose.test.ts` holds every service to these rules, one by one, and the job `gcx` to all but the health check, which a job that ends does not need. `lgtm` is the one exception to the last-but-one row: it is six programs in one container, which start as root and write to their own folders. It runs on the laptop only.
|
|
109
|
+
|
|
110
|
+
| Service | Memory limit | CPU limit | Used when idle on 2026-11-22 |
|
|
111
|
+
| -------------- | ------------ | --------- | ---------------------------- |
|
|
112
|
+
| `traefik` | 128 MiB | 1 | 24 MiB |
|
|
113
|
+
| `docker-proxy` | 64 MiB | 0.25 | 11 MiB |
|
|
114
|
+
| `alloy` | 256 MiB | 1 | 51 MiB |
|
|
115
|
+
| `lgtm` | 2 GiB | 2 | 614 MiB |
|
|
116
|
+
| `mailpit` | 128 MiB | 0.5 | 10 MiB |
|
|
117
|
+
|
|
118
|
+
### The Docker proxy
|
|
119
|
+
|
|
120
|
+
The proxy refuses everything it was not told to allow. It answers only the ingress and the agent, and only these requests: `GET` on the version, the list of containers, one container, its log lines, the events and the networks, and `HEAD` on the ping. No request that starts, stops or changes anything gets through. It runs as a user that is not root, in the group that owns Docker's socket. On Docker Desktop that is group 0. Elsewhere the variable `DOCKER_SOCKET_GROUP` names it, as the pipeline does on its own machine.
|
|
121
|
+
|
|
122
|
+
### The ingress
|
|
123
|
+
|
|
124
|
+
Traefik takes all its settings from variables, so its own health check reads the same settings. Three choices are worth knowing:
|
|
125
|
+
|
|
126
|
+
| Choice | Why |
|
|
127
|
+
| -------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------- |
|
|
128
|
+
| A header whose name only imitates another one is dropped | `X_Forwarded_For` is not `X-Forwarded-For`, but some servers read both as the same. Dropping it means nobody can fake one |
|
|
129
|
+
| No access log | Traefik reports its request numbers as metrics. A line per request would carry addresses and paths into the logs |
|
|
130
|
+
| It calls nobody | The check for a new version and the usage report are off |
|
|
131
|
+
|
|
132
|
+
Traefik warns once at each start that it "can reject some encoded characters in the request path". That is a notice about a setting we leave as it is.
|
|
133
|
+
|
|
134
|
+
### The laptop and production
|
|
135
|
+
|
|
136
|
+
Production is built in phase 3. It will start `compose.yaml` with a `compose.production.yaml` of its own.
|
|
137
|
+
|
|
138
|
+
| Thing | On the laptop | In production |
|
|
139
|
+
| ---------------------------- | --------------------------------------------------------------- | --------------------------------------------------- |
|
|
140
|
+
| The three shared services | From `compose.yaml` | The same file |
|
|
141
|
+
| How a request arrives | Port 80 on the laptop itself, over IPv4 and IPv6 | Through Cloudflare's tunnel, with no published port |
|
|
142
|
+
| Where the agent sends | To `lgtm`, with a made-up name and password that nothing checks | To Grafana Cloud |
|
|
143
|
+
| Grafana and the mail catcher | `lgtm` and `mailpit` | Grafana Cloud and Amazon SES |
|
|
144
|
+
| The ingress's own pages | At `traefik.localhost` | Off |
|
|
145
|
+
| The proxy's group | 0, which owns the socket on Docker Desktop | The group that owns the socket on the host |
|
|
146
|
+
|
|
147
|
+
## How to use it, with one worked example
|
|
148
|
+
|
|
149
|
+
In this repo:
|
|
150
|
+
|
|
151
|
+
```bash
|
|
152
|
+
pnpm local:up
|
|
153
|
+
pnpm local:down
|
|
154
|
+
pnpm local:reset
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
`local:up` builds the dashboard files, starts the services and waits until each one is healthy. It then pushes the dashboards and the alert rules, and prints the four addresses. `local:down` stops them and keeps their data. `local:reset` stops them, deletes their data and starts them again.
|
|
158
|
+
|
|
159
|
+
| Address | What opens |
|
|
160
|
+
| -------------------------- | --------------------------------------------------------------------- |
|
|
161
|
+
| `http://grafana.localhost` | Grafana. Explore searches every log line, trace and metric |
|
|
162
|
+
| `http://mail.localhost` | Mailpit, with every email that was sent on this laptop |
|
|
163
|
+
| `http://traefik.localhost` | Traefik's own pages: the routes it knows, and why one is missing |
|
|
164
|
+
| `http://alloy.localhost` | Alloy's own pages: each part of its config, and whether it is healthy |
|
|
165
|
+
|
|
166
|
+
The worked example is an app named `hello-api`, of a product named `hello`. This is everything its compose file needs for the platform to serve it:
|
|
167
|
+
|
|
168
|
+
```yaml
|
|
169
|
+
services:
|
|
170
|
+
hello-api:
|
|
171
|
+
image: ghcr.io/zigordev/hello-api:1f3a9c2
|
|
172
|
+
environment:
|
|
173
|
+
PORT: "3000"
|
|
174
|
+
OTEL_SERVICE_NAME: hello-api
|
|
175
|
+
OTEL_EXPORTER_OTLP_ENDPOINT: http://alloy:4318
|
|
176
|
+
healthcheck:
|
|
177
|
+
test: [CMD, node, healthcheck.js]
|
|
178
|
+
labels:
|
|
179
|
+
traefik.enable: "true"
|
|
180
|
+
traefik.http.routers.hello-api.rule: Host(`hello.localhost`) && PathPrefix(`/api`)
|
|
181
|
+
traefik.http.services.hello-api.loadbalancer.server.port: "3000"
|
|
182
|
+
networks: [zigordev]
|
|
183
|
+
|
|
184
|
+
networks:
|
|
185
|
+
zigordev:
|
|
186
|
+
external: true
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
With the shared services running, `http://hello.localhost/api/…` reaches the app as soon as its health check passes. Its log lines show in Grafana under `hello-api`, and so do its traces and metrics.
|
|
190
|
+
|
|
191
|
+
### From another repo
|
|
192
|
+
|
|
193
|
+
A product needs no copy of this repo. It takes this package from the public npm registry, as a dev dependency, and starts the same services with the command the package brings:
|
|
194
|
+
|
|
195
|
+
```bash
|
|
196
|
+
pnpm add --save-dev @zigordev/stack
|
|
197
|
+
pnpm exec zigordev-stack up
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
| Command | What it does |
|
|
201
|
+
| ---------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
202
|
+
| `zigordev-stack up` | Starts the services, waits until each one is healthy, and pushes the dashboards and the alert rules. When they run already, it changes nothing |
|
|
203
|
+
| `zigordev-stack down` | Stops them and keeps their data |
|
|
204
|
+
| `zigordev-stack reset` | Stops them, deletes their data and starts them again |
|
|
205
|
+
|
|
206
|
+
The package holds the two compose files, the dashboard and alert files already built, and the command. It has no dependency of its own. It needs Node.js 26 or later, and Docker running.
|
|
207
|
+
|
|
208
|
+
The product template in `toolkit` begins its own `pnpm local:up` with `zigordev-stack up`, so one command brings up the platform and then the product.
|
|
209
|
+
|
|
210
|
+
Every product starts the same project, named `platform`. Two products that hold the same version of this package therefore share one set of services, and the second start changes nothing. With two different versions, each start recreates the services that differ, so the laptop runs what was started last. Renovate proposes each new version to every product at once, which keeps them together.
|
|
211
|
+
|
|
212
|
+
## How to check that it works, and what to do when it does not
|
|
213
|
+
|
|
214
|
+
| Try this | What must happen |
|
|
215
|
+
| ---------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
216
|
+
| `pnpm local:up` | It ends with "The shared services are up:" and the four addresses |
|
|
217
|
+
| `pnpm local:up` a second time | The same, within seconds, and no container is recreated |
|
|
218
|
+
| Open `http://grafana.localhost`, then Dashboards, then the folder `zigordev` | The dashboards App and Platform are there, and Platform shows the machine's numbers |
|
|
219
|
+
| In Grafana, open Alerting, then Alert rules | Four rules are listed in the folder `zigordev`, each one "Normal" |
|
|
220
|
+
| Open `http://grafana.localhost` and `http://mail.localhost` | Both pages open, with no sign-in |
|
|
221
|
+
| In Grafana's Explore, pick Loki and run `{service_name="traefik"}` | Traefik's own log lines show |
|
|
222
|
+
| Open `http://nothing.localhost` | Traefik answers 404, because no container asked for that address |
|
|
223
|
+
| `pnpm exec vitest run stack` | Every rule on this page that a machine can check passes |
|
|
224
|
+
| Open a pull request | The job "Shared services" starts all five on GitHub's machine, opens the four addresses and stops them. A change that breaks a start cannot merge |
|
|
225
|
+
|
|
226
|
+
| What you see | What it means | What to do |
|
|
227
|
+
| ------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
228
|
+
| `Cannot connect to the Docker daemon` | Docker is not running | Start Docker Desktop |
|
|
229
|
+
| `Bind for 127.0.0.1:80 failed: port is already allocated` | Another program on the laptop holds port 80 | Find it with `lsof -nP -iTCP:80 -sTCP:LISTEN`, and stop it |
|
|
230
|
+
| `local:up` ends with "not every shared service became healthy" | One container did not pass its health check in 5 minutes | The lines above name it. `docker logs platform-<service>-1` shows why |
|
|
231
|
+
| `zigordev-stack up` says "the dashboard files are missing" | The files in `stack/observability/` are built, not committed | `pnpm build`, which `pnpm local:up` does by itself |
|
|
232
|
+
| `local:up` says the dashboards and the alert rules could not be pushed | gcx could not reach Grafana, or Grafana refused a file | The lines above name the file and the reason. `pnpm exec vitest run observability` checks the files' shape |
|
|
233
|
+
| A dashboard or a rule that was removed from the code is still in Grafana | gcx does not delete what the files no longer hold | `pnpm local:reset` empties the local Grafana |
|
|
234
|
+
| `docker-proxy` is unhealthy, and its log says `permission denied` on the socket | The proxy is not in the group that owns Docker's socket on this machine | Start with that group in `DOCKER_SOCKET_GROUP`. `stat -c %g /var/run/docker.sock` prints it on Linux. On Docker Desktop it is 0, which is the default |
|
|
235
|
+
| An app answers on its own port and Traefik answers 404 for its address | The app is not on the network `zigordev`, has no `traefik.enable`, or is not healthy | `http://traefik.localhost` lists the routes Traefik knows. A container without a passing health check is not there |
|
|
236
|
+
| An app's log lines do not show in Grafana | The app is not on the network `zigordev`, so the agent does not read it | Add the network to the app's service |
|
|
237
|
+
| An app's traces do not show | The app sends them somewhere else, or nowhere | Set `OTEL_EXPORTER_OTLP_ENDPOINT` to `http://alloy:4318`. `http://alloy.localhost` shows what Alloy received |
|
|
238
|
+
| The App dashboard lists a new app, and its request panels say "No data" | The app has reported its request numbers once. A rate needs two reports, and an app reports once a minute, so the requests before its first report are never counted | Send a few more requests and wait a minute |
|
|
239
|
+
| Grafana is slow, or `lgtm` restarts | `lgtm` reached its memory limit | `docker stats --no-stream` shows each container against its limit. `pnpm local:reset` empties the stores |
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { spawnSync } from 'node:child_process';
|
|
3
|
+
import { existsSync } from 'node:fs';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
|
|
6
|
+
const source = new URL('../src/cli.ts', import.meta.url);
|
|
7
|
+
const entry = existsSync(fileURLToPath(source))
|
|
8
|
+
? source
|
|
9
|
+
: new URL('../dist/cli.js', import.meta.url);
|
|
10
|
+
const { main } = await import(entry.href);
|
|
11
|
+
|
|
12
|
+
process.exitCode = main(process.argv.slice(2), {
|
|
13
|
+
folder: fileURLToPath(new URL('../', import.meta.url)),
|
|
14
|
+
interact: (command, args, cwd) => spawnSync(command, args, { cwd, stdio: 'inherit' }).status ?? 1,
|
|
15
|
+
has: (path) => existsSync(path),
|
|
16
|
+
write: (text) => {
|
|
17
|
+
process.stdout.write(text);
|
|
18
|
+
},
|
|
19
|
+
});
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
services:
|
|
2
|
+
docker-proxy:
|
|
3
|
+
user: "65534:${DOCKER_SOCKET_GROUP:-0}"
|
|
4
|
+
|
|
5
|
+
traefik:
|
|
6
|
+
environment:
|
|
7
|
+
TRAEFIK_API: "true"
|
|
8
|
+
ports:
|
|
9
|
+
- 127.0.0.1:80:8080
|
|
10
|
+
- "[::1]:80:8080"
|
|
11
|
+
labels:
|
|
12
|
+
traefik.enable: "true"
|
|
13
|
+
traefik.http.routers.traefik.rule: Host(`traefik.localhost`)
|
|
14
|
+
traefik.http.routers.traefik.service: api@internal
|
|
15
|
+
|
|
16
|
+
alloy:
|
|
17
|
+
environment:
|
|
18
|
+
OTLP_DESTINATION: http://lgtm:4318
|
|
19
|
+
OTLP_USERNAME: local
|
|
20
|
+
OTLP_PASSWORD: local
|
|
21
|
+
LOKI_DESTINATION: http://lgtm:3100/loki/api/v1/push
|
|
22
|
+
LOKI_USERNAME: local
|
|
23
|
+
LOKI_PASSWORD: local
|
|
24
|
+
labels:
|
|
25
|
+
traefik.enable: "true"
|
|
26
|
+
traefik.http.routers.alloy.rule: Host(`alloy.localhost`)
|
|
27
|
+
traefik.http.services.alloy.loadbalancer.server.port: "12345"
|
|
28
|
+
|
|
29
|
+
lgtm:
|
|
30
|
+
image: grafana/otel-lgtm:0.41.1
|
|
31
|
+
init: true
|
|
32
|
+
cap_drop: [ALL]
|
|
33
|
+
security_opt: [no-new-privileges:true]
|
|
34
|
+
stop_grace_period: 30s
|
|
35
|
+
mem_limit: 2g
|
|
36
|
+
cpus: 2
|
|
37
|
+
environment:
|
|
38
|
+
GF_SERVER_ROOT_URL: http://grafana.localhost
|
|
39
|
+
volumes:
|
|
40
|
+
- lgtm-data:/data
|
|
41
|
+
healthcheck:
|
|
42
|
+
test: [CMD, /otel-lgtm/docker/healthcheck.sh]
|
|
43
|
+
interval: 5s
|
|
44
|
+
timeout: 5s
|
|
45
|
+
retries: 60
|
|
46
|
+
labels:
|
|
47
|
+
traefik.enable: "true"
|
|
48
|
+
traefik.http.routers.grafana.rule: Host(`grafana.localhost`)
|
|
49
|
+
traefik.http.services.grafana.loadbalancer.server.port: "3000"
|
|
50
|
+
networks: [zigordev]
|
|
51
|
+
|
|
52
|
+
mailpit:
|
|
53
|
+
image: axllent/mailpit:v1.34.0
|
|
54
|
+
user: "1000:1000"
|
|
55
|
+
init: true
|
|
56
|
+
read_only: true
|
|
57
|
+
cap_drop: [ALL]
|
|
58
|
+
security_opt: [no-new-privileges:true]
|
|
59
|
+
stop_grace_period: 10s
|
|
60
|
+
mem_limit: 128m
|
|
61
|
+
cpus: 0.5
|
|
62
|
+
environment:
|
|
63
|
+
MP_SMTP_AUTH_ACCEPT_ANY: "true"
|
|
64
|
+
MP_SMTP_AUTH_ALLOW_INSECURE: "true"
|
|
65
|
+
tmpfs:
|
|
66
|
+
- /tmp
|
|
67
|
+
healthcheck:
|
|
68
|
+
test: [CMD, /mailpit, readyz]
|
|
69
|
+
interval: 5s
|
|
70
|
+
timeout: 3s
|
|
71
|
+
retries: 12
|
|
72
|
+
labels:
|
|
73
|
+
traefik.enable: "true"
|
|
74
|
+
traefik.http.routers.mail.rule: Host(`mail.localhost`)
|
|
75
|
+
traefik.http.services.mail.loadbalancer.server.port: "8025"
|
|
76
|
+
networks: [zigordev]
|
|
77
|
+
|
|
78
|
+
gcx:
|
|
79
|
+
image: grafana/gcx:v1.8.0
|
|
80
|
+
profiles: [push]
|
|
81
|
+
command: [resources, push, --path, /resources, --on-error, abort]
|
|
82
|
+
user: "65532:65532"
|
|
83
|
+
init: true
|
|
84
|
+
read_only: true
|
|
85
|
+
cap_drop: [ALL]
|
|
86
|
+
security_opt: [no-new-privileges:true]
|
|
87
|
+
stop_grace_period: 10s
|
|
88
|
+
mem_limit: 128m
|
|
89
|
+
cpus: 0.5
|
|
90
|
+
environment:
|
|
91
|
+
GRAFANA_SERVER: http://lgtm:3000
|
|
92
|
+
GRAFANA_ORG_ID: "1"
|
|
93
|
+
GRAFANA_USER: admin
|
|
94
|
+
GRAFANA_PASSWORD: admin
|
|
95
|
+
GCX_TELEMETRY: disabled
|
|
96
|
+
GCX_KEYCHAIN: "off"
|
|
97
|
+
tmpfs:
|
|
98
|
+
- /home/nonroot/.config
|
|
99
|
+
volumes:
|
|
100
|
+
- ./observability:/resources:ro
|
|
101
|
+
depends_on:
|
|
102
|
+
lgtm:
|
|
103
|
+
condition: service_healthy
|
|
104
|
+
networks: [zigordev]
|
|
105
|
+
|
|
106
|
+
volumes:
|
|
107
|
+
lgtm-data:
|
package/compose.yaml
ADDED
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
name: platform
|
|
2
|
+
|
|
3
|
+
services:
|
|
4
|
+
docker-proxy:
|
|
5
|
+
image: wollomatic/socket-proxy:1.14.0
|
|
6
|
+
command:
|
|
7
|
+
- -loglevel=info
|
|
8
|
+
- -logjson
|
|
9
|
+
- -listenip=0.0.0.0
|
|
10
|
+
- -allowfrom=traefik,alloy
|
|
11
|
+
- -allowGET=/v1\..{1,2}/(version|info|events.*|containers/json.*|containers/[^/]+/json|containers/[^/]+/logs.*|networks.*)
|
|
12
|
+
- -allowHEAD=/_ping
|
|
13
|
+
- -allowhealthcheck
|
|
14
|
+
- -shutdowngracetime=5
|
|
15
|
+
init: true
|
|
16
|
+
read_only: true
|
|
17
|
+
cap_drop: [ALL]
|
|
18
|
+
security_opt: [no-new-privileges:true]
|
|
19
|
+
stop_grace_period: 10s
|
|
20
|
+
mem_limit: 64m
|
|
21
|
+
cpus: 0.25
|
|
22
|
+
volumes:
|
|
23
|
+
- /var/run/docker.sock:/var/run/docker.sock:ro
|
|
24
|
+
healthcheck:
|
|
25
|
+
test: [CMD, ./healthcheck]
|
|
26
|
+
interval: 5s
|
|
27
|
+
timeout: 3s
|
|
28
|
+
retries: 12
|
|
29
|
+
networks: [docker]
|
|
30
|
+
|
|
31
|
+
traefik:
|
|
32
|
+
image: traefik:v3.7.19
|
|
33
|
+
user: "65532:65532"
|
|
34
|
+
init: true
|
|
35
|
+
read_only: true
|
|
36
|
+
cap_drop: [ALL]
|
|
37
|
+
security_opt: [no-new-privileges:true]
|
|
38
|
+
stop_grace_period: 30s
|
|
39
|
+
mem_limit: 128m
|
|
40
|
+
cpus: 1
|
|
41
|
+
environment:
|
|
42
|
+
USER: traefik
|
|
43
|
+
TRAEFIK_GLOBAL_CHECKNEWVERSION: "false"
|
|
44
|
+
TRAEFIK_GLOBAL_SENDANONYMOUSUSAGE: "false"
|
|
45
|
+
TRAEFIK_GLOBAL_ALIASHEADERSSTRATEGY: delete
|
|
46
|
+
TRAEFIK_LOG_LEVEL: INFO
|
|
47
|
+
TRAEFIK_LOG_FORMAT: json
|
|
48
|
+
TRAEFIK_ENTRYPOINTS_WEB_ADDRESS: ":8080"
|
|
49
|
+
TRAEFIK_ENTRYPOINTS_PING_ADDRESS: ":8082"
|
|
50
|
+
TRAEFIK_PING: "true"
|
|
51
|
+
TRAEFIK_PING_ENTRYPOINT: ping
|
|
52
|
+
TRAEFIK_PROVIDERS_DOCKER: "true"
|
|
53
|
+
TRAEFIK_PROVIDERS_DOCKER_ENDPOINT: tcp://docker-proxy:2375
|
|
54
|
+
TRAEFIK_PROVIDERS_DOCKER_EXPOSEDBYDEFAULT: "false"
|
|
55
|
+
TRAEFIK_PROVIDERS_DOCKER_NETWORK: zigordev
|
|
56
|
+
TRAEFIK_METRICS_OTLP: "true"
|
|
57
|
+
TRAEFIK_METRICS_OTLP_HTTP_ENDPOINT: http://alloy:4318/v1/metrics
|
|
58
|
+
healthcheck:
|
|
59
|
+
test: [CMD, traefik, healthcheck]
|
|
60
|
+
interval: 5s
|
|
61
|
+
timeout: 3s
|
|
62
|
+
retries: 12
|
|
63
|
+
depends_on:
|
|
64
|
+
docker-proxy:
|
|
65
|
+
condition: service_healthy
|
|
66
|
+
networks: [zigordev, docker]
|
|
67
|
+
|
|
68
|
+
alloy:
|
|
69
|
+
image: grafana/alloy:v1.22.0
|
|
70
|
+
entrypoint:
|
|
71
|
+
- sh
|
|
72
|
+
- -c
|
|
73
|
+
- printf '%s' "$$ALLOY_CONFIG" > /tmp/config.alloy && exec alloy "$$@"
|
|
74
|
+
- alloy
|
|
75
|
+
command:
|
|
76
|
+
- run
|
|
77
|
+
- /tmp/config.alloy
|
|
78
|
+
- --storage.path=/var/lib/alloy/data
|
|
79
|
+
- --server.http.listen-addr=0.0.0.0:12345
|
|
80
|
+
- --disable-reporting
|
|
81
|
+
user: "473:473"
|
|
82
|
+
init: true
|
|
83
|
+
read_only: true
|
|
84
|
+
cap_drop: [ALL]
|
|
85
|
+
security_opt: [no-new-privileges:true]
|
|
86
|
+
stop_grace_period: 20s
|
|
87
|
+
mem_limit: 256m
|
|
88
|
+
cpus: 1
|
|
89
|
+
environment:
|
|
90
|
+
DOCKER_HOST: tcp://docker-proxy:2375
|
|
91
|
+
ALLOY_CONFIG: |
|
|
92
|
+
otelcol.receiver.otlp "apps" {
|
|
93
|
+
grpc {
|
|
94
|
+
endpoint = "0.0.0.0:4317"
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
http {
|
|
98
|
+
endpoint = "0.0.0.0:4318"
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
output {
|
|
102
|
+
metrics = [otelcol.processor.batch.apps.input]
|
|
103
|
+
logs = [otelcol.processor.batch.apps.input]
|
|
104
|
+
traces = [otelcol.processor.batch.apps.input]
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
otelcol.processor.batch "apps" {
|
|
109
|
+
output {
|
|
110
|
+
metrics = [otelcol.exporter.otlphttp.destination.input]
|
|
111
|
+
logs = [otelcol.exporter.otlphttp.destination.input]
|
|
112
|
+
traces = [otelcol.exporter.otlphttp.destination.input]
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
otelcol.auth.basic "destination" {
|
|
117
|
+
username = sys.env("OTLP_USERNAME")
|
|
118
|
+
password = sys.env("OTLP_PASSWORD")
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
otelcol.exporter.otlphttp "destination" {
|
|
122
|
+
client {
|
|
123
|
+
endpoint = sys.env("OTLP_DESTINATION")
|
|
124
|
+
auth = otelcol.auth.basic.destination.handler
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
discovery.docker "containers" {
|
|
129
|
+
host = sys.env("DOCKER_HOST")
|
|
130
|
+
refresh_interval = "5s"
|
|
131
|
+
|
|
132
|
+
filter {
|
|
133
|
+
name = "network"
|
|
134
|
+
values = ["zigordev", "zigordev-docker"]
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
discovery.relabel "containers" {
|
|
139
|
+
targets = discovery.docker.containers.targets
|
|
140
|
+
|
|
141
|
+
rule {
|
|
142
|
+
source_labels = ["__meta_docker_container_label_com_docker_compose_service"]
|
|
143
|
+
target_label = "service_name"
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
rule {
|
|
147
|
+
source_labels = ["__meta_docker_container_label_com_docker_compose_project"]
|
|
148
|
+
target_label = "compose_project"
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
rule {
|
|
152
|
+
source_labels = ["__meta_docker_container_name"]
|
|
153
|
+
regex = "/(.*)"
|
|
154
|
+
target_label = "container"
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
loki.source.docker "containers" {
|
|
159
|
+
host = sys.env("DOCKER_HOST")
|
|
160
|
+
targets = discovery.relabel.containers.output
|
|
161
|
+
forward_to = [loki.process.containers.receiver]
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
loki.process "containers" {
|
|
165
|
+
forward_to = [loki.write.destination.receiver]
|
|
166
|
+
|
|
167
|
+
stage.json {
|
|
168
|
+
expressions = { trace_id = "traceId" }
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
stage.structured_metadata {
|
|
172
|
+
values = { trace_id = "" }
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
loki.write "destination" {
|
|
177
|
+
endpoint {
|
|
178
|
+
url = sys.env("LOKI_DESTINATION")
|
|
179
|
+
|
|
180
|
+
basic_auth {
|
|
181
|
+
username = sys.env("LOKI_USERNAME")
|
|
182
|
+
password = sys.env("LOKI_PASSWORD")
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
prometheus.exporter.self "alloy" { }
|
|
188
|
+
|
|
189
|
+
prometheus.exporter.unix "host" {
|
|
190
|
+
procfs_path = "/host/proc"
|
|
191
|
+
sysfs_path = "/host/sys"
|
|
192
|
+
rootfs_path = "/host/root"
|
|
193
|
+
set_collectors = ["cpu", "meminfo", "filesystem"]
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
prometheus.scrape "machine" {
|
|
197
|
+
targets = array.concat(
|
|
198
|
+
prometheus.exporter.self.alloy.targets,
|
|
199
|
+
prometheus.exporter.unix.host.targets,
|
|
200
|
+
)
|
|
201
|
+
scrape_interval = "60s"
|
|
202
|
+
forward_to = [prometheus.relabel.machine.receiver]
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
prometheus.relabel "machine" {
|
|
206
|
+
forward_to = [otelcol.receiver.prometheus.machine.receiver]
|
|
207
|
+
|
|
208
|
+
rule {
|
|
209
|
+
source_labels = ["__name__", "mode", "fstype"]
|
|
210
|
+
regex = "alloy_build_info;;|node_cpu_seconds_total;idle;|node_memory_(MemTotal|MemAvailable)_bytes;;|node_filesystem_(size|avail)_bytes;;(ext4|xfs)"
|
|
211
|
+
action = "keep"
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
rule {
|
|
215
|
+
source_labels = ["job"]
|
|
216
|
+
regex = "integrations/self"
|
|
217
|
+
target_label = "job"
|
|
218
|
+
replacement = "alloy"
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
rule {
|
|
222
|
+
source_labels = ["job"]
|
|
223
|
+
regex = "integrations/unix"
|
|
224
|
+
target_label = "job"
|
|
225
|
+
replacement = "host"
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
otelcol.receiver.prometheus "machine" {
|
|
230
|
+
output {
|
|
231
|
+
metrics = [otelcol.processor.batch.apps.input]
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
tmpfs:
|
|
235
|
+
- /tmp
|
|
236
|
+
volumes:
|
|
237
|
+
- alloy-data:/var/lib/alloy/data
|
|
238
|
+
- /proc:/host/proc:ro
|
|
239
|
+
- /sys:/host/sys:ro
|
|
240
|
+
- /:/host/root:ro
|
|
241
|
+
healthcheck:
|
|
242
|
+
test:
|
|
243
|
+
- CMD
|
|
244
|
+
- bash
|
|
245
|
+
- -c
|
|
246
|
+
- exec 3<>/dev/tcp/127.0.0.1/12345 && printf 'GET /-/ready HTTP/1.0\r\n\r\n' >&3 && grep -q '200 OK' <&3
|
|
247
|
+
interval: 5s
|
|
248
|
+
timeout: 3s
|
|
249
|
+
retries: 12
|
|
250
|
+
depends_on:
|
|
251
|
+
docker-proxy:
|
|
252
|
+
condition: service_healthy
|
|
253
|
+
networks: [zigordev, docker]
|
|
254
|
+
|
|
255
|
+
networks:
|
|
256
|
+
zigordev:
|
|
257
|
+
name: zigordev
|
|
258
|
+
docker:
|
|
259
|
+
name: zigordev-docker
|
|
260
|
+
internal: true
|
|
261
|
+
|
|
262
|
+
volumes:
|
|
263
|
+
alloy-data:
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type Interact = (command: string, args: readonly string[], cwd: string) => number;
|
|
2
|
+
export interface Io {
|
|
3
|
+
readonly folder: string;
|
|
4
|
+
readonly interact: Interact;
|
|
5
|
+
readonly has: (path: string) => boolean;
|
|
6
|
+
readonly write: (text: string) => void;
|
|
7
|
+
}
|
|
8
|
+
export declare const files: readonly ['compose.yaml', 'compose.local.yaml'];
|
|
9
|
+
export declare const resources = "observability";
|
|
10
|
+
export declare const addresses: readonly [readonly ['http://grafana.localhost', 'Grafana: the logs, traces and metrics of every app'], readonly ['http://mail.localhost', 'Mailpit: every email sent on this laptop'], readonly ['http://traefik.localhost', 'Traefik: the routes it knows'], readonly ['http://alloy.localhost', 'Alloy: what it receives and where it sends it']];
|
|
11
|
+
export declare function main(args: readonly string[], io: Io): number;
|
|
12
|
+
//# sourceMappingURL=cli.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,QAAQ,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,KAAK,MAAM,CAAC;AAEzF,MAAM,WAAW,EAAE;IACjB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,QAAQ,CAAC,GAAG,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC;IACxC,QAAQ,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CACxC;AAED,eAAO,MAAM,KAAK,YAAI,cAAc,EAAE,oBAAoB,CAAU,CAAC;AACrE,eAAO,MAAM,SAAS,kBAAkB,CAAC;AAEzC,eAAO,MAAM,SAAS,sBACnB,0BAA0B,EAAE,oDAAoD,aAChF,uBAAuB,EAAE,0CAA0C,aACnE,0BAA0B,EAAE,8BAA8B,aAC1D,wBAAwB,EAAE,+CAA+C,EAClE,CAAC;AA4DX,wBAAgB,IAAI,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,GAAG,MAAM,CAe5D"}
|