@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 +19 -0
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/index.cjs +52 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +52 -10
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/observability/v-next/ddl.d.ts +15 -2
- package/dist/storage/domains/observability/v-next/ddl.d.ts.map +1 -1
- package/dist/storage/domains/observability/v-next/discovery.d.ts +6 -0
- package/dist/storage/domains/observability/v-next/discovery.d.ts.map +1 -1
- package/dist/storage/domains/observability/v-next/index.d.ts.map +1 -1
- package/dist/storage/domains/observability/v-next/metrics.d.ts.map +1 -1
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -2889,6 +2889,14 @@ var DELTA_MV_NAMES = [
|
|
|
2889
2889
|
MV_SCORE_EVENTS_DELTA,
|
|
2890
2890
|
MV_FEEDBACK_EVENTS_DELTA
|
|
2891
2891
|
];
|
|
2892
|
+
var DELTA_CURSOR_COUNTER_NAMES = [
|
|
2893
|
+
"mastra_trace_roots_delta_cursor",
|
|
2894
|
+
"mastra_trace_branches_delta_cursor",
|
|
2895
|
+
"mastra_metric_events_delta_cursor",
|
|
2896
|
+
"mastra_log_events_delta_cursor",
|
|
2897
|
+
"mastra_score_events_delta_cursor",
|
|
2898
|
+
"mastra_feedback_events_delta_cursor"
|
|
2899
|
+
];
|
|
2892
2900
|
var BRANCH_SPAN_TYPE_VALUES = [
|
|
2893
2901
|
"agent_run",
|
|
2894
2902
|
"workflow_run",
|
|
@@ -3609,7 +3617,7 @@ CREATE TABLE IF NOT EXISTS ${TABLE_DISCOVERY_VALUES} (
|
|
|
3609
3617
|
key1 String,
|
|
3610
3618
|
value String
|
|
3611
3619
|
)
|
|
3612
|
-
ENGINE =
|
|
3620
|
+
ENGINE = ReplacingMergeTree
|
|
3613
3621
|
ORDER BY (kind, key1, value)
|
|
3614
3622
|
`;
|
|
3615
3623
|
var DISCOVERY_PAIRS_DDL = `
|
|
@@ -3619,7 +3627,7 @@ CREATE TABLE IF NOT EXISTS ${TABLE_DISCOVERY_PAIRS} (
|
|
|
3619
3627
|
key2 String,
|
|
3620
3628
|
value String
|
|
3621
3629
|
)
|
|
3622
|
-
ENGINE =
|
|
3630
|
+
ENGINE = ReplacingMergeTree
|
|
3623
3631
|
ORDER BY (kind, key1, key2, value)
|
|
3624
3632
|
`;
|
|
3625
3633
|
var SIGNAL_TABLES = [TABLE_SPAN_EVENTS, TABLE_METRIC_EVENTS, TABLE_LOG_EVENTS];
|
|
@@ -4389,7 +4397,7 @@ async function queryJson(client, query, params = {}) {
|
|
|
4389
4397
|
async function getEntityTypes(client, _args) {
|
|
4390
4398
|
const rows = await queryJson(
|
|
4391
4399
|
client,
|
|
4392
|
-
`SELECT value FROM ${TABLE_DISCOVERY_VALUES} WHERE kind = 'entityType' ORDER BY value`
|
|
4400
|
+
`SELECT DISTINCT value FROM ${TABLE_DISCOVERY_VALUES} WHERE kind = 'entityType' ORDER BY value`
|
|
4393
4401
|
);
|
|
4394
4402
|
const validTypes = new Set(Object.values(EntityType));
|
|
4395
4403
|
const entityTypes = [];
|
|
@@ -4409,7 +4417,7 @@ async function getEntityNames(client, args) {
|
|
|
4409
4417
|
}
|
|
4410
4418
|
const rows = await queryJson(
|
|
4411
4419
|
client,
|
|
4412
|
-
`SELECT value FROM ${TABLE_DISCOVERY_PAIRS} WHERE ${conditions.join(" AND ")} ORDER BY value`,
|
|
4420
|
+
`SELECT DISTINCT value FROM ${TABLE_DISCOVERY_PAIRS} WHERE ${conditions.join(" AND ")} ORDER BY value`,
|
|
4413
4421
|
params
|
|
4414
4422
|
);
|
|
4415
4423
|
return { names: rows.map((r) => r.value) };
|
|
@@ -4417,14 +4425,14 @@ async function getEntityNames(client, args) {
|
|
|
4417
4425
|
async function getServiceNames(client, _args) {
|
|
4418
4426
|
const rows = await queryJson(
|
|
4419
4427
|
client,
|
|
4420
|
-
`SELECT value FROM ${TABLE_DISCOVERY_VALUES} WHERE kind = 'serviceName' ORDER BY value`
|
|
4428
|
+
`SELECT DISTINCT value FROM ${TABLE_DISCOVERY_VALUES} WHERE kind = 'serviceName' ORDER BY value`
|
|
4421
4429
|
);
|
|
4422
4430
|
return { serviceNames: rows.map((r) => r.value) };
|
|
4423
4431
|
}
|
|
4424
4432
|
async function getEnvironments(client, _args) {
|
|
4425
4433
|
const rows = await queryJson(
|
|
4426
4434
|
client,
|
|
4427
|
-
`SELECT value FROM ${TABLE_DISCOVERY_VALUES} WHERE kind = 'environment' ORDER BY value`
|
|
4435
|
+
`SELECT DISTINCT value FROM ${TABLE_DISCOVERY_VALUES} WHERE kind = 'environment' ORDER BY value`
|
|
4428
4436
|
);
|
|
4429
4437
|
return { environments: rows.map((r) => r.value) };
|
|
4430
4438
|
}
|
|
@@ -4437,7 +4445,7 @@ async function getTags(client, args) {
|
|
|
4437
4445
|
}
|
|
4438
4446
|
const rows = await queryJson(
|
|
4439
4447
|
client,
|
|
4440
|
-
`SELECT value FROM ${TABLE_DISCOVERY_VALUES} WHERE ${conditions.join(" AND ")} ORDER BY value`,
|
|
4448
|
+
`SELECT DISTINCT value FROM ${TABLE_DISCOVERY_VALUES} WHERE ${conditions.join(" AND ")} ORDER BY value`,
|
|
4441
4449
|
params
|
|
4442
4450
|
);
|
|
4443
4451
|
return { tags: rows.map((r) => r.value) };
|
|
@@ -5717,7 +5725,7 @@ async function getMetricNames(client, args) {
|
|
|
5717
5725
|
if (args.limit) params.nameLimit = args.limit;
|
|
5718
5726
|
const rows = await queryJson3(
|
|
5719
5727
|
client,
|
|
5720
|
-
`SELECT value FROM ${TABLE_DISCOVERY_VALUES} WHERE ${conditions.join(" AND ")} ORDER BY value ${limitClause}`,
|
|
5728
|
+
`SELECT DISTINCT value FROM ${TABLE_DISCOVERY_VALUES} WHERE ${conditions.join(" AND ")} ORDER BY value ${limitClause}`,
|
|
5721
5729
|
params
|
|
5722
5730
|
);
|
|
5723
5731
|
return { names: rows.map((r) => r.value) };
|
|
@@ -5725,7 +5733,7 @@ async function getMetricNames(client, args) {
|
|
|
5725
5733
|
async function getMetricLabelKeys(client, args) {
|
|
5726
5734
|
const rows = await queryJson3(
|
|
5727
5735
|
client,
|
|
5728
|
-
`SELECT value FROM ${TABLE_DISCOVERY_VALUES} WHERE kind = 'metricLabelKey' AND key1 = {metricName:String} ORDER BY value`,
|
|
5736
|
+
`SELECT DISTINCT value FROM ${TABLE_DISCOVERY_VALUES} WHERE kind = 'metricLabelKey' AND key1 = {metricName:String} ORDER BY value`,
|
|
5729
5737
|
{ metricName: args.metricName }
|
|
5730
5738
|
);
|
|
5731
5739
|
return { keys: rows.map((r) => r.value) };
|
|
@@ -5744,7 +5752,7 @@ async function getMetricLabelValues(client, args) {
|
|
|
5744
5752
|
if (args.limit) params.valLimit = args.limit;
|
|
5745
5753
|
const rows = await queryJson3(
|
|
5746
5754
|
client,
|
|
5747
|
-
`SELECT value FROM ${TABLE_DISCOVERY_PAIRS} WHERE ${conditions.join(" AND ")} ORDER BY value ${limitClause}`,
|
|
5755
|
+
`SELECT DISTINCT value FROM ${TABLE_DISCOVERY_PAIRS} WHERE ${conditions.join(" AND ")} ORDER BY value ${limitClause}`,
|
|
5748
5756
|
params
|
|
5749
5757
|
);
|
|
5750
5758
|
return { values: rows.map((r) => r.value) };
|
|
@@ -6979,6 +6987,30 @@ async function filterAppliedRetention(client, entries) {
|
|
|
6979
6987
|
return current.column !== e.column || current.days !== e.days;
|
|
6980
6988
|
});
|
|
6981
6989
|
}
|
|
6990
|
+
async function reconcileDiscoveryTables(client) {
|
|
6991
|
+
let engines;
|
|
6992
|
+
try {
|
|
6993
|
+
const result = await client.query({
|
|
6994
|
+
query: `SELECT name, engine FROM system.tables WHERE database = currentDatabase() AND name IN ({tables:Array(String)})`,
|
|
6995
|
+
query_params: { tables: [TABLE_DISCOVERY_VALUES, TABLE_DISCOVERY_PAIRS] },
|
|
6996
|
+
format: "JSONEachRow"
|
|
6997
|
+
});
|
|
6998
|
+
const rows = await result.json();
|
|
6999
|
+
engines = new Map(rows.map((r) => [r.name, r.engine]));
|
|
7000
|
+
} catch {
|
|
7001
|
+
return;
|
|
7002
|
+
}
|
|
7003
|
+
const targets = [
|
|
7004
|
+
{ table: TABLE_DISCOVERY_VALUES, mv: MV_DISCOVERY_VALUES },
|
|
7005
|
+
{ table: TABLE_DISCOVERY_PAIRS, mv: MV_DISCOVERY_PAIRS }
|
|
7006
|
+
];
|
|
7007
|
+
for (const { table, mv } of targets) {
|
|
7008
|
+
const engine = engines.get(table);
|
|
7009
|
+
if (!engine || isReplacingMergeTreeEngine(engine)) continue;
|
|
7010
|
+
await client.command({ query: `DROP VIEW IF EXISTS ${mv}` });
|
|
7011
|
+
await client.command({ query: `DROP TABLE IF EXISTS ${table}` });
|
|
7012
|
+
}
|
|
7013
|
+
}
|
|
6982
7014
|
async function queryNamesByTable(client, query, tables) {
|
|
6983
7015
|
const result = await client.query({
|
|
6984
7016
|
query,
|
|
@@ -7094,6 +7126,7 @@ var ObservabilityStorageClickhouseVNext = class extends ObservabilityStorage {
|
|
|
7094
7126
|
} else {
|
|
7095
7127
|
this.#deltaCursorStrategy = await detectDeltaCursorStrategy(this.#client, void 0, existingStrategy);
|
|
7096
7128
|
}
|
|
7129
|
+
await reconcileDiscoveryTables(this.#client);
|
|
7097
7130
|
const coreDdl = this.#deltaCursorStrategy === null ? [...BASE_TABLE_DDL, ...BASE_MV_DDL] : [...buildAllTableDDL(), ...buildAllMvDDL(this.#deltaCursorStrategy)];
|
|
7098
7131
|
for (const ddl of coreDdl) {
|
|
7099
7132
|
await this.#client.command({ query: ddl });
|
|
@@ -7108,6 +7141,15 @@ var ObservabilityStorageClickhouseVNext = class extends ObservabilityStorage {
|
|
|
7108
7141
|
await this.#client.command({ query: entry.sql });
|
|
7109
7142
|
}
|
|
7110
7143
|
}
|
|
7144
|
+
if (this.#deltaCursorStrategy === "serial") {
|
|
7145
|
+
for (const counterName of DELTA_CURSOR_COUNTER_NAMES) {
|
|
7146
|
+
await this.#client.query({
|
|
7147
|
+
query: `SELECT generateSerialID({counterName:String}) AS cursorId`,
|
|
7148
|
+
query_params: { counterName },
|
|
7149
|
+
format: "JSONEachRow"
|
|
7150
|
+
});
|
|
7151
|
+
}
|
|
7152
|
+
}
|
|
7111
7153
|
} catch (error) {
|
|
7112
7154
|
if (error instanceof MastraError) {
|
|
7113
7155
|
throw error;
|