docker-compose.yml 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504
  1. # docker-compose.yml — single-host M0 stack.
  2. # Run: docker compose up -d
  3. # Then: see M0_VERIFICATION.md for the loadgen smoke test.
  4. #
  5. # Port conventions (project rule):
  6. # - app HTTP services: 8800–8899 (ingestd/routerd/deliverd-fcm/deliverd-telegram/telegramd/admind/loadgen/faketgmd)
  7. # - canonical ports stay (5432 postgres, 4222 nats, 6379 redis,
  8. # 1883 mqtt, 9090 prometheus, 3000 grafana, etc.)
  9. services:
  10. # ── Data tier ────────────────────────────────────────────────────
  11. postgres:
  12. image: timescale/timescaledb:latest-pg16
  13. environment:
  14. POSTGRES_USER: ba
  15. POSTGRES_PASSWORD: ba
  16. POSTGRES_DB: ba
  17. # No host port mapping: a host-local postgres is already on
  18. # :5432. The app services reach this one via the docker network
  19. # DNS name 'postgres'. Use `docker compose exec postgres psql ...`
  20. # to talk to it from the host.
  21. expose: ["5432"]
  22. volumes:
  23. - pgdata:/var/lib/postgresql/data
  24. healthcheck:
  25. test: ["CMD-SHELL", "pg_isready -U ba"]
  26. interval: 5s
  27. timeout: 3s
  28. retries: 10
  29. redis:
  30. image: redis:7-alpine
  31. # No host port mapping: a host-local redis is on :6379. App
  32. # services reach this one via docker DNS 'redis'.
  33. expose: ["6379"]
  34. healthcheck:
  35. test: ["CMD", "redis-cli", "ping"]
  36. interval: 5s
  37. timeout: 3s
  38. retries: 10
  39. nats:
  40. image: nats:2.10-alpine
  41. # -js : JetStream enabled
  42. # -sd /data : store dir (mounted from natsdata volume)
  43. # -m 8222 : HTTP monitoring port
  44. # -ms 10G : max_storage cap. M11 NATS investigation set
  45. # this explicitly after the default (~5.5 GiB on
  46. # parres with 6.5 GiB free) was exceeded by
  47. # accumulated ALERTS data. With the docker prune
  48. # (2026-06-16) we now have 11 GiB free, so 10G
  49. # is safe. See M11_NATS_INVESTIGATION.md.
  50. command: ["-js", "-sd", "/data", "-m", "8222", "-ms", "10G"]
  51. ports: ["4222:4222", "8222:8222"] # 8222 is the monitoring HTTP
  52. volumes:
  53. - natsdata:/data
  54. healthcheck:
  55. test: ["CMD", "wget", "-qO-", "http://localhost:8222/healthz"]
  56. interval: 5s
  57. timeout: 3s
  58. retries: 20
  59. emqx:
  60. image: emqx/emqx:5.10.4
  61. ports: ["1883:1883", "18083:18083"] # MQTT + admin UI
  62. volumes:
  63. # M4: per-company ACL + auth bootstrap. acl.conf is read on
  64. # SIGHUP; the auth CSV is read on first boot. M11 promotes
  65. # this to a Postgres-backed authentication chain.
  66. - ./deploy/emqx/acl.conf:/opt/emqx/etc/acl.conf:ro
  67. - ./deploy/emqx/auth-built-in-db-bootstrap.csv:/opt/emqx/etc/auth-built-in-db-bootstrap.csv:ro
  68. # EMQX 5.x prefers env-var config over emqx.conf. The HOCON
  69. # path is emqx.conf → base.hocon → cluster.hocon → env vars
  70. # (highest precedence). The double-underscore separator in
  71. # env-var names maps to nested HOCON keys.
  72. environment:
  73. # Built-in-db authentication (one chain, password_based, plain)
  74. EMQX_AUTHENTICATION__1__BACKEND: "built_in_database"
  75. EMQX_AUTHENTICATION__1__MECHANISM: "password_based"
  76. EMQX_AUTHENTICATION__1__USER_ID_TYPE: "username"
  77. EMQX_AUTHENTICATION__1__PASSWORD_HASH_ALGORITHM__NAME: "plain"
  78. EMQX_AUTHENTICATION__1__PASSWORD_HASH_ALGORITHM__SALT_POSITION: "disable"
  79. # File-based authorization, default-deny
  80. EMQX_AUTHORIZATION__NO_MATCH: "deny"
  81. EMQX_AUTHORIZATION__DENY_ACTION: "disconnect"
  82. EMQX_AUTHORIZATION__SOURCES__1__TYPE: "file"
  83. EMQX_AUTHORIZATION__SOURCES__1__ENABLE: "true"
  84. EMQX_AUTHORIZATION__SOURCES__1__PATH: "/opt/emqx/etc/acl.conf"
  85. healthcheck:
  86. # The original `echo > /dev/tcp/...` ran under sh on
  87. # Debian-based EMQX and reported unhealthy even when the
  88. # broker was fine. Switch to `bash -c` and a TCP probe.
  89. test: ["CMD", "bash", "-c", "exec 3<>/dev/tcp/127.0.0.1/1883"]
  90. interval: 10s
  91. timeout: 5s
  92. retries: 20
  93. clickhouse:
  94. image: clickhouse/clickhouse-server:24-alpine
  95. ports: ["8123:8123", "9000:9000"]
  96. volumes:
  97. - chdata:/var/lib/clickhouse
  98. ulimits:
  99. nofile: { soft: 262144, hard: 262144 }
  100. # ── App tier ─────────────────────────────────────────────────────
  101. ingestd:
  102. build: .
  103. command: ["/app/ingestd"]
  104. environment:
  105. BA_ENV: dev
  106. BA_HTTP_ADDR: ":8800"
  107. BA_NATS_URL: nats://nats:4222
  108. BA_REDIS_URL: redis://redis:6379/0
  109. BA_POSTGRES_DSN: postgres://ba:ba@postgres:5432/ba?sslmode=disable
  110. BA_INGESTD_SOURCES: "acme-001:acme-001-prom:s3cret-acme-001,acme-002:acme-002-prom:s3cret-acme-002,globex-002:grafana:s3cret-globex"
  111. BA_INGESTD_RATE_LIMIT_PER_SOURCE: "20000"
  112. BA_INGESTD_RATE_LIMIT_PER_COMPANY: "10000"
  113. # M4: MQTT subscriber. ingestd subscribes to ba/+/+/incoming
  114. # with the dedicated `ingestd` user. The auth file lists
  115. # this user (password "ingestd-broker-only") so EMQX's
  116. # built-in-db authenticates the connection.
  117. BA_INGESTD_MQTT_BROKER: "tcp://emqx:1883"
  118. BA_INGESTD_MQTT_USERNAME: "ingestd"
  119. BA_INGESTD_MQTT_PASSWORD: "ingestd-broker-only"
  120. BA_INGESTD_MQTT_SUBSCRIBE: "ba/+/+/incoming"
  121. # M5: WebSocket ingest + live tail. TAIL_TOKEN gates the
  122. # /v1/tail/ws endpoint; a static token is fine for the
  123. # dev path; M11 swaps for JWT.
  124. BA_INGESTD_TAIL_TOKEN: "tail-dev-token-please-change-in-prod"
  125. BA_INGESTD_MAX_CONCURRENT_PER_IP: "32"
  126. BA_INGESTD_DEDUPE_TTL_SECONDS: "300"
  127. # M9 layer 6: circuit breaker (trips after 5 failures in 10s, 30s open)
  128. BA_INGESTD_CB_FAILURE_THRESHOLD: "5"
  129. BA_INGESTD_CB_FAILURE_WINDOW_SECS: "10"
  130. BA_INGESTD_CB_OPEN_DURATION_SECS: "30"
  131. BA_INGESTD_CB_MAX_HALF_OPEN: "1"
  132. # M9 layer 7: quarantine (bans source at 100 hits/5min for 10min)
  133. BA_INGESTD_QUARANTINE_HITS_THRESHOLD: "100"
  134. BA_INGESTD_QUARANTINE_WINDOW_SECONDS: "300"
  135. BA_INGESTD_QUARANTINE_DURATION_SECONDS: "600"
  136. ports: ["8800:8800"]
  137. depends_on:
  138. nats: { condition: service_healthy }
  139. redis: { condition: service_healthy }
  140. postgres: { condition: service_healthy }
  141. emqx: { condition: service_healthy }
  142. routerd:
  143. build: .
  144. command: ["/app/routerd"]
  145. environment:
  146. BA_ENV: dev
  147. BA_HTTP_ADDR: ":8801"
  148. BA_NATS_URL: nats://nats:4222
  149. BA_POSTGRES_DSN: postgres://ba:ba@postgres:5432/ba?sslmode=disable
  150. # M6.5: router-level dedupe collapse window. A burst of
  151. # identical alerts is held for up to this many ms, then
  152. # a single delivery is fanned out with the final
  153. # dedupe_count. A continuous stream re-flushes every
  154. # DedupeFlushMs.
  155. BA_ROUTERD_DEDUPE_FLUSH_MS: "2000"
  156. ports: ["8801:8801"]
  157. depends_on:
  158. nats: { condition: service_healthy }
  159. postgres: { condition: service_healthy }
  160. deliverd-fcm:
  161. build: .
  162. command: ["/app/deliverd-fcm"]
  163. environment:
  164. BA_ENV: dev
  165. BA_HTTP_ADDR: ":8802"
  166. BA_NATS_URL: nats://nats:4222
  167. BA_POSTGRES_DSN: postgres://ba:ba@postgres:5432/ba?sslmode=disable
  168. BA_FAKECMD_URL: "http://fakefcmd:8820"
  169. # M8: in-process retry. Defaults match
  170. # internal/retry.Default() — 10 attempts, base
  171. # 100ms, cap 2s, total budget 30s. Tuned to
  172. # terminate in ~12s for a fully failing target
  173. # so a single misbehaving source can't tie up a
  174. # consumer.
  175. BA_DELIVERD_MAX_ATTEMPTS: "10"
  176. BA_DELIVERD_RETRY_BASE_MS: "100"
  177. BA_DELIVERD_RETRY_MAX_MS: "2000"
  178. BA_DELIVERD_RETRY_BUDGET_MS: "30000"
  179. ports: ["8802:8802"]
  180. depends_on:
  181. nats: { condition: service_healthy }
  182. postgres: { condition: service_healthy }
  183. fakefcmd: { condition: service_started }
  184. deliverd-telegram:
  185. build: .
  186. command: ["/app/deliverd-telegram"]
  187. environment:
  188. BA_ENV: dev
  189. BA_HTTP_ADDR: ":8821"
  190. BA_NATS_URL: nats://nats:4222
  191. BA_POSTGRES_DSN: postgres://ba:ba@postgres:5432/ba?sslmode=disable
  192. BA_TELEGRAM_BOT_TOKEN: "fake-tg-bot-token-acme-001"
  193. BA_TELEGRAM_FAKE_URL: "http://faketgmd:8830"
  194. # M8: same retry knobs as deliverd-fcm.
  195. BA_DELIVERD_MAX_ATTEMPTS: "10"
  196. BA_DELIVERD_RETRY_BASE_MS: "100"
  197. BA_DELIVERD_RETRY_MAX_MS: "2000"
  198. BA_DELIVERD_RETRY_BUDGET_MS: "30000"
  199. ports: ["8821:8821"]
  200. depends_on:
  201. nats: { condition: service_healthy }
  202. postgres: { condition: service_healthy }
  203. faketgmd: { condition: service_started }
  204. telegramd:
  205. build: .
  206. command: ["/app/telegramd"]
  207. environment:
  208. BA_ENV: dev
  209. BA_HTTP_ADDR: ":8822"
  210. BA_NATS_URL: nats://nats:4222
  211. BA_POSTGRES_DSN: postgres://ba:ba@postgres:5432/ba?sslmode=disable
  212. BA_TELEGRAM_FAKE_URL: "http://faketgmd:8830"
  213. ports: ["8822:8822"]
  214. depends_on:
  215. nats: { condition: service_healthy }
  216. postgres: { condition: service_healthy }
  217. faketgmd: { condition: service_started }
  218. faketgmd:
  219. build: .
  220. command: ["/app/faketgmd", "--addr", ":8830", "--timeout", "5"]
  221. ports: ["8830:8830"]
  222. fakefcmd:
  223. build: .
  224. command: ["/app/fakefcmd", "--addr", ":8820"]
  225. ports: ["8820:8820"]
  226. healthcheck:
  227. test: ["CMD", "wget", "-qO-", "http://localhost:8820/health"]
  228. interval: 5s
  229. timeout: 3s
  230. retries: 10
  231. seed:
  232. build: .
  233. command: ["/app/seed"]
  234. environment:
  235. BA_POSTGRES_DSN: postgres://ba:ba@postgres:5432/ba?sslmode=disable
  236. BA_MIGRATIONS_DIR: /migrations
  237. volumes:
  238. - ./migrations:/migrations:ro
  239. depends_on:
  240. postgres: { condition: service_healthy }
  241. admind:
  242. build: .
  243. command: ["/app/admind"]
  244. environment:
  245. BA_ENV: dev
  246. BA_HTTP_ADDR: ":8803"
  247. BA_NATS_URL: nats://nats:4222
  248. BA_POSTGRES_DSN: postgres://ba:ba@postgres:5432/ba?sslmode=disable
  249. # M8: admind connects to NATS to publish DLQ
  250. # replays back onto the deliveries.<chan>.<co>
  251. # subject. The HTTPAddr serves /v1/ping, /v1/dlq*,
  252. # /dlq, /health, /metrics.
  253. ports: ["8803:8803"]
  254. depends_on:
  255. nats: { condition: service_healthy }
  256. postgres: { condition: service_healthy }
  257. archiverd:
  258. build: .
  259. command: ["/app/archiverd"]
  260. environment:
  261. BA_ENV: dev
  262. BA_HTTP_ADDR: ":8804"
  263. BA_POSTGRES_DSN: postgres://ba:ba@postgres:5432/ba?sslmode=disable
  264. # M7: archiver cadence + retention cutoff. The
  265. # Timescale retention policy does the same at 7d;
  266. # the archiver just runs ahead so ClickHouse has
  267. # the data before TS drops it.
  268. BA_ARCHIVERD_RUN_EVERY_SECONDS: "3600"
  269. BA_ARCHIVERD_OLDER_THAN_HOURS: "168"
  270. BA_ARCHIVERD_BATCH_SIZE: "10000"
  271. BA_ARCHIVERD_CLICKHOUSE_URL: "http://clickhouse:8123"
  272. ports: ["8804:8804"]
  273. depends_on:
  274. postgres: { condition: service_healthy }
  275. clickhouse: { condition: service_started }
  276. # ── Observability ────────────────────────────────────────────────
  277. prometheus:
  278. image: prom/prometheus:latest
  279. command:
  280. - --config.file=/etc/prometheus/prometheus.yml
  281. volumes:
  282. - ./deploy/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml:ro
  283. ports: ["9090:9090"]
  284. depends_on: [ingestd, routerd, deliverd-fcm, deliverd-telegram, telegramd, admind]
  285. grafana:
  286. image: grafana/grafana:latest
  287. # :3000 is held by gogs (git3) on this host. Map to :3001
  288. # on the host, keep :3000 internal. M0 ports convention
  289. # says canonical ports stay; the host-port override is a
  290. # one-line exception, fully isolated to grafana.
  291. ports: ["3001:3000"]
  292. environment:
  293. GF_SECURITY_ADMIN_USER: admin
  294. GF_SECURITY_ADMIN_PASSWORD: admin
  295. GF_SECURITY_DISABLE_LOGIN_FORM: "false"
  296. # M9: provisioning paths for dashboards + datasources.
  297. GF_PATHS_PROVISIONING: /etc/grafana/provisioning
  298. GF_DASHBOARDS_ENABLED: "true"
  299. volumes:
  300. - ./deploy/grafana/provisioning/datasources:/etc/grafana/provisioning/datasources:ro
  301. - ./deploy/grafana/provisioning/dashboards:/etc/grafana/provisioning/dashboards:ro
  302. - ./deploy/grafana/provisioning/dashboards/broad-announce-overview.json:/var/lib/grafana/dashboards/broad-announce-overview.json:ro
  303. depends_on: [prometheus]
  304. # ── Loadgen (one-shot smoke profile) ────────────────────
  305. loadgen-http:
  306. build: .
  307. command:
  308. - /app/loadgen-http
  309. - --target=http://ingestd:8800
  310. - --api-key=acme-001:prom-prod:s3cret-acme
  311. - --mode=normal
  312. - --rate=50
  313. - --duration=30s
  314. - --metrics=:8891
  315. - --instance=loadgen-http
  316. - --cluster-id=smoke
  317. profiles: ["loadgen"]
  318. depends_on:
  319. ingestd: { condition: service_started }
  320. # M10: 3-instance cluster hitting 5k/s. Each instance does ~1.7k/s.
  321. # Per-company cap is 10k/s, so 3 × 1.7k = 5.1k is safe.
  322. # Use `docker compose --profile loadgen-m10 up -d` to bring up all 3.
  323. loadgen-http-1:
  324. build: .
  325. command:
  326. - /app/loadgen-http
  327. - --target=http://ingestd:8800
  328. - --api-key=acme-001:prom-prod:s3cret-acme-001
  329. - --mode=normal
  330. - --rate=1700
  331. - --duration=10m
  332. - --ramp-up=30s
  333. - --metrics=:8891
  334. - --instance=loadgen-http-1
  335. - --cluster-id=m10
  336. profiles: ["loadgen-m10"]
  337. depends_on:
  338. ingestd: { condition: service_started }
  339. loadgen-http-2:
  340. build: .
  341. command:
  342. - /app/loadgen-http
  343. - --target=http://ingestd:8800
  344. - --api-key=acme-002:prom-prod:s3cret-acme-002
  345. - --mode=normal
  346. - --rate=1700
  347. - --duration=10m
  348. - --ramp-up=30s
  349. - --metrics=:8891
  350. - --instance=loadgen-http-2
  351. - --cluster-id=m10
  352. profiles: ["loadgen-m10"]
  353. depends_on:
  354. ingestd: { condition: service_started }
  355. loadgen-http-3:
  356. build: .
  357. command:
  358. - /app/loadgen-http
  359. - --target=http://ingestd:8800
  360. - --api-key=acme-003:prom-prod:s3cret-acme-003
  361. - --mode=normal
  362. - --rate=1700
  363. - --duration=10m
  364. - --ramp-up=30s
  365. - --metrics=:8891
  366. - --instance=loadgen-http-3
  367. - --cluster-id=m10
  368. profiles: ["loadgen-m10"]
  369. depends_on:
  370. ingestd: { condition: service_started }
  371. # M10 W4: Rogue loadgen — same company+source as loadgen-http-1 but
  372. # firing at 10× the per-source cap (100/s). Simulates a compromised source
  373. # at 1000/s. Per-source limiter drops 900/s (429); other companies stay clean.
  374. # NOT started by default with --profile loadgen-m10; spawned by step3_runaway_test().
  375. loadgen-http-4:
  376. build: .
  377. command:
  378. - /app/loadgen-http
  379. - --target=http://ingestd:8800
  380. - --api-key=acme-001:prom-prod:s3cret-acme-001
  381. - --mode=normal
  382. - --rate=1000
  383. - --duration=10m
  384. - --ramp-up=10s
  385. - --metrics=:8891
  386. - --instance=loadgen-http-4
  387. - --cluster-id=m10
  388. profiles: ["loadgen-m10"]
  389. depends_on:
  390. ingestd: { condition: service_started }
  391. # M11 W4: gRPC loadgen — 2-instance cluster at 10k/s total.
  392. # Each instance opens 8 parallel streams (workers) at 5k/s each.
  393. # Use: docker compose --profile loadgen-grpc up -d
  394. loadgen-grpc-1:
  395. build: .
  396. command:
  397. - /app/loadgen-grpc
  398. - --target=ingestd:9090
  399. - --api-key=acme-001:acme-001-prom:s3cret-acme-001
  400. - --rate=8000
  401. - --workers=16
  402. - --dedupe-pct=0
  403. - --duration=15m
  404. - --metrics=:8892
  405. - --instance=loadgen-grpc-1
  406. - --cluster-id=m11
  407. profiles: ["loadgen-grpc"]
  408. depends_on:
  409. ingestd: { condition: service_started }
  410. loadgen-grpc-2:
  411. build: .
  412. command:
  413. - /app/loadgen-grpc
  414. - --target=ingestd:9090
  415. - --api-key=acme-002:acme-002-prom:s3cret-acme-002
  416. - --rate=8000
  417. - --workers=16
  418. - --dedupe-pct=0
  419. - --duration=15m
  420. - --metrics=:8892
  421. - --instance=loadgen-grpc-2
  422. - --cluster-id=m11
  423. profiles: ["loadgen-grpc"]
  424. depends_on:
  425. ingestd: { condition: service_started }
  426. # M10-bench: delivery tier stubbed with deliverd-bench (no-op).
  427. # No FCM, no Telegram, no Postgres writes — just consume and ACK.
  428. # Allows broker+router ceiling testing at 50k/s without burning FCM credits.
  429. deliverd-bench:
  430. build: .
  431. command: ["/app/deliverd-bench"]
  432. environment:
  433. BA_ENV: dev
  434. BA_NATS_URL: nats://nats:4222
  435. profiles: ["bench"]
  436. depends_on:
  437. nats: { condition: service_healthy }
  438. # 10-instance loadgen cluster for 50k/s bench (5 × 5k instances × 2 = 50k).
  439. # Split across 2 host machines in production; on docker-compose single-host
  440. # we run 10 instances at 5k/s each for a total of 50k/s.
  441. loadgen-bench-1:
  442. build: .
  443. command:
  444. - /app/loadgen-http
  445. - --target=http://ingestd:8800
  446. - --api-key=acme-bench:prom-bench:s3cret-bench
  447. - --mode=normal
  448. - --rate=5000
  449. - --duration=5m
  450. - --ramp-up=15s
  451. - --metrics=:8891
  452. - --instance=loadgen-bench-1
  453. - --cluster-id=m10-bench
  454. profiles: ["bench"]
  455. depends_on:
  456. ingestd: { condition: service_started }
  457. loadgen-bench-2:
  458. build: .
  459. command:
  460. - /app/loadgen-http
  461. - --target=http://ingestd:8800
  462. - --api-key=acme-bench:prom-bench:s3cret-bench
  463. - --mode=normal
  464. - --rate=5000
  465. - --duration=5m
  466. - --ramp-up=15s
  467. - --metrics=:8891
  468. - --instance=loadgen-bench-2
  469. - --cluster-id=m10-bench
  470. profiles: ["bench"]
  471. depends_on:
  472. ingestd: { condition: service_started }
  473. volumes:
  474. pgdata: {}
  475. natsdata: {}
  476. chdata: {}