feat(elasticsearch): add custom checks and tabular REST results
This commit is contained in:
1 parent
e2b35944ce
commit
a49137ae8b
44 files changed
+917
-74
No files matched your search
@@ -1,8 +1,10 @@
|
||||
export type ElasticsearchConnectionMode = "direct" | "kibana";
|
||||
|
||||
export interface ElasticsearchExternalConfig {
|
||||
mode: "kibana";
|
||||
mode?: "kibana" | "direct";
|
||||
kibanaBasePath?: string;
|
||||
/** GET path for connect/test/health. Empty means GET /. */
|
||||
connectivityCheckPath?: string;
|
||||
}
|
||||
|
||||
function externalConfigRecord(value: unknown): Record<string, unknown> {
|
||||
@@ -14,6 +16,16 @@ export function normalizeKibanaBasePath(value: string): string {
|
||||
return path ? `/${path}` : "";
|
||||
}
|
||||
|
||||
/** Normalize a connectivity-check path. Empty → "" (driver defaults to GET /). */
|
||||
export function normalizeElasticsearchConnectivityCheckPath(value: string): string {
|
||||
const raw = value.trim();
|
||||
if (!raw) return "";
|
||||
const line = raw.split(/\r?\n/, 1)[0]?.trim() ?? "";
|
||||
const withoutMethod = line.replace(/^GET\s+/i, "").trim();
|
||||
if (!withoutMethod || withoutMethod === "/") return "";
|
||||
return withoutMethod.startsWith("/") ? withoutMethod : `/${withoutMethod}`;
|
||||
}
|
||||
|
||||
export function elasticsearchConnectionModeFromConfig(value: unknown): ElasticsearchConnectionMode {
|
||||
const config = externalConfigRecord(value);
|
||||
return config.mode === "kibana" ? "kibana" : "direct";
|
||||
@@ -26,8 +38,20 @@ export function elasticsearchKibanaBasePathFromConfig(value: unknown): string {
|
||||
return typeof path === "string" ? normalizeKibanaBasePath(path) : "";
|
||||
}
|
||||
|
||||
export function buildElasticsearchExternalConfig(mode: ElasticsearchConnectionMode, kibanaBasePath: string): ElasticsearchExternalConfig | undefined {
|
||||
if (mode !== "kibana") return undefined;
|
||||
export function elasticsearchConnectivityCheckPathFromConfig(value: unknown): string {
|
||||
const config = externalConfigRecord(value);
|
||||
const path = config.connectivityCheckPath;
|
||||
return typeof path === "string" ? normalizeElasticsearchConnectivityCheckPath(path) : "";
|
||||
}
|
||||
|
||||
export function buildElasticsearchExternalConfig(mode: ElasticsearchConnectionMode, kibanaBasePath: string, connectivityCheckPath = ""): ElasticsearchExternalConfig | undefined {
|
||||
const checkPath = normalizeElasticsearchConnectivityCheckPath(connectivityCheckPath);
|
||||
if (mode !== "kibana") {
|
||||
return checkPath ? { connectivityCheckPath: checkPath } : undefined;
|
||||
}
|
||||
const normalizedPath = normalizeKibanaBasePath(kibanaBasePath);
|
||||
return normalizedPath ? { mode: "kibana", kibanaBasePath: normalizedPath } : { mode: "kibana" };
|
||||
const config: ElasticsearchExternalConfig = { mode: "kibana" };
|
||||
if (normalizedPath) config.kibanaBasePath = normalizedPath;
|
||||
if (checkPath) config.connectivityCheckPath = checkPath;
|
||||
return config;
|
||||
}
|
||||
Reference in new issue
Block a user