Commit 890dd66
feat(webapp): route ClickHouse reads to an optional read replica (#4081)
## Summary
Adds optional configuration to send ClickHouse read traffic to a
separate instance (for example a read replica) while writes stay on the
primary `CLICKHOUSE_URL`. This lets operators offload read load (runs
list, traces, logs, queries) from the cluster that handles inserts.
Fully backwards compatible: with nothing new set, every client resolves
to `CLICKHOUSE_URL` exactly as before.
## What it adds
- `CLICKHOUSE_READER_URL` (optional): a single reader endpoint that the
read-only clients fall back to. Read clients resolve `<own URL> ??
CLICKHOUSE_READER_URL ?? CLICKHOUSE_URL`. The task-events client (which
both inserts events and reads traces, spans, and logs) is built as a
reader/writer pair so queries use the reader while inserts stay on
`CLICKHOUSE_URL`.
- `RUNS_LIST_CLICKHOUSE_URL` (optional): a dedicated client for the runs
list (dashboard list, runs list API, live reload, child-status counts),
so the highest-traffic read path can target its own instance.
## Safety
Only read-only clients fall back to the reader: logs, query, admin, runs
list, the pending-version lookup, and the realtime run-id resolver. The
query page is constrained to read-only (the TSQL parser rejects anything
that is not a `SELECT`, and a `readonly` setting is applied). The
task-events client routes inserts to the writer and queries to the
reader per method, so a write can never reach the reader. Pure-write
clients (event inserts, replication) always use `CLICKHOUSE_URL`.
Note: this PR targets a baseline branch rather than `main` so the diff
stays scoped to the read-replica changes. It will be retargeted to
`main` before merge.
---------
Co-authored-by: Eric Allam <eallam@icloud.com>1 parent b902e65 commit 890dd66
8 files changed
Lines changed: 97 additions & 16 deletions
File tree
- .server-changes
- apps/webapp/app
- presenters/v3
- routes
- _app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.runs.$runParam
- _app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.runs._index
- services/clickhouse
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1718 | 1718 | | |
1719 | 1719 | | |
1720 | 1720 | | |
| 1721 | + | |
| 1722 | + | |
| 1723 | + | |
| 1724 | + | |
| 1725 | + | |
1721 | 1726 | | |
1722 | 1727 | | |
1723 | 1728 | | |
| |||
1780 | 1785 | | |
1781 | 1786 | | |
1782 | 1787 | | |
1783 | | - | |
| 1788 | + | |
1784 | 1789 | | |
1785 | 1790 | | |
1786 | 1791 | | |
1787 | 1792 | | |
1788 | 1793 | | |
1789 | | - | |
| 1794 | + | |
1790 | 1795 | | |
1791 | 1796 | | |
1792 | 1797 | | |
| |||
1805 | 1810 | | |
1806 | 1811 | | |
1807 | 1812 | | |
1808 | | - | |
| 1813 | + | |
1809 | 1814 | | |
1810 | 1815 | | |
1811 | 1816 | | |
1812 | 1817 | | |
1813 | 1818 | | |
| 1819 | + | |
| 1820 | + | |
1814 | 1821 | | |
1815 | 1822 | | |
1816 | 1823 | | |
| |||
1823 | 1830 | | |
1824 | 1831 | | |
1825 | 1832 | | |
1826 | | - | |
| 1833 | + | |
1827 | 1834 | | |
1828 | 1835 | | |
1829 | 1836 | | |
| |||
1835 | 1842 | | |
1836 | 1843 | | |
1837 | 1844 | | |
1838 | | - | |
| 1845 | + | |
1839 | 1846 | | |
1840 | 1847 | | |
1841 | 1848 | | |
| |||
1846 | 1853 | | |
1847 | 1854 | | |
1848 | 1855 | | |
| 1856 | + | |
| 1857 | + | |
| 1858 | + | |
| 1859 | + | |
| 1860 | + | |
| 1861 | + | |
| 1862 | + | |
| 1863 | + | |
| 1864 | + | |
| 1865 | + | |
| 1866 | + | |
| 1867 | + | |
| 1868 | + | |
| 1869 | + | |
1849 | 1870 | | |
1850 | 1871 | | |
1851 | 1872 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
290 | 290 | | |
291 | 291 | | |
292 | 292 | | |
293 | | - | |
| 293 | + | |
294 | 294 | | |
295 | 295 | | |
296 | 296 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
193 | 193 | | |
194 | 194 | | |
195 | 195 | | |
196 | | - | |
| 196 | + | |
197 | 197 | | |
198 | 198 | | |
199 | 199 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
104 | 104 | | |
105 | 105 | | |
106 | 106 | | |
107 | | - | |
| 107 | + | |
108 | 108 | | |
109 | 109 | | |
110 | 110 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
70 | | - | |
| 70 | + | |
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
| 36 | + | |
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| |||
Lines changed: 60 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
251 | 251 | | |
252 | 252 | | |
253 | 253 | | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
254 | 284 | | |
255 | 285 | | |
256 | 286 | | |
| |||
262 | 292 | | |
263 | 293 | | |
264 | 294 | | |
265 | | - | |
266 | | - | |
| 295 | + | |
| 296 | + | |
267 | 297 | | |
268 | | - | |
269 | | - | |
270 | | - | |
| 298 | + | |
271 | 299 | | |
272 | 300 | | |
273 | 301 | | |
| |||
277 | 305 | | |
278 | 306 | | |
279 | 307 | | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
280 | 330 | | |
281 | 331 | | |
282 | 332 | | |
| |||
298 | 348 | | |
299 | 349 | | |
300 | 350 | | |
301 | | - | |
| 351 | + | |
| 352 | + | |
302 | 353 | | |
303 | 354 | | |
304 | 355 | | |
| |||
388 | 439 | | |
389 | 440 | | |
390 | 441 | | |
| 442 | + | |
391 | 443 | | |
392 | 444 | | |
393 | 445 | | |
| |||
455 | 507 | | |
456 | 508 | | |
457 | 509 | | |
| 510 | + | |
| 511 | + | |
458 | 512 | | |
459 | 513 | | |
460 | 514 | | |
| |||
0 commit comments