@mastra/clickhouse 1.7.1-alpha.1 → 1.7.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/CHANGELOG.md +32 -0
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/reference-storage-clickhouse.md +8 -8
- package/dist/docs/references/reference-storage-composite.md +1 -1
- package/dist/index.cjs +131 -36
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +131 -36
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/observability/v-next/ddl.d.ts +41 -1
- package/dist/storage/domains/observability/v-next/ddl.d.ts.map +1 -1
- package/dist/storage/domains/observability/v-next/index.d.ts.map +1 -1
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,37 @@
|
|
|
1
1
|
# @mastra/clickhouse
|
|
2
2
|
|
|
3
|
+
## 1.7.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Fixed agent streams intermittently hanging when observability storage was backed by Replicated/Shared ClickHouse. Startup no longer re-applies no-op schema updates (e.g. `ADD COLUMN IF NOT EXISTS`, `ADD INDEX IF NOT EXISTS`, `MODIFY TTL`), so it no longer triggers replica-lag retry errors that could leave storage in a stuck state. ([#16420](https://github.com/mastra-ai/mastra/pull/16420))
|
|
8
|
+
|
|
9
|
+
- Respect optional `resourceId` in `getThreadById` so scoped thread lookups return `null` when the thread belongs to a different resource. ([#14237](https://github.com/mastra-ai/mastra/pull/14237))
|
|
10
|
+
|
|
11
|
+
Example:
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
const thread = await memory.getThreadById({
|
|
15
|
+
threadId: 'my-thread-id',
|
|
16
|
+
resourceId: 'my-user-id',
|
|
17
|
+
});
|
|
18
|
+
// Returns null if the thread does not belong to 'my-user-id'.
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
- Track `suspendedAt` and `suspendPayload` on background tasks. SQL adapters auto-migrate the new columns via `alterTable`. ([#16260](https://github.com/mastra-ai/mastra/pull/16260))
|
|
22
|
+
|
|
23
|
+
- Updated dependencies [[`9f17410`](https://github.com/mastra-ai/mastra/commit/9f1741080def23d42ee50b39887a385ae316a3c6), [`7ad5585`](https://github.com/mastra-ai/mastra/commit/7ad55856406f1de398dc713f6a9eaa78b2784bb6), [`ac47842`](https://github.com/mastra-ai/mastra/commit/ac478427aa7a5f5fdaed633a911218689b438c60), [`cc189cc`](https://github.com/mastra-ai/mastra/commit/cc189cc0128eb7af233476b5e421ec6888bffde7), [`d1fdbd0`](https://github.com/mastra-ai/mastra/commit/d1fdbd012add5623cb7e6b7f882b605ab358bbb4), [`210ea7a`](https://github.com/mastra-ai/mastra/commit/210ea7af559791b73a44fc9c12179908aaa3183f), [`7c275a8`](https://github.com/mastra-ai/mastra/commit/7c275a810595e1a6c41ccc39720531ab65734700), [`bae019e`](https://github.com/mastra-ai/mastra/commit/bae019ecb6694da96909f7ec7b9eb3a0a33aa887), [`890b24c`](https://github.com/mastra-ai/mastra/commit/890b24cc7d32ed6aa4dfe253e54dc6bf4099f690), [`f984b4d`](https://github.com/mastra-ai/mastra/commit/f984b4d6c60bf2ae2a9b156f0e8c35a66fe96c91), [`6742347`](https://github.com/mastra-ai/mastra/commit/6742347d71955d7639adc9ddf6ff8282de7ee3ba), [`b59316f`](https://github.com/mastra-ai/mastra/commit/b59316ffa0f7688165b0f9c81ccdf85da461e5b2), [`0f48ebf`](https://github.com/mastra-ai/mastra/commit/0f48ebfc7ac7897b2092a189f45751924cf56d1c), [`37c0dc5`](https://github.com/mastra-ai/mastra/commit/37c0dc5697d343db98628bf867bf71ce6deec6d7), [`087e413`](https://github.com/mastra-ai/mastra/commit/087e4133e5d6efa36619e9556c16750e4179c047), [`83218c8`](https://github.com/mastra-ai/mastra/commit/83218c88b37773c9424fbe733b37be556e55e94d), [`ef6b584`](https://github.com/mastra-ai/mastra/commit/ef6b5847ac33c0a7e80af3a86e8801e2933dd3ee), [`c6eb39e`](https://github.com/mastra-ai/mastra/commit/c6eb39ea6dca381c6563cb240237fbe608e02f93), [`7b0ad1f`](https://github.com/mastra-ai/mastra/commit/7b0ad1f5c53dc118c6da12ae82ae2587037dc2b8), [`d91ebe2`](https://github.com/mastra-ai/mastra/commit/d91ebe28ee065d8f2ed6df741c3c07f58d359529), [`62666c3`](https://github.com/mastra-ai/mastra/commit/62666c367eaeac3941ead454b1d38810cc855721), [`33f5061`](https://github.com/mastra-ai/mastra/commit/33f5061cd1c0335020c3faae61ce96de822854fa), [`4af2160`](https://github.com/mastra-ai/mastra/commit/4af2160322f4718cac421930cce85641e9512389), [`087e413`](https://github.com/mastra-ai/mastra/commit/087e4133e5d6efa36619e9556c16750e4179c047), [`265ec9f`](https://github.com/mastra-ai/mastra/commit/265ec9f887b5c81255c873a76ff7796f16e4f99b), [`ce01024`](https://github.com/mastra-ai/mastra/commit/ce010242eee9bdfc09e4c26725b9d37998679a8d), [`6ce80bf`](https://github.com/mastra-ai/mastra/commit/6ce80bf4872a891e0bddf8b80561a80584efb14b), [`f984b4d`](https://github.com/mastra-ai/mastra/commit/f984b4d6c60bf2ae2a9b156f0e8c35a66fe96c91), [`136c959`](https://github.com/mastra-ai/mastra/commit/136c9592fb0eeb0cd212f28629d8a29b7557a2fc), [`9268531`](https://github.com/mastra-ai/mastra/commit/9268531e7ec4be98beeba3b3ae8be0a7ea380662), [`13ead79`](https://github.com/mastra-ai/mastra/commit/13ead79149486b88144db7e11e6ff551caef5be1), [`dccd8f1`](https://github.com/mastra-ai/mastra/commit/dccd8f1f8b8f1ad203b77556207e5529567c616d), [`4df7cc7`](https://github.com/mastra-ai/mastra/commit/4df7cc79342fd065fe7fdeef93c094db14b12bcd), [`f180e49`](https://github.com/mastra-ai/mastra/commit/f180e4990e71b04c9a475b523584071712f0048f), [`9260e01`](https://github.com/mastra-ai/mastra/commit/9260e015276fb1b500f7878ee452b47476bf1583), [`2f6c54e`](https://github.com/mastra-ai/mastra/commit/2f6c54e17c041cac1def54baaa6b771647836414), [`aca3121`](https://github.com/mastra-ai/mastra/commit/aca31211233dac25459f140ea4fcfb3a5af64c18), [`e06a159`](https://github.com/mastra-ai/mastra/commit/e06a1598ca07a6c3778aefc2a2d288363c6294ff), [`4dd900d`](https://github.com/mastra-ai/mastra/commit/4dd900d75dfe9be89f8c15188b368a8622aa1e18), [`b560d6f`](https://github.com/mastra-ai/mastra/commit/b560d6f88b9b904b15c10f75c949eb145bc27684), [`99869ec`](https://github.com/mastra-ai/mastra/commit/99869ecb1f2aa6dfcc44fa4e843e5ee0344efa64), [`900d086`](https://github.com/mastra-ai/mastra/commit/900d086bb737b9cf2fcf68f11b0389b801a2738c), [`4c0e286`](https://github.com/mastra-ai/mastra/commit/4c0e28637c9cfb4f416549b55e97ebfa13319dfc), [`55f1e2d`](https://github.com/mastra-ai/mastra/commit/55f1e2d65425b95a49ae788053b266f256e38c96), [`4ff5bdf`](https://github.com/mastra-ai/mastra/commit/4ff5bdfe170cba6dfb5260c6af0f4ba668430772), [`9cdf38e`](https://github.com/mastra-ai/mastra/commit/9cdf38e58506e1109c8b38f97cd7770978a4218e), [`087e413`](https://github.com/mastra-ai/mastra/commit/087e4133e5d6efa36619e9556c16750e4179c047), [`db34bc6`](https://github.com/mastra-ai/mastra/commit/db34bc6fb36cf125bda0c46be4d3fdc774b70cc4), [`990851e`](https://github.com/mastra-ai/mastra/commit/990851edcb0e30be5c2c18b6532f1a876cc2d335), [`bbcd93c`](https://github.com/mastra-ai/mastra/commit/bbcd93cf7d8aa1007d6d84bfd033b8015c912087), [`8373ff4`](https://github.com/mastra-ai/mastra/commit/8373ff46745d77af79f183c4470f80fa2727a6b2), [`d48a705`](https://github.com/mastra-ai/mastra/commit/d48a705ff3dfbdc7a996e07ecd8293b5effd9a2a), [`308bd07`](https://github.com/mastra-ai/mastra/commit/308bd074f35cef0c75d82fc1eb19382fe04ecf6f), [`6068a6c`](https://github.com/mastra-ai/mastra/commit/6068a6c42950fad3ebfc92346417896ba60803d2), [`36b3bbf`](https://github.com/mastra-ai/mastra/commit/36b3bbf5a8d59f7e23d47e29340e76c681b4929c), [`d86f031`](https://github.com/mastra-ai/mastra/commit/d86f031eb6b0b2570145afafea664e59bf688962), [`b275631`](https://github.com/mastra-ai/mastra/commit/b275631dc10541a482b2e2d4a3e3cfa843bd5fa1), [`00106be`](https://github.com/mastra-ai/mastra/commit/00106bede59b81e5b0e9cd6aad8d3b5dbc336387), [`bd36d8e`](https://github.com/mastra-ai/mastra/commit/bd36d8eb6de8c9a0310352649dbd4b06703c2299), [`11c1528`](https://github.com/mastra-ai/mastra/commit/11c152848c5d0ef227184853b5040f5b41ee7b1e), [`4999667`](https://github.com/mastra-ai/mastra/commit/49996678b68356cad7f088430009690406c50fbd), [`e2a079c`](https://github.com/mastra-ai/mastra/commit/e2a079cc3755b1895f7bd5dc36e9be81b11c7c22), [`8ac9141`](https://github.com/mastra-ai/mastra/commit/8ac9141439caa8fdd674944c4d84f29b3c730296), [`25184ff`](https://github.com/mastra-ai/mastra/commit/25184ffaf1293ec95119426eb1a1f8d38831b96c), [`534a456`](https://github.com/mastra-ai/mastra/commit/534a456a25e4df1e5407e7e632f4cb3b1fa14f9d), [`105e454`](https://github.com/mastra-ai/mastra/commit/105e454c95af06a7c741c15969d8f9b0f02463a7), [`aebde9c`](https://github.com/mastra-ai/mastra/commit/aebde9cfacf56592c6b6350cae721740fe090b8a), [`36bae07`](https://github.com/mastra-ai/mastra/commit/36bae07c0e70b1b3006f2fd20830e8883dcbd066), [`5688881`](https://github.com/mastra-ai/mastra/commit/5688881669c7ed157f31ac77f6fc5f8d95ceea32)]:
|
|
24
|
+
- @mastra/core@1.33.0
|
|
25
|
+
|
|
26
|
+
## 1.7.1-alpha.2
|
|
27
|
+
|
|
28
|
+
### Patch Changes
|
|
29
|
+
|
|
30
|
+
- Fixed agent streams intermittently hanging when observability storage was backed by Replicated/Shared ClickHouse. Startup no longer re-applies no-op schema updates (e.g. `ADD COLUMN IF NOT EXISTS`, `ADD INDEX IF NOT EXISTS`, `MODIFY TTL`), so it no longer triggers replica-lag retry errors that could leave storage in a stuck state. ([#16420](https://github.com/mastra-ai/mastra/pull/16420))
|
|
31
|
+
|
|
32
|
+
- Updated dependencies [[`7ad5585`](https://github.com/mastra-ai/mastra/commit/7ad55856406f1de398dc713f6a9eaa78b2784bb6), [`210ea7a`](https://github.com/mastra-ai/mastra/commit/210ea7af559791b73a44fc9c12179908aaa3183f), [`83218c8`](https://github.com/mastra-ai/mastra/commit/83218c88b37773c9424fbe733b37be556e55e94d), [`265ec9f`](https://github.com/mastra-ai/mastra/commit/265ec9f887b5c81255c873a76ff7796f16e4f99b), [`6ce80bf`](https://github.com/mastra-ai/mastra/commit/6ce80bf4872a891e0bddf8b80561a80584efb14b), [`9268531`](https://github.com/mastra-ai/mastra/commit/9268531e7ec4be98beeba3b3ae8be0a7ea380662), [`13ead79`](https://github.com/mastra-ai/mastra/commit/13ead79149486b88144db7e11e6ff551caef5be1), [`bd36d8e`](https://github.com/mastra-ai/mastra/commit/bd36d8eb6de8c9a0310352649dbd4b06703c2299), [`8ac9141`](https://github.com/mastra-ai/mastra/commit/8ac9141439caa8fdd674944c4d84f29b3c730296)]:
|
|
33
|
+
- @mastra/core@1.33.0-alpha.10
|
|
34
|
+
|
|
3
35
|
## 1.7.1-alpha.1
|
|
4
36
|
|
|
5
37
|
### Patch Changes
|
package/dist/docs/SKILL.md
CHANGED
|
@@ -3,7 +3,7 @@ name: mastra-clickhouse
|
|
|
3
3
|
description: Documentation for @mastra/clickhouse. Use when working with @mastra/clickhouse APIs, configuration, or implementation.
|
|
4
4
|
metadata:
|
|
5
5
|
package: "@mastra/clickhouse"
|
|
6
|
-
version: "1.7.1
|
|
6
|
+
version: "1.7.1"
|
|
7
7
|
---
|
|
8
8
|
|
|
9
9
|
## When to use
|
|
@@ -51,7 +51,7 @@ import { Mastra } from '@mastra/core'
|
|
|
51
51
|
import { MastraCompositeStore } from '@mastra/core/storage'
|
|
52
52
|
import { PostgresStore } from '@mastra/pg'
|
|
53
53
|
import { ObservabilityStorageClickhouseVNext } from '@mastra/clickhouse'
|
|
54
|
-
import { Observability,
|
|
54
|
+
import { Observability, MastraStorageExporter } from '@mastra/observability'
|
|
55
55
|
|
|
56
56
|
const observabilityStore = new ObservabilityStorageClickhouseVNext({
|
|
57
57
|
url: process.env.CLICKHOUSE_URL!,
|
|
@@ -74,14 +74,14 @@ export const mastra = new Mastra({
|
|
|
74
74
|
configs: {
|
|
75
75
|
default: {
|
|
76
76
|
serviceName: 'mastra',
|
|
77
|
-
exporters: [new
|
|
77
|
+
exporters: [new MastraStorageExporter()],
|
|
78
78
|
},
|
|
79
79
|
},
|
|
80
80
|
}),
|
|
81
81
|
})
|
|
82
82
|
```
|
|
83
83
|
|
|
84
|
-
`
|
|
84
|
+
`MastraStorageExporter` automatically selects the `insert-only` strategy when ClickHouse is the observability backend, which gives the highest write throughput. See [tracing strategies](https://mastra.ai/docs/observability/tracing/exporters/mastra-storage) for details.
|
|
85
85
|
|
|
86
86
|
### Observability with the legacy domain
|
|
87
87
|
|
|
@@ -226,7 +226,7 @@ import { Mastra } from '@mastra/core'
|
|
|
226
226
|
import { MastraCompositeStore } from '@mastra/core/storage'
|
|
227
227
|
import { PostgresStore } from '@mastra/pg'
|
|
228
228
|
import { ObservabilityStorageClickhouseVNext } from '@mastra/clickhouse'
|
|
229
|
-
import { Observability,
|
|
229
|
+
import { Observability, MastraStorageExporter } from '@mastra/observability'
|
|
230
230
|
|
|
231
231
|
export const mastra = new Mastra({
|
|
232
232
|
storage: new MastraCompositeStore({
|
|
@@ -247,7 +247,7 @@ export const mastra = new Mastra({
|
|
|
247
247
|
configs: {
|
|
248
248
|
default: {
|
|
249
249
|
serviceName: 'mastra',
|
|
250
|
-
exporters: [new
|
|
250
|
+
exporters: [new MastraStorageExporter()],
|
|
251
251
|
},
|
|
252
252
|
},
|
|
253
253
|
}),
|
|
@@ -287,14 +287,14 @@ In CI/CD pipelines, set `disableInit: true` on `ClickhouseStore` and run `init()
|
|
|
287
287
|
|
|
288
288
|
ClickHouse is the recommended backend for production observability:
|
|
289
289
|
|
|
290
|
-
- **Insert-only strategy**: `
|
|
290
|
+
- **Insert-only strategy**: `MastraStorageExporter` writes completed spans in batches without per-span updates, which is the highest-throughput strategy available.
|
|
291
291
|
- **Columnar compression**: Span attributes and log payloads compress well compared to the same data in row-oriented databases.
|
|
292
292
|
|
|
293
|
-
For the full strategy matrix and production guidance, see the [`
|
|
293
|
+
For the full strategy matrix and production guidance, see the [`MastraStorageExporter` reference](https://mastra.ai/docs/observability/tracing/exporters/mastra-storage).
|
|
294
294
|
|
|
295
295
|
## Related
|
|
296
296
|
|
|
297
297
|
- [Storage overview](https://mastra.ai/reference/storage/overview)
|
|
298
298
|
- [Composite storage](https://mastra.ai/reference/storage/composite)
|
|
299
|
-
- [`
|
|
299
|
+
- [`MastraStorageExporter`](https://mastra.ai/docs/observability/tracing/exporters/mastra-storage)
|
|
300
300
|
- [Observability overview](https://mastra.ai/docs/observability/overview)
|
|
@@ -242,4 +242,4 @@ const storage = new MastraCompositeStore({
|
|
|
242
242
|
|
|
243
243
|
> **Note:** `ObservabilityStorageClickhouseVNext` is the current observability domain implementation. The legacy `ObservabilityStorageClickhouse` class is also exported and remains supported for projects that have not migrated. See the [ClickHouse storage reference](https://mastra.ai/reference/storage/clickhouse) for details.
|
|
244
244
|
|
|
245
|
-
> **Info:** This approach is also required when using storage providers that don't support observability (like Convex, DynamoDB, or Cloudflare). See the [
|
|
245
|
+
> **Info:** This approach is also required when using storage providers that don't support observability (like Convex, DynamoDB, or Cloudflare). See the [MastraStorageExporter documentation](https://mastra.ai/docs/observability/tracing/exporters/mastra-storage) for the full list of supported providers.
|
package/dist/index.cjs
CHANGED
|
@@ -3424,44 +3424,56 @@ var ALL_TABLE_DDL = [
|
|
|
3424
3424
|
];
|
|
3425
3425
|
var ALL_MV_DDL = [TRACE_ROOTS_MV_DDL, TRACE_BRANCHES_MV_DDL];
|
|
3426
3426
|
var DISCOVERY_MV_DDL = [DISCOVERY_VALUES_MV_DDL, DISCOVERY_PAIRS_MV_DDL];
|
|
3427
|
+
var addColumn = (table, name, type) => ({
|
|
3428
|
+
kind: "column",
|
|
3429
|
+
table,
|
|
3430
|
+
name,
|
|
3431
|
+
sql: `ALTER TABLE ${table} ADD COLUMN IF NOT EXISTS ${name} ${type}`
|
|
3432
|
+
});
|
|
3433
|
+
var addBloomIndex = (table, name, column) => ({
|
|
3434
|
+
kind: "index",
|
|
3435
|
+
table,
|
|
3436
|
+
name,
|
|
3437
|
+
sql: `ALTER TABLE ${table} ADD INDEX IF NOT EXISTS ${name} ${column} TYPE bloom_filter(0.01) GRANULARITY 2`
|
|
3438
|
+
});
|
|
3427
3439
|
var ALL_MIGRATIONS = [
|
|
3428
3440
|
// Span events
|
|
3429
|
-
|
|
3430
|
-
|
|
3431
|
-
|
|
3441
|
+
addColumn(TABLE_SPAN_EVENTS, "entityVersionId", "Nullable(String)"),
|
|
3442
|
+
addColumn(TABLE_SPAN_EVENTS, "parentEntityVersionId", "Nullable(String)"),
|
|
3443
|
+
addColumn(TABLE_SPAN_EVENTS, "rootEntityVersionId", "Nullable(String)"),
|
|
3432
3444
|
// Trace roots
|
|
3433
|
-
|
|
3434
|
-
|
|
3435
|
-
|
|
3445
|
+
addColumn(TABLE_TRACE_ROOTS, "entityVersionId", "Nullable(String)"),
|
|
3446
|
+
addColumn(TABLE_TRACE_ROOTS, "parentEntityVersionId", "Nullable(String)"),
|
|
3447
|
+
addColumn(TABLE_TRACE_ROOTS, "rootEntityVersionId", "Nullable(String)"),
|
|
3436
3448
|
// Metrics
|
|
3437
|
-
|
|
3438
|
-
|
|
3439
|
-
|
|
3449
|
+
addColumn(TABLE_METRIC_EVENTS, "entityVersionId", "Nullable(String)"),
|
|
3450
|
+
addColumn(TABLE_METRIC_EVENTS, "parentEntityVersionId", "Nullable(String)"),
|
|
3451
|
+
addColumn(TABLE_METRIC_EVENTS, "rootEntityVersionId", "Nullable(String)"),
|
|
3440
3452
|
// Logs
|
|
3441
|
-
|
|
3442
|
-
|
|
3443
|
-
|
|
3453
|
+
addColumn(TABLE_LOG_EVENTS, "entityVersionId", "Nullable(String)"),
|
|
3454
|
+
addColumn(TABLE_LOG_EVENTS, "parentEntityVersionId", "Nullable(String)"),
|
|
3455
|
+
addColumn(TABLE_LOG_EVENTS, "rootEntityVersionId", "Nullable(String)"),
|
|
3444
3456
|
// Scores
|
|
3445
|
-
|
|
3446
|
-
|
|
3447
|
-
|
|
3457
|
+
addColumn(TABLE_SCORE_EVENTS, "entityVersionId", "Nullable(String)"),
|
|
3458
|
+
addColumn(TABLE_SCORE_EVENTS, "parentEntityVersionId", "Nullable(String)"),
|
|
3459
|
+
addColumn(TABLE_SCORE_EVENTS, "rootEntityVersionId", "Nullable(String)"),
|
|
3448
3460
|
// Feedback
|
|
3449
|
-
|
|
3450
|
-
|
|
3451
|
-
|
|
3461
|
+
addColumn(TABLE_FEEDBACK_EVENTS, "entityVersionId", "Nullable(String)"),
|
|
3462
|
+
addColumn(TABLE_FEEDBACK_EVENTS, "parentEntityVersionId", "Nullable(String)"),
|
|
3463
|
+
addColumn(TABLE_FEEDBACK_EVENTS, "rootEntityVersionId", "Nullable(String)"),
|
|
3452
3464
|
// Metric skip indexes — additive, instant DDL. Existing parts keep no index
|
|
3453
3465
|
// until merged or `MATERIALIZE INDEX` is run; new parts are bloom-filtered
|
|
3454
3466
|
// immediately. With normal retention turning over the table, the index
|
|
3455
3467
|
// converges to full coverage without an explicit backfill.
|
|
3456
|
-
|
|
3457
|
-
|
|
3458
|
-
|
|
3459
|
-
|
|
3460
|
-
|
|
3461
|
-
|
|
3462
|
-
|
|
3463
|
-
|
|
3464
|
-
|
|
3468
|
+
addBloomIndex(TABLE_METRIC_EVENTS, "idx_traceId", "traceId"),
|
|
3469
|
+
addBloomIndex(TABLE_METRIC_EVENTS, "idx_threadId", "threadId"),
|
|
3470
|
+
addBloomIndex(TABLE_METRIC_EVENTS, "idx_resourceId", "resourceId"),
|
|
3471
|
+
addBloomIndex(TABLE_METRIC_EVENTS, "idx_userId", "userId"),
|
|
3472
|
+
addBloomIndex(TABLE_METRIC_EVENTS, "idx_organizationId", "organizationId"),
|
|
3473
|
+
addBloomIndex(TABLE_METRIC_EVENTS, "idx_experimentId", "experimentId"),
|
|
3474
|
+
addBloomIndex(TABLE_METRIC_EVENTS, "idx_runId", "runId"),
|
|
3475
|
+
addBloomIndex(TABLE_METRIC_EVENTS, "idx_sessionId", "sessionId"),
|
|
3476
|
+
addBloomIndex(TABLE_METRIC_EVENTS, "idx_requestId", "requestId")
|
|
3465
3477
|
];
|
|
3466
3478
|
var ALL_TABLE_NAMES = [
|
|
3467
3479
|
TABLE_SPAN_EVENTS,
|
|
@@ -3490,8 +3502,8 @@ var SIGNAL_TO_TABLES = {
|
|
|
3490
3502
|
scores: [TABLE_SCORE_EVENTS],
|
|
3491
3503
|
feedback: [TABLE_FEEDBACK_EVENTS]
|
|
3492
3504
|
};
|
|
3493
|
-
function
|
|
3494
|
-
const
|
|
3505
|
+
function buildRetentionEntries(retention) {
|
|
3506
|
+
const entries = [];
|
|
3495
3507
|
for (const [signal, days] of Object.entries(retention)) {
|
|
3496
3508
|
const safeDays = Math.floor(Number(days));
|
|
3497
3509
|
if (!Number.isFinite(safeDays) || safeDays <= 0) continue;
|
|
@@ -3500,10 +3512,24 @@ function buildRetentionDDL(retention) {
|
|
|
3500
3512
|
for (const table of tables) {
|
|
3501
3513
|
const col = SIGNAL_TTL_COLUMNS[table];
|
|
3502
3514
|
if (!col) continue;
|
|
3503
|
-
|
|
3515
|
+
entries.push({
|
|
3516
|
+
table,
|
|
3517
|
+
column: col,
|
|
3518
|
+
days: safeDays,
|
|
3519
|
+
sql: `ALTER TABLE ${table} MODIFY TTL ${col} + INTERVAL ${safeDays} DAY`
|
|
3520
|
+
});
|
|
3504
3521
|
}
|
|
3505
3522
|
}
|
|
3506
|
-
return
|
|
3523
|
+
return entries;
|
|
3524
|
+
}
|
|
3525
|
+
function parseTtlExpression(expr) {
|
|
3526
|
+
const match = expr.match(/TTL\s+(?:`([^`]+)`|(\w+))\s*\+\s*(?:toIntervalDay\((\d+)\)|INTERVAL\s+(\d+)\s+DAY)/i);
|
|
3527
|
+
if (!match) return null;
|
|
3528
|
+
const column = match[1] ?? match[2];
|
|
3529
|
+
if (!column) return null;
|
|
3530
|
+
const days = Number(match[3] ?? match[4]);
|
|
3531
|
+
if (!Number.isFinite(days)) return null;
|
|
3532
|
+
return { column, days };
|
|
3507
3533
|
}
|
|
3508
3534
|
var CH_SETTINGS = {
|
|
3509
3535
|
date_time_input_format: "best_effort",
|
|
@@ -5964,6 +5990,74 @@ time for large databases. Please ensure you have a backup before proceeding.
|
|
|
5964
5990
|
===========================================================================
|
|
5965
5991
|
`;
|
|
5966
5992
|
}
|
|
5993
|
+
async function filterAppliedMigrations(client, migrations) {
|
|
5994
|
+
if (migrations.length === 0) return migrations;
|
|
5995
|
+
const tables = [...new Set(migrations.map((m) => m.table))];
|
|
5996
|
+
let existingColumns;
|
|
5997
|
+
let existingIndices;
|
|
5998
|
+
try {
|
|
5999
|
+
[existingColumns, existingIndices] = await Promise.all([
|
|
6000
|
+
queryNamesByTable(
|
|
6001
|
+
client,
|
|
6002
|
+
`SELECT table, name FROM system.columns WHERE database = currentDatabase() AND table IN ({tables:Array(String)})`,
|
|
6003
|
+
tables
|
|
6004
|
+
),
|
|
6005
|
+
queryNamesByTable(
|
|
6006
|
+
client,
|
|
6007
|
+
`SELECT table, name FROM system.data_skipping_indices WHERE database = currentDatabase() AND table IN ({tables:Array(String)})`,
|
|
6008
|
+
tables
|
|
6009
|
+
)
|
|
6010
|
+
]);
|
|
6011
|
+
} catch {
|
|
6012
|
+
return migrations;
|
|
6013
|
+
}
|
|
6014
|
+
return migrations.filter((m) => {
|
|
6015
|
+
const present = m.kind === "column" ? existingColumns.get(m.table) : existingIndices.get(m.table);
|
|
6016
|
+
if (!present) return true;
|
|
6017
|
+
return !present.has(m.name);
|
|
6018
|
+
});
|
|
6019
|
+
}
|
|
6020
|
+
async function filterAppliedRetention(client, entries) {
|
|
6021
|
+
if (entries.length === 0) return entries;
|
|
6022
|
+
const tables = [...new Set(entries.map((e) => e.table))];
|
|
6023
|
+
let createQueries;
|
|
6024
|
+
try {
|
|
6025
|
+
const result = await client.query({
|
|
6026
|
+
query: `SELECT name, create_table_query FROM system.tables WHERE database = currentDatabase() AND name IN ({tables:Array(String)})`,
|
|
6027
|
+
query_params: { tables },
|
|
6028
|
+
format: "JSONEachRow"
|
|
6029
|
+
});
|
|
6030
|
+
const rows = await result.json();
|
|
6031
|
+
createQueries = new Map(rows.map((r) => [r.name, r.create_table_query ?? ""]));
|
|
6032
|
+
} catch {
|
|
6033
|
+
return entries;
|
|
6034
|
+
}
|
|
6035
|
+
return entries.filter((e) => {
|
|
6036
|
+
const createQuery = createQueries.get(e.table);
|
|
6037
|
+
if (!createQuery) return true;
|
|
6038
|
+
const current = parseTtlExpression(createQuery);
|
|
6039
|
+
if (!current) return true;
|
|
6040
|
+
return current.column !== e.column || current.days !== e.days;
|
|
6041
|
+
});
|
|
6042
|
+
}
|
|
6043
|
+
async function queryNamesByTable(client, query, tables) {
|
|
6044
|
+
const result = await client.query({
|
|
6045
|
+
query,
|
|
6046
|
+
query_params: { tables },
|
|
6047
|
+
format: "JSONEachRow"
|
|
6048
|
+
});
|
|
6049
|
+
const rows = await result.json();
|
|
6050
|
+
const out = /* @__PURE__ */ new Map();
|
|
6051
|
+
for (const row of rows) {
|
|
6052
|
+
let set = out.get(row.table);
|
|
6053
|
+
if (!set) {
|
|
6054
|
+
set = /* @__PURE__ */ new Set();
|
|
6055
|
+
out.set(row.table, set);
|
|
6056
|
+
}
|
|
6057
|
+
set.add(row.name);
|
|
6058
|
+
}
|
|
6059
|
+
return out;
|
|
6060
|
+
}
|
|
5967
6061
|
var ObservabilityStorageClickhouseVNext = class extends storage.ObservabilityStorage {
|
|
5968
6062
|
#client;
|
|
5969
6063
|
#retention;
|
|
@@ -5993,13 +6087,14 @@ var ObservabilityStorageClickhouseVNext = class extends storage.ObservabilitySto
|
|
|
5993
6087
|
for (const ddl of [...ALL_TABLE_DDL, ...ALL_MV_DDL]) {
|
|
5994
6088
|
await this.#client.command({ query: ddl });
|
|
5995
6089
|
}
|
|
5996
|
-
|
|
5997
|
-
|
|
6090
|
+
const pendingMigrations = await filterAppliedMigrations(this.#client, ALL_MIGRATIONS);
|
|
6091
|
+
for (const migration of pendingMigrations) {
|
|
6092
|
+
await this.#client.command({ query: migration.sql });
|
|
5998
6093
|
}
|
|
5999
6094
|
if (this.#retention) {
|
|
6000
|
-
const
|
|
6001
|
-
for (const
|
|
6002
|
-
await this.#client.command({ query:
|
|
6095
|
+
const pendingRetention = await filterAppliedRetention(this.#client, buildRetentionEntries(this.#retention));
|
|
6096
|
+
for (const entry of pendingRetention) {
|
|
6097
|
+
await this.#client.command({ query: entry.sql });
|
|
6003
6098
|
}
|
|
6004
6099
|
}
|
|
6005
6100
|
} catch (error$1) {
|