feat(db): 支持 VictoriaMetrics 数据库

* feat(victoriametrics): support native MetricsQL queries

* fix(victoriametrics): 完善指标浏览和结果导出

* fix(victoriametrics): 修复指标对象通用操作入口

* fix(victoriametrics): 修正指标注释和截断提示

* fix(i18n): 补齐 VictoriaMetrics 连接配置翻译

---------

Co-authored-by: zipg <4047349+zipg@users.noreply.github.com>
This commit is contained in:
zipgandzipg authored and GitHub committed 2026-08-05 23:58:11 +08:00
1 parent 930aa48c20
commit 2ede64f1cb
64 files changed
+1293 -64

No files matched your search

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

@@ -16,6 +16,7 @@ import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover
import { Switch } from "@/components/ui/switch"; import { Switch } from "@/components/ui/switch";
import type { ConnectionConfig, ConnectionTestResult, DatabaseConnectionInfo, DatabaseType, HttpTunnelConfig, IdentifierCase, JdbcDriverInfo, JdbcLocalBundleInfo, JdbcMavenBundleInfo, ProxyTunnelConfig, SshConfigHostEntry, SshTunnelConfig, TransportLayerConfig } from "@/types/database"; import type { ConnectionConfig, ConnectionTestResult, DatabaseConnectionInfo, DatabaseType, HttpTunnelConfig, IdentifierCase, JdbcDriverInfo, JdbcLocalBundleInfo, JdbcMavenBundleInfo, ProxyTunnelConfig, SshConfigHostEntry, SshTunnelConfig, TransportLayerConfig } from "@/types/database";
import type { InfluxDbExternalConfig, InfluxDbVersion } from "@/types/influxdb"; import type { InfluxDbExternalConfig, InfluxDbVersion } from "@/types/influxdb";
import type { VictoriaMetricsExternalConfig } from "@/types/victoriametrics";
import type { MqAdminConfig, MqAuth, MqSystemKind } from "@/types/mq"; import type { MqAdminConfig, MqAuth, MqSystemKind } from "@/types/mq";
import type { MqttConnectionConfig } from "@/types/mqtt"; import type { MqttConnectionConfig } from "@/types/mqtt";
import type { NacosAdminConfig, NacosAuthConfig, NacosImplementation, NacosMetricsMode, NacosRNacosConsoleAuth, NacosVersionMode } from "@/types/nacos"; import type { NacosAdminConfig, NacosAuthConfig, NacosImplementation, NacosMetricsMode, NacosRNacosConsoleAuth, NacosVersionMode } from "@/types/nacos";
@@ -1025,6 +1026,7 @@ const driverProfiles: Record<
mqtt: { type: "mqtt", port: 1883, user: "", label: "MQTT", icon: "mqtt", host: "127.0.0.1" }, mqtt: { type: "mqtt", port: 1883, user: "", label: "MQTT", icon: "mqtt", host: "127.0.0.1" },
iris: { type: "iris", port: 1972, user: "_SYSTEM", label: "IRIS", icon: "iris" }, iris: { type: "iris", port: 1972, user: "_SYSTEM", label: "IRIS", icon: "iris" },
influxdb: { type: "influxdb", port: 8086, user: "", label: "InfluxDB", icon: "InfluxDB" }, influxdb: { type: "influxdb", port: 8086, user: "", label: "InfluxDB", icon: "InfluxDB" },
victoriametrics: { type: "victoriametrics", port: 8428, user: "", label: "VictoriaMetrics", icon: "victoriametrics" },
custom_mysql: { custom_mysql: {
type: "mysql", type: "mysql",
port: 3306, port: 3306,
@@ -1291,6 +1293,8 @@ function buildMqttExternalConfig(): MqttConnectionConfig {
const influxDbVersion = ref<InfluxDbVersion>("1"); const influxDbVersion = ref<InfluxDbVersion>("1");
const influxDbOrg = ref(""); const influxDbOrg = ref("");
const victoriaMetricsApiPath = ref("/prometheus");
const victoriaMetricsLookback = ref("1h");
function resetInfluxDbFields(config?: Partial<InfluxDbExternalConfig>) { function resetInfluxDbFields(config?: Partial<InfluxDbExternalConfig>) {
influxDbVersion.value = config?.version === "2" ? "2" : "1"; influxDbVersion.value = config?.version === "2" ? "2" : "1";
@@ -1328,6 +1332,33 @@ function buildInfluxDbExternalConfig(): InfluxDbExternalConfig {
return { version: "2", org }; return { version: "2", org };
} }
function resetVictoriaMetricsFields(config?: Partial<VictoriaMetricsExternalConfig>) {
victoriaMetricsApiPath.value = config?.apiPath?.trim() || "/prometheus";
victoriaMetricsLookback.value = config?.lookback?.trim() || "1h";
}
function hydrateVictoriaMetricsFields(value: unknown) {
if (!value || typeof value !== "object") {
resetVictoriaMetricsFields();
return;
}
const config = value as Partial<VictoriaMetricsExternalConfig> & { api_path?: string };
resetVictoriaMetricsFields({
apiPath: config.apiPath || config.api_path,
lookback: config.lookback,
});
}
function buildVictoriaMetricsExternalConfig(): VictoriaMetricsExternalConfig {
const apiPath = victoriaMetricsApiPath.value.trim().replace(/\/+$/, "");
if (apiPath && !apiPath.startsWith("/")) throw new Error(t("connection.victoriametricsInvalidApiPath"));
const lookback = victoriaMetricsLookback.value.trim();
if (!/^\d+(?:ms|[smhdwy])$/.test(lookback) || lookback.startsWith("0")) {
throw new Error(t("connection.victoriametricsInvalidLookback"));
}
return { apiPath, lookback };
}
watch(influxDbVersion, (version) => { watch(influxDbVersion, (version) => {
if (form.value.db_type !== "influxdb") return; if (form.value.db_type !== "influxdb") return;
if (version === "2") { if (version === "2") {
@@ -2070,6 +2101,13 @@ function applyProfile(val: string, preserveConnectionFields = false) {
form.value.password = ""; form.value.password = "";
form.value.connection_string = undefined; form.value.connection_string = undefined;
} }
if (profile.type === "victoriametrics") {
resetVictoriaMetricsFields();
form.value.database = "metrics";
form.value.password = "";
form.value.connection_string = undefined;
form.value.url_params = "";
}
resetHiveKerberosFields(profile.type === "hive" ? form.value : undefined); resetHiveKerberosFields(profile.type === "hive" ? form.value : undefined);
} }
} }
@@ -2177,6 +2215,11 @@ watch(
} else { } else {
resetInfluxDbFields(); resetInfluxDbFields();
} }
if (config.db_type === "victoriametrics") {
hydrateVictoriaMetricsFields(config.external_config);
} else {
resetVictoriaMetricsFields();
}
resetElasticsearchProxyFields(config.db_type === "elasticsearch" ? config.external_config : undefined); resetElasticsearchProxyFields(config.db_type === "elasticsearch" ? config.external_config : undefined);
resetHiveKerberosFields(config.db_type === "hive" ? config : undefined); resetHiveKerberosFields(config.db_type === "hive" ? config : undefined);
resetDamengJvmOptions(config.db_type === "dameng" ? config : undefined); resetDamengJvmOptions(config.db_type === "dameng" ? config : undefined);
@@ -2436,6 +2479,7 @@ const iconTypeMap: Record<string, string> = {
sundb: "sundb", sundb: "sundb",
oscar: "oscar", oscar: "oscar",
influxdb: "influxdb", influxdb: "influxdb",
victoriametrics: "victoriametrics",
jdbc: "jdbc", jdbc: "jdbc",
custom_mysql: "mysql", custom_mysql: "mysql",
custom_postgres: "postgres", custom_postgres: "postgres",
@@ -2519,6 +2563,7 @@ const dbOptions: DbOption[] = [
{ value: "mqtt", label: "MQTT" }, { value: "mqtt", label: "MQTT" },
{ value: "nacos", label: "Nacos" }, { value: "nacos", label: "Nacos" },
{ value: "influxdb", label: "InfluxDB" }, { value: "influxdb", label: "InfluxDB" },
{ value: "victoriametrics", label: "VictoriaMetrics" },
{ value: "iris", label: "IRIS" }, { value: "iris", label: "IRIS" },
{ value: "jdbcx", label: "JDBCX" }, { value: "jdbcx", label: "JDBCX" },
{ value: "manticoresearch", label: "Manticore Search" }, { value: "manticoresearch", label: "Manticore Search" },
@@ -2565,7 +2610,7 @@ const dbCategoryDefinitions: Array<{
{ {
key: "timeseries", key: "timeseries",
titleKey: "connection.databaseCategoryTimeseries", titleKey: "connection.databaseCategoryTimeseries",
optionValues: ["questdb", "tdengine", "iotdb", "influxdb"], optionValues: ["questdb", "tdengine", "iotdb", "influxdb", "victoriametrics"],
}, },
{ {
key: "mq", key: "mq",
@@ -2670,9 +2715,31 @@ const sqliteExtensionPaths = computed({
form.value.url_params = setSqliteExtensionPaths(form.value.url_params, value); form.value.url_params = setSqliteExtensionPaths(form.value.url_params, value);
}, },
}); });
const tlsCapableDatabaseTypes = new Set<DatabaseType>(["mysql", "starrocks", "postgres", "redshift", "gaussdb", "kwdb", "opengauss", "questdb", "dameng", "redis", "etcd", "clickhouse", "elasticsearch", "easysearch", "hbase", "qdrant", "milvus", "weaviate", "chromadb", "influxdb"]); const tlsCapableDatabaseTypes = new Set<DatabaseType>([
"mysql",
"starrocks",
"postgres",
"redshift",
"gaussdb",
"kwdb",
"opengauss",
"questdb",
"dameng",
"redis",
"etcd",
"clickhouse",
"elasticsearch",
"easysearch",
"hbase",
"qdrant",
"milvus",
"weaviate",
"chromadb",
"influxdb",
"victoriametrics",
]);
const supportsTlsToggle = computed(() => tlsCapableDatabaseTypes.has(form.value.db_type)); const supportsTlsToggle = computed(() => tlsCapableDatabaseTypes.has(form.value.db_type));
const supportsCaCertificatePath = computed(() => form.value.db_type === "clickhouse"); const supportsCaCertificatePath = computed(() => form.value.db_type === "clickhouse" || form.value.db_type === "victoriametrics");
const supportsGenericUrlParams = computed(() => form.value.db_type !== "manticoresearch" && form.value.db_type !== "hbase"); const supportsGenericUrlParams = computed(() => form.value.db_type !== "manticoresearch" && form.value.db_type !== "hbase");
const bareMysqlProfiles = new Set(["doris", "selectdb", "oceanbase"]); const bareMysqlProfiles = new Set(["doris", "selectdb", "oceanbase"]);
const supportsMysqlTlsOptions = computed(() => form.value.db_type === "starrocks" || (form.value.db_type === "mysql" && !bareMysqlProfiles.has(selectedType.value))); const supportsMysqlTlsOptions = computed(() => form.value.db_type === "starrocks" || (form.value.db_type === "mysql" && !bareMysqlProfiles.has(selectedType.value)));
@@ -3117,6 +3184,9 @@ function applyConnectionUrlToForm(input: string): boolean {
const parsed = parseConnectionUrl(input, selectedType.value); const parsed = parseConnectionUrl(input, selectedType.value);
form.value = applyParsedConnectionUrl(form.value, parsed); form.value = applyParsedConnectionUrl(form.value, parsed);
if (form.value.db_type === "victoriametrics") {
hydrateVictoriaMetricsFields(form.value.external_config);
}
oracleTnsAdminPath.value = parseOracleTnsConnectionString(parsed.connectionString)?.tnsAdmin || ""; oracleTnsAdminPath.value = parseOracleTnsConnectionString(parsed.connectionString)?.tnsAdmin || "";
selectedType.value = parsed.driverProfile; selectedType.value = parsed.driverProfile;
customDriverName.value = isCustomCompatibleProfile() ? parsed.driverLabel : ""; customDriverName.value = isCustomCompatibleProfile() ? parsed.driverLabel : "";
@@ -3405,6 +3475,11 @@ function connectionConfigForSubmit(id: string, generatedName = ""): ConnectionCo
config.password = config.password.trim(); config.password = config.password.trim();
config.database = config.database?.trim() || undefined; config.database = config.database?.trim() || undefined;
} }
} else if (config.db_type === "victoriametrics") {
config.external_config = buildVictoriaMetricsExternalConfig();
config.connection_string = undefined;
config.database = "metrics";
config.username = config.username.trim();
} else if (config.db_type === "elasticsearch") { } else if (config.db_type === "elasticsearch") {
config.external_config = buildElasticsearchExternalConfig(elasticsearchConnectionMode.value, elasticsearchKibanaBasePath.value, elasticsearchConnectivityCheckPath.value); config.external_config = buildElasticsearchExternalConfig(elasticsearchConnectionMode.value, elasticsearchKibanaBasePath.value, elasticsearchConnectivityCheckPath.value);
} else if (config.db_type === "sqlserver") { } else if (config.db_type === "sqlserver") {
@@ -3518,7 +3593,7 @@ function connectionConfigForSubmit(id: string, generatedName = ""): ConnectionCo
config.client_cert_path = undefined; config.client_cert_path = undefined;
config.client_key_path = undefined; config.client_key_path = undefined;
} }
if (config.db_type !== "mysql" && config.db_type !== "clickhouse" && config.db_type !== "etcd" && config.db_type !== "starrocks" && config.db_type !== "mongodb") { if (config.db_type !== "mysql" && config.db_type !== "clickhouse" && config.db_type !== "etcd" && config.db_type !== "starrocks" && config.db_type !== "mongodb" && config.db_type !== "victoriametrics") {
config.ca_cert_path = undefined; config.ca_cert_path = undefined;
} else { } else {
config.ca_cert_path = config.ca_cert_path?.trim() || ""; config.ca_cert_path = config.ca_cert_path?.trim() || "";
@@ -6062,6 +6137,43 @@ function openExternalUrl(url: string) {
</div> </div>
</template> </template>
<template v-else-if="form.db_type === 'victoriametrics'">
<div class="grid grid-cols-4 items-center gap-4">
<Label :class="connectionLabelClass">{{ t("connection.host") }}</Label>
<Input v-model="form.host" class="col-span-2" />
<Input v-model.number="form.port" type="number" class="col-span-1" />
</div>
<div class="grid grid-cols-4 items-center gap-4">
<span />
<label class="col-span-3 flex items-center gap-2 text-sm">
<input type="checkbox" v-model="form.ssl" />
<span>{{ t("connection.sslEnable") }}</span>
</label>
</div>
<div class="grid grid-cols-4 items-center gap-4">
<Label :class="connectionLabelClass">{{ t("connection.user") }}</Label>
<Input v-model="form.username" class="col-span-3" autocomplete="username" />
</div>
<div class="grid grid-cols-4 items-center gap-4">
<Label :class="connectionLabelClass">{{ t("connection.password") }}</Label>
<PasswordInput v-model="form.password" class="col-span-3" />
</div>
<div class="grid grid-cols-4 items-start gap-4">
<Label :class="connectionLabelSmallClass">{{ t("connection.victoriametricsApiPath") }}</Label>
<div class="col-span-3 space-y-1.5">
<Input v-model="victoriaMetricsApiPath" placeholder="/prometheus" />
<p class="text-xs leading-5 text-muted-foreground">{{ t("connection.victoriametricsApiPathHint") }}</p>
</div>
</div>
<div class="grid grid-cols-4 items-start gap-4">
<Label :class="connectionLabelSmallClass">{{ t("connection.victoriametricsLookback") }}</Label>
<div class="col-span-3 space-y-1.5">
<Input v-model="victoriaMetricsLookback" class="w-28" placeholder="1h" />
<p class="text-xs leading-5 text-muted-foreground">{{ t("connection.victoriametricsLookbackHint") }}</p>
</div>
</div>
</template>
<!-- InfluxDB: v1 username/password or v2 token/org/bucket --> <!-- InfluxDB: v1 username/password or v2 token/org/bucket -->
<template v-else-if="form.db_type === 'influxdb'"> <template v-else-if="form.db_type === 'influxdb'">
<div class="grid grid-cols-4 items-center gap-4"> <div class="grid grid-cols-4 items-center gap-4">
@@ -1489,7 +1489,7 @@ function runKeymapExtension(codeMirrorKeymap: (typeof import("@codemirror/view")
function extendQueryEditorSelectionForView(currentView: EditorViewType): boolean { function extendQueryEditorSelectionForView(currentView: EditorViewType): boolean {
const databaseType = props.databaseType; const databaseType = props.databaseType;
const language = databaseType === "redis" || databaseType === "mongodb" || databaseType === "elasticsearch" ? "text" : "sql"; const language = databaseType === "redis" || databaseType === "mongodb" || databaseType === "elasticsearch" || databaseType === "victoriametrics" ? "text" : "sql";
return extendQueryEditorSelection(currentView, { return extendQueryEditorSelection(currentView, {
databaseType, databaseType,
dialect: props.syntaxDialect ?? props.dialect, dialect: props.syntaxDialect ?? props.dialect,
@@ -1688,7 +1688,7 @@ function getInsertValueHintTableColumns(table: string, schema?: string, database
function requestInsertValueHintTableColumns(table: string, schema?: string, database?: string) { function requestInsertValueHintTableColumns(table: string, schema?: string, database?: string) {
if (!props.connectionId || props.database == null) return; if (!props.connectionId || props.database == null) return;
if (props.databaseType === "redis" || props.databaseType === "mongodb" || props.databaseType === "elasticsearch" || props.databaseType === "easysearch") return; if (props.databaseType === "redis" || props.databaseType === "mongodb" || props.databaseType === "elasticsearch" || props.databaseType === "easysearch" || props.databaseType === "victoriametrics") return;
const cacheKey = insertHintCacheKey({ name: table, schema, database }); const cacheKey = insertHintCacheKey({ name: table, schema, database });
const hasCachedColumns = props.databaseType === "sqlserver" ? cachedInsertValueHintColumnsByTable.has(cacheKey) : cachedColumnsByTable.has(cacheKey); const hasCachedColumns = props.databaseType === "sqlserver" ? cachedInsertValueHintColumnsByTable.has(cacheKey) : cachedColumnsByTable.has(cacheKey);
if (hasCachedColumns || pendingInsertValueHintColumnLoads.has(cacheKey)) return; if (hasCachedColumns || pendingInsertValueHintColumnLoads.has(cacheKey)) return;
@@ -2122,7 +2122,7 @@ function invalidateSemanticDiagnosticsForDocumentChange() {
} }
function shouldSkipSqlSemanticDiagnostics() { function shouldSkipSqlSemanticDiagnostics() {
return props.databaseType !== "redis" && !settingsStore.editorSettings.sqlSemanticDiagnosticsEnabled; return props.databaseType === "victoriametrics" || (props.databaseType !== "redis" && !settingsStore.editorSettings.sqlSemanticDiagnosticsEnabled);
} }
function rangesOverlap(left: { from: number; to: number }, right: { from: number; to: number }): boolean { function rangesOverlap(left: { from: number; to: number }, right: { from: number; to: number }): boolean {
@@ -2248,7 +2248,7 @@ async function refreshSemanticDiagnostics(options: { preserveOutsideRanges?: boo
setSemanticDiagnostics([]); setSemanticDiagnostics([]);
return; return;
} }
if (props.databaseType === "mongodb" || props.databaseType === "elasticsearch" || props.databaseType === "easysearch") { if (props.databaseType === "mongodb" || props.databaseType === "elasticsearch" || props.databaseType === "easysearch" || props.databaseType === "victoriametrics") {
setSemanticDiagnostics([]); setSemanticDiagnostics([]);
return; return;
} }
@@ -2363,6 +2363,7 @@ function scheduleSemanticDiagnostics(delay = 500, options: { preserveOutsideRang
async function formatCurrentSql() { async function formatCurrentSql() {
if (props.readOnly) return; if (props.readOnly) return;
if (props.databaseType === "victoriametrics") return;
const currentView = view.value; const currentView = view.value;
if (!currentView) return; if (!currentView) return;
@@ -2581,7 +2582,7 @@ function localCompletionSchemasForDatabaseDisambiguation(completionContext: Retu
} }
function shouldInsertSqlCompletionSpace(): boolean { function shouldInsertSqlCompletionSpace(): boolean {
return props.databaseType !== "mongodb" && props.databaseType !== "redis" && props.databaseType !== "elasticsearch" && props.databaseType !== "easysearch"; return props.databaseType !== "mongodb" && props.databaseType !== "redis" && props.databaseType !== "elasticsearch" && props.databaseType !== "easysearch" && props.databaseType !== "victoriametrics";
} }
function completionOptionForItem(item: QueryCompletionItem) { function completionOptionForItem(item: QueryCompletionItem) {
@@ -2764,6 +2765,7 @@ async function provideSqlCompletions(context: CompletionContext) {
if (props.databaseType === "redis") { if (props.databaseType === "redis") {
return provideRedisCompletions(currentState, position, explicit); return provideRedisCompletions(currentState, position, explicit);
} }
if (props.databaseType === "victoriametrics") return null;
const hasDatabase = props.database != null; const hasDatabase = props.database != null;
const epoch = ++completionEpoch; const epoch = ++completionEpoch;
@@ -2971,6 +2973,7 @@ function shouldStartSqlCompletionAfterInput(insertedText: string, removedText: s
if (props.databaseType === "mongodb") { if (props.databaseType === "mongodb") {
return !!(insertedText || removedText) && shouldAutoOpenMongoCompletion(fullDoc, position); return !!(insertedText || removedText) && shouldAutoOpenMongoCompletion(fullDoc, position);
} }
if (props.databaseType === "victoriametrics") return false;
if (!insertedText && removedText) { if (!insertedText && removedText) {
const completionContext = getSqlCompletionContext(fullDoc, position, sqlCompletionDialectOptions()); const completionContext = getSqlCompletionContext(fullDoc, position, sqlCompletionDialectOptions());
return isTableNameCompletionContext(completionContext) && shouldAutoOpenSqlCompletion(fullDoc, position, sqlCompletionDialectOptions()); return isTableNameCompletionContext(completionContext) && shouldAutoOpenSqlCompletion(fullDoc, position, sqlCompletionDialectOptions());
@@ -4010,7 +4013,7 @@ onMounted(async () => {
const endLine = view.state.doc.lineAt(Math.max(range.from, frameTo - 1)); const endLine = view.state.doc.lineAt(Math.max(range.from, frameTo - 1));
let insertValueHints: Array<{ from: number; column: string }> = []; let insertValueHints: Array<{ from: number; column: string }> = [];
try { try {
if (settingsStore.editorSettings.showInsertValueHints && props.databaseType !== "redis" && props.databaseType !== "mongodb" && props.databaseType !== "elasticsearch" && props.databaseType !== "easysearch") { if (settingsStore.editorSettings.showInsertValueHints && props.databaseType !== "redis" && props.databaseType !== "mongodb" && props.databaseType !== "elasticsearch" && props.databaseType !== "easysearch" && props.databaseType !== "victoriametrics") {
const statementSql = view.state.doc.sliceString(range.from, range.to); const statementSql = view.state.doc.sliceString(range.from, range.to);
if (/\binsert\b/i.test(statementSql)) { if (/\binsert\b/i.test(statementSql)) {
insertValueHints = parseInsertValueHints(statementSql, { resolveTableColumns: getInsertValueHintTableColumns }).map((hint) => ({ insertValueHints = parseInsertValueHints(statementSql, { resolveTableColumns: getInsertValueHintTableColumns }).map((hint) => ({
@@ -4163,7 +4166,7 @@ onMounted(async () => {
sqlSignatureComp.of(buildSqlSignatureExtension()), sqlSignatureComp.of(buildSqlSignatureExtension()),
diagnosticComp.of(buildSqlDiagnosticExtension()), diagnosticComp.of(buildSqlDiagnosticExtension()),
createInsertValueHintsExtension({ createInsertValueHintsExtension({
isEnabled: () => settingsStore.editorSettings.showInsertValueHints && props.databaseType !== "redis" && props.databaseType !== "mongodb" && props.databaseType !== "elasticsearch" && props.databaseType !== "easysearch", isEnabled: () => settingsStore.editorSettings.showInsertValueHints && props.databaseType !== "redis" && props.databaseType !== "mongodb" && props.databaseType !== "elasticsearch" && props.databaseType !== "easysearch" && props.databaseType !== "victoriametrics",
getTableColumns: getInsertValueHintTableColumns, getTableColumns: getInsertValueHintTableColumns,
requestTableColumns: requestInsertValueHintTableColumns, requestTableColumns: requestInsertValueHintTableColumns,
}), }),
@@ -4746,7 +4749,7 @@ watch(
watch( watch(
() => settingsStore.editorSettings.sqlSemanticDiagnosticsEnabled, () => settingsStore.editorSettings.sqlSemanticDiagnosticsEnabled,
(enabled) => { (enabled) => {
if (props.databaseType === "redis") return; if (props.databaseType === "redis" || props.databaseType === "victoriametrics") return;
if (!shouldSkipSqlSemanticDiagnostics() && enabled) { if (!shouldSkipSqlSemanticDiagnostics() && enabled) {
scheduleSemanticDiagnostics(0); scheduleSemanticDiagnostics(0);
return; return;
@@ -139,7 +139,7 @@ import { BOOLEAN_CELL_EDITOR_VALUES, booleanCellEditorValue, isBooleanCellValue,
import { resolveDataGridColumnsByResultIndex } from "@/lib/dataGrid/dataGridColumnMetadata"; import { resolveDataGridColumnsByResultIndex } from "@/lib/dataGrid/dataGridColumnMetadata";
import { isCancelSearchShortcut, isCopyCurrentRowShortcut, isDeleteCurrentRowShortcut, isFocusSearchShortcut, isModRShortcut, isSaveShortcut, isToggleTransposeShortcut } from "@/lib/editor/keyboardShortcuts"; import { isCancelSearchShortcut, isCopyCurrentRowShortcut, isDeleteCurrentRowShortcut, isFocusSearchShortcut, isModRShortcut, isSaveShortcut, isToggleTransposeShortcut } from "@/lib/editor/keyboardShortcuts";
import { dataGridHeaderContentWidth, scrollbarGutterWidth } from "@/lib/dataGrid/dataGridScrollGutter"; import { dataGridHeaderContentWidth, scrollbarGutterWidth } from "@/lib/dataGrid/dataGridScrollGutter";
import { canFetchNextDataGridSegment, canGoNextDataGridPage, dataGridTotalRowCountLabelKey, hasCompleteLocalDataGridResult, resolveDataGridPaginationTotal, type DataGridInexactTotalRowCountMode } from "@/lib/dataGrid/dataGridPagination"; import { canFetchNextDataGridSegment, canGoNextDataGridPage, dataGridTotalRowCountLabelKey, dataGridTruncationHintKey, hasCompleteLocalDataGridResult, resolveDataGridPaginationTotal, type DataGridInexactTotalRowCountMode } from "@/lib/dataGrid/dataGridPagination";
import { dataGridCountQueryOptions } from "@/lib/dataGrid/dataGridQueryOptions"; import { dataGridCountQueryOptions } from "@/lib/dataGrid/dataGridQueryOptions";
import { dataGridBottomScrollTop, dataGridScrollPosition, isDataGridAtScrollBottom, isDataGridNearScrollBottom, isDataGridPrefixAppend, shouldCheckInfiniteScrollAfterScroll, type DataGridScrollPosition } from "@/lib/dataGrid/dataGridInfiniteScroll"; import { dataGridBottomScrollTop, dataGridScrollPosition, isDataGridAtScrollBottom, isDataGridNearScrollBottom, isDataGridPrefixAppend, shouldCheckInfiniteScrollAfterScroll, type DataGridScrollPosition } from "@/lib/dataGrid/dataGridInfiniteScroll";
import { CANVAS_DATA_GRID_ROW_HEIGHT, canvasDataGridActionOverlayWidth, canvasDataGridActionReservedWidth, dataGridSearchMatchKey, drawCanvasDataGrid, type CanvasDevicePixelSize } from "@/lib/dataGrid/canvasDataGridRenderer"; import { CANVAS_DATA_GRID_ROW_HEIGHT, canvasDataGridActionOverlayWidth, canvasDataGridActionReservedWidth, dataGridSearchMatchKey, drawCanvasDataGrid, type CanvasDevicePixelSize } from "@/lib/dataGrid/canvasDataGridRenderer";
@@ -2484,6 +2484,7 @@ watch(
const manualTotalRowCount = ref<number | undefined>(undefined); const manualTotalRowCount = ref<number | undefined>(undefined);
const manualTotalRowCountLoading = ref(false); const manualTotalRowCountLoading = ref(false);
const showTruncationWarning = computed(() => props.result.truncated === true && typeof props.pageLimit !== "number" && props.result.has_more !== true); const showTruncationWarning = computed(() => props.result.truncated === true && typeof props.pageLimit !== "number" && props.result.has_more !== true);
const truncationHintKey = computed(() => dataGridTruncationHintKey(resolvedDatabaseType.value));
const isResultsContext = computed(() => props.context === "results"); const isResultsContext = computed(() => props.context === "results");
// affected_rows reported by the backend can be larger than the rows we // affected_rows reported by the backend can be larger than the rows we
// actually have in memory — e.g. ES auto-pages SELECT * on a big index and // actually have in memory — e.g. ES auto-pages SELECT * on a big index and
@@ -2613,8 +2614,8 @@ watch(
const showQueryEditReadOnlyBadge = computed(() => isResultsContext.value && hasData.value && !props.editable && !!props.queryEditabilityReason); const showQueryEditReadOnlyBadge = computed(() => isResultsContext.value && hasData.value && !props.editable && !!props.queryEditabilityReason);
const queryEditReadOnlyReason = computed(() => (props.queryEditabilityReason ? t(`grid.queryEditUnsupported.${props.queryEditabilityReason}`) : "")); const queryEditReadOnlyReason = computed(() => (props.queryEditabilityReason ? t(`grid.queryEditUnsupported.${props.queryEditabilityReason}`) : ""));
const showKeylessEditWarning = computed(() => !!props.editable && !!props.tableMeta && canUseKeylessRowPredicate(props.databaseType, props.tableMeta.primaryKeys ?? [])); const showKeylessEditWarning = computed(() => !!props.editable && !!props.tableMeta && canUseKeylessRowPredicate(props.databaseType, props.tableMeta.primaryKeys ?? []));
const canShowWhereSearch = computed(() => !!props.onExecuteSql && !isResultsContext.value); const canShowWhereSearch = computed(() => !!props.onExecuteSql && !isResultsContext.value && resolvedDatabaseType.value !== "victoriametrics");
const canUseWhereSearch = computed(() => !!props.tableMeta && !!props.onExecuteSql && !isResultsContext.value); const canUseWhereSearch = computed(() => !!props.tableMeta && canShowWhereSearch.value);
const canUseServerColumnFilter = computed(() => canUseWhereSearch.value && !!props.connectionId && !!props.tableMeta); const canUseServerColumnFilter = computed(() => canUseWhereSearch.value && !!props.connectionId && !!props.tableMeta);
type DataGridTableMeta = NonNullable<typeof props.tableMeta>; type DataGridTableMeta = NonNullable<typeof props.tableMeta>;
const hiveTableTransactional = ref<boolean | undefined>(undefined); const hiveTableTransactional = ref<boolean | undefined>(undefined);
@@ -8635,7 +8636,7 @@ const gridContextMenuItems = computed<ContextMenuItem[]>(() => {
</div> </div>
<!-- Truncation warning banner --> <!-- Truncation warning banner -->
<div v-if="showTruncationWarning" class="shrink-0 px-3 py-1 bg-amber-500/10 border-b border-amber-500/20 text-xs text-amber-600 dark:text-amber-400 flex items-center gap-1.5"> <div v-if="showTruncationWarning" class="shrink-0 px-3 py-1 bg-amber-500/10 border-b border-amber-500/20 text-xs text-amber-600 dark:text-amber-400 flex items-center gap-1.5">
<span>{{ t("grid.truncatedHint", { count: result.rows.length }) }}</span> <span>{{ t(truncationHintKey, { count: result.rows.length }) }}</span>
</div> </div>
<!-- Content area: table + side/bottom detail panes --> <!-- Content area: table + side/bottom detail panes -->
<div class="flex-1 grid min-h-0 overflow-hidden" :style="contentGridStyle"> <div class="flex-1 grid min-h-0 overflow-hidden" :style="contentGridStyle">
@@ -1,11 +1,17 @@
import { describe, expect, it } from "vitest"; import { describe, expect, it } from "vitest";
import { dataGridTotalRowCountLabelKey } from "@/lib/dataGrid/dataGridPagination"; import { dataGridTotalRowCountLabelKey, dataGridTruncationHintKey } from "@/lib/dataGrid/dataGridPagination";
import DataGrid from "../DataGrid.vue"; import DataGrid from "../DataGrid.vue";
type VuePropDefinition = { default?: unknown }; type VuePropDefinition = { default?: unknown };
type VueComponentWithProps = { props?: Record<string, VuePropDefinition> }; type VueComponentWithProps = { props?: Record<string, VuePropDefinition> };
describe("DataGrid total row count exactness", () => { describe("DataGrid total row count exactness", () => {
it("uses a VictoriaMetrics-specific truncation explanation", () => {
expect(dataGridTruncationHintKey("victoriametrics")).toBe("grid.victoriaMetricsTruncatedHint");
expect(dataGridTruncationHintKey("mysql")).toBe("grid.truncatedHint");
expect(dataGridTruncationHintKey()).toBe("grid.truncatedHint");
});
it("treats totals as exact unless a caller explicitly marks them as a lower bound", () => { it("treats totals as exact unless a caller explicitly marks them as a lower bound", () => {
const component = DataGrid as unknown as VueComponentWithProps; const component = DataGrid as unknown as VueComponentWithProps;
expect(component.props?.totalRowCountIsExact?.default).toBe(true); expect(component.props?.totalRowCountIsExact?.default).toBe(true);
@@ -100,6 +100,7 @@ const assetIcons: Record<string, string> = {
nacos: "nacos.png", nacos: "nacos.png",
iris: "iris", iris: "iris",
influxdb: "influxdb", influxdb: "influxdb",
victoriametrics: "victoriametrics.png",
zookeeper: "zookeeper", zookeeper: "zookeeper",
oscar: "oscar.png", oscar: "oscar.png",
jdbcx: "jdbcx", jdbcx: "jdbcx",
@@ -96,7 +96,21 @@ const activeConnectionValue = computed(() => props.activeConnection?.id || "");
const activeSchemaValue = computed(() => props.activeTab.schema || ""); const activeSchemaValue = computed(() => props.activeTab.schema || "");
const supportsExplain = computed(() => { const supportsExplain = computed(() => {
const dbType = props.activeConnection?.db_type; const dbType = props.activeConnection?.db_type;
return dbType !== "redis" && dbType !== "mongodb" && dbType !== "elasticsearch" && dbType !== "easysearch" && dbType !== "qdrant" && dbType !== "milvus" && dbType !== "weaviate" && dbType !== "chromadb" && dbType !== "etcd" && dbType !== "zookeeper" && dbType !== "mq" && dbType !== "nacos"; return (
dbType !== "redis" &&
dbType !== "mongodb" &&
dbType !== "elasticsearch" &&
dbType !== "easysearch" &&
dbType !== "qdrant" &&
dbType !== "milvus" &&
dbType !== "weaviate" &&
dbType !== "chromadb" &&
dbType !== "etcd" &&
dbType !== "zookeeper" &&
dbType !== "mq" &&
dbType !== "nacos" &&
dbType !== "victoriametrics"
);
}); });
const isSingleDb = computed(() => isSingleDatabase(props.activeConnection?.db_type)); const isSingleDb = computed(() => isSingleDatabase(props.activeConnection?.db_type));
const supportsExPaste = computed(() => supportsSqlInListPaste(props.activeConnection?.db_type)); const supportsExPaste = computed(() => supportsSqlInListPaste(props.activeConnection?.db_type));
@@ -198,6 +198,8 @@ const isResizingSidePanel = ref(false);
const sidePanelGuard = createSidePanelRequestGuard(); const sidePanelGuard = createSidePanelRequestGuard();
const tableMetadataCapabilities = computed<TableMetadataCapabilities>(() => getTableMetadataCapabilities(effectiveDatabaseType.value)); const tableMetadataCapabilities = computed<TableMetadataCapabilities>(() => getTableMetadataCapabilities(effectiveDatabaseType.value));
const effectiveDatabaseType = computed(() => effectiveDatabaseTypeForConnection(props.connection) ?? props.connection.db_type); const effectiveDatabaseType = computed(() => effectiveDatabaseTypeForConnection(props.connection) ?? props.connection.db_type);
const isVictoriaMetrics = computed(() => effectiveDatabaseType.value === "victoriametrics");
const objectRowsLabel = computed(() => t(isVictoriaMetrics.value ? "objects.series" : "objects.rows"));
const tableStructureDatabaseType = computed(() => tableStructureDatabaseTypeForConnection(props.connection) ?? props.connection.db_type); const tableStructureDatabaseType = computed(() => tableStructureDatabaseTypeForConnection(props.connection) ?? props.connection.db_type);
const sourceEditableText = ref(""); const sourceEditableText = ref("");
const sourceDraft = ref(""); const sourceDraft = ref("");
@@ -438,7 +440,8 @@ function toggleCheckboxColumn() {
const objectBrowserColumns = computed<ObjectBrowserColumnKey[]>(() => { const objectBrowserColumns = computed<ObjectBrowserColumnKey[]>(() => {
const columns: ObjectBrowserColumnKey[] = []; const columns: ObjectBrowserColumnKey[] = [];
if (showCheckboxColumn.value) columns.push("select"); if (showCheckboxColumn.value) columns.push("select");
columns.push("name", "type", "estimatedRows", "totalBytes"); columns.push("name", "type", "estimatedRows");
if (!isVictoriaMetrics.value) columns.push("totalBytes");
if (hasCreatedAt.value) columns.push("created_at"); if (hasCreatedAt.value) columns.push("created_at");
if (hasUpdatedAt.value) columns.push("updated_at"); if (hasUpdatedAt.value) columns.push("updated_at");
columns.push("comment"); columns.push("comment");
@@ -600,7 +603,8 @@ function toggleSort(key: ObjectBrowserSortKey) {
} }
const sortKeyOptions = computed<ObjectBrowserSortKey[]>(() => { const sortKeyOptions = computed<ObjectBrowserSortKey[]>(() => {
const options: ObjectBrowserSortKey[] = ["name", "type", "estimatedRows", "totalBytes"]; const options: ObjectBrowserSortKey[] = ["name", "type", "estimatedRows"];
if (!isVictoriaMetrics.value) options.push("totalBytes");
if (hasCreatedAt.value) options.push("created_at"); if (hasCreatedAt.value) options.push("created_at");
if (hasUpdatedAt.value) options.push("updated_at"); if (hasUpdatedAt.value) options.push("updated_at");
options.push("comment"); options.push("comment");
@@ -617,7 +621,7 @@ watch(sortKeyOptions, (options) => {
function sortKeyLabel(key: ObjectBrowserSortKey): string { function sortKeyLabel(key: ObjectBrowserSortKey): string {
if (key === "name") return t("objects.name"); if (key === "name") return t("objects.name");
if (key === "type") return t("objects.type"); if (key === "type") return t("objects.type");
if (key === "estimatedRows") return t("objects.rows"); if (key === "estimatedRows") return objectRowsLabel.value;
if (key === "totalBytes") return t("objects.size"); if (key === "totalBytes") return t("objects.size");
if (key === "created_at") return t("objects.createdAt"); if (key === "created_at") return t("objects.createdAt");
if (key === "updated_at") return t("objects.updatedAt"); if (key === "updated_at") return t("objects.updatedAt");
@@ -1856,6 +1860,22 @@ async function exportTableData(row: ObjectBrowserRow, format: "csv" | "xlsx" | "
let task: ExportTask | null = null; let task: ExportTask | null = null;
try { try {
if (isVictoriaMetrics.value) {
const result = await fetchTableDataForExport({
databaseType: effectiveDatabaseType.value,
schema,
tableName: row.name,
executePage: (sql) => api.executeQuery(props.connection.id, props.database, sql),
});
if (format === "csv") {
await api.exportQueryResultCsv(filePath, result.columns, result.rows);
} else {
const comments = useCommentHeader ? result.columns.map((name) => columnInfos?.find((column) => column.name.toLocaleLowerCase() === name.toLocaleLowerCase())?.comment ?? null) : undefined;
await api.exportQueryResultXlsx(filePath, row.name, result.columns, result.column_types ?? result.columns.map(() => ""), comments, result.rows);
}
toast(t("grid.exported"));
return;
}
let columns: string[] | undefined; let columns: string[] | undefined;
let columnComments: (string | null)[] | undefined; let columnComments: (string | null)[] | undefined;
@@ -1969,7 +1989,7 @@ function copySelectedTablesToClipboard() {
} }
function canPasteTableClipboard(): boolean { function canPasteTableClipboard(): boolean {
return tableClipboardMatchesTarget(normalizedObjectBrowserTableClipboardEntries(), pasteTableTargetContext()); return !isVictoriaMetrics.value && tableClipboardMatchesTarget(normalizedObjectBrowserTableClipboardEntries(), pasteTableTargetContext());
} }
function normalizedObjectBrowserTableClipboardEntries() { function normalizedObjectBrowserTableClipboardEntries() {
@@ -1982,6 +2002,7 @@ function normalizedObjectBrowserTableClipboardEntries() {
} }
function canTransferTableClipboard(): boolean { function canTransferTableClipboard(): boolean {
if (isVictoriaMetrics.value) return false;
const entries = normalizedObjectBrowserTableClipboardEntries(); const entries = normalizedObjectBrowserTableClipboardEntries();
const target = pasteTableTargetContext(); const target = pasteTableTargetContext();
if (entries.length === 0 || props.connection.read_only) return false; if (entries.length === 0 || props.connection.read_only) return false;
@@ -2548,15 +2569,16 @@ watch(
// ---- CustomContextMenu helpers ---- // ---- CustomContextMenu helpers ----
function exportDataSubmenu(item: ObjectBrowserRow): ContextMenuItem { function exportDataSubmenu(item: ObjectBrowserRow): ContextMenuItem {
const formats: ContextMenuItem[] = [
{ label: "CSV", action: () => exportData(item, "csv") },
{ label: "JSON", action: () => exportData(item, "json") },
];
if (!isVictoriaMetrics.value) formats.push({ label: "SQL INSERT", action: () => exportData(item, "sql") });
formats.push({ label: "XLSX", action: () => exportDataXlsx(item) });
return { return {
label: t("contextMenu.exportData"), label: t("contextMenu.exportData"),
icon: Upload, icon: Upload,
children: [ children: formats,
{ label: "CSV", action: () => exportData(item, "csv") },
{ label: "JSON", action: () => exportData(item, "json") },
{ label: "SQL INSERT", action: () => exportData(item, "sql") },
{ label: "XLSX", action: () => exportDataXlsx(item) },
],
}; };
} }
@@ -2574,6 +2596,7 @@ function objectBrowserTableClipboardMenuState(item: ObjectBrowserRow) {
} }
function tableClipboardMenuItems(item: ObjectBrowserRow): ContextMenuItem[] { function tableClipboardMenuItems(item: ObjectBrowserRow): ContextMenuItem[] {
if (isVictoriaMetrics.value) return [];
const copyItem: ContextMenuItem = { label: t("contextMenu.copyTable"), action: () => copySingleTableToClipboard(item), icon: Copy }; const copyItem: ContextMenuItem = { label: t("contextMenu.copyTable"), action: () => copySingleTableToClipboard(item), icon: Copy };
const state = objectBrowserTableClipboardMenuState(item); const state = objectBrowserTableClipboardMenuState(item);
if (state === "copy") return [copyItem]; if (state === "copy") return [copyItem];
@@ -2590,6 +2613,16 @@ function selectedBatchTableCountLabel(key: "batchDrop" | "batchTruncate" | "batc
} }
function getTableMenuItems(item: ObjectBrowserRow): ContextMenuItem[] { function getTableMenuItems(item: ObjectBrowserRow): ContextMenuItem[] {
if (isVictoriaMetrics.value) {
return [
{ label: t("contextMenu.viewData"), action: () => openViewData(item), icon: Table2 },
{ label: t("contextMenu.newQuery"), action: () => openNewQuery(item), icon: TerminalSquare },
{ label: "", separator: true },
exportDataSubmenu(item),
{ label: "", separator: true },
{ label: t("contextMenu.copyName"), action: () => copyName(item), icon: Copy },
];
}
const useBatchActions = isSelectedBatchTableContext(item); const useBatchActions = isSelectedBatchTableContext(item);
return [ return [
{ label: t("contextMenu.viewData"), action: () => openViewData(item), icon: Table2 }, { label: t("contextMenu.viewData"), action: () => openViewData(item), icon: Table2 },
@@ -2789,23 +2822,23 @@ function getObjectBrowserMenuItems(item: ObjectBrowserRow): ContextMenuItem[] {
<div class="min-w-0 flex-1 truncate text-muted-foreground"> <div class="min-w-0 flex-1 truncate text-muted-foreground">
{{ t("objects.selectedTables", { count: selectedTableCount }) }} {{ t("objects.selectedTables", { count: selectedTableCount }) }}
</div> </div>
<Button variant="ghost" size="sm" class="h-7 px-2 text-xs" @click="openBatchDatabaseExport"> <Button v-if="!isVictoriaMetrics" variant="ghost" size="sm" class="h-7 px-2 text-xs" @click="openBatchDatabaseExport">
<Upload class="mr-1.5 h-3.5 w-3.5" /> <Upload class="mr-1.5 h-3.5 w-3.5" />
{{ t("objects.exportSelected") }} {{ t("objects.exportSelected") }}
</Button> </Button>
<Button variant="ghost" size="sm" class="h-7 px-2 text-xs" @click="copySelectedTablesToClipboard"> <Button v-if="!isVictoriaMetrics" variant="ghost" size="sm" class="h-7 px-2 text-xs" @click="copySelectedTablesToClipboard">
<Clipboard class="mr-1.5 h-3.5 w-3.5" /> <Clipboard class="mr-1.5 h-3.5 w-3.5" />
{{ t("objects.copyTableSelected") }} {{ t("objects.copyTableSelected") }}
</Button> </Button>
<Button v-if="supportsTruncateTable" variant="ghost" size="sm" class="h-7 px-2 text-xs text-destructive" @click="requestBatchTruncateTables"> <Button v-if="!isVictoriaMetrics && supportsTruncateTable" variant="ghost" size="sm" class="h-7 px-2 text-xs text-destructive" @click="requestBatchTruncateTables">
<Scissors class="mr-1.5 h-3.5 w-3.5" /> <Scissors class="mr-1.5 h-3.5 w-3.5" />
{{ t("objects.truncateSelected") }} {{ t("objects.truncateSelected") }}
</Button> </Button>
<Button variant="ghost" size="sm" class="h-7 px-2 text-xs text-destructive" @click="requestBatchEmptyTables"> <Button v-if="!isVictoriaMetrics" variant="ghost" size="sm" class="h-7 px-2 text-xs text-destructive" @click="requestBatchEmptyTables">
<Eraser class="mr-1.5 h-3.5 w-3.5" /> <Eraser class="mr-1.5 h-3.5 w-3.5" />
{{ t("contextMenu.batchEmpty", { count: selectedTableCount }) }} {{ t("contextMenu.batchEmpty", { count: selectedTableCount }) }}
</Button> </Button>
<Button variant="ghost" size="sm" class="h-7 px-2 text-xs text-destructive" @click="requestBatchDropTables"> <Button v-if="!isVictoriaMetrics" variant="ghost" size="sm" class="h-7 px-2 text-xs text-destructive" @click="requestBatchDropTables">
<Trash2 class="mr-1.5 h-3.5 w-3.5" /> <Trash2 class="mr-1.5 h-3.5 w-3.5" />
{{ t("objects.dropSelected") }} {{ t("objects.dropSelected") }}
</Button> </Button>
@@ -2858,7 +2891,7 @@ function getObjectBrowserMenuItems(item: ObjectBrowserRow): ContextMenuItem[] {
</div> </div>
<div class="relative flex min-w-0 items-center"> <div class="relative flex min-w-0 items-center">
<button class="flex min-w-0 items-center gap-1 truncate pr-4 text-left" type="button" :title="t('objects.statisticsHint')" @click="toggleSort('estimatedRows')"> <button class="flex min-w-0 items-center gap-1 truncate pr-4 text-left" type="button" :title="t('objects.statisticsHint')" @click="toggleSort('estimatedRows')">
<span class="truncate">{{ t("objects.rows") }}</span> <span class="truncate">{{ objectRowsLabel }}</span>
<component :is="sortIconFor('estimatedRows')" v-if="sortIconFor('estimatedRows')" class="h-3 w-3 shrink-0" /> <component :is="sortIconFor('estimatedRows')" v-if="sortIconFor('estimatedRows')" class="h-3 w-3 shrink-0" />
</button> </button>
<div <div
@@ -2869,7 +2902,7 @@ function getObjectBrowserMenuItems(item: ObjectBrowserRow): ContextMenuItem[] {
<GripVertical class="h-3 w-3" /> <GripVertical class="h-3 w-3" />
</div> </div>
</div> </div>
<div class="relative flex min-w-0 items-center"> <div v-if="!isVictoriaMetrics" class="relative flex min-w-0 items-center">
<button class="flex min-w-0 items-center gap-1 truncate pr-4 text-left" type="button" :title="t('objects.statisticsHint')" @click="toggleSort('totalBytes')"> <button class="flex min-w-0 items-center gap-1 truncate pr-4 text-left" type="button" :title="t('objects.statisticsHint')" @click="toggleSort('totalBytes')">
<span class="truncate">{{ t("objects.size") }}</span> <span class="truncate">{{ t("objects.size") }}</span>
<component :is="sortIconFor('totalBytes')" v-if="sortIconFor('totalBytes')" class="h-3 w-3 shrink-0" /> <component :is="sortIconFor('totalBytes')" v-if="sortIconFor('totalBytes')" class="h-3 w-3 shrink-0" />
@@ -2962,7 +2995,7 @@ function getObjectBrowserMenuItems(item: ObjectBrowserRow): ContextMenuItem[] {
<div class="truncate text-xs tabular-nums text-muted-foreground" :title="item.estimatedRows == null ? '' : formatObjectBrowserCount(item.estimatedRows)"> <div class="truncate text-xs tabular-nums text-muted-foreground" :title="item.estimatedRows == null ? '' : formatObjectBrowserCount(item.estimatedRows)">
{{ formatObjectBrowserCount(item.estimatedRows) }} {{ formatObjectBrowserCount(item.estimatedRows) }}
</div> </div>
<div class="truncate text-xs tabular-nums text-muted-foreground" :title="item.totalBytes == null ? '' : formatObjectBrowserBytes(item.totalBytes)"> <div v-if="!isVictoriaMetrics" class="truncate text-xs tabular-nums text-muted-foreground" :title="item.totalBytes == null ? '' : formatObjectBrowserBytes(item.totalBytes)">
{{ formatObjectBrowserBytes(item.totalBytes) }} {{ formatObjectBrowserBytes(item.totalBytes) }}
</div> </div>
<div v-if="hasCreatedAt" class="truncate text-xs tabular-nums text-muted-foreground" :title="formatObjectBrowserTimestamp(item.created_at)"> <div v-if="hasCreatedAt" class="truncate text-xs tabular-nums text-muted-foreground" :title="formatObjectBrowserTimestamp(item.created_at)">
@@ -3008,7 +3041,9 @@ function getObjectBrowserMenuItems(item: ObjectBrowserRow): ContextMenuItem[] {
<span v-if="item.estimatedRows != null && item.estimatedRows > 0" class="object-browser-stat-badge object-browser-stat-badge-rows rounded-full bg-primary/10 px-1.5 py-0.5 text-[10px] font-medium tabular-nums text-primary">{{ <span v-if="item.estimatedRows != null && item.estimatedRows > 0" class="object-browser-stat-badge object-browser-stat-badge-rows rounded-full bg-primary/10 px-1.5 py-0.5 text-[10px] font-medium tabular-nums text-primary">{{
formatObjectBrowserCount(item.estimatedRows) formatObjectBrowserCount(item.estimatedRows)
}}</span> }}</span>
<span v-if="item.totalBytes != null && item.totalBytes > 0" class="object-browser-stat-badge object-browser-stat-badge-bytes rounded-full bg-muted px-1.5 py-0.5 text-[10px] font-medium tabular-nums text-muted-foreground">{{ formatObjectBrowserBytes(item.totalBytes) }}</span> <span v-if="!isVictoriaMetrics && item.totalBytes != null && item.totalBytes > 0" class="object-browser-stat-badge object-browser-stat-badge-bytes rounded-full bg-muted px-1.5 py-0.5 text-[10px] font-medium tabular-nums text-muted-foreground">{{
formatObjectBrowserBytes(item.totalBytes)
}}</span>
</div> </div>
<!-- Always reserve timestamp/comment slots when the dataset has them so every card shares one height. --> <!-- Always reserve timestamp/comment slots when the dataset has them so every card shares one height. -->
<div v-if="hasCreatedAt || hasUpdatedAt" class="flex min-h-[15px] items-center gap-1 text-[10px] leading-[15px] text-muted-foreground/70"> <div v-if="hasCreatedAt || hasUpdatedAt" class="flex min-h-[15px] items-center gap-1 text-[10px] leading-[15px] text-muted-foreground/70">
@@ -3034,7 +3069,7 @@ function getObjectBrowserMenuItems(item: ObjectBrowserRow): ContextMenuItem[] {
<div class="flex items-center gap-2 px-3 py-1.5 border-b shrink-0 bg-muted/20 h-9"> <div class="flex items-center gap-2 px-3 py-1.5 border-b shrink-0 bg-muted/20 h-9">
<TableProperties class="w-3.5 h-3.5 text-muted-foreground" /> <TableProperties class="w-3.5 h-3.5 text-muted-foreground" />
<span class="text-xs font-medium flex-1 min-w-0 truncate">{{ sidePanelRow?.name }}</span> <span class="text-xs font-medium flex-1 min-w-0 truncate">{{ sidePanelRow?.name }}</span>
<div v-if="tableInfoTab === 'ddl'" class="table-info-actions flex min-w-0 shrink-0 items-center gap-1"> <div v-if="tableInfoTab === 'ddl' && tableMetadataCapabilities.ddl" class="table-info-actions flex min-w-0 shrink-0 items-center gap-1">
<Button variant="ghost" size="sm" class="table-info-action-button h-6 px-2 text-xs" :title="t('grid.copyDdl')" :aria-label="t('grid.copyDdl')" @click="copyTableDdl"> <Button variant="ghost" size="sm" class="table-info-action-button h-6 px-2 text-xs" :title="t('grid.copyDdl')" :aria-label="t('grid.copyDdl')" @click="copyTableDdl">
<Copy class="w-3 h-3" /> <Copy class="w-3 h-3" />
<span class="table-info-action-label">{{ t("grid.copyDdl") }}</span> <span class="table-info-action-label">{{ t("grid.copyDdl") }}</span>
@@ -891,7 +891,7 @@ function normalizedTreeClipboardTableEntries(): TableClipboardTableContext[] {
} }
function canPasteTreeClipboardToCurrentNode(): boolean { function canPasteTreeClipboardToCurrentNode(): boolean {
return tableClipboardMatchesTarget(normalizedTreeClipboardTableEntries(), pasteTableTargetContext()); return currentDatabaseType() !== "victoriametrics" && tableClipboardMatchesTarget(normalizedTreeClipboardTableEntries(), pasteTableTargetContext());
} }
function canTransferTreeClipboardToCurrentNode(): boolean { function canTransferTreeClipboardToCurrentNode(): boolean {
@@ -924,6 +924,7 @@ function openTransferFromTreeClipboard(): boolean {
} }
function requestPasteTreeClipboard(): boolean { function requestPasteTreeClipboard(): boolean {
if (currentDatabaseType() === "victoriametrics") return false;
claimTreeItemDialogOwnership(); claimTreeItemDialogOwnership();
ensureDangerDialogRouting(); ensureDangerDialogRouting();
routeTreeItemDialogController(); routeTreeItemDialogController();
@@ -1376,6 +1377,7 @@ async function newDeleteTemplate() {
} }
async function generateDdlTemplate() { async function generateDdlTemplate() {
if (currentDatabaseType() === "victoriametrics") return;
const targets = selectedDdlTargets(); const targets = selectedDdlTargets();
if (!targets.length) return; if (!targets.length) return;
const tabTarget = targets.find((target) => target.id === activeNode.value.id) ?? targets[0]!; const tabTarget = targets.find((target) => target.id === activeNode.value.id) ?? targets[0]!;
@@ -1411,6 +1413,7 @@ function selectedDdlTargets() {
} }
async function openDdl() { async function openDdl() {
if (currentDatabaseType() === "victoriametrics") return;
const targets = selectedDdlTargets(); const targets = selectedDdlTargets();
if (!targets.length) return; if (!targets.length) return;
if (targets.length > 1) { if (targets.length > 1) {
@@ -1471,6 +1474,10 @@ function updateTreeClipboardForNodes(nodes: TreeNode[]) {
connectionStore.treeClipboard = null; connectionStore.treeClipboard = null;
return; return;
} }
if (tableNodes.some((node) => databaseTypeForNode(node) === "victoriametrics")) {
connectionStore.treeClipboard = null;
return;
}
connectionStore.treeClipboard = { connectionStore.treeClipboard = {
kind: "table-copy", kind: "table-copy",
tables: tableNodes.map((node) => ({ tables: tableNodes.map((node) => ({
@@ -3083,6 +3090,7 @@ async function confirmDropSchema() {
function duplicateStructure(source: TreeNode = activeNode.value) { function duplicateStructure(source: TreeNode = activeNode.value) {
if (!isDuplicateStructureSource(source)) return; if (!isDuplicateStructureSource(source)) return;
if (databaseTypeForNode(source) === "victoriametrics") return;
duplicateStructureSource.value = source; duplicateStructureSource.value = source;
duplicateTableName.value = `${source.label}_copy`; duplicateTableName.value = `${source.label}_copy`;
showDuplicateDialog.value = true; showDuplicateDialog.value = true;
@@ -3096,6 +3104,7 @@ async function confirmDuplicateStructure() {
const node = duplicateStructureSource.value || (isDuplicateStructureSource(activeNode.value) ? activeNode.value : null); const node = duplicateStructureSource.value || (isDuplicateStructureSource(activeNode.value) ? activeNode.value : null);
const newName = duplicateTableName.value.trim(); const newName = duplicateTableName.value.trim();
if (!newName || !node) return; if (!newName || !node) return;
if (databaseTypeForNode(node) === "victoriametrics") return;
showDuplicateDialog.value = false; showDuplicateDialog.value = false;
try { try {
await connectionStore.ensureConnected(node.connectionId); await connectionStore.ensureConnected(node.connectionId);
@@ -3840,16 +3849,17 @@ const shortcutRefresh = "F5";
const shortcutDelete = "Delete"; const shortcutDelete = "Delete";
function exportDataSubmenu(): ContextMenuItem { function exportDataSubmenu(includeSqlInsert = true): ContextMenuItem {
const children: ContextMenuItem[] = [
{ label: "CSV", action: () => exportData("csv") },
{ label: "JSON", action: () => exportData("json") },
];
if (includeSqlInsert) children.push({ label: "SQL INSERT", action: () => exportData("sql") });
children.push({ label: "XLSX", action: () => exportDataXlsx() });
return { return {
label: t("contextMenu.exportData"), label: t("contextMenu.exportData"),
icon: Upload, icon: Upload,
children: [ children,
{ label: "CSV", action: () => exportData("csv") },
{ label: "JSON", action: () => exportData("json") },
{ label: "SQL INSERT", action: () => exportData("sql") },
{ label: "XLSX", action: () => exportDataXlsx() },
],
}; };
} }
@@ -4349,6 +4359,17 @@ function buildObjectSidebarMenu(context: SidebarMenuFactoryContext): boolean {
const { node, items, deleteMenuLabel, deleteMenuAction, truncateMenuLabel, truncateMenuAction, emptyMenuLabel, emptyMenuAction } = context; const { node, items, deleteMenuLabel, deleteMenuAction, truncateMenuLabel, truncateMenuAction, emptyMenuLabel, emptyMenuAction } = context;
// 6. Table / View / Materialized View // 6. Table / View / Materialized View
if (node.type === "table" || node.type === "view" || node.type === "materialized_view") { if (node.type === "table" || node.type === "view" || node.type === "materialized_view") {
if (currentDatabaseType() === "victoriametrics" && node.type === "table") {
items.push({ label: t("contextMenu.copyName"), action: copyName, icon: Copy, shortcut: shortcutCopyName.value });
items.push({ label: "", separator: true });
items.push({ label: t("contextMenu.viewData"), action: openDataImmediately, icon: TableProperties });
items.push({ label: t("contextMenu.openInNewDataTab"), action: openDataInNewTabImmediately, icon: CopyPlus });
items.push({ label: t("contextMenu.newQuery"), action: newQuery, icon: TerminalSquare });
items.push({ label: "", separator: true });
items.push(exportDataSubmenu(false));
items.push({ label: t("contextMenu.refreshChildren"), action: refresh, icon: RefreshCw, shortcut: shortcutRefresh });
return true;
}
const destructiveActions: ContextMenuItem[] = []; const destructiveActions: ContextMenuItem[] = [];
items.push({ label: t("contextMenu.copyName"), action: copyName, icon: Copy, shortcut: shortcutCopyName.value }); items.push({ label: t("contextMenu.copyName"), action: copyName, icon: Copy, shortcut: shortcutCopyName.value });
items.push({ label: "", separator: true }); items.push({ label: "", separator: true });
@@ -4568,6 +4589,7 @@ function buildObjectSidebarMenu(context: SidebarMenuFactoryContext): boolean {
} }
function treeTableClipboardMenuItems(node: TreeNode): ContextMenuItem[] { function treeTableClipboardMenuItems(node: TreeNode): ContextMenuItem[] {
if (currentDatabaseType() === "victoriametrics") return [];
const copyItem: ContextMenuItem = { label: t("contextMenu.copyTable"), action: copySelectedNames, icon: Copy }; const copyItem: ContextMenuItem = { label: t("contextMenu.copyTable"), action: copySelectedNames, icon: Copy };
if (!node.connectionId || !node.database) return [copyItem]; if (!node.connectionId || !node.database) return [copyItem];
const state = tableClipboardMenuState( const state = tableClipboardMenuState(
+1 -1
View File
@@ -18,7 +18,7 @@ const QUICK_OPEN_MAX_RESULTS = 200;
const INITIAL_SQL_LIBRARY_LIMIT = 20; const INITIAL_SQL_LIBRARY_LIMIT = 20;
const INITIAL_SQL_FILE_LIMIT = 20; const INITIAL_SQL_FILE_LIMIT = 20;
const REMOTE_SEARCH_UNSUPPORTED_TYPES = new Set<ConnectionConfig["db_type"]>(["redis", "mongodb", "elasticsearch", "easysearch", "qdrant", "milvus", "weaviate", "chromadb", "neo4j", "influxdb", "etcd", "zookeeper", "mq", "nacos"]); const REMOTE_SEARCH_UNSUPPORTED_TYPES = new Set<ConnectionConfig["db_type"]>(["redis", "mongodb", "elasticsearch", "easysearch", "qdrant", "milvus", "weaviate", "chromadb", "neo4j", "influxdb", "victoriametrics", "etcd", "zookeeper", "mq", "nacos"]);
export interface QuickOpenItem { export interface QuickOpenItem {
id: string; id: string;
@@ -258,6 +258,26 @@ export function useSidebarTreeExportRuntime(options: SidebarTreeExportRuntimeOpt
await connectionStore.ensureConnected(connectionId); await connectionStore.ensureConnected(connectionId);
task = addExportTask(node.label, format, outputPath); task = addExportTask(node.label, format, outputPath);
const currentTask = task; const currentTask = task;
const effectiveDbType = effectiveDatabaseTypeForConnection(config);
if (effectiveDbType === "victoriametrics") {
const result = await fetchTableDataForExport({
databaseType: effectiveDbType,
schema: node.schema,
tableName: node.label,
tableType: node.tableType,
executePage: (sql) => api.executeQuery(connectionId, database, sql),
});
if (format === "csv") {
await api.exportQueryResultCsv(outputPath, result.columns, result.rows);
} else {
await api.exportQueryResultXlsx(outputPath, node.label, result.columns, result.column_types ?? result.columns.map(() => ""), undefined, result.rows);
}
currentTask.status = "Done";
currentTask.rowsExported = result.rows.length;
currentTask.totalRows = result.rows.length;
toast(t("grid.exported"));
return;
}
const queryColumns = config.db_type === "neo4j" ? (await api.getColumns(connectionId, database, node.schema || database, node.label)).map((column) => column.name) : undefined; const queryColumns = config.db_type === "neo4j" ? (await api.getColumns(connectionId, database, node.schema || database, node.label)).map((column) => column.name) : undefined;
const rowLimit = settingsStore.editorSettings.exportRowLimitEnabled ? settingsStore.editorSettings.exportRowLimit : null; const rowLimit = settingsStore.editorSettings.exportRowLimitEnabled ? settingsStore.editorSettings.exportRowLimit : null;
const request: api.TableExportRequest = { const request: api.TableExportRequest = {
@@ -366,7 +366,7 @@ export function useSqlExecution(deps: {
export function supportsSqlTemplateParameters(connection: Pick<ConnectionConfig, "db_type"> | undefined, sql = ""): boolean { export function supportsSqlTemplateParameters(connection: Pick<ConnectionConfig, "db_type"> | undefined, sql = ""): boolean {
if (!connection) return false; if (!connection) return false;
if (connection.db_type === "elasticsearch" || connection.db_type === "easysearch") return !isElasticsearchRestRequestText(sql); if (connection.db_type === "elasticsearch" || connection.db_type === "easysearch") return !isElasticsearchRestRequestText(sql);
return connection.db_type !== "redis" && connection.db_type !== "mongodb"; return connection.db_type !== "redis" && connection.db_type !== "mongodb" && connection.db_type !== "victoriametrics";
} }
export function requiresDatabaseSelection(tab: QueryTab, connection: ConnectionConfig | undefined, _sql = ""): boolean { export function requiresDatabaseSelection(tab: QueryTab, connection: ConnectionConfig | undefined, _sql = ""): boolean {
+8
View File
@@ -243,6 +243,12 @@ export default {
elasticsearchConnectivityCheckPath: "Connectivity Path", elasticsearchConnectivityCheckPath: "Connectivity Path",
elasticsearchConnectivityCheckPathPlaceholder: "/ or /my-index/_search", elasticsearchConnectivityCheckPathPlaceholder: "/ or /my-index/_search",
version: "Version", version: "Version",
victoriametricsApiPath: "API Path",
victoriametricsApiPathHint: "Use /prometheus for single-node deployments, or /select/tenantID/prometheus for clusters.",
victoriametricsLookback: "Metadata Lookback",
victoriametricsLookbackHint: "Used for metric discovery and label columns, for example 1h or 7d. Metric previews use 1h and remain editable.",
victoriametricsInvalidApiPath: "The VictoriaMetrics API path must be empty or start with /.",
victoriametricsInvalidLookback: "Invalid VictoriaMetrics lookback. Use a value such as 15m, 1h, or 7d.",
driverInstallHintPrefix: "Install the required driver from ", driverInstallHintPrefix: "Install the required driver from ",
driverInstallHintSuffix: " in the top toolbar before connecting.", driverInstallHintSuffix: " in the top toolbar before connecting.",
driverName: "Driver Name", driverName: "Driver Name",
@@ -1562,6 +1568,7 @@ export default {
}, },
sortUnsupported: "This SQL does not support full-result sorting. Try again with a single SELECT query.", sortUnsupported: "This SQL does not support full-result sorting. Try again with a single SELECT query.",
truncatedHint: "Results were truncated after loading {count} rows. Use the footer pagination to browse loaded data; exporting the full result reruns the database query.", truncatedHint: "Results were truncated after loading {count} rows. Use the footer pagination to browse loaded data; exporting the full result reruns the database query.",
victoriaMetricsTruncatedHint: "Results exceeded the loading limit, so only the first {count} rows were loaded. Rows per page only paginates loaded data; shorten the time range or add filters to retrieve a complete result.",
}, },
exportProgress: { exportProgress: {
streamingUnsupported: "Streaming export is unsupported for this query. Simplify it or use a supported driver.", streamingUnsupported: "Streaming export is unsupported for this query. Simplify it or use a supported driver.",
@@ -2719,6 +2726,7 @@ export default {
name: "Name", name: "Name",
type: "Type", type: "Type",
rows: "Rows", rows: "Rows",
series: "Series",
size: "Size", size: "Size",
statisticsHint: "Estimated from database statistics; no COUNT(*) is executed.", statisticsHint: "Estimated from database statistics; no COUNT(*) is executed.",
createdAt: "Created", createdAt: "Created",
+8
View File
@@ -239,6 +239,12 @@ export default withEnglishFallback({
oracleTnsAdminRequired: "El modo Oracle TNS requiere el directorio TNS_ADMIN que contiene tnsnames.ora.", oracleTnsAdminRequired: "El modo Oracle TNS requiere el directorio TNS_ADMIN que contiene tnsnames.ora.",
oracleTnsTransportUnsupported: "Oracle TNS no se puede combinar con túneles SSH, proxy o HTTP. Elimine la capa de transporte o use Servicio/SID.", oracleTnsTransportUnsupported: "Oracle TNS no se puede combinar con túneles SSH, proxy o HTTP. Elimine la capa de transporte o use Servicio/SID.",
version: "Versión", version: "Versión",
victoriametricsApiPath: "Ruta de la API",
victoriametricsApiPathHint: "Use /prometheus para implementaciones de nodo único o /select/tenantID/prometheus para clústeres.",
victoriametricsLookback: "Intervalo retrospectivo de metadatos",
victoriametricsLookbackHint: "Se usa para descubrir métricas y columnas de etiquetas, por ejemplo, 1h o 7d. Las vistas previas de métricas usan 1h y se pueden editar.",
victoriametricsInvalidApiPath: "La ruta de la API de VictoriaMetrics debe estar vacía o comenzar por /.",
victoriametricsInvalidLookback: "El intervalo retrospectivo de VictoriaMetrics no es válido. Use un valor como 15m, 1h o 7d.",
driverInstallHintPrefix: "Instala el driver requerido desde ", driverInstallHintPrefix: "Instala el driver requerido desde ",
driverInstallHintSuffix: " en la barra superior antes de conectar.", driverInstallHintSuffix: " en la barra superior antes de conectar.",
driverName: "Nombre del driver", driverName: "Nombre del driver",
@@ -1440,6 +1446,7 @@ export default withEnglishFallback({
}, },
sortUnsupported: "Este SQL no admite ordenamiento del resultado completo. Intenta con una consulta SELECT simple.", sortUnsupported: "Este SQL no admite ordenamiento del resultado completo. Intenta con una consulta SELECT simple.",
truncatedHint: "Los resultados se truncaron después de cargar {count} filas. Usa la paginación inferior para explorar los datos cargados; al exportar el resultado completo se vuelve a consultar la base de datos.", truncatedHint: "Los resultados se truncaron después de cargar {count} filas. Usa la paginación inferior para explorar los datos cargados; al exportar el resultado completo se vuelve a consultar la base de datos.",
victoriaMetricsTruncatedHint: "Los resultados superaron el límite de carga, por lo que solo se cargaron las primeras {count} filas. Las filas por página solo paginan los datos cargados; reduce el intervalo de tiempo o añade filtros para obtener el resultado completo.",
filterBuilderSearchColumns: "Buscar columnas...", filterBuilderSearchColumns: "Buscar columnas...",
filterBuilderNoMatchingColumns: "Sin columnas coincidentes", filterBuilderNoMatchingColumns: "Sin columnas coincidentes",
copyExtractorSmart: "Copia inteligente", copyExtractorSmart: "Copia inteligente",
@@ -2571,6 +2578,7 @@ export default withEnglishFallback({
name: "Nombre", name: "Nombre",
type: "Tipo", type: "Tipo",
rows: "Filas", rows: "Filas",
series: "Series",
size: "Tamaño", size: "Tamaño",
statisticsHint: "Estimado desde estadísticas de la base de datos; no se ejecuta COUNT(*).", statisticsHint: "Estimado desde estadísticas de la base de datos; no se ejecuta COUNT(*).",
createdAt: "Creado", createdAt: "Creado",
+8
View File
@@ -238,6 +238,12 @@ export default withEnglishFallback({
oracleTnsAdminRequired: "La modalità Oracle TNS richiede la directory TNS_ADMIN contenente tnsnames.ora.", oracleTnsAdminRequired: "La modalità Oracle TNS richiede la directory TNS_ADMIN contenente tnsnames.ora.",
oracleTnsTransportUnsupported: "Oracle TNS non può usare tunnel SSH, proxy o HTTP. Rimuovi il livello di trasporto o usa Servizio/SID.", oracleTnsTransportUnsupported: "Oracle TNS non può usare tunnel SSH, proxy o HTTP. Rimuovi il livello di trasporto o usa Servizio/SID.",
version: "Versione", version: "Versione",
victoriametricsApiPath: "Percorso API",
victoriametricsApiPathHint: "Usa /prometheus per le installazioni a nodo singolo oppure /select/tenantID/prometheus per i cluster.",
victoriametricsLookback: "Intervallo metadati",
victoriametricsLookbackHint: "Usato per rilevare metriche e colonne delle etichette, ad esempio 1h o 7d. Le anteprime delle metriche usano 1h e restano modificabili.",
victoriametricsInvalidApiPath: "Il percorso API di VictoriaMetrics deve essere vuoto o iniziare con /.",
victoriametricsInvalidLookback: "Intervallo VictoriaMetrics non valido. Usa un valore come 15m, 1h o 7d.",
driverInstallHintPrefix: "Installa il driver richiesto da ", driverInstallHintPrefix: "Installa il driver richiesto da ",
driverInstallHintSuffix: " nella barra degli strumenti superiore prima di connetterti.", driverInstallHintSuffix: " nella barra degli strumenti superiore prima di connetterti.",
driverName: "Nome Driver", driverName: "Nome Driver",
@@ -1438,6 +1444,7 @@ export default withEnglishFallback({
}, },
sortUnsupported: "Questo SQL non supporta l'ordinamento sull'intero risultato. Riprova con una query SELECT semplice.", sortUnsupported: "Questo SQL non supporta l'ordinamento sull'intero risultato. Riprova con una query SELECT semplice.",
truncatedHint: "I risultati sono stati troncati dopo il caricamento di {count} righe. Usa la paginazione in basso per consultare i dati caricati; l'esportazione del risultato completo riesegue la query sul database.", truncatedHint: "I risultati sono stati troncati dopo il caricamento di {count} righe. Usa la paginazione in basso per consultare i dati caricati; l'esportazione del risultato completo riesegue la query sul database.",
victoriaMetricsTruncatedHint: "I risultati hanno superato il limite di caricamento, quindi sono state caricate solo le prime {count} righe. Le righe per pagina suddividono solo i dati caricati; riduci l'intervallo di tempo o aggiungi filtri per ottenere il risultato completo.",
filterBuilderSearchColumns: "Cerca campi...", filterBuilderSearchColumns: "Cerca campi...",
filterBuilderNoMatchingColumns: "Nessun campo corrispondente", filterBuilderNoMatchingColumns: "Nessun campo corrispondente",
copyExtractorSmart: "Copia intelligente", copyExtractorSmart: "Copia intelligente",
@@ -2569,6 +2576,7 @@ export default withEnglishFallback({
name: "Nome", name: "Nome",
type: "Tipo", type: "Tipo",
rows: "Righe", rows: "Righe",
series: "Serie",
size: "Dimensione", size: "Dimensione",
statisticsHint: "Stimato dalle statistiche del database; COUNT(*) non viene eseguito.", statisticsHint: "Stimato dalle statistiche del database; COUNT(*) non viene eseguito.",
createdAt: "Creato", createdAt: "Creato",
+8
View File
@@ -238,6 +238,12 @@ export default withEnglishFallback({
oracleTnsAdminRequired: "Oracle TNS モードでは tnsnames.ora を含む TNS_ADMIN ディレクトリが必要です。", oracleTnsAdminRequired: "Oracle TNS モードでは tnsnames.ora を含む TNS_ADMIN ディレクトリが必要です。",
oracleTnsTransportUnsupported: "Oracle TNS 接続は SSH、プロキシ、HTTP トンネルと併用できません。トランスポート層を削除するか、サービス名/SID モードを使用してください。", oracleTnsTransportUnsupported: "Oracle TNS 接続は SSH、プロキシ、HTTP トンネルと併用できません。トランスポート層を削除するか、サービス名/SID モードを使用してください。",
version: "バージョン", version: "バージョン",
victoriametricsApiPath: "APIパス",
victoriametricsApiPathHint: "単一ノード構成では /prometheus、クラスター構成では /select/tenantID/prometheus を使用します。",
victoriametricsLookback: "メタデータ参照範囲",
victoriametricsLookbackHint: "メトリクスとラベル列の検出に使用します(例: 1h、7d)。メトリクスのプレビューには 1h を使用し、クエリは編集できます。",
victoriametricsInvalidApiPath: "VictoriaMetrics の API パスは空にするか、/ で始める必要があります。",
victoriametricsInvalidLookback: "VictoriaMetrics の参照範囲が無効です。15m、1h、7d などの値を使用してください。",
driverInstallHintPrefix: "接続前に上部ツールバーの", driverInstallHintPrefix: "接続前に上部ツールバーの",
driverInstallHintSuffix: "から必要なドライバーをインストールしてください。", driverInstallHintSuffix: "から必要なドライバーをインストールしてください。",
driverName: "ドライバー名", driverName: "ドライバー名",
@@ -1454,6 +1460,7 @@ export default withEnglishFallback({
}, },
sortUnsupported: "このSQLは完全な結果の並び替えをサポートしていません。単一のSELECTクエリで再試行してください。", sortUnsupported: "このSQLは完全な結果の並び替えをサポートしていません。単一のSELECTクエリで再試行してください。",
truncatedHint: "結果は{count}行を読み込んだ時点で切り詰められました。フッターのページネーションで読み込み済みデータを参照できます。完全な結果のエクスポート時はデータベースへ再問い合わせします。", truncatedHint: "結果は{count}行を読み込んだ時点で切り詰められました。フッターのページネーションで読み込み済みデータを参照できます。完全な結果のエクスポート時はデータベースへ再問い合わせします。",
victoriaMetricsTruncatedHint: "結果が読み込み上限を超えたため、先頭の{count}行のみ読み込みました。1ページあたりの行数は読み込み済みデータだけをページ分割します。完全な結果を取得するには、時間範囲を短くするかフィルターを追加してください。",
loadingMore: "さらにデータを読み込み中...", loadingMore: "さらにデータを読み込み中...",
allLoaded: "すべて読み込み済み", allLoaded: "すべて読み込み済み",
previewSqlEmpty: "プレビューする保留中のSQL変更はありません", previewSqlEmpty: "プレビューする保留中のSQL変更はありません",
@@ -2630,6 +2637,7 @@ export default withEnglishFallback({
name: "名前", name: "名前",
type: "タイプ", type: "タイプ",
rows: "行数", rows: "行数",
series: "系列数",
size: "サイズ", size: "サイズ",
statisticsHint: "データベース統計からの推定値です。COUNT(*) は実行しません。", statisticsHint: "データベース統計からの推定値です。COUNT(*) は実行しません。",
createdAt: "作成日時", createdAt: "作成日時",
+8
View File
@@ -239,6 +239,12 @@ export default withEnglishFallback({
elasticsearchConnectivityCheckPath: "연결 확인 경로", elasticsearchConnectivityCheckPath: "연결 확인 경로",
elasticsearchConnectivityCheckPathPlaceholder: "/ 또는 /my-index/_search", elasticsearchConnectivityCheckPathPlaceholder: "/ 또는 /my-index/_search",
version: "버전", version: "버전",
victoriametricsApiPath: "API 경로",
victoriametricsApiPathHint: "단일 노드 배포에는 /prometheus를, 클러스터에는 /select/tenantID/prometheus를 사용하세요.",
victoriametricsLookback: "메타데이터 조회 범위",
victoriametricsLookbackHint: "메트릭 및 레이블 열 검색에 사용합니다(예: 1h 또는 7d). 메트릭 미리보기는 1h를 사용하며 쿼리를 편집할 수 있습니다.",
victoriametricsInvalidApiPath: "VictoriaMetrics API 경로는 비워 두거나 /로 시작해야 합니다.",
victoriametricsInvalidLookback: "VictoriaMetrics 조회 범위가 올바르지 않습니다. 15m, 1h 또는 7d와 같은 값을 사용하세요.",
driverInstallHintPrefix: "연결 전에 상단 도구 모음의 ", driverInstallHintPrefix: "연결 전에 상단 도구 모음의 ",
driverInstallHintSuffix: "에서 필수 드라이버를 설치하세요.", driverInstallHintSuffix: "에서 필수 드라이버를 설치하세요.",
driverName: "드라이버 이름", driverName: "드라이버 이름",
@@ -1457,6 +1463,7 @@ export default withEnglishFallback({
}, },
sortUnsupported: "이 SQL은 전체 결과 정렬을 지원하지 않습니다. 단일 SELECT 쿼리로 다시 시도하세요.", sortUnsupported: "이 SQL은 전체 결과 정렬을 지원하지 않습니다. 단일 SELECT 쿼리로 다시 시도하세요.",
truncatedHint: "{count}행 로드 후 결과가 잘렸습니다. 로드된 데이터를 탐색하려면 푸터 페이지 매김을 사용하세요. 전체 결과를 내보내면 데이터베이스 쿼리를 다시 실행합니다.", truncatedHint: "{count}행 로드 후 결과가 잘렸습니다. 로드된 데이터를 탐색하려면 푸터 페이지 매김을 사용하세요. 전체 결과를 내보내면 데이터베이스 쿼리를 다시 실행합니다.",
victoriaMetricsTruncatedHint: "결과가 로드 한도를 초과하여 처음 {count}행만 로드했습니다. 페이지당 행 수는 로드된 데이터만 나눠 표시합니다. 전체 결과를 가져오려면 시간 범위를 줄이거나 필터를 추가하세요.",
}, },
exportProgress: { exportProgress: {
streamingUnsupported: "이 쿼리는 스트리밍 내보내기를 지원하지 않습니다. 쿼리를 단순화하거나 지원되는 드라이버를 사용하세요.", streamingUnsupported: "이 쿼리는 스트리밍 내보내기를 지원하지 않습니다. 쿼리를 단순화하거나 지원되는 드라이버를 사용하세요.",
@@ -2600,6 +2607,7 @@ export default withEnglishFallback({
name: "이름", name: "이름",
type: "유형", type: "유형",
rows: "행", rows: "행",
series: "시계열 수",
size: "크기", size: "크기",
statisticsHint: "데이터베이스 통계에서 추정한 값이며, COUNT(*)는 실행되지 않습니다.", statisticsHint: "데이터베이스 통계에서 추정한 값이며, COUNT(*)는 실행되지 않습니다.",
createdAt: "생성일", createdAt: "생성일",
+8
View File
@@ -239,6 +239,12 @@ export default withEnglishFallback({
oracleTnsAdminRequired: "O modo Oracle TNS requer o diretório TNS_ADMIN que contém tnsnames.ora.", oracleTnsAdminRequired: "O modo Oracle TNS requer o diretório TNS_ADMIN que contém tnsnames.ora.",
oracleTnsTransportUnsupported: "Oracle TNS não pode usar túneis SSH, proxy ou HTTP. Remova a camada de transporte ou use Serviço/SID.", oracleTnsTransportUnsupported: "Oracle TNS não pode usar túneis SSH, proxy ou HTTP. Remova a camada de transporte ou use Serviço/SID.",
version: "Versão", version: "Versão",
victoriametricsApiPath: "Caminho da API",
victoriametricsApiPathHint: "Use /prometheus para implantações de nó único ou /select/tenantID/prometheus para clusters.",
victoriametricsLookback: "Intervalo de consulta de metadados",
victoriametricsLookbackHint: "Usado para descobrir métricas e colunas de rótulos, por exemplo, 1h ou 7d. As visualizações de métricas usam 1h e podem ser editadas.",
victoriametricsInvalidApiPath: "O caminho da API do VictoriaMetrics deve estar vazio ou começar com /.",
victoriametricsInvalidLookback: "O intervalo de consulta do VictoriaMetrics é inválido. Use um valor como 15m, 1h ou 7d.",
driverInstallHintPrefix: "Instale o driver necessário em ", driverInstallHintPrefix: "Instale o driver necessário em ",
driverInstallHintSuffix: " na barra de ferramentas superior antes de conectar.", driverInstallHintSuffix: " na barra de ferramentas superior antes de conectar.",
driverName: "Nome do Driver", driverName: "Nome do Driver",
@@ -1440,6 +1446,7 @@ export default withEnglishFallback({
}, },
sortUnsupported: "Este SQL não suporta a ordenação do resultado completo. Tente novamente com uma única consulta SELECT.", sortUnsupported: "Este SQL não suporta a ordenação do resultado completo. Tente novamente com uma única consulta SELECT.",
truncatedHint: "Os resultados foram truncados após carregar {count} linhas. Use a paginação no rodapé para navegar pelos dados carregados; exportar o resultado completo executa novamente a consulta no banco de dados.", truncatedHint: "Os resultados foram truncados após carregar {count} linhas. Use a paginação no rodapé para navegar pelos dados carregados; exportar o resultado completo executa novamente a consulta no banco de dados.",
victoriaMetricsTruncatedHint: "Os resultados excederam o limite de carregamento, então apenas as primeiras {count} linhas foram carregadas. As linhas por página paginam somente os dados carregados; reduza o intervalo de tempo ou adicione filtros para obter o resultado completo.",
filterBuilderSearchColumns: "Pesquisar campos...", filterBuilderSearchColumns: "Pesquisar campos...",
filterBuilderNoMatchingColumns: "Nenhum campo correspondente", filterBuilderNoMatchingColumns: "Nenhum campo correspondente",
copyExtractorSmart: "Cópia inteligente", copyExtractorSmart: "Cópia inteligente",
@@ -2571,6 +2578,7 @@ export default withEnglishFallback({
name: "Nome", name: "Nome",
type: "Tipo", type: "Tipo",
rows: "Linhas", rows: "Linhas",
series: "Séries",
size: "Tamanho", size: "Tamanho",
statisticsHint: "Estimado pelas estatísticas do banco de dados; COUNT(*) não é executado.", statisticsHint: "Estimado pelas estatísticas do banco de dados; COUNT(*) não é executado.",
createdAt: "Criado em", createdAt: "Criado em",
+8
View File
@@ -245,6 +245,12 @@ export default withEnglishFallback({
elasticsearchConnectivityCheckPath: "连通性检查路径", elasticsearchConnectivityCheckPath: "连通性检查路径",
elasticsearchConnectivityCheckPathPlaceholder: "/ 或 /my-index/_search", elasticsearchConnectivityCheckPathPlaceholder: "/ 或 /my-index/_search",
version: "版本", version: "版本",
victoriametricsApiPath: "API 路径",
victoriametricsApiPathHint: "单机版通常为 /prometheus;集群版可填写 /select/租户ID/prometheus。",
victoriametricsLookback: "元数据回看范围",
victoriametricsLookbackHint: "用于指标列表和标签列,例如 1h、7d。双击指标默认预览 1h,并可直接修改查询。",
victoriametricsInvalidApiPath: "VictoriaMetrics API 路径必须为空或以 / 开头。",
victoriametricsInvalidLookback: "VictoriaMetrics 回看范围格式无效,请使用 15m、1h、7d 等格式。",
driverInstallHintPrefix: "需要在顶部导航栏「", driverInstallHintPrefix: "需要在顶部导航栏「",
driverInstallHintSuffix: "」中安装对应的驱动才能连接。", driverInstallHintSuffix: "」中安装对应的驱动才能连接。",
driverName: "驱动名称", driverName: "驱动名称",
@@ -1563,6 +1569,7 @@ export default withEnglishFallback({
}, },
sortUnsupported: "当前 SQL 不支持全量排序,请改为单条 SELECT 查询后再尝试。", sortUnsupported: "当前 SQL 不支持全量排序,请改为单条 SELECT 查询后再尝试。",
truncatedHint: "结果已截断,已加载前 {count} 行。可通过底部分页浏览已加载数据;导出完整结果时会重新查询数据库。", truncatedHint: "结果已截断,已加载前 {count} 行。可通过底部分页浏览已加载数据;导出完整结果时会重新查询数据库。",
victoriaMetricsTruncatedHint: "结果超过加载上限,仅加载前 {count} 行。右下角每页行数只调整已加载数据的分页显示;请缩短查询时间范围或增加筛选条件以获取完整结果。",
}, },
exportProgress: { exportProgress: {
streamingUnsupported: "当前查询暂不支持流式导出,请简化查询或使用受支持的驱动。", streamingUnsupported: "当前查询暂不支持流式导出,请简化查询或使用受支持的驱动。",
@@ -2719,6 +2726,7 @@ export default withEnglishFallback({
name: "名称", name: "名称",
type: "类型", type: "类型",
rows: "行数", rows: "行数",
series: "序列数",
size: "大小", size: "大小",
statisticsHint: "来自数据库统计信息的估算值,不执行 COUNT(*)。", statisticsHint: "来自数据库统计信息的估算值,不执行 COUNT(*)。",
createdAt: "创建时间", createdAt: "创建时间",
+8
View File
@@ -239,6 +239,12 @@ export default withEnglishFallback({
oracleTnsAdminRequired: "Oracle TNS 模式需要填寫包含 tnsnames.ora 的 TNS_ADMIN 目錄。", oracleTnsAdminRequired: "Oracle TNS 模式需要填寫包含 tnsnames.ora 的 TNS_ADMIN 目錄。",
oracleTnsTransportUnsupported: "Oracle TNS 連線不能與 SSH、代理或 HTTP Tunnel 組合使用。請移除傳輸層,或改用服務名稱/SID 模式。", oracleTnsTransportUnsupported: "Oracle TNS 連線不能與 SSH、代理或 HTTP Tunnel 組合使用。請移除傳輸層,或改用服務名稱/SID 模式。",
version: "版本", version: "版本",
victoriametricsApiPath: "API 路徑",
victoriametricsApiPathHint: "單機版通常使用 /prometheus;叢集版可填寫 /select/tenantID/prometheus。",
victoriametricsLookback: "中繼資料回看範圍",
victoriametricsLookbackHint: "用於探索指標與標籤欄位,例如 1h 或 7d。指標預覽使用 1h,且查詢內容可直接修改。",
victoriametricsInvalidApiPath: "VictoriaMetrics API 路徑必須為空或以 / 開頭。",
victoriametricsInvalidLookback: "VictoriaMetrics 回看範圍格式無效,請使用 15m、1h 或 7d 等格式。",
driverInstallHintPrefix: "需要在上方導覽列「", driverInstallHintPrefix: "需要在上方導覽列「",
driverInstallHintSuffix: "」中安裝對應的驅動程式才能連線。", driverInstallHintSuffix: "」中安裝對應的驅動程式才能連線。",
driverName: "驅動程式名稱", driverName: "驅動程式名稱",
@@ -1439,6 +1445,7 @@ export default withEnglishFallback({
}, },
sortUnsupported: "目前 SQL 不支援完整排序,請改為單條 SELECT 查詢後再嘗試。", sortUnsupported: "目前 SQL 不支援完整排序,請改為單條 SELECT 查詢後再嘗試。",
truncatedHint: "結果已截斷,已載入前 {count} 筆。可透過底部分頁瀏覽已載入資料;匯出完整結果時會重新查詢資料庫。", truncatedHint: "結果已截斷,已載入前 {count} 筆。可透過底部分頁瀏覽已載入資料;匯出完整結果時會重新查詢資料庫。",
victoriaMetricsTruncatedHint: "結果超過載入上限,僅載入前 {count} 筆。右下角每頁筆數只調整已載入資料的分頁顯示;請縮短查詢時間範圍或增加篩選條件以取得完整結果。",
filterBuilderSearchColumns: "搜尋欄位...", filterBuilderSearchColumns: "搜尋欄位...",
filterBuilderNoMatchingColumns: "沒有匹配的欄位", filterBuilderNoMatchingColumns: "沒有匹配的欄位",
copyExtractorSmart: "智慧複製", copyExtractorSmart: "智慧複製",
@@ -2440,6 +2447,7 @@ export default withEnglishFallback({
name: "名稱", name: "名稱",
type: "類型", type: "類型",
rows: "列數", rows: "列數",
series: "序列數",
size: "大小", size: "大小",
statisticsHint: "來自資料庫統計資訊的估算值,不執行 COUNT(*)。", statisticsHint: "來自資料庫統計資訊的估算值,不執行 COUNT(*)。",
createdAt: "建立時間", createdAt: "建立時間",
@@ -2,10 +2,11 @@ import { readFileSync } from "node:fs";
import { describe, expect, it } from "vitest"; import { describe, expect, it } from "vitest";
const dialogSource = readFileSync(new URL("../../../components/connection/ConnectionDialog.vue", import.meta.url), "utf8"); const dialogSource = readFileSync(new URL("../../../components/connection/ConnectionDialog.vue", import.meta.url), "utf8");
const tlsCapableDatabaseTypesSource = dialogSource.match(/const tlsCapableDatabaseTypes = new Set<DatabaseType>\(\[([\s\S]*?)\]\);/)?.[1] ?? "";
describe("Dameng SSL connection form", () => { describe("Dameng SSL connection form", () => {
it("shows Dameng in the TLS tab with certificate directory and password fields", () => { it("shows Dameng in the TLS tab with certificate directory and password fields", () => {
expect(dialogSource).toContain('"questdb", "dameng", "redis"'); expect(tlsCapableDatabaseTypesSource).toContain('"dameng"');
expect(dialogSource).toContain("<template v-if=\"form.db_type === 'dameng'\">"); expect(dialogSource).toContain("<template v-if=\"form.db_type === 'dameng'\">");
expect(dialogSource).toContain('v-model="damengSslFilesPath"'); expect(dialogSource).toContain('v-model="damengSslFilesPath"');
expect(dialogSource).toContain('v-model="damengSslKeystorePassword"'); expect(dialogSource).toContain('v-model="damengSslKeystorePassword"');
@@ -0,0 +1,38 @@
import { describe, expect, it } from "vitest";
import { applyParsedConnectionUrl, parseConnectionUrl } from "@/lib/connection/connectionUrl";
import type { ConnectionConfig } from "@/types/database";
describe("VictoriaMetrics connection URL", () => {
it("parses single-node HTTP URLs with Basic Auth", () => {
expect(parseConnectionUrl("http://vm_user:secret@vm.example.com:8428/prometheus", "victoriametrics")).toMatchObject({
dbType: "victoriametrics",
host: "vm.example.com",
port: 8428,
username: "vm_user",
password: "secret",
database: "metrics",
apiPath: "/prometheus",
ssl: false,
});
});
it("preserves cluster tenant API paths in external config", () => {
const parsed = parseConnectionUrl("https://vm.example.com/select/42/prometheus", "victoriametrics");
const config = applyParsedConnectionUrl(
{
db_type: "victoriametrics",
name: "VictoriaMetrics",
host: "",
port: 8428,
username: "",
password: "",
ssl: false,
external_config: { lookback: "7d" },
} as Omit<ConnectionConfig, "id">,
parsed,
);
expect(config.ssl).toBe(true);
expect(config.external_config).toEqual({ lookback: "7d", apiPath: "/select/42/prometheus" });
});
});
@@ -0,0 +1,12 @@
import { describe, expect, it } from "vitest";
import { filterModeIsSupportedForDatabase } from "@/lib/dataGrid/dataGridColumnFilter";
import type { DataGridContextFilterMode } from "@/lib/dataGrid/dataGridSql";
describe("VictoriaMetrics data grid filters", () => {
it("does not expose SQL filter modes for MetricsQL results", () => {
const modes: DataGridContextFilterMode[] = ["equals", "not-equals", "is-null", "is-not-null", "like", "not-like", "less-than", "greater-than", "in", "not-in", "between", "not-between"];
expect(modes.every((mode) => !filterModeIsSupportedForDatabase(mode, "victoriametrics"))).toBe(true);
expect(filterModeIsSupportedForDatabase("equals", "postgres")).toBe(true);
});
});
@@ -169,6 +169,10 @@ describe("resolveNewQueryTable", () => {
}); });
describe("buildSelectAllSql", () => { describe("buildSelectAllSql", () => {
it("builds a MetricsQL range query for VictoriaMetrics metrics", () => {
expect(buildSelectAllSql("victoriametrics", { tableName: "flag" })).toBe('{__name__="flag"}[1h]');
});
it("quotes a MySQL table with backticks", () => { it("quotes a MySQL table with backticks", () => {
expect(buildSelectAllSql("mysql", { tableName: "users" })).toBe("SELECT * FROM `users`"); expect(buildSelectAllSql("mysql", { tableName: "users" })).toBe("SELECT * FROM `users`");
}); });
@@ -1276,6 +1276,7 @@ describe("supportsExecutionTargetPicker", () => {
expect(supportsExecutionTargetPicker("zookeeper")).toBe(false); expect(supportsExecutionTargetPicker("zookeeper")).toBe(false);
expect(supportsExecutionTargetPicker("mq")).toBe(false); expect(supportsExecutionTargetPicker("mq")).toBe(false);
expect(supportsExecutionTargetPicker("neo4j")).toBe(false); expect(supportsExecutionTargetPicker("neo4j")).toBe(false);
expect(supportsExecutionTargetPicker("victoriametrics")).toBe(false);
expect(supportsExecutionTargetPicker(undefined)).toBe(false); expect(supportsExecutionTargetPicker(undefined)).toBe(false);
}); });
}); });
@@ -236,6 +236,9 @@ export function connectionUrlPlaceholder(dbType: DatabaseType): string {
case "influxdb": case "influxdb":
return "influxdb://user:password@host:port/database"; return "influxdb://user:password@host:port/database";
case "victoriametrics":
return "http://user:password@host:port/prometheus";
case "jdbc": case "jdbc":
return "jdbc:mysql://host:3306/database"; return "jdbc:mysql://host:3306/database";
@@ -18,6 +18,7 @@ export interface ParsedConnectionUrl {
oracleConnectionType?: "service_name" | "sid"; oracleConnectionType?: "service_name" | "sid";
useMongoUrl?: boolean; useMongoUrl?: boolean;
portExplicit?: boolean; portExplicit?: boolean;
apiPath?: string;
} }
export type ConnectionProfile = { export type ConnectionProfile = {
@@ -68,6 +69,7 @@ const SCHEME_PROFILES: Record<string, ConnectionProfile> = {
xugu: { type: "xugu", profile: "xugu", label: "XuguDB", defaultPort: 5138 }, xugu: { type: "xugu", profile: "xugu", label: "XuguDB", defaultPort: 5138 },
iotdb: { type: "iotdb", profile: "iotdb", label: "Apache IoTDB", defaultPort: 6667 }, iotdb: { type: "iotdb", profile: "iotdb", label: "Apache IoTDB", defaultPort: 6667 },
iris: { type: "iris", profile: "iris", label: "IRIS", defaultPort: 1972 }, iris: { type: "iris", profile: "iris", label: "IRIS", defaultPort: 1972 },
victoriametrics: { type: "victoriametrics", profile: "victoriametrics", label: "VictoriaMetrics", defaultPort: 8428 },
}; };
const HTTP_SELECTED_PROFILES: Record<string, ConnectionProfile> = { const HTTP_SELECTED_PROFILES: Record<string, ConnectionProfile> = {
@@ -78,6 +80,7 @@ const HTTP_SELECTED_PROFILES: Record<string, ConnectionProfile> = {
milvus: SCHEME_PROFILES.milvus, milvus: SCHEME_PROFILES.milvus,
weaviate: SCHEME_PROFILES.weaviate, weaviate: SCHEME_PROFILES.weaviate,
chromadb: SCHEME_PROFILES.chromadb, chromadb: SCHEME_PROFILES.chromadb,
victoriametrics: SCHEME_PROFILES.victoriametrics,
}; };
function decodeUrlPart(value: string): string { function decodeUrlPart(value: string): string {
@@ -640,9 +643,10 @@ export function parseConnectionUrl(value: string, preferredProfile?: string): Pa
...(profile.type === "sqlserver" && parsed.port ? { portExplicit: true } : {}), ...(profile.type === "sqlserver" && parsed.port ? { portExplicit: true } : {}),
username: mysqlCredentials?.username ?? decodeUrlPart(parsed.username), username: mysqlCredentials?.username ?? decodeUrlPart(parsed.username),
password: mysqlCredentials?.password ?? decodeUrlPart(parsed.password), password: mysqlCredentials?.password ?? decodeUrlPart(parsed.password),
database: databaseFromPath(parsed.pathname), database: profile.type === "victoriametrics" ? "metrics" : databaseFromPath(parsed.pathname),
urlParams: effectiveUrlParams, urlParams: effectiveUrlParams,
ssl: scheme === "rediss" || scheme === "https" || urlParamsRequireTls(profile.type, effectiveUrlParams) || (profile.type === "mysql" && isTidbCloudHost(parsed.hostname)), ssl: scheme === "rediss" || scheme === "https" || urlParamsRequireTls(profile.type, effectiveUrlParams) || (profile.type === "mysql" && isTidbCloudHost(parsed.hostname)),
...(profile.type === "victoriametrics" ? { apiPath: parsed.pathname.replace(/\/+$/, "") } : {}),
}; };
} }
@@ -678,7 +682,12 @@ function isRecord(value: unknown): value is Record<string, unknown> {
return !!value && typeof value === "object" && !Array.isArray(value); return !!value && typeof value === "object" && !Array.isArray(value);
} }
function sqlServerExternalConfig(existing: unknown, parsed: ParsedConnectionUrl): unknown { function parsedExternalConfig(existing: unknown, parsed: ParsedConnectionUrl): unknown {
if (parsed.dbType === "victoriametrics") {
const next = isRecord(existing) ? { ...existing } : {};
next.apiPath = parsed.apiPath || "/prometheus";
return next;
}
if (parsed.dbType !== "sqlserver") return existing; if (parsed.dbType !== "sqlserver") return existing;
const next = isRecord(existing) ? { ...existing } : {}; const next = isRecord(existing) ? { ...existing } : {};
@@ -707,6 +716,6 @@ export function applyParsedConnectionUrl(config: Omit<ConnectionConfig, "id">, p
ssl: parsed.ssl, ssl: parsed.ssl,
connection_string: parsed.connectionString, connection_string: parsed.connectionString,
oracle_connection_type: parsed.oracleConnectionType, oracle_connection_type: parsed.oracleConnectionType,
external_config: sqlServerExternalConfig(config.external_config, parsed), external_config: parsedExternalConfig(config.external_config, parsed),
}; };
} }
@@ -184,6 +184,7 @@ export function filterModeUsesRange(mode: DataGridContextFilterMode): boolean {
} }
export function filterModeIsSupportedForDatabase(mode: DataGridContextFilterMode, databaseType?: DatabaseType): boolean { export function filterModeIsSupportedForDatabase(mode: DataGridContextFilterMode, databaseType?: DatabaseType): boolean {
if (databaseType === "victoriametrics") return false;
if (!filterModeUsesList(mode) && !filterModeUsesRange(mode)) return true; if (!filterModeUsesList(mode) && !filterModeUsesRange(mode)) return true;
// These targets do not support all four new SQL predicates reliably. // These targets do not support all four new SQL predicates reliably.
return databaseType !== "cassandra" && databaseType !== "influxdb" && databaseType !== "jdbc"; return databaseType !== "cassandra" && databaseType !== "influxdb" && databaseType !== "jdbc";
@@ -25,7 +25,7 @@ export function isColumnNameCopySeparator(value: unknown): value is ColumnNameCo
} }
// SQL 执行能力是产品能力,不代表数据库支持 SQL 标识符引用。 // SQL 执行能力是产品能力,不代表数据库支持 SQL 标识符引用。
const NON_SQL_DATABASE_TYPES = new Set<DatabaseType>(["redis", "mongodb", "elasticsearch", "easysearch", "qdrant", "milvus", "weaviate", "chromadb", "etcd", "zookeeper", "mq", "nacos"]); const NON_SQL_DATABASE_TYPES = new Set<DatabaseType>(["redis", "mongodb", "elasticsearch", "easysearch", "qdrant", "milvus", "weaviate", "chromadb", "etcd", "zookeeper", "mq", "nacos", "victoriametrics"]);
// quoteTableIdentifier 对 jdbc/iotdb 原样返回(无引用字符可用)。 // quoteTableIdentifier 对 jdbc/iotdb 原样返回(无引用字符可用)。
const UNQUOTABLE_DATABASE_TYPES = new Set<DatabaseType>(["jdbc", "iotdb"]); const UNQUOTABLE_DATABASE_TYPES = new Set<DatabaseType>(["jdbc", "iotdb"]);
@@ -1,3 +1,5 @@
import type { DatabaseType } from "@/types/database";
export interface CanGoNextDataGridPageOptions { export interface CanGoNextDataGridPageOptions {
hasMore?: boolean; hasMore?: boolean;
rowCount: number; rowCount: number;
@@ -31,6 +33,10 @@ export interface CanFetchNextDataGridSegmentOptions {
export type DataGridInexactTotalRowCountMode = "at-least" | "estimated"; export type DataGridInexactTotalRowCountMode = "at-least" | "estimated";
export function dataGridTruncationHintKey(databaseType?: DatabaseType): "grid.truncatedHint" | "grid.victoriaMetricsTruncatedHint" {
return databaseType === "victoriametrics" ? "grid.victoriaMetricsTruncatedHint" : "grid.truncatedHint";
}
export function dataGridTotalRowCountLabelKey(totalRowCountIsExact: boolean, inexactMode: DataGridInexactTotalRowCountMode): "grid.totalRowCount" | "grid.totalRowCountAtLeast" | "grid.totalRowCountEstimated" { export function dataGridTotalRowCountLabelKey(totalRowCountIsExact: boolean, inexactMode: DataGridInexactTotalRowCountMode): "grid.totalRowCount" | "grid.totalRowCountAtLeast" | "grid.totalRowCountEstimated" {
if (totalRowCountIsExact) return "grid.totalRowCount"; if (totalRowCountIsExact) return "grid.totalRowCount";
return inexactMode === "estimated" ? "grid.totalRowCountEstimated" : "grid.totalRowCountAtLeast"; return inexactMode === "estimated" ? "grid.totalRowCountEstimated" : "grid.totalRowCountAtLeast";
@@ -43,7 +43,7 @@ export const SCHEMA_AWARE_TYPES = new Set<DatabaseType>([
// query another database through a three-part name on the same connection. // query another database through a three-part name on the same connection.
export const DATABASE_SCHEMA_QUALIFIED_TYPES = new Set<DatabaseType>(["sqlserver", "trino", "prestosql"]); export const DATABASE_SCHEMA_QUALIFIED_TYPES = new Set<DatabaseType>(["sqlserver", "trino", "prestosql"]);
export const SINGLE_DATABASE_TYPES = new Set<DatabaseType>(["oracle", "dameng", "firebird", "oceanbase-oracle", "access", "questdb"]); export const SINGLE_DATABASE_TYPES = new Set<DatabaseType>(["oracle", "dameng", "firebird", "oceanbase-oracle", "access", "questdb", "victoriametrics"]);
export const CLEARABLE_QUERY_SCHEMA_TYPES = new Set<DatabaseType>(["oracle", "dameng", "gaussdb", "oceanbase-oracle"]); export const CLEARABLE_QUERY_SCHEMA_TYPES = new Set<DatabaseType>(["oracle", "dameng", "gaussdb", "oceanbase-oracle"]);
@@ -140,7 +140,7 @@ export function supportsObjectBrowserTreeNode(dbType: DatabaseType | undefined,
} }
export function supportsTableTruncate(dbType?: DatabaseType): boolean { export function supportsTableTruncate(dbType?: DatabaseType): boolean {
return !!dbType && dbType !== "sqlite" && dbType !== "rqlite" && dbType !== "turso" && dbType !== "cloudflare-d1" && dbType !== "duckdb" && dbType !== "influxdb" && dbType !== "manticoresearch"; return !!dbType && dbType !== "sqlite" && dbType !== "rqlite" && dbType !== "turso" && dbType !== "cloudflare-d1" && dbType !== "duckdb" && dbType !== "influxdb" && dbType !== "victoriametrics" && dbType !== "manticoresearch";
} }
export function usesPostgresLikeStructureCopy(dbType?: DatabaseType): boolean { export function usesPostgresLikeStructureCopy(dbType?: DatabaseType): boolean {
@@ -81,6 +81,7 @@ export const DATABASE_NAMESPACE_CREATION_MATRIX = {
zookeeper: { deferred: "key-value namespaces are not databases" }, zookeeper: { deferred: "key-value namespaces are not databases" },
iris: { database: "schema" }, iris: { database: "schema" },
influxdb: { connection: "database" }, influxdb: { connection: "database" },
victoriametrics: { deferred: "metric namespaces are managed by VictoriaMetrics deployment configuration" },
jdbc: { deferred: "generic JDBC does not expose a reliable dialect-specific create target" }, jdbc: { deferred: "generic JDBC does not expose a reliable dialect-specific create target" },
mq: { deferred: "message queue namespaces are handled by MQ admin panels" }, mq: { deferred: "message queue namespaces are handled by MQ admin panels" },
nacos: { deferred: "Nacos namespace creation already uses the Nacos admin flow" }, nacos: { deferred: "Nacos namespace creation already uses the Nacos admin flow" },
@@ -62,6 +62,7 @@ const DATABASE_TYPE_OBJECTS = new Map<DatabaseType, SidebarObjectKind[]>([
["neo4j", TABLE_VIEW_OBJECTS], ["neo4j", TABLE_VIEW_OBJECTS],
// others // others
["influxdb", ["TABLE"]], ["influxdb", ["TABLE"]],
["victoriametrics", ["TABLE"]],
["hbase", ["TABLE"]], ["hbase", ["TABLE"]],
["questdb", ["TABLE", "VIEW", "MATERIALIZED_VIEW"]], ["questdb", ["TABLE", "VIEW", "MATERIALIZED_VIEW"]],
["manticoresearch", ["TABLE", "FUNCTION"]], ["manticoresearch", ["TABLE", "FUNCTION"]],
@@ -81,6 +81,7 @@ export const DATABASE_PROPERTY_EDITING_MATRIX = {
zookeeper: { deferred: "key-value namespaces are not databases" }, zookeeper: { deferred: "key-value namespaces are not databases" },
iris: { deferred: "schema properties need product-specific handling" }, iris: { deferred: "schema properties need product-specific handling" },
influxdb: { deferred: "database retention policies need a dedicated workflow" }, influxdb: { deferred: "database retention policies need a dedicated workflow" },
victoriametrics: { deferred: "metric and retention settings are managed by VictoriaMetrics deployment configuration" },
jdbc: { deferred: "generic JDBC does not expose reliable dialect-specific properties" }, jdbc: { deferred: "generic JDBC does not expose reliable dialect-specific properties" },
mq: { deferred: "message queue namespaces are handled by MQ admin panels" }, mq: { deferred: "message queue namespaces are handled by MQ admin panels" },
nacos: { deferred: "Nacos namespace editing already uses the Nacos admin flow" }, nacos: { deferred: "Nacos namespace editing already uses the Nacos admin flow" },
@@ -176,6 +176,18 @@ const DATABASE_CAPABILITY_OVERRIDES: Partial<Record<DatabaseType, Partial<Databa
readonly: true, readonly: true,
}, },
}, },
victoriametrics: {
tableData: {
insert: false,
updateRequiresPrimaryKey: false,
deleteRequiresPrimaryKey: true,
keylessRowPredicate: false,
requiresTransactionalTableForExistingRows: false,
existingRowsReadonly: true,
transaction: false,
readonly: true,
},
},
}; };
function defaultTableDataCapability(dbType?: DatabaseType): TableDataCapability { function defaultTableDataCapability(dbType?: DatabaseType): TableDataCapability {
+2 -1
View File
@@ -1,6 +1,6 @@
import { resolveDefaultDatabase } from "@/lib/database/defaultDatabase"; import { resolveDefaultDatabase } from "@/lib/database/defaultDatabase";
import { normalizeSqliteNamespace } from "@/lib/database/sqliteNamespace"; import { normalizeSqliteNamespace } from "@/lib/database/sqliteNamespace";
import { qualifiedTableName } from "@/lib/table/tableSelectSql"; import { metricRangeQuery, qualifiedTableName } from "@/lib/table/tableSelectSql";
import type { ConnectionConfig, DatabaseType, QueryTab, TreeNode } from "@/types/database"; import type { ConnectionConfig, DatabaseType, QueryTab, TreeNode } from "@/types/database";
export interface NewQueryTarget { export interface NewQueryTarget {
@@ -145,6 +145,7 @@ export function resolveNewQueryTable(input: ResolveNewQueryTableInput): NewQuery
* by the table-data view. * by the table-data view.
*/ */
export function buildSelectAllSql(databaseType: DatabaseType | undefined, table: Pick<NewQueryTable, "schema" | "catalog" | "tableName"> & Partial<Pick<NewQueryTable, "database">>): string { export function buildSelectAllSql(databaseType: DatabaseType | undefined, table: Pick<NewQueryTable, "schema" | "catalog" | "tableName"> & Partial<Pick<NewQueryTable, "database">>): string {
if (databaseType === "victoriametrics") return metricRangeQuery(table.tableName);
const ref = qualifiedTableName({ databaseType, database: table.database, schema: table.schema, catalog: table.catalog, tableName: table.tableName }); const ref = qualifiedTableName({ databaseType, database: table.database, schema: table.schema, catalog: table.catalog, tableName: table.tableName });
return `SELECT * FROM ${ref}`; return `SELECT * FROM ${ref}`;
} }
@@ -22,7 +22,7 @@ export function elasticsearchRestRequestRanges(sql: string, databaseType?: Datab
return requests.length > 0 && requests.every((request) => ELASTICSEARCH_REST_REQUEST.test(request.sql)) ? requests : []; return requests.length > 0 && requests.every((request) => ELASTICSEARCH_REST_REQUEST.test(request.sql)) ? requests : [];
} }
const NON_SQL_EXECUTION_TARGET_TYPES: ReadonlySet<DatabaseType> = new Set(["mongodb", "elasticsearch", "easysearch", "qdrant", "milvus", "weaviate", "chromadb", "etcd", "zookeeper", "mq", "neo4j"]); const NON_SQL_EXECUTION_TARGET_TYPES: ReadonlySet<DatabaseType> = new Set(["mongodb", "elasticsearch", "easysearch", "qdrant", "milvus", "weaviate", "chromadb", "etcd", "zookeeper", "mq", "neo4j", "victoriametrics"]);
export function supportsExecutionTargetPicker(databaseType?: DatabaseType): boolean { export function supportsExecutionTargetPicker(databaseType?: DatabaseType): boolean {
return !!databaseType && (databaseType === "redis" || isElasticsearchCompatibleDatabaseType(databaseType) || !NON_SQL_EXECUTION_TARGET_TYPES.has(databaseType)); return !!databaseType && (databaseType === "redis" || isElasticsearchCompatibleDatabaseType(databaseType) || !NON_SQL_EXECUTION_TARGET_TYPES.has(databaseType));
+1 -1
View File
@@ -56,7 +56,7 @@ export function tableClipboardMenuState(entries: TableClipboardTableContext[], t
} }
export function supportsWholeRowTableDataCopy(databaseType: DatabaseType | undefined): boolean { export function supportsWholeRowTableDataCopy(databaseType: DatabaseType | undefined): boolean {
return !!databaseType; return !!databaseType && databaseType !== "victoriametrics";
} }
export function defaultPasteTableMode(databaseType: DatabaseType | undefined): PasteTableMode { export function defaultPasteTableMode(databaseType: DatabaseType | undefined): PasteTableMode {
@@ -17,6 +17,18 @@ export interface FetchTableDataForExportOptions {
export async function fetchTableDataForExport(options: FetchTableDataForExportOptions): Promise<QueryResult> { export async function fetchTableDataForExport(options: FetchTableDataForExportOptions): Promise<QueryResult> {
const pageSize = Math.max(1, options.pageSize ?? TABLE_DATA_EXPORT_PAGE_SIZE); const pageSize = Math.max(1, options.pageSize ?? TABLE_DATA_EXPORT_PAGE_SIZE);
if (options.databaseType === "victoriametrics") {
const query = await (options.buildPageSql ?? buildTableSelectSql)({
databaseType: options.databaseType,
schema: options.schema,
tableName: options.tableName,
tableType: options.tableType,
columns: options.columns,
limit: pageSize,
offset: 0,
});
return options.executePage(query);
}
let offset = 0; let offset = 0;
const rows: QueryResult["rows"] = []; const rows: QueryResult["rows"] = [];
let columns: string[] = []; let columns: string[] = [];
@@ -79,6 +79,12 @@ const capabilityByType: Partial<Record<DatabaseType, Partial<TableMetadataCapabi
triggers: false, triggers: false,
ddl: false, ddl: false,
}, },
victoriametrics: {
indexes: false,
foreignKeys: false,
triggers: false,
ddl: false,
},
questdb: { questdb: {
indexes: true, indexes: true,
foreignKeys: false, foreignKeys: false,
@@ -96,11 +96,21 @@ export function qualifiedTableName(options: Pick<BuildTableSelectSqlOptions, "da
return quoteTableIdentifier(databaseType, tableName); return quoteTableIdentifier(databaseType, tableName);
} }
export function metricSelector(metricName: string): string {
const escaped = metricName.replaceAll("\\", "\\\\").replaceAll('"', '\\"').replaceAll("\n", "\\n");
return `{__name__="${escaped}"}`;
}
export function metricRangeQuery(metricName: string, lookback = "1h"): string {
return `${metricSelector(metricName)}[${lookback}]`;
}
export function normalizeWhereInput(whereInput?: string): string { export function normalizeWhereInput(whereInput?: string): string {
const withoutSemicolon = whereInput?.trim().replace(/;+$/, "").trim() ?? ""; const withoutSemicolon = whereInput?.trim().replace(/;+$/, "").trim() ?? "";
return withoutSemicolon.replace(/^where\b/i, "").trim(); return withoutSemicolon.replace(/^where\b/i, "").trim();
} }
export async function buildTableSelectSql(options: BuildTableSelectSqlOptions): Promise<string> { export async function buildTableSelectSql(options: BuildTableSelectSqlOptions): Promise<string> {
if (options.databaseType === "victoriametrics") return metricRangeQuery(options.tableName);
return api.buildTableSelectSql(options); return api.buildTableSelectSql(options);
} }
@@ -1,5 +1,5 @@
import type { ColumnInfo, DatabaseType } from "@/types/database"; import type { ColumnInfo, DatabaseType } from "@/types/database";
import { qualifiedTableName, quoteTableDataIdentifier } from "@/lib/table/tableSelectSql"; import { metricRangeQuery, qualifiedTableName, quoteTableDataIdentifier } from "@/lib/table/tableSelectSql";
export interface TableSqlTemplateOptions { export interface TableSqlTemplateOptions {
databaseType?: DatabaseType; databaseType?: DatabaseType;
@@ -13,6 +13,7 @@ export interface TableSqlTemplateOptions {
} }
export function buildTableSelectTemplate(options: TableSqlTemplateOptions): string { export function buildTableSelectTemplate(options: TableSqlTemplateOptions): string {
if (options.databaseType === "victoriametrics") return metricRangeQuery(options.tableName);
const tableName = templateTableName(options); const tableName = templateTableName(options);
const columns = options.columns ?? []; const columns = options.columns ?? [];
if (!columns.length) { if (!columns.length) {
@@ -1011,6 +1011,7 @@ export const useConnectionStore = defineStore("connection", () => {
sundb: "科蓝 SUNDB", sundb: "科蓝 SUNDB",
oscar: "神通 OSCAR", oscar: "神通 OSCAR",
influxdb: "InfluxDB", influxdb: "InfluxDB",
victoriametrics: "VictoriaMetrics",
}; };
const profile = config.driver_profile || config.db_type; const profile = config.driver_profile || config.db_type;
+1
View File
@@ -66,6 +66,7 @@ export type DatabaseType =
| "zookeeper" | "zookeeper"
| "iris" | "iris"
| "influxdb" | "influxdb"
| "victoriametrics"
| "jdbc" | "jdbc"
| "mq" | "mq"
| "mqtt" | "mqtt"
@@ -0,0 +1,4 @@
export interface VictoriaMetricsExternalConfig {
apiPath: string;
lookback: string;
}
@@ -1926,6 +1926,35 @@
"driverManagement": false "driverManagement": false
} }
}, },
{
"dbType": "victoriametrics",
"label": "VictoriaMetrics",
"runtimeMode": "native",
"mcpMode": "bridge",
"singleConnectionPool": true,
"metadataConnectionScoped": false,
"skipTcpProbe": true,
"defaultPort": 8428,
"supportLevel": "browse",
"capabilities": {
"queryExecution": true,
"metadataBrowse": true,
"objectBrowser": true,
"objectSource": false,
"schemaSearch": false,
"diagram": false,
"tableDataEdit": false,
"tableStructureEdit": false,
"tableImport": false,
"dataTransfer": false,
"sqlFileExecution": true,
"databaseCreate": false,
"fieldLineage": false,
"sqlExplain": false,
"userAdmin": false,
"driverManagement": false
}
},
{ {
"dbType": "jdbc", "dbType": "jdbc",
"label": "JDBC", "label": "JDBC",
+40
View File
@@ -106,6 +106,7 @@ pub enum PoolKind {
HBase(db::hbase_driver::HBaseClient), HBase(db::hbase_driver::HBaseClient),
VectorDb(db::vector_driver::VectorClient), VectorDb(db::vector_driver::VectorClient),
InfluxDb(db::influxdb_driver::InfluxdbClient), InfluxDb(db::influxdb_driver::InfluxdbClient),
VictoriaMetrics(db::victoriametrics_driver::VictoriaMetricsClient),
Agent(Arc<db::agent_driver::PooledAgentClient>), Agent(Arc<db::agent_driver::PooledAgentClient>),
ExternalDriver { ExternalDriver {
driver_id: String, driver_id: String,
@@ -1950,6 +1951,15 @@ impl AppState {
db::influxdb_driver::test_connection(&client, connect_timeout).await?; db::influxdb_driver::test_connection(&client, connect_timeout).await?;
PoolKind::InfluxDb(client) PoolKind::InfluxDb(client)
} }
DatabaseType::VictoriaMetrics => {
let client = db::victoriametrics_driver::VictoriaMetricsClient::new_for_config(
&url,
&db_config,
connect_timeout,
)?;
db::victoriametrics_driver::test_connection(&client, connect_timeout).await?;
PoolKind::VictoriaMetrics(client)
}
DatabaseType::Nacos => { DatabaseType::Nacos => {
let admin_config = self.nacos_admin_config_for_connection(connection_id, &config).await?; let admin_config = self.nacos_admin_config_for_connection(connection_id, &config).await?;
let adapter = self.nacos_registry.build_transient_config(admin_config).await?; let adapter = self.nacos_registry.build_transient_config(admin_config).await?;
@@ -2892,6 +2902,18 @@ impl AppState {
} }
} }
} }
PoolKind::VictoriaMetrics(client) => {
let client = client.clone();
drop(connections);
let timeout = crate::db::connection_timeout();
match db::victoriametrics_driver::test_connection(&client, timeout).await {
Ok(()) => false,
Err(err) => {
log::warn!("VictoriaMetrics connection pool '{pool_key}' is stale: {err}");
true
}
}
}
PoolKind::Rqlite(client) => { PoolKind::Rqlite(client) => {
let client = client.clone(); let client = client.clone();
drop(connections); drop(connections);
@@ -3788,6 +3810,15 @@ impl AppState {
false false
} }
}, },
PoolKind::VictoriaMetrics(client) => {
match db::victoriametrics_driver::test_connection(client, timeout).await {
Ok(()) => true,
Err(e) => {
log::warn!("VictoriaMetrics connection pool '{key}' is unhealthy: {e}");
false
}
}
}
PoolKind::Rqlite(client) => match db::rqlite_driver::test_connection(client, timeout).await { PoolKind::Rqlite(client) => match db::rqlite_driver::test_connection(client, timeout).await {
Ok(()) => true, Ok(()) => true,
Err(e) => { Err(e) => {
@@ -4060,6 +4091,7 @@ enum KeepaliveTarget {
HBase(db::hbase_driver::HBaseClient), HBase(db::hbase_driver::HBaseClient),
VectorDb(db::vector_driver::VectorClient), VectorDb(db::vector_driver::VectorClient),
InfluxDb(db::influxdb_driver::InfluxdbClient), InfluxDb(db::influxdb_driver::InfluxdbClient),
VictoriaMetrics(db::victoriametrics_driver::VictoriaMetricsClient),
Agent(Arc<db::agent_driver::PooledAgentClient>), Agent(Arc<db::agent_driver::PooledAgentClient>),
} }
@@ -4153,6 +4185,7 @@ fn keepalive_target_from_pool(pool: &PoolKind, config: &ConnectionConfig) -> Opt
PoolKind::HBase(client) => Some(KeepaliveTarget::HBase(client.clone())), PoolKind::HBase(client) => Some(KeepaliveTarget::HBase(client.clone())),
PoolKind::VectorDb(client) => Some(KeepaliveTarget::VectorDb(client.clone())), PoolKind::VectorDb(client) => Some(KeepaliveTarget::VectorDb(client.clone())),
PoolKind::InfluxDb(client) => Some(KeepaliveTarget::InfluxDb(client.clone())), PoolKind::InfluxDb(client) => Some(KeepaliveTarget::InfluxDb(client.clone())),
PoolKind::VictoriaMetrics(client) => Some(KeepaliveTarget::VictoriaMetrics(client.clone())),
PoolKind::Agent(client) => Some(KeepaliveTarget::Agent(client.clone())), PoolKind::Agent(client) => Some(KeepaliveTarget::Agent(client.clone())),
_ => None, _ => None,
} }
@@ -4199,6 +4232,9 @@ async fn ping_keepalive_target(target: &mut KeepaliveTarget, timeout: Duration)
KeepaliveTarget::InfluxDb(client) => { KeepaliveTarget::InfluxDb(client) => {
db::influxdb_driver::test_connection(client, timeout).await.map_err(Into::into) db::influxdb_driver::test_connection(client, timeout).await.map_err(Into::into)
} }
KeepaliveTarget::VictoriaMetrics(client) => {
db::victoriametrics_driver::test_connection(client, timeout).await.map_err(Into::into)
}
KeepaliveTarget::Agent(client) => { KeepaliveTarget::Agent(client) => {
let Ok(mut client) = client.try_lock() else { let Ok(mut client) = client.try_lock() else {
return Ok(()); return Ok(());
@@ -4429,6 +4465,7 @@ fn clone_pool_kind(pool: &PoolKind) -> PoolKind {
PoolKind::HBase(client) => PoolKind::HBase(client.clone()), PoolKind::HBase(client) => PoolKind::HBase(client.clone()),
PoolKind::VectorDb(client) => PoolKind::VectorDb(client.clone()), PoolKind::VectorDb(client) => PoolKind::VectorDb(client.clone()),
PoolKind::InfluxDb(client) => PoolKind::InfluxDb(client.clone()), PoolKind::InfluxDb(client) => PoolKind::InfluxDb(client.clone()),
PoolKind::VictoriaMetrics(client) => PoolKind::VictoriaMetrics(client.clone()),
PoolKind::Agent(client) => PoolKind::Agent(client.clone()), PoolKind::Agent(client) => PoolKind::Agent(client.clone()),
PoolKind::ExternalDriver { driver_id, config, session } => { PoolKind::ExternalDriver { driver_id, config, session } => {
PoolKind::ExternalDriver { driver_id: driver_id.clone(), config: config.clone(), session: session.clone() } PoolKind::ExternalDriver { driver_id: driver_id.clone(), config: config.clone(), session: session.clone() }
@@ -4484,6 +4521,9 @@ async fn close_pool_kind(pool: PoolKind) -> Result<(), String> {
PoolKind::InfluxDb(client) => { PoolKind::InfluxDb(client) => {
drop(client); drop(client);
} }
PoolKind::VictoriaMetrics(client) => {
drop(client);
}
PoolKind::Agent(client) => { PoolKind::Agent(client) => {
let mut client = client.lock().await; let mut client = client.lock().await;
client.disconnect().await?; client.disconnect().await?;
+30
View File
@@ -150,6 +150,9 @@ fn supports_data_grid_context_filter_mode(
database_type: Option<DatabaseType>, database_type: Option<DatabaseType>,
mode: DataGridContextFilterMode, mode: DataGridContextFilterMode,
) -> bool { ) -> bool {
if database_type == Some(DatabaseType::VictoriaMetrics) {
return false;
}
!matches!( !matches!(
(database_type, mode), (database_type, mode),
( (
@@ -3767,6 +3770,33 @@ mod tests {
} }
} }
#[test]
fn does_not_emit_sql_filters_for_victoriametrics() {
for mode in [
DataGridContextFilterMode::Equals,
DataGridContextFilterMode::Like,
DataGridContextFilterMode::GreaterThan,
DataGridContextFilterMode::IsNull,
DataGridContextFilterMode::In,
DataGridContextFilterMode::Between,
] {
assert_eq!(
build_data_grid_context_filter_condition(DataGridContextFilterConditionOptions {
database_type: Some(DatabaseType::VictoriaMetrics),
identifier_quote: None,
column_name: "value".to_string(),
mode,
value: json!(10),
values: vec![json!(10), json!(20)],
end_value: Some(json!(20)),
column_info: Some(column("value", "double", false, None)),
}),
None,
"VictoriaMetrics must not emit SQL filter mode {mode:?}"
);
}
}
#[test] #[test]
fn context_membership_and_range_filters_require_complete_values() { fn context_membership_and_range_filters_require_complete_values() {
let column_info = Some(column("score", "int", false, None)); let column_info = Some(column("score", "int", false, None));
@@ -33,6 +33,7 @@ pub fn is_single_connection_pool(db_type: &DatabaseType) -> bool {
| DatabaseType::OceanbaseOracle | DatabaseType::OceanbaseOracle
| DatabaseType::Access | DatabaseType::Access
| DatabaseType::Jdbc | DatabaseType::Jdbc
| DatabaseType::VictoriaMetrics
) )
} }
@@ -57,6 +58,7 @@ pub fn skips_tcp_probe(db_type: &DatabaseType) -> bool {
| DatabaseType::Jdbc | DatabaseType::Jdbc
| DatabaseType::MessageQueue | DatabaseType::MessageQueue
| DatabaseType::Mqtt | DatabaseType::Mqtt
| DatabaseType::VictoriaMetrics
) || is_agent_type(db_type) ) || is_agent_type(db_type)
} }
+1
View File
@@ -36,6 +36,7 @@ pub mod starrocks;
pub mod transport_layer_tunnel; pub mod transport_layer_tunnel;
pub mod turso_driver; pub mod turso_driver;
pub mod vector_driver; pub mod vector_driver;
pub mod victoriametrics_driver;
pub mod wkb; pub mod wkb;
use reqwest::ClientBuilder; use reqwest::ClientBuilder;
@@ -0,0 +1,569 @@
use chrono::{DateTime, Utc};
use reqwest::{Certificate, Client as HttpClient, Response};
use serde::Deserialize;
use serde_json::{json, Value};
use std::collections::{BTreeSet, HashMap};
use std::fs;
use std::time::{Duration, Instant};
use super::with_connection_timeout;
use crate::models::connection::ConnectionConfig;
use crate::types::{ColumnInfo, DatabaseInfo, ObjectStatistics, QueryResult, TableInfo};
const DEFAULT_API_PATH: &str = "/prometheus";
const DEFAULT_LOOKBACK: &str = "1h";
#[derive(Clone)]
pub struct VictoriaMetricsClient {
http: HttpClient,
base_url: String,
api_path: String,
username: Option<String>,
password: Option<String>,
database_label: String,
lookback: String,
}
#[derive(Debug, Deserialize)]
#[serde(bound(deserialize = "T: Deserialize<'de>"))]
struct ApiResponse<T> {
status: String,
#[serde(default)]
data: Option<T>,
#[serde(default)]
error_type: Option<String>,
#[serde(default)]
error: Option<String>,
}
#[derive(Debug, Deserialize)]
struct QueryData {
#[serde(rename = "resultType")]
result_type: String,
result: Value,
}
#[derive(Debug, Deserialize)]
struct SeriesResult {
#[serde(default)]
metric: HashMap<String, String>,
#[serde(default)]
value: Option<(f64, String)>,
#[serde(default)]
values: Vec<(f64, String)>,
}
#[derive(Debug, Deserialize)]
struct TsdbStatus {
#[serde(rename = "seriesCountByMetricName", default)]
series_count_by_metric_name: Vec<TsdbMetricStatistic>,
}
#[derive(Debug, Deserialize)]
struct TsdbMetricStatistic {
name: String,
value: Value,
}
impl VictoriaMetricsClient {
pub fn new_for_config(url: &str, config: &ConnectionConfig, timeout: Duration) -> Result<Self, String> {
let api_path = external_string(config, &["apiPath", "api_path"])
.map(|value| normalize_api_path(&value))
.unwrap_or_else(|| DEFAULT_API_PATH.to_string());
let lookback = external_string(config, &["lookback"])
.filter(|value| valid_lookback(value))
.unwrap_or_else(|| DEFAULT_LOOKBACK.to_string());
let database_label = config
.database
.as_deref()
.map(str::trim)
.filter(|value| !value.is_empty())
.unwrap_or("metrics")
.to_string();
let http = build_http_client(Some(&config.ca_cert_path), timeout)?;
Ok(Self {
http,
base_url: url.trim_end_matches('/').to_string(),
api_path,
username: (!config.username.trim().is_empty()).then(|| config.username.clone()),
password: (!config.password.is_empty()).then(|| config.password.clone()),
database_label,
lookback,
})
}
fn endpoint(&self, suffix: &str) -> String {
format!("{}{}{}", self.base_url, self.api_path, suffix)
}
fn request(&self, request: reqwest::RequestBuilder) -> reqwest::RequestBuilder {
match (&self.username, &self.password) {
(Some(username), password) => request.basic_auth(username, password.as_deref()),
_ => request,
}
}
}
fn external_string(config: &ConnectionConfig, keys: &[&str]) -> Option<String> {
let value = config.external_config.as_ref()?;
keys.iter()
.find_map(|key| value.get(key))
.and_then(Value::as_str)
.map(str::trim)
.filter(|value| !value.is_empty())
.map(str::to_string)
}
fn normalize_api_path(value: &str) -> String {
let trimmed = value.trim().trim_end_matches('/');
if trimmed.is_empty() || trimmed == "/" {
String::new()
} else if trimmed.starts_with('/') {
trimmed.to_string()
} else {
format!("/{trimmed}")
}
}
fn valid_lookback(value: &str) -> bool {
let value = value.trim();
let split = value.find(|character: char| !character.is_ascii_digit()).unwrap_or(value.len());
split > 0
&& split < value.len()
&& value[..split].parse::<u64>().is_ok_and(|number| number > 0)
&& matches!(&value[split..], "ms" | "s" | "m" | "h" | "d" | "w" | "y")
}
fn build_http_client(ca_cert_path: Option<&str>, timeout: Duration) -> Result<HttpClient, String> {
let mut builder = HttpClient::builder().connect_timeout(timeout);
if let Some(path) = ca_cert_path.map(str::trim).filter(|path| !path.is_empty()) {
let path = expand_cert_path(path);
let cert_bytes = fs::read(&path)
.map_err(|error| format!("Failed to read VictoriaMetrics CA certificate at {path}: {error}"))?;
let cert = Certificate::from_pem(&cert_bytes)
.or_else(|_| Certificate::from_der(&cert_bytes))
.map_err(|error| format!("Failed to parse VictoriaMetrics CA certificate at {path}: {error}"))?;
builder = builder.add_root_certificate(cert);
}
builder.build().map_err(|error| format!("Failed to configure VictoriaMetrics HTTP client: {error}"))
}
fn expand_cert_path(path: &str) -> String {
let home = || std::env::var(if cfg!(windows) { "USERPROFILE" } else { "HOME" }).ok();
if path == "~" || path.starts_with("~/") || path.starts_with("~\\") {
if let Some(home) = home() {
return format!("{}{}", home, &path[1..]);
}
}
if let Some(rest) = path.strip_prefix("$HOME") {
if let Some(home) = home() {
return format!("{home}{rest}");
}
}
if let Some(rest) = path.strip_prefix("${HOME}") {
if let Some(home) = home() {
return format!("{home}{rest}");
}
}
if let Some(rest) = path.strip_prefix("%USERPROFILE%") {
if let Ok(home) = std::env::var("USERPROFILE") {
return format!("{home}{rest}");
}
}
path.to_string()
}
pub async fn test_connection(client: &VictoriaMetricsClient, timeout: Duration) -> Result<(), String> {
let request = client.request(client.http.get(client.endpoint("/api/v1/status/buildinfo")));
let response = with_connection_timeout("VictoriaMetrics", timeout, async {
request.send().await.map_err(|error| format!("VictoriaMetrics connection failed: {error}"))
})
.await?;
parse_api_response::<Value>(response).await.map(|_| ())
}
pub async fn list_databases(client: &VictoriaMetricsClient) -> Result<Vec<DatabaseInfo>, String> {
Ok(vec![DatabaseInfo { name: client.database_label.clone() }])
}
pub async fn list_tables(client: &VictoriaMetricsClient) -> Result<Vec<TableInfo>, String> {
let request = client.request(
client
.http
.get(client.endpoint("/api/v1/label/__name__/values"))
.query(&[("start", format!("-{}", client.lookback))]),
);
let mut names = parse_api_response::<Vec<String>>(request.send().await.map_err(request_error)?).await?;
names.sort();
names.dedup();
Ok(names
.into_iter()
.filter(|name| !name.trim().is_empty())
.map(|name| TableInfo {
name,
table_type: "TABLE".to_string(),
comment: None,
parent_schema: None,
parent_name: None,
})
.collect())
}
pub async fn get_columns(client: &VictoriaMetricsClient, metric_name: &str) -> Result<Vec<ColumnInfo>, String> {
let selector = metric_selector(metric_name);
let request = client.request(
client
.http
.post(client.endpoint("/api/v1/series"))
.form(&[("match[]", selector.as_str()), ("start", format!("-{}", client.lookback).as_str())]),
);
let series =
parse_api_response::<Vec<HashMap<String, String>>>(request.send().await.map_err(request_error)?).await?;
let label_names = series
.iter()
.flat_map(|labels| labels.keys())
.filter(|name| name.as_str() != "__name__")
.cloned()
.collect::<BTreeSet<_>>();
let label_names = label_names.into_iter().collect::<Vec<_>>();
let (timestamp_name, value_name, metric_name) = result_column_names(&label_names);
let mut columns = vec![
column(&timestamp_name, "timestamp", false, true, Some("Sample timestamp")),
column(&value_name, "double", false, false, Some("Sample value")),
column(&metric_name, "string", false, true, Some("Metric name")),
];
columns.extend(label_names.into_iter().map(|name| column(&name, "string", true, true, Some("Metric label"))));
Ok(columns)
}
pub async fn list_object_statistics(client: &VictoriaMetricsClient) -> Result<Vec<ObjectStatistics>, String> {
let request = client.request(client.http.get(client.endpoint("/api/v1/status/tsdb"))).query(&[("topN", "100000")]);
let status = parse_api_response::<TsdbStatus>(request.send().await.map_err(request_error)?).await?;
Ok(status
.series_count_by_metric_name
.into_iter()
.filter(|item| !item.name.trim().is_empty())
.map(|item| ObjectStatistics {
name: item.name,
schema: None,
estimated_rows: item.value.as_i64().or_else(|| item.value.as_str().and_then(|value| value.parse().ok())),
// VictoriaMetrics exposes series counts here, but no per-metric storage size.
total_bytes: None,
})
.collect())
}
fn column(name: &str, data_type: &str, is_nullable: bool, is_primary_key: bool, comment: Option<&str>) -> ColumnInfo {
ColumnInfo {
name: name.to_string(),
data_type: data_type.to_string(),
is_nullable,
is_primary_key,
comment: comment.map(str::to_string),
..Default::default()
}
}
pub async fn execute_query(client: &VictoriaMetricsClient, query: &str) -> Result<QueryResult, String> {
let start = Instant::now();
let query = query.trim().trim_end_matches(';').trim();
if query.is_empty() {
return Err("VictoriaMetrics query is empty".to_string());
}
let request = client.request(client.http.post(client.endpoint("/api/v1/query")).form(&[("query", query)]));
let data = parse_api_response::<QueryData>(request.send().await.map_err(request_error)?).await?;
query_data_to_result(data, start)
}
fn query_data_to_result(data: QueryData, start: Instant) -> Result<QueryResult, String> {
match data.result_type.as_str() {
"vector" | "matrix" => {
let series = serde_json::from_value::<Vec<SeriesResult>>(data.result)
.map_err(|error| format!("VictoriaMetrics response parse failed: {error}"))?;
Ok(series_result_to_query_result(series, start))
}
"scalar" => {
let (timestamp, value) = serde_json::from_value::<(f64, String)>(data.result)
.map_err(|error| format!("VictoriaMetrics response parse failed: {error}"))?;
Ok(simple_result(vec![vec![timestamp_value(timestamp), sample_value(&value)]], "double", start))
}
"string" => {
let (timestamp, value) = serde_json::from_value::<(f64, String)>(data.result)
.map_err(|error| format!("VictoriaMetrics response parse failed: {error}"))?;
Ok(simple_result(vec![vec![timestamp_value(timestamp), Value::String(value)]], "string", start))
}
other => Err(format!("VictoriaMetrics returned unsupported result type: {other}")),
}
}
fn series_result_to_query_result(series: Vec<SeriesResult>, start: Instant) -> QueryResult {
let labels = series
.iter()
.flat_map(|item| item.metric.keys())
.filter(|name| name.as_str() != "__name__")
.cloned()
.collect::<BTreeSet<_>>()
.into_iter()
.collect::<Vec<_>>();
let (timestamp_name, value_name, metric_name) = result_column_names(&labels);
let mut columns = vec![timestamp_name, value_name, metric_name];
columns.extend(labels.iter().cloned());
let mut rows = Vec::new();
for item in series {
let metric_name = item.metric.get("__name__").cloned().map(Value::String).unwrap_or(Value::Null);
let samples = item.value.into_iter().chain(item.values);
for (timestamp, value) in samples {
let mut row = vec![timestamp_value(timestamp), sample_value(&value), metric_name.clone()];
row.extend(
labels.iter().map(|label| item.metric.get(label).cloned().map(Value::String).unwrap_or(Value::Null)),
);
rows.push(row);
}
}
QueryResult {
column_types: std::iter::once("timestamp".to_string())
.chain(std::iter::once("double".to_string()))
.chain(std::iter::repeat_n("string".to_string(), columns.len().saturating_sub(2)))
.collect(),
column_sortables: vec![true; columns.len()],
columns,
affected_rows: rows.len() as u64,
rows,
execution_time_ms: start.elapsed().as_millis(),
spatial_columns: vec![],
spatial_values: vec![],
truncated: false,
session_id: None,
has_more: false,
elasticsearch_raw_body: None,
}
}
fn result_column_names(labels: &[String]) -> (String, String, String) {
let mut used = labels.iter().cloned().collect::<BTreeSet<_>>();
let timestamp = unique_result_column_name("timestamp", "sample_timestamp", &mut used);
let value = unique_result_column_name("value", "sample_value", &mut used);
let metric = unique_result_column_name("metric", "metric_name", &mut used);
(timestamp, value, metric)
}
fn unique_result_column_name(preferred: &str, fallback: &str, used: &mut BTreeSet<String>) -> String {
let mut candidate = if used.contains(preferred) { fallback.to_string() } else { preferred.to_string() };
let mut suffix = 2;
while used.contains(&candidate) {
candidate = format!("{fallback}_{suffix}");
suffix += 1;
}
used.insert(candidate.clone());
candidate
}
fn simple_result(rows: Vec<Vec<Value>>, value_type: &str, start: Instant) -> QueryResult {
QueryResult {
columns: vec!["timestamp".to_string(), "value".to_string()],
column_types: vec!["timestamp".to_string(), value_type.to_string()],
column_sortables: vec![true, true],
affected_rows: rows.len() as u64,
rows,
execution_time_ms: start.elapsed().as_millis(),
spatial_columns: vec![],
spatial_values: vec![],
truncated: false,
session_id: None,
has_more: false,
elasticsearch_raw_body: None,
}
}
fn timestamp_value(timestamp: f64) -> Value {
DateTime::<Utc>::from_timestamp(timestamp.trunc() as i64, (timestamp.fract() * 1_000_000_000.0) as u32)
.map(|value| Value::String(value.to_rfc3339()))
.unwrap_or_else(|| json!(timestamp))
}
fn sample_value(value: &str) -> Value {
value
.parse::<f64>()
.ok()
.filter(|number| number.is_finite())
.map(|number| json!(number))
.unwrap_or_else(|| json!(value))
}
pub fn metric_selector(metric_name: &str) -> String {
format!(r#"{{__name__="{}"}}"#, escape_label_value(metric_name))
}
pub fn metric_range_query(metric_name: &str, lookback: &str) -> String {
format!("{}[{}]", metric_selector(metric_name), if valid_lookback(lookback) { lookback } else { DEFAULT_LOOKBACK })
}
fn escape_label_value(value: &str) -> String {
value.replace('\\', "\\\\").replace('"', "\\\"").replace('\n', "\\n")
}
async fn parse_api_response<T: for<'de> Deserialize<'de>>(response: Response) -> Result<T, String> {
let status = response.status();
let body = response.text().await.unwrap_or_default();
if !status.is_success() {
return Err(http_error(status, &body));
}
let parsed = serde_json::from_str::<ApiResponse<T>>(&body)
.map_err(|error| format!("VictoriaMetrics response parse failed: {error}; response: {body}"))?;
if parsed.status != "success" {
let kind =
parsed.error_type.filter(|value| !value.is_empty()).map(|value| format!("{value}: ")).unwrap_or_default();
return Err(format!(
"VictoriaMetrics error: {kind}{}",
parsed.error.unwrap_or_else(|| "unknown error".to_string())
));
}
parsed.data.ok_or_else(|| "VictoriaMetrics response is missing data".to_string())
}
fn http_error(status: reqwest::StatusCode, body: &str) -> String {
let detail = serde_json::from_str::<Value>(body)
.ok()
.and_then(|value| value.get("error").and_then(Value::as_str).map(str::to_string))
.filter(|value| !value.trim().is_empty())
.unwrap_or_else(|| body.trim().to_string());
let detail =
if detail.is_empty() { status.canonical_reason().unwrap_or("request failed").to_string() } else { detail };
format!("VictoriaMetrics error: status={}, message={detail}", status.as_u16())
}
fn request_error(error: reqwest::Error) -> String {
format!("VictoriaMetrics request failed: {error}")
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn normalizes_api_paths_and_lookbacks() {
assert_eq!(normalize_api_path("prometheus/"), "/prometheus");
assert_eq!(normalize_api_path("/select/42/prometheus/"), "/select/42/prometheus");
assert_eq!(normalize_api_path("/"), "");
assert!(valid_lookback("15m"));
assert!(valid_lookback("250ms"));
assert!(!valid_lookback("0h"));
assert!(!valid_lookback("1 hour"));
}
#[test]
fn metric_queries_escape_label_values() {
assert_eq!(metric_selector("rack\\\"temp"), r#"{__name__="rack\\\"temp"}"#);
assert_eq!(metric_range_query("cpu_usage", "2h"), r#"{__name__="cpu_usage"}[2h]"#);
assert_eq!(metric_range_query("cpu_usage", "bad"), r#"{__name__="cpu_usage"}[1h]"#);
}
#[test]
fn parses_metric_statistics() {
let status: TsdbStatus = serde_json::from_value(json!({
"seriesCountByMetricName": [{"name": "flag", "value": "276"}]
}))
.unwrap();
assert_eq!(status.series_count_by_metric_name[0].name, "flag");
assert_eq!(status.series_count_by_metric_name[0].value.as_str(), Some("276"));
}
#[test]
fn parses_matrix_results_into_rows() {
let data = QueryData {
result_type: "matrix".to_string(),
result: json!([
{
"metric": {"__name__": "temperature", "site": "shanghai"},
"values": [[1720000000.0, "23.5"], [1720000060.0, "24"]]
}
]),
};
let result = query_data_to_result(data, Instant::now()).unwrap();
assert_eq!(result.columns, vec!["timestamp", "value", "metric", "site"]);
assert_eq!(result.rows.len(), 2);
assert_eq!(result.rows[0][1], json!(23.5));
assert_eq!(result.rows[0][2], json!("temperature"));
assert_eq!(result.rows[0][3], json!("shanghai"));
}
#[test]
fn keeps_reserved_label_names_unique() {
let data = QueryData {
result_type: "vector".to_string(),
result: json!([
{
"metric": {
"__name__": "flag",
"metric": "label-metric",
"timestamp": "label-timestamp",
"value": "label-value"
},
"value": [1720000000.0, "1"]
}
]),
};
let result = query_data_to_result(data, Instant::now()).unwrap();
assert_eq!(
result.columns,
vec!["sample_timestamp", "sample_value", "metric_name", "metric", "timestamp", "value"]
);
assert_eq!(result.rows[0].len(), result.columns.len());
assert_eq!(result.rows[0][3], json!("label-metric"));
assert_eq!(result.rows[0][5], json!("label-value"));
}
#[test]
fn parses_scalar_and_preserves_non_finite_values() {
let scalar = QueryData { result_type: "scalar".to_string(), result: json!([1720000000.0, "42"]) };
let result = query_data_to_result(scalar, Instant::now()).unwrap();
assert_eq!(result.rows[0][1], json!(42.0));
assert_eq!(sample_value("NaN"), json!("NaN"));
}
#[test]
fn keeps_string_query_results_as_strings() {
let string = QueryData { result_type: "string".to_string(), result: json!([1720000000.0, "healthy"]) };
let result = query_data_to_result(string, Instant::now()).unwrap();
assert_eq!(result.column_types, vec!["timestamp", "string"]);
assert_eq!(result.rows[0][1], json!("healthy"));
}
#[tokio::test]
#[ignore = "requires DBX_LIVE_VICTORIAMETRICS_* env vars pointing at a VictoriaMetrics endpoint"]
async fn live_connection_metadata_and_query() {
let url = std::env::var("DBX_LIVE_VICTORIAMETRICS_URL").expect("DBX_LIVE_VICTORIAMETRICS_URL");
let username = std::env::var("DBX_LIVE_VICTORIAMETRICS_USER").unwrap_or_default();
let password = std::env::var("DBX_LIVE_VICTORIAMETRICS_PASSWORD").unwrap_or_default();
let api_path = std::env::var("DBX_LIVE_VICTORIAMETRICS_API_PATH").unwrap_or_else(|_| "/prometheus".into());
let metric = std::env::var("DBX_LIVE_VICTORIAMETRICS_METRIC").expect("DBX_LIVE_VICTORIAMETRICS_METRIC");
let config: ConnectionConfig = serde_json::from_value(json!({
"id": "live-victoriametrics",
"name": "Live VictoriaMetrics",
"db_type": "victoriametrics",
"host": "unused",
"port": 8428,
"username": username,
"password": password,
"database": "metrics",
"external_config": { "apiPath": api_path, "lookback": "1h" }
}))
.expect("live VictoriaMetrics config");
let client = VictoriaMetricsClient::new_for_config(&url, &config, Duration::from_secs(10)).unwrap();
test_connection(&client, Duration::from_secs(10)).await.unwrap();
let tables = list_tables(&client).await.unwrap();
assert!(tables.iter().any(|table| table.name == metric));
let columns = get_columns(&client, &metric).await.unwrap();
assert!(columns.iter().any(|column| column.name == "timestamp"));
assert!(columns.iter().any(|column| column.name == "value"));
assert!(columns.iter().any(|column| column.name == "metric"));
let statistics = list_object_statistics(&client).await.unwrap();
assert!(statistics.iter().any(|stat| stat.name == metric && stat.estimated_rows.unwrap_or_default() > 0));
let result = execute_query(&client, &metric_range_query(&metric, "1h")).await.unwrap();
assert!(!result.rows.is_empty());
}
}
+5 -2
View File
@@ -538,6 +538,8 @@ pub enum DatabaseType {
CloudflareD1, CloudflareD1,
#[serde(rename = "influxdb")] #[serde(rename = "influxdb")]
InfluxDb, InfluxDb,
#[serde(rename = "victoriametrics")]
VictoriaMetrics,
#[serde(rename = "questdb")] #[serde(rename = "questdb")]
Questdb, Questdb,
Jdbc, Jdbc,
@@ -890,6 +892,7 @@ impl ConnectionConfig {
DatabaseType::H2 => Some("test"), DatabaseType::H2 => Some("test"),
DatabaseType::Informix => Some("sysmaster"), DatabaseType::Informix => Some("sysmaster"),
DatabaseType::Neo4j => Some("neo4j"), DatabaseType::Neo4j => Some("neo4j"),
DatabaseType::VictoriaMetrics => Some("metrics"),
_ => None, _ => None,
} }
} }
@@ -1100,7 +1103,7 @@ impl ConnectionConfig {
format!("zookeeper://{host}:{port}") format!("zookeeper://{host}:{port}")
} }
DatabaseType::Iris => format!("iris://{host}:{port}{db_part}"), DatabaseType::Iris => format!("iris://{host}:{port}{db_part}"),
DatabaseType::InfluxDb => { DatabaseType::InfluxDb | DatabaseType::VictoriaMetrics => {
let scheme = if self.ssl { "https" } else { "http" }; let scheme = if self.ssl { "https" } else { "http" };
format!("{scheme}://{host}:{port}") format!("{scheme}://{host}:{port}")
} }
@@ -1340,7 +1343,7 @@ impl ConnectionConfig {
DatabaseType::Iris => { DatabaseType::Iris => {
format!("iris://{}:{}@{host}:{port}{db_part}", username, password) format!("iris://{}:{}@{host}:{port}{db_part}", username, password)
} }
DatabaseType::InfluxDb => { DatabaseType::InfluxDb | DatabaseType::VictoriaMetrics => {
let scheme = if self.ssl { "https" } else { "http" }; let scheme = if self.ssl { "https" } else { "http" };
format!("{scheme}://{host}:{port}") format!("{scheme}://{host}:{port}")
} }
+19
View File
@@ -851,6 +851,7 @@ fn should_discard_pool_after_query_timeout(db_type: Option<DatabaseType>) -> boo
| DatabaseType::Weaviate | DatabaseType::Weaviate
| DatabaseType::ChromaDb | DatabaseType::ChromaDb
| DatabaseType::InfluxDb | DatabaseType::InfluxDb
| DatabaseType::VictoriaMetrics
) )
} }
@@ -1562,6 +1563,22 @@ async fn do_execute_typed(
} }
result result
} }
PoolKind::VictoriaMetrics(client) => {
let client = client.clone();
let max_rows = options.max_rows;
drop(connections);
let result = wait_for_query_opt(
cancel_token,
query_timeout,
db::victoriametrics_driver::execute_query(&client, sql),
)
.await
.map(|result| truncate_result_with_max_rows(result, max_rows));
if matches!(result.as_ref(), Err(err) if should_discard_pool_after_error(pool_db_type, err)) {
state.remove_pool_by_key(pool_key).await;
}
result
}
PoolKind::Agent(client) => { PoolKind::Agent(client) => {
let client = client.clone(); let client = client.clone();
let source_client = client.clone(); let source_client = client.clone();
@@ -2840,6 +2857,7 @@ fn pool_kind_has_transactional_path(pool: &PoolKind) -> bool {
| PoolKind::Easysearch(_) | PoolKind::Easysearch(_)
| PoolKind::VectorDb(_) | PoolKind::VectorDb(_)
| PoolKind::InfluxDb(_) | PoolKind::InfluxDb(_)
| PoolKind::VictoriaMetrics(_)
| PoolKind::ExternalDriver { .. } => false, | PoolKind::ExternalDriver { .. } => false,
#[cfg(feature = "mq-admin")] #[cfg(feature = "mq-admin")]
PoolKind::Mqtt(_) => false, PoolKind::Mqtt(_) => false,
@@ -3084,6 +3102,7 @@ pub async fn execute_statements_in_transaction_on_pool_typed(
| PoolKind::Easysearch(_) | PoolKind::Easysearch(_)
| PoolKind::VectorDb(_) | PoolKind::VectorDb(_)
| PoolKind::InfluxDb(_) | PoolKind::InfluxDb(_)
| PoolKind::VictoriaMetrics(_)
| PoolKind::ExternalDriver { .. } => TxPath::None, | PoolKind::ExternalDriver { .. } => TxPath::None,
}) })
}; };
+21 -1
View File
@@ -141,7 +141,7 @@ pub fn is_safe_explain_sql(sql: &str) -> bool {
} }
/// Returns true for databases that support SQL query execution (execute_query / get_sample_data). /// Returns true for databases that support SQL query execution (execute_query / get_sample_data).
/// Non-SQL databases (Redis, MongoDB, Elasticsearch, InfluxDB, Neo4j, etcd) are excluded. /// Non-SQL databases (Redis, MongoDB, Elasticsearch, InfluxDB, VictoriaMetrics, Neo4j, etcd) are excluded.
pub fn supports_sql_query(database_type: DatabaseType) -> bool { pub fn supports_sql_query(database_type: DatabaseType) -> bool {
!matches!( !matches!(
database_type, database_type,
@@ -154,6 +154,7 @@ pub fn supports_sql_query(database_type: DatabaseType) -> bool {
| DatabaseType::Weaviate | DatabaseType::Weaviate
| DatabaseType::ChromaDb | DatabaseType::ChromaDb
| DatabaseType::InfluxDb | DatabaseType::InfluxDb
| DatabaseType::VictoriaMetrics
| DatabaseType::Neo4j | DatabaseType::Neo4j
| DatabaseType::Etcd | DatabaseType::Etcd
) )
@@ -228,6 +229,11 @@ pub fn is_write_sql(sql: &str) -> bool {
/// executable comments and file exports, plus PostgreSQL-family/SQL Server /// executable comments and file exports, plus PostgreSQL-family/SQL Server
/// `SELECT ... INTO` table creation. /// `SELECT ... INTO` table creation.
pub fn is_write_sql_for_database(sql: &str, database_type: DatabaseType) -> bool { pub fn is_write_sql_for_database(sql: &str, database_type: DatabaseType) -> bool {
// VictoriaMetrics execution is hard-wired to the read-only query API; MetricsQL
// does not use SQL verbs and must not be rejected by SQL write classification.
if database_type == DatabaseType::VictoriaMetrics {
return false;
}
if let Some(risk) = classify_search_engine_query_risk(sql, database_type) { if let Some(risk) = classify_search_engine_query_risk(sql, database_type) {
return risk != SearchEngineQueryRisk::ReadOnly; return risk != SearchEngineQueryRisk::ReadOnly;
} }
@@ -1530,4 +1536,18 @@ mod tests {
DatabaseType::Easysearch DatabaseType::Easysearch
)); ));
} }
#[test]
fn excludes_victoriametrics_from_sql_query_paths() {
assert!(!supports_sql_query(DatabaseType::VictoriaMetrics));
assert!(supports_sql_query(DatabaseType::Postgres));
assert_eq!(
check_read_only(
r#"{__name__="dbx_issue_5352_temperature_celsius"}[5m]"#,
"VictoriaMetrics",
DatabaseType::VictoriaMetrics,
),
Ok(())
);
}
} }
+18
View File
@@ -581,6 +581,10 @@ async fn list_databases_once(state: &AppState, connection_id: &str) -> Result<Ve
drop(connections); drop(connections);
return db::influxdb_driver::list_databases(&client).await; return db::influxdb_driver::list_databases(&client).await;
} }
if let Some(client) = extract_pool!(&connections, connection_id, VictoriaMetrics) {
drop(connections);
return db::victoriametrics_driver::list_databases(&client).await;
}
try_sqlserver!(connections, connection_id, list_databases); try_sqlserver!(connections, connection_id, list_databases);
if let Some(client) = extract_pool!(&connections, connection_id, Agent) { if let Some(client) = extract_pool!(&connections, connection_id, Agent) {
let is_mongo = let is_mongo =
@@ -1854,6 +1858,12 @@ async fn list_tables_once(
.await .await
.map(|tables| filter_table_infos(tables, filter, limit, offset, object_types, table_name_filter)); .map(|tables| filter_table_infos(tables, filter, limit, offset, object_types, table_name_filter));
} }
if let Some(client) = extract_pool!(&connections, &pool_key, VictoriaMetrics) {
drop(connections);
return db::victoriametrics_driver::list_tables(&client)
.await
.map(|tables| filter_table_infos(tables, filter, limit, offset, object_types, table_name_filter));
}
if let Some(linked) = crate::sql_dialect::parse_sqlserver_linked_schema_ref(schema) { if let Some(linked) = crate::sql_dialect::parse_sqlserver_linked_schema_ref(schema) {
if let Some(client) = extract_pool!(&connections, &pool_key, SqlServer) { if let Some(client) = extract_pool!(&connections, &pool_key, SqlServer) {
drop(connections); drop(connections);
@@ -4538,6 +4548,10 @@ async fn list_object_statistics_once(
.await; .await;
} }
} }
if let Some(client) = extract_pool!(&connections, &pool_key, VictoriaMetrics) {
drop(connections);
return db::victoriametrics_driver::list_object_statistics(&client).await;
}
let pool = connections.get(&pool_key).ok_or("Pool not found")?; let pool = connections.get(&pool_key).ok_or("Pool not found")?;
match pool { match pool {
PoolKind::Mysql(p, mode) => { PoolKind::Mysql(p, mode) => {
@@ -5217,6 +5231,10 @@ async fn get_columns_core_for_session_inner(
drop(connections); drop(connections);
return db::influxdb_driver::get_columns(&client, database, table).await.map(deduplicate_column_infos); return db::influxdb_driver::get_columns(&client, database, table).await.map(deduplicate_column_infos);
} }
if let Some(client) = extract_pool!(&connections, &pool_key, VictoriaMetrics) {
drop(connections);
return db::victoriametrics_driver::get_columns(&client, table).await.map(deduplicate_column_infos);
}
if let Some(linked) = crate::sql_dialect::parse_sqlserver_linked_schema_ref(schema) { if let Some(linked) = crate::sql_dialect::parse_sqlserver_linked_schema_ref(schema) {
if let Some(client) = extract_pool!(&connections, &pool_key, SqlServer) { if let Some(client) = extract_pool!(&connections, &pool_key, SqlServer) {
drop(connections); drop(connections);
@@ -674,7 +674,9 @@ pub fn profile_for(db_type: DatabaseType) -> DdlDialectProfile {
// Non-tabular / not applicable for relational CREATE TABLE // Non-tabular / not applicable for relational CREATE TABLE
Redis | MongoDb | Elasticsearch | Easysearch | Qdrant | Milvus | Weaviate | ChromaDb | Neo4j | Cassandra Redis | MongoDb | Elasticsearch | Easysearch | Qdrant | Milvus | Weaviate | ChromaDb | Neo4j | Cassandra
| Etcd | ZooKeeper | Nacos | InfluxDb | MessageQueue | Mqtt | Hbase => conservative_ansi(db_type), | Etcd | ZooKeeper | Nacos | InfluxDb | VictoriaMetrics | MessageQueue | Mqtt | Hbase => {
conservative_ansi(db_type)
}
} }
} }
@@ -13,6 +13,9 @@ use super::types::{
}; };
pub fn build_count_table_sql(database_type: Option<DatabaseType>, schema: Option<&str>, table_name: &str) -> String { pub fn build_count_table_sql(database_type: Option<DatabaseType>, schema: Option<&str>, table_name: &str) -> String {
if database_type == Some(DatabaseType::VictoriaMetrics) {
return format!("count({})", victoriametrics_metric_selector(table_name));
}
format!("SELECT COUNT(*) AS row_count FROM {}", qualified_table_name(database_type, schema, table_name)) format!("SELECT COUNT(*) AS row_count FROM {}", qualified_table_name(database_type, schema, table_name))
} }
@@ -22,6 +25,9 @@ pub fn build_table_data_select_sql(options: TableDataSelectSqlOptions) -> String
if database_type == Some(DatabaseType::Neo4j) { if database_type == Some(DatabaseType::Neo4j) {
return build_neo4j_table_select_sql(&options, limit); return build_neo4j_table_select_sql(&options, limit);
} }
if database_type == Some(DatabaseType::VictoriaMetrics) {
return format!("{}[1h]", victoriametrics_metric_selector(&options.table_name));
}
// Doris / StarRocks multi-catalog: prefix the catalog for external-catalog tables. // Doris / StarRocks multi-catalog: prefix the catalog for external-catalog tables.
let table = if uses_connection_identifier_quote(database_type, options.identifier_quote.as_deref()) { let table = if uses_connection_identifier_quote(database_type, options.identifier_quote.as_deref()) {
@@ -214,6 +220,9 @@ fn is_view_table_type(table_type: Option<&str>) -> bool {
pub fn build_table_select_sql(options: TableSelectSqlOptions<'_>) -> String { pub fn build_table_select_sql(options: TableSelectSqlOptions<'_>) -> String {
let database_type = options.database_type; let database_type = options.database_type;
if database_type == Some(DatabaseType::VictoriaMetrics) {
return format!("{}[1h]", victoriametrics_metric_selector(options.table_name));
}
let table = qualified_table_name(database_type, options.schema, options.table_name); let table = qualified_table_name(database_type, options.schema, options.table_name);
let select_columns = quoted_table_columns_or_star(database_type, options.columns); let select_columns = quoted_table_columns_or_star(database_type, options.columns);
let order_by = if options.order_columns.is_empty() { let order_by = if options.order_columns.is_empty() {
@@ -257,6 +266,11 @@ pub fn build_table_select_sql(options: TableSelectSqlOptions<'_>) -> String {
} }
} }
fn victoriametrics_metric_selector(metric_name: &str) -> String {
let escaped = metric_name.replace('\\', "\\\\").replace('"', "\\\"").replace('\n', "\\n");
format!(r#"{{__name__="{escaped}"}}"#)
}
fn informix_row_limit_clause(limit: usize, offset: usize) -> String { fn informix_row_limit_clause(limit: usize, offset: usize) -> String {
if offset > 0 { if offset > 0 {
format!("SKIP {offset} FIRST {limit}") format!("SKIP {offset} FIRST {limit}")
@@ -555,4 +569,16 @@ mod tests {
assert!(!sql.contains("iceberg_catalog"), "sql was: {sql}"); assert!(!sql.contains("iceberg_catalog"), "sql was: {sql}");
assert!(sql.contains("orders"), "sql was: {sql}"); assert!(sql.contains("orders"), "sql was: {sql}");
} }
#[test]
fn victoriametrics_builds_metric_queries_without_sql_identifiers() {
assert_eq!(
build_table_data_select_sql(opts(DatabaseType::VictoriaMetrics, None, None, "rack_temperature")),
r#"{__name__="rack_temperature"}[1h]"#
);
assert_eq!(
build_count_table_sql(Some(DatabaseType::VictoriaMetrics), None, "rack\\\"temperature"),
r#"count({__name__="rack\\\"temperature"})"#
);
}
} }
+24 -1
View File
@@ -430,6 +430,29 @@ async fn fetch_table_export_batch(
}); });
} }
// VictoriaMetrics metrics are read through MetricsQL rather than SQL table
// pagination. Execute the range query once and let the normal writers emit
// the returned matrix/vector rows.
if *db_type == DatabaseType::VictoriaMetrics {
*table_read_attempted = true;
*table_read_completed = true;
let query = crate::db::victoriametrics_driver::metric_range_query(&request.table_name, "1h");
return execute_sql_statement_with_options(
state,
&request.connection_id,
&request.database,
&query,
request.schema.as_deref(),
Some(cancel_token),
QueryExecutionOptions {
max_rows: request.row_limit,
client_session_id: Some(table_export_client_session_id(&request.export_id)),
..Default::default()
},
)
.await;
}
if !*table_read_attempted { if !*table_read_attempted {
match table_export_cursor_kind(state, pool_key).await { match table_export_cursor_kind(state, pool_key).await {
Some(TableExportCursorKind::Agent) => { Some(TableExportCursorKind::Agent) => {
@@ -1205,7 +1228,7 @@ async fn export_table_data_core_inner(
// grid exports skip this by default because COUNT can be the slowest query // grid exports skip this by default because COUNT can be the slowest query
// on large HANA/JDBC tables, especially with filters. // on large HANA/JDBC tables, especially with filters.
let row_limit = request.row_limit; let row_limit = request.row_limit;
let total_rows = if request.skip_count { let total_rows = if request.skip_count || db_type == DatabaseType::VictoriaMetrics {
None None
} else { } else {
let count_query = count_sql_with_where_and_identifier_quote( let count_query = count_sql_with_where_and_identifier_quote(
@@ -174,6 +174,7 @@ fn identifies_single_connection_pool_types() {
assert!(is_single_connection_pool(&DatabaseType::Firebird)); assert!(is_single_connection_pool(&DatabaseType::Firebird));
assert!(is_single_connection_pool(&DatabaseType::OceanbaseOracle)); assert!(is_single_connection_pool(&DatabaseType::OceanbaseOracle));
assert!(is_single_connection_pool(&DatabaseType::Jdbc)); assert!(is_single_connection_pool(&DatabaseType::Jdbc));
assert!(is_single_connection_pool(&DatabaseType::VictoriaMetrics));
assert!(!is_single_connection_pool(&DatabaseType::Trino)); assert!(!is_single_connection_pool(&DatabaseType::Trino));
assert!(!is_single_connection_pool(&DatabaseType::Postgres)); assert!(!is_single_connection_pool(&DatabaseType::Postgres));
assert!(!is_single_connection_pool(&DatabaseType::Kwdb)); assert!(!is_single_connection_pool(&DatabaseType::Kwdb));
@@ -207,6 +208,7 @@ fn skips_tcp_probe_for_local_file_plugin_and_agent_types() {
assert!(skips_tcp_probe(&DatabaseType::Gbase)); assert!(skips_tcp_probe(&DatabaseType::Gbase));
assert!(skips_tcp_probe(&DatabaseType::Databend)); assert!(skips_tcp_probe(&DatabaseType::Databend));
assert!(skips_tcp_probe(&DatabaseType::InfluxDb)); assert!(skips_tcp_probe(&DatabaseType::InfluxDb));
assert!(skips_tcp_probe(&DatabaseType::VictoriaMetrics));
assert!(skips_tcp_probe(&DatabaseType::MessageQueue)); assert!(skips_tcp_probe(&DatabaseType::MessageQueue));
assert!(skips_tcp_probe(&DatabaseType::ZooKeeper)); assert!(skips_tcp_probe(&DatabaseType::ZooKeeper));
assert!(!skips_tcp_probe(&DatabaseType::Postgres)); assert!(!skips_tcp_probe(&DatabaseType::Postgres));
@@ -328,6 +330,15 @@ fn driver_manifest_declares_expected_product_capabilities() {
assert!(zookeeper.capabilities.driver_management); assert!(zookeeper.capabilities.driver_management);
assert!(!zookeeper.capabilities.metadata_browse); assert!(!zookeeper.capabilities.metadata_browse);
let victoriametrics = find_driver(DatabaseType::VictoriaMetrics);
assert_eq!(victoriametrics.runtime_mode, "native");
assert_eq!(victoriametrics.support_level, "browse");
assert!(victoriametrics.capabilities.query_execution);
assert!(victoriametrics.capabilities.metadata_browse);
assert!(victoriametrics.capabilities.object_browser);
assert!(!victoriametrics.capabilities.table_data_edit);
assert!(!victoriametrics.capabilities.sql_explain);
let uxdb = find_driver(DatabaseType::Uxdb); let uxdb = find_driver(DatabaseType::Uxdb);
assert_eq!(uxdb.label, "优炫 UXDB"); assert_eq!(uxdb.label, "优炫 UXDB");
assert_eq!(uxdb.runtime_mode, "agent"); assert_eq!(uxdb.runtime_mode, "agent");
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

+15
View File
@@ -33,3 +33,18 @@ test("fetchTableDataForExport pages past the 10000 row export boundary", async (
assert.deepEqual(sqls, ["SELECT * FROM `users` LIMIT 10000;", "SELECT * FROM `users` LIMIT 10000 OFFSET 10000;"]); assert.deepEqual(sqls, ["SELECT * FROM `users` LIMIT 10000;", "SELECT * FROM `users` LIMIT 10000 OFFSET 10000;"]);
assert.equal(exported.truncated, false); assert.equal(exported.truncated, false);
}); });
test("fetchTableDataForExport executes a VictoriaMetrics range query once", async () => {
const sqls: string[] = [];
const exported = await fetchTableDataForExport({
databaseType: "victoriametrics",
tableName: "flag",
executePage: async (sql) => {
sqls.push(sql);
return result([[1], [2]]);
},
});
assert.deepEqual(sqls, ['{__name__="flag"}[1h]']);
assert.equal(exported.rows.length, 2);
});
+4
View File
@@ -31,6 +31,10 @@ test("builds SELECT template with explicit table columns", () => {
); );
}); });
test("builds a MetricsQL range query for VictoriaMetrics metrics", () => {
assert.equal(buildTableSelectTemplate({ databaseType: "victoriametrics", tableName: "flag" }), '{__name__="flag"}[1h]');
});
test("builds INSERT template without auto generated columns", () => { test("builds INSERT template without auto generated columns", () => {
assert.equal( assert.equal(
buildTableInsertTemplate({ buildTableInsertTemplate({
+13
View File
@@ -1077,6 +1077,13 @@ async fn test_connection_with_info_inner(
.await .await
.map(|_| "Connection successful".to_string()) .map(|_| "Connection successful".to_string())
} }
DatabaseType::VictoriaMetrics => {
let client =
db::victoriametrics_driver::VictoriaMetricsClient::new_for_config(&url, &config, connect_timeout)?;
db::victoriametrics_driver::test_connection(&client, connect_timeout)
.await
.map(|_| "Connection successful".to_string())
}
DatabaseType::Nacos => { DatabaseType::Nacos => {
let admin_config = state.nacos_admin_config_for_connection(connection_id, &config).await?; let admin_config = state.nacos_admin_config_for_connection(connection_id, &config).await?;
let adapter = state.nacos_registry.build_transient_config(admin_config).await?; let adapter = state.nacos_registry.build_transient_config(admin_config).await?;
@@ -1414,6 +1421,12 @@ pub async fn connect_db(
db::influxdb_driver::test_connection(&client, connect_timeout).await?; db::influxdb_driver::test_connection(&client, connect_timeout).await?;
PoolKind::InfluxDb(client) PoolKind::InfluxDb(client)
} }
DatabaseType::VictoriaMetrics => {
let client =
db::victoriametrics_driver::VictoriaMetricsClient::new_for_config(&url, &db_config, connect_timeout)?;
db::victoriametrics_driver::test_connection(&client, connect_timeout).await?;
PoolKind::VictoriaMetrics(client)
}
DatabaseType::Nacos => { DatabaseType::Nacos => {
let admin_config = state.nacos_admin_config_for_connection(&id, &config).await?; let admin_config = state.nacos_admin_config_for_connection(&id, &config).await?;
let adapter = state.nacos_registry.build_transient_config(admin_config).await?; let adapter = state.nacos_registry.build_transient_config(admin_config).await?;