@mastra/clickhouse 1.9.0-alpha.0 → 1.9.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/CHANGELOG.md CHANGED
@@ -1,5 +1,24 @@
1
1
  # @mastra/clickhouse
2
2
 
3
+ ## 1.9.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Added delta polling support for observability list APIs in core, DuckDB, and ClickHouse. ([#16632](https://github.com/mastra-ai/mastra/pull/16632))
8
+
9
+ ### Patch Changes
10
+
11
+ - Fixed duplicate entries in the ClickHouse v-next observability discovery endpoints — tags, services, environments, entities, metric names, and metric labels now return each value once. Existing deployments are reconciled automatically on next startup; no manual migration required. ([#16798](https://github.com/mastra-ai/mastra/pull/16798))
12
+
13
+ - Updated dependencies [[`452036a`](https://github.com/mastra-ai/mastra/commit/452036a0d965b4f4c1efd93606e4f03b50b807a5), [`c272d50`](https://github.com/mastra-ai/mastra/commit/c272d50610a54496b6b6d92ccd4d37b333a2613a), [`27fd1b7`](https://github.com/mastra-ai/mastra/commit/27fd1b79ac62eb7694f92587eb7d1be05b59be01), [`5ba7253`](https://github.com/mastra-ai/mastra/commit/5ba7253745c85e8df8012a76d954c640ffa336f7), [`5556cc1`](https://github.com/mastra-ai/mastra/commit/5556cc1befec71518d84f826b3bfe3a079a9daf7), [`f73980d`](https://github.com/mastra-ai/mastra/commit/f73980d651eb5f7f1ab20582de4615a1b6f10fce), [`5499303`](https://github.com/mastra-ai/mastra/commit/54993032c1ebc09642625b78d2014e0cf84a3cae), [`a702009`](https://github.com/mastra-ai/mastra/commit/a702009d3cfaa745120f501e21c783ed4d6a3072), [`9aee493`](https://github.com/mastra-ai/mastra/commit/9aee493ed6089b5133472623dcce49934bf2d509), [`d8692af`](https://github.com/mastra-ai/mastra/commit/d8692afa253028e39cdce2aafa0ac414071a762e), [`1a9cc60`](https://github.com/mastra-ai/mastra/commit/1a9cc6069f9910fc3d59e4953ac8cd95d89ad6f5), [`8cdb86c`](https://github.com/mastra-ai/mastra/commit/8cdb86ceed1137bc2768e147dce85a0692b9fb26), [`8534d79`](https://github.com/mastra-ai/mastra/commit/8534d791fa1cb70fe1c19e2604c4b63cc10dd051), [`eda90c5`](https://github.com/mastra-ai/mastra/commit/eda90c5bfd7de11805ecc9f4552716c895fbaf78), [`a935b0a`](https://github.com/mastra-ai/mastra/commit/a935b0a0977ae3f196b33ec7621f528069c82db0), [`9c88701`](https://github.com/mastra-ai/mastra/commit/9c8870195b41a38dc40b6ba2aa55eda04df8fa69), [`c78f8cd`](https://github.com/mastra-ai/mastra/commit/c78f8cd6222a86e6c60ae5210b6929ad5221b6fb), [`e146aad`](https://github.com/mastra-ai/mastra/commit/e146aadbba66c410ba0e74bac4c50135495cb8dd), [`ac79462`](https://github.com/mastra-ai/mastra/commit/ac79462b98f1062394c45093aa515b0766f27ee2), [`1a0ec78`](https://github.com/mastra-ai/mastra/commit/1a0ec789a26cae443744e9abbd62ed6ee676af39), [`e47bca7`](https://github.com/mastra-ai/mastra/commit/e47bca7b72866d3abd173b9f530ac4318113a8ff), [`afc004f`](https://github.com/mastra-ai/mastra/commit/afc004f5cc7e30697809e7021820b9f5881e6719), [`0031d0f`](https://github.com/mastra-ai/mastra/commit/0031d0f13831d7843ac5d498734a7d92862e2ce3), [`841a222`](https://github.com/mastra-ai/mastra/commit/841a222560d8c19238f8213713f30535cdd82284), [`64c1e0b`](https://github.com/mastra-ai/mastra/commit/64c1e0b35165c96b659818bd0177aa18794ef11f), [`40d83a9`](https://github.com/mastra-ai/mastra/commit/40d83a90d9be31a1b83e04649edb703eb7753e33), [`4e88dc6`](https://github.com/mastra-ai/mastra/commit/4e88dc6b89f154c0eae37221c8126be0c23c569f), [`19018f0`](https://github.com/mastra-ai/mastra/commit/19018f05722af74a5978781a7731a654b26f7f2a), [`19281c7`](https://github.com/mastra-ai/mastra/commit/19281c70424f757219782de16c2699743c5e04d0), [`3498b49`](https://github.com/mastra-ai/mastra/commit/3498b4946be94f4313cd817733589680dcda5278), [`d52b6fe`](https://github.com/mastra-ai/mastra/commit/d52b6fe1c56853eb38864baae0bbfa75cc739ccb), [`408be73`](https://github.com/mastra-ai/mastra/commit/408be73449dfab92b51eab8c6623b6c443debc25), [`359439b`](https://github.com/mastra-ai/mastra/commit/359439bb8c635e048176306828195f8297f50021), [`71a820b`](https://github.com/mastra-ai/mastra/commit/71a820b2353fa1406772c50760a3732058a8b337), [`1698f5e`](https://github.com/mastra-ai/mastra/commit/1698f5ec141d34f22a873efdb145ce3cdf848a5e)]:
14
+ - @mastra/core@1.36.0
15
+
16
+ ## 1.9.0-alpha.1
17
+
18
+ ### Patch Changes
19
+
20
+ - Fixed duplicate entries in the ClickHouse v-next observability discovery endpoints — tags, services, environments, entities, metric names, and metric labels now return each value once. Existing deployments are reconciled automatically on next startup; no manual migration required. ([#16798](https://github.com/mastra-ai/mastra/pull/16798))
21
+
3
22
  ## 1.9.0-alpha.0
4
23
 
5
24
  ### Minor Changes
@@ -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.9.0-alpha.0"
6
+ version: "1.9.0"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.9.0-alpha.0",
2
+ "version": "1.9.0",
3
3
  "package": "@mastra/clickhouse",
4
4
  "exports": {},
5
5
  "modules": {}
package/dist/index.cjs CHANGED
@@ -2891,6 +2891,14 @@ var DELTA_MV_NAMES = [
2891
2891
  MV_SCORE_EVENTS_DELTA,
2892
2892
  MV_FEEDBACK_EVENTS_DELTA
2893
2893
  ];
2894
+ var DELTA_CURSOR_COUNTER_NAMES = [
2895
+ "mastra_trace_roots_delta_cursor",
2896
+ "mastra_trace_branches_delta_cursor",
2897
+ "mastra_metric_events_delta_cursor",
2898
+ "mastra_log_events_delta_cursor",
2899
+ "mastra_score_events_delta_cursor",
2900
+ "mastra_feedback_events_delta_cursor"
2901
+ ];
2894
2902
  var BRANCH_SPAN_TYPE_VALUES = [
2895
2903
  "agent_run",
2896
2904
  "workflow_run",
@@ -3611,7 +3619,7 @@ CREATE TABLE IF NOT EXISTS ${TABLE_DISCOVERY_VALUES} (
3611
3619
  key1 String,
3612
3620
  value String
3613
3621
  )
3614
- ENGINE = MergeTree
3622
+ ENGINE = ReplacingMergeTree
3615
3623
  ORDER BY (kind, key1, value)
3616
3624
  `;
3617
3625
  var DISCOVERY_PAIRS_DDL = `
@@ -3621,7 +3629,7 @@ CREATE TABLE IF NOT EXISTS ${TABLE_DISCOVERY_PAIRS} (
3621
3629
  key2 String,
3622
3630
  value String
3623
3631
  )
3624
- ENGINE = MergeTree
3632
+ ENGINE = ReplacingMergeTree
3625
3633
  ORDER BY (kind, key1, key2, value)
3626
3634
  `;
3627
3635
  var SIGNAL_TABLES = [TABLE_SPAN_EVENTS, TABLE_METRIC_EVENTS, TABLE_LOG_EVENTS];
@@ -4391,7 +4399,7 @@ async function queryJson(client, query, params = {}) {
4391
4399
  async function getEntityTypes(client, _args) {
4392
4400
  const rows = await queryJson(
4393
4401
  client,
4394
- `SELECT value FROM ${TABLE_DISCOVERY_VALUES} WHERE kind = 'entityType' ORDER BY value`
4402
+ `SELECT DISTINCT value FROM ${TABLE_DISCOVERY_VALUES} WHERE kind = 'entityType' ORDER BY value`
4395
4403
  );
4396
4404
  const validTypes = new Set(Object.values(storage.EntityType));
4397
4405
  const entityTypes = [];
@@ -4411,7 +4419,7 @@ async function getEntityNames(client, args) {
4411
4419
  }
4412
4420
  const rows = await queryJson(
4413
4421
  client,
4414
- `SELECT value FROM ${TABLE_DISCOVERY_PAIRS} WHERE ${conditions.join(" AND ")} ORDER BY value`,
4422
+ `SELECT DISTINCT value FROM ${TABLE_DISCOVERY_PAIRS} WHERE ${conditions.join(" AND ")} ORDER BY value`,
4415
4423
  params
4416
4424
  );
4417
4425
  return { names: rows.map((r) => r.value) };
@@ -4419,14 +4427,14 @@ async function getEntityNames(client, args) {
4419
4427
  async function getServiceNames(client, _args) {
4420
4428
  const rows = await queryJson(
4421
4429
  client,
4422
- `SELECT value FROM ${TABLE_DISCOVERY_VALUES} WHERE kind = 'serviceName' ORDER BY value`
4430
+ `SELECT DISTINCT value FROM ${TABLE_DISCOVERY_VALUES} WHERE kind = 'serviceName' ORDER BY value`
4423
4431
  );
4424
4432
  return { serviceNames: rows.map((r) => r.value) };
4425
4433
  }
4426
4434
  async function getEnvironments(client, _args) {
4427
4435
  const rows = await queryJson(
4428
4436
  client,
4429
- `SELECT value FROM ${TABLE_DISCOVERY_VALUES} WHERE kind = 'environment' ORDER BY value`
4437
+ `SELECT DISTINCT value FROM ${TABLE_DISCOVERY_VALUES} WHERE kind = 'environment' ORDER BY value`
4430
4438
  );
4431
4439
  return { environments: rows.map((r) => r.value) };
4432
4440
  }
@@ -4439,7 +4447,7 @@ async function getTags(client, args) {
4439
4447
  }
4440
4448
  const rows = await queryJson(
4441
4449
  client,
4442
- `SELECT value FROM ${TABLE_DISCOVERY_VALUES} WHERE ${conditions.join(" AND ")} ORDER BY value`,
4450
+ `SELECT DISTINCT value FROM ${TABLE_DISCOVERY_VALUES} WHERE ${conditions.join(" AND ")} ORDER BY value`,
4443
4451
  params
4444
4452
  );
4445
4453
  return { tags: rows.map((r) => r.value) };
@@ -5719,7 +5727,7 @@ async function getMetricNames(client, args) {
5719
5727
  if (args.limit) params.nameLimit = args.limit;
5720
5728
  const rows = await queryJson3(
5721
5729
  client,
5722
- `SELECT value FROM ${TABLE_DISCOVERY_VALUES} WHERE ${conditions.join(" AND ")} ORDER BY value ${limitClause}`,
5730
+ `SELECT DISTINCT value FROM ${TABLE_DISCOVERY_VALUES} WHERE ${conditions.join(" AND ")} ORDER BY value ${limitClause}`,
5723
5731
  params
5724
5732
  );
5725
5733
  return { names: rows.map((r) => r.value) };
@@ -5727,7 +5735,7 @@ async function getMetricNames(client, args) {
5727
5735
  async function getMetricLabelKeys(client, args) {
5728
5736
  const rows = await queryJson3(
5729
5737
  client,
5730
- `SELECT value FROM ${TABLE_DISCOVERY_VALUES} WHERE kind = 'metricLabelKey' AND key1 = {metricName:String} ORDER BY value`,
5738
+ `SELECT DISTINCT value FROM ${TABLE_DISCOVERY_VALUES} WHERE kind = 'metricLabelKey' AND key1 = {metricName:String} ORDER BY value`,
5731
5739
  { metricName: args.metricName }
5732
5740
  );
5733
5741
  return { keys: rows.map((r) => r.value) };
@@ -5746,7 +5754,7 @@ async function getMetricLabelValues(client, args) {
5746
5754
  if (args.limit) params.valLimit = args.limit;
5747
5755
  const rows = await queryJson3(
5748
5756
  client,
5749
- `SELECT value FROM ${TABLE_DISCOVERY_PAIRS} WHERE ${conditions.join(" AND ")} ORDER BY value ${limitClause}`,
5757
+ `SELECT DISTINCT value FROM ${TABLE_DISCOVERY_PAIRS} WHERE ${conditions.join(" AND ")} ORDER BY value ${limitClause}`,
5750
5758
  params
5751
5759
  );
5752
5760
  return { values: rows.map((r) => r.value) };
@@ -6981,6 +6989,30 @@ async function filterAppliedRetention(client, entries) {
6981
6989
  return current.column !== e.column || current.days !== e.days;
6982
6990
  });
6983
6991
  }
6992
+ async function reconcileDiscoveryTables(client) {
6993
+ let engines;
6994
+ try {
6995
+ const result = await client.query({
6996
+ query: `SELECT name, engine FROM system.tables WHERE database = currentDatabase() AND name IN ({tables:Array(String)})`,
6997
+ query_params: { tables: [TABLE_DISCOVERY_VALUES, TABLE_DISCOVERY_PAIRS] },
6998
+ format: "JSONEachRow"
6999
+ });
7000
+ const rows = await result.json();
7001
+ engines = new Map(rows.map((r) => [r.name, r.engine]));
7002
+ } catch {
7003
+ return;
7004
+ }
7005
+ const targets = [
7006
+ { table: TABLE_DISCOVERY_VALUES, mv: MV_DISCOVERY_VALUES },
7007
+ { table: TABLE_DISCOVERY_PAIRS, mv: MV_DISCOVERY_PAIRS }
7008
+ ];
7009
+ for (const { table, mv } of targets) {
7010
+ const engine = engines.get(table);
7011
+ if (!engine || isReplacingMergeTreeEngine(engine)) continue;
7012
+ await client.command({ query: `DROP VIEW IF EXISTS ${mv}` });
7013
+ await client.command({ query: `DROP TABLE IF EXISTS ${table}` });
7014
+ }
7015
+ }
6984
7016
  async function queryNamesByTable(client, query, tables) {
6985
7017
  const result = await client.query({
6986
7018
  query,
@@ -7096,6 +7128,7 @@ var ObservabilityStorageClickhouseVNext = class extends storage.ObservabilitySto
7096
7128
  } else {
7097
7129
  this.#deltaCursorStrategy = await detectDeltaCursorStrategy(this.#client, void 0, existingStrategy);
7098
7130
  }
7131
+ await reconcileDiscoveryTables(this.#client);
7099
7132
  const coreDdl = this.#deltaCursorStrategy === null ? [...BASE_TABLE_DDL, ...BASE_MV_DDL] : [...buildAllTableDDL(), ...buildAllMvDDL(this.#deltaCursorStrategy)];
7100
7133
  for (const ddl of coreDdl) {
7101
7134
  await this.#client.command({ query: ddl });
@@ -7110,6 +7143,15 @@ var ObservabilityStorageClickhouseVNext = class extends storage.ObservabilitySto
7110
7143
  await this.#client.command({ query: entry.sql });
7111
7144
  }
7112
7145
  }
7146
+ if (this.#deltaCursorStrategy === "serial") {
7147
+ for (const counterName of DELTA_CURSOR_COUNTER_NAMES) {
7148
+ await this.#client.query({
7149
+ query: `SELECT generateSerialID({counterName:String}) AS cursorId`,
7150
+ query_params: { counterName },
7151
+ format: "JSONEachRow"
7152
+ });
7153
+ }
7154
+ }
7113
7155
  } catch (error$1) {
7114
7156
  if (error$1 instanceof error.MastraError) {
7115
7157
  throw error$1;