Add prefix query parameter to /admin/opensearch/indices endpoint so the UI can fetch execution and log indices separately. OpenSearch admin page now shows two card sections: Execution Indices and Log Indices, each with doc count and size summary. Page restyled with CSS module replacing inline styles. Delete endpoint also allows log index deletion. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
110 lines
3.3 KiB
TypeScript
110 lines
3.3 KiB
TypeScript
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
|
|
import { adminFetch } from './admin-api';
|
|
import { useRefreshInterval } from '../use-refresh-interval';
|
|
|
|
// ── Types ──────────────────────────────────────────────────────────────
|
|
|
|
export interface OpenSearchStatus {
|
|
reachable: boolean;
|
|
clusterHealth: string;
|
|
version: string | null;
|
|
nodeCount: number;
|
|
host: string;
|
|
}
|
|
|
|
export interface PipelineStats {
|
|
queueDepth: number;
|
|
maxQueueSize: number;
|
|
failedCount: number;
|
|
indexedCount: number;
|
|
debounceMs: number;
|
|
indexingRate: number;
|
|
lastIndexedAt: string | null;
|
|
}
|
|
|
|
export interface IndexInfo {
|
|
name: string;
|
|
docCount: number;
|
|
size: string;
|
|
sizeBytes: number;
|
|
health: string;
|
|
primaryShards: number;
|
|
replicas: number;
|
|
}
|
|
|
|
export interface IndicesPage {
|
|
indices: IndexInfo[];
|
|
totalIndices: number;
|
|
totalDocs: number;
|
|
totalSize: string;
|
|
page: number;
|
|
pageSize: number;
|
|
totalPages: number;
|
|
}
|
|
|
|
export interface PerformanceStats {
|
|
queryCacheHitRate: number;
|
|
requestCacheHitRate: number;
|
|
searchLatencyMs: number;
|
|
indexingLatencyMs: number;
|
|
heapUsedBytes: number;
|
|
heapMaxBytes: number;
|
|
}
|
|
|
|
// ── Query Hooks ────────────────────────────────────────────────────────
|
|
|
|
export function useOpenSearchStatus() {
|
|
const refetchInterval = useRefreshInterval(30_000);
|
|
return useQuery({
|
|
queryKey: ['admin', 'opensearch', 'status'],
|
|
queryFn: () => adminFetch<OpenSearchStatus>('/opensearch/status'),
|
|
refetchInterval,
|
|
});
|
|
}
|
|
|
|
export function usePipelineStats() {
|
|
const refetchInterval = useRefreshInterval(10_000);
|
|
return useQuery({
|
|
queryKey: ['admin', 'opensearch', 'pipeline'],
|
|
queryFn: () => adminFetch<PipelineStats>('/opensearch/pipeline'),
|
|
refetchInterval,
|
|
});
|
|
}
|
|
|
|
export function useOpenSearchIndices(page = 0, size = 20, search = '', prefix = 'executions') {
|
|
return useQuery({
|
|
queryKey: ['admin', 'opensearch', 'indices', prefix, page, size, search],
|
|
queryFn: () => {
|
|
const params = new URLSearchParams();
|
|
params.set('page', String(page));
|
|
params.set('size', String(size));
|
|
params.set('prefix', prefix);
|
|
if (search) params.set('search', search);
|
|
return adminFetch<IndicesPage>(`/opensearch/indices?${params}`);
|
|
},
|
|
placeholderData: (prev) => prev,
|
|
});
|
|
}
|
|
|
|
export function useOpenSearchPerformance() {
|
|
const refetchInterval = useRefreshInterval(30_000);
|
|
return useQuery({
|
|
queryKey: ['admin', 'opensearch', 'performance'],
|
|
queryFn: () => adminFetch<PerformanceStats>('/opensearch/performance'),
|
|
refetchInterval,
|
|
});
|
|
}
|
|
|
|
// ── Mutation Hooks ─────────────────────────────────────────────────────
|
|
|
|
export function useDeleteIndex() {
|
|
const qc = useQueryClient();
|
|
return useMutation({
|
|
mutationFn: (indexName: string) =>
|
|
adminFetch<void>(`/opensearch/indices/${indexName}`, { method: 'DELETE' }),
|
|
onSuccess: () => {
|
|
qc.invalidateQueries({ queryKey: ['admin', 'opensearch', 'indices'] });
|
|
},
|
|
});
|
|
}
|