fix(influxdb): support InfluxDB 2 connections
This commit is contained in:
1 parent
b118ca31ed
commit
5db35307d3
5 files changed
+563
-52
No files matched your search
@@ -14,6 +14,7 @@ import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip
|
||||
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
|
||||
import { Switch } from "@/components/ui/switch";
|
||||
import type { ConnectionConfig, DatabaseType, HttpTunnelConfig, JdbcDriverInfo, JdbcMavenBundleInfo, ProxyTunnelConfig, SshConfigHostEntry, SshTunnelConfig, TransportLayerConfig } from "@/types/database";
|
||||
import type { InfluxDbExternalConfig, InfluxDbVersion } from "@/types/influxdb";
|
||||
import type { MqAdminConfig, MqAuth, MqSystemKind } from "@/types/mq";
|
||||
import type { NacosAdminConfig, NacosAuthConfig } from "@/types/nacos";
|
||||
import { CONNECTION_ATTEMPT_CANCELLED_MESSAGE, useConnectionStore } from "@/stores/connectionStore";
|
||||
@@ -756,6 +757,38 @@ function hydrateNacosFields(value: unknown) {
|
||||
resetNacosFields(value as Partial<NacosAdminConfig>);
|
||||
}
|
||||
|
||||
const influxDbVersion = ref<InfluxDbVersion>("1");
|
||||
const influxDbOrg = ref("");
|
||||
|
||||
function resetInfluxDbFields(config?: Partial<InfluxDbExternalConfig>) {
|
||||
influxDbVersion.value = config?.version === "2" ? "2" : "1";
|
||||
influxDbOrg.value = config?.org?.trim() || "";
|
||||
}
|
||||
|
||||
function hydrateInfluxDbFields(value: unknown) {
|
||||
if (!value || typeof value !== "object") {
|
||||
resetInfluxDbFields();
|
||||
return;
|
||||
}
|
||||
resetInfluxDbFields(value as Partial<InfluxDbExternalConfig>);
|
||||
}
|
||||
|
||||
function buildInfluxDbExternalConfig(): InfluxDbExternalConfig {
|
||||
if (influxDbVersion.value !== "2") return { version: "1" };
|
||||
const org = influxDbOrg.value.trim();
|
||||
if (!org) throw new Error("InfluxDB 2.x organization is required");
|
||||
if (!form.value.password.trim()) throw new Error("InfluxDB 2.x token is required");
|
||||
if (!form.value.database?.trim()) throw new Error("InfluxDB 2.x bucket is required");
|
||||
return { version: "2", org };
|
||||
}
|
||||
|
||||
watch(influxDbVersion, (version) => {
|
||||
if (form.value.db_type !== "influxdb") return;
|
||||
if (version === "2") {
|
||||
form.value.username = "";
|
||||
}
|
||||
});
|
||||
|
||||
function requireMqField(value: string, message: string): string {
|
||||
const trimmed = value.trim();
|
||||
if (!trimmed) throw new Error(message);
|
||||
@@ -1235,6 +1268,12 @@ function applyProfile(val: string, preserveConnectionFields = false) {
|
||||
form.value.connection_string = undefined;
|
||||
form.value.url_params = "";
|
||||
}
|
||||
if (profile.type === "influxdb") {
|
||||
resetInfluxDbFields();
|
||||
form.value.database = undefined;
|
||||
form.value.password = "";
|
||||
form.value.connection_string = undefined;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1302,6 +1341,7 @@ watch(
|
||||
redis_scan_page_size: config.redis_scan_page_size ?? REDIS_SCAN_PAGE_SIZE_DEFAULT,
|
||||
etcd_endpoints: config.etcd_endpoints || "",
|
||||
informix_server: config.informix_server || "",
|
||||
external_config: config.external_config,
|
||||
read_only: config.read_only || false,
|
||||
visible_databases: config.visible_databases,
|
||||
};
|
||||
@@ -1317,6 +1357,11 @@ watch(
|
||||
} else {
|
||||
resetNacosFields();
|
||||
}
|
||||
if (config.db_type === "influxdb") {
|
||||
hydrateInfluxDbFields(config.external_config);
|
||||
} else {
|
||||
resetInfluxDbFields();
|
||||
}
|
||||
h2ConnectionMode.value = h2ConnectionModeForConfig(config);
|
||||
customColorInput.value = config.color || "";
|
||||
selectedTransportLayerId.value = form.value.transport_layers?.[0]?.id || null;
|
||||
@@ -1343,6 +1388,7 @@ watch(
|
||||
customDriverName.value = "";
|
||||
resetMqFields();
|
||||
resetNacosFields();
|
||||
resetInfluxDbFields();
|
||||
oceanbaseSubMode.value = "mysql";
|
||||
h2ConnectionMode.value = "file";
|
||||
dremioConnectionMode.value = "legacy";
|
||||
@@ -1363,7 +1409,11 @@ watch(
|
||||
},
|
||||
);
|
||||
|
||||
const databaseLabel = computed(() => (form.value.db_type === "oracle" ? t("connection.serviceName") : t("connection.database")));
|
||||
const databaseLabel = computed(() => {
|
||||
if (form.value.db_type === "oracle") return t("connection.serviceName");
|
||||
if (form.value.db_type === "influxdb" && influxDbVersion.value === "2") return "Bucket";
|
||||
return t("connection.database");
|
||||
});
|
||||
|
||||
const databasePlaceholder = computed(() => {
|
||||
const fallback = defaultDatabaseForProfile();
|
||||
@@ -2110,6 +2160,14 @@ function connectionConfigForSubmit(id: string): ConnectionConfig {
|
||||
config.database = nacosConfig.namespace || undefined;
|
||||
config.connection_string = undefined;
|
||||
config.url_params = "";
|
||||
} else if (config.db_type === "influxdb") {
|
||||
config.external_config = buildInfluxDbExternalConfig();
|
||||
config.connection_string = undefined;
|
||||
if (influxDbVersion.value === "2") {
|
||||
config.username = "";
|
||||
config.password = config.password.trim();
|
||||
config.database = config.database?.trim() || undefined;
|
||||
}
|
||||
} else {
|
||||
config.external_config = undefined;
|
||||
}
|
||||
@@ -4201,6 +4259,66 @@ function openExternalUrl(url: string) {
|
||||
</template>
|
||||
</template>
|
||||
|
||||
<!-- InfluxDB: v1 username/password or v2 token/org/bucket -->
|
||||
<template v-else-if="form.db_type === 'influxdb'">
|
||||
<div class="grid grid-cols-4 items-center gap-4">
|
||||
<Label :class="connectionLabelSmallClass">{{ t("connection.version") }}</Label>
|
||||
<Select v-model="influxDbVersion">
|
||||
<SelectTrigger class="col-span-3">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="1">InfluxDB 1.x</SelectItem>
|
||||
<SelectItem value="2">InfluxDB 2.x</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
<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" class="mr-0" />
|
||||
<span>{{ t("connection.sslEnable") }}</span>
|
||||
</label>
|
||||
</div>
|
||||
<template v-if="influxDbVersion === '2'">
|
||||
<div class="grid grid-cols-4 items-center gap-4">
|
||||
<Label :class="connectionLabelClass">Organization</Label>
|
||||
<Input v-model="influxDbOrg" class="col-span-3" placeholder="my-org" />
|
||||
</div>
|
||||
<div class="grid grid-cols-4 items-center gap-4">
|
||||
<Label :class="connectionLabelClass">Bucket</Label>
|
||||
<Input v-model="form.database" class="col-span-3" placeholder="my-bucket" />
|
||||
</div>
|
||||
<div class="grid grid-cols-4 items-center gap-4">
|
||||
<Label :class="connectionLabelClass">Token</Label>
|
||||
<PasswordInput v-model="form.password" class="col-span-3" />
|
||||
</div>
|
||||
</template>
|
||||
<template v-else>
|
||||
<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" />
|
||||
</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-center gap-4">
|
||||
<Label :class="connectionLabelClass">{{ t("connection.database") }}</Label>
|
||||
<Input v-model="form.database" class="col-span-3" :placeholder="t('connection.databasePlaceholder')" />
|
||||
</div>
|
||||
</template>
|
||||
<div class="grid grid-cols-4 items-center gap-4">
|
||||
<Label :class="connectionLabelClass">{{ t("connection.urlParams") }}</Label>
|
||||
<Input v-model="form.url_params" class="col-span-3" :placeholder="influxDbVersion === '2' ? 'precision=ns' : 'epoch=ms'" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- Turso: simplified form (URL + Token) -->
|
||||
<template v-else-if="form.db_type === 'turso'">
|
||||
<div class="grid grid-cols-4 items-center gap-4">
|
||||
@@ -4318,9 +4436,7 @@ function openExternalUrl(url: string) {
|
||||
? 'OAuthType=0;OAuthServiceAcctEmail=svc@project.iam.gserviceaccount.com;OAuthPvtKeyPath=/path/key.json'
|
||||
: form.db_type === 'informix'
|
||||
? 'CLIENT_LOCALE=en_US.utf8;DB_LOCALE=en_US.utf8'
|
||||
: form.db_type === 'influxdb'
|
||||
? 'epoch=ms'
|
||||
: 'sslmode=disable'
|
||||
: 'sslmode=disable'
|
||||
"
|
||||
/>
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user