feat: persistent per-application config with GET/PUT endpoints
Some checks failed
CI / build (push) Failing after 1m10s
CI / cleanup-branch (push) Has been skipped
CI / docker (push) Has been skipped
CI / deploy (push) Has been skipped
CI / deploy-feature (push) Has been skipped

Add application_config table (V4 migration), repository, and REST
controller. GET /api/v1/config/{app} returns config, PUT saves and
pushes CONFIG_UPDATE to all LIVE agents via SSE. UI tracing toggle
now uses config API instead of direct SET_TRACED_PROCESSORS command.
Tracing store syncs with server config on load.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
hsiegeln
2026-03-25 07:42:55 +01:00
parent 488a32f319
commit 69a3eb192f
7 changed files with 257 additions and 16 deletions

View File

@@ -1,6 +1,51 @@
import { useMutation } from '@tanstack/react-query'
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
import { api } from '../client'
// ── Application Config ────────────────────────────────────────────────────
export interface ApplicationConfig {
application: string
version: number
updatedAt?: string
engineLevel?: string
payloadCaptureMode?: string
metricsEnabled: boolean
samplingRate: number
tracedProcessors: Record<string, string>
}
export function useApplicationConfig(application: string | undefined) {
return useQuery({
queryKey: ['applicationConfig', application],
queryFn: async () => {
const res = await fetch(`/api/v1/config/${application}`)
if (!res.ok) throw new Error('Failed to fetch config')
return res.json() as Promise<ApplicationConfig>
},
enabled: !!application,
})
}
export function useUpdateApplicationConfig() {
const queryClient = useQueryClient()
return useMutation({
mutationFn: async (config: ApplicationConfig) => {
const res = await fetch(`/api/v1/config/${config.application}`, {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(config),
})
if (!res.ok) throw new Error('Failed to update config')
return res.json() as Promise<ApplicationConfig>
},
onSuccess: (saved) => {
queryClient.setQueryData(['applicationConfig', saved.application], saved)
},
})
}
// ── Generic Group Command (kept for non-config commands) ──────────────────
interface SendGroupCommandParams {
group: string
type: string

View File

@@ -1,4 +1,4 @@
import { useState, useMemo, useCallback } from 'react'
import { useState, useMemo, useCallback, useEffect } from 'react'
import { useParams, useNavigate } from 'react-router'
import {
Badge, StatusDot, MonoText, CodeBlock, InfoCallout,
@@ -10,7 +10,7 @@ import { useCorrelationChain } from '../../api/queries/correlation'
import { useDiagramLayout } from '../../api/queries/diagrams'
import { mapDiagramToRouteNodes } from '../../utils/diagram-mapping'
import { useTracingStore } from '../../stores/tracing-store'
import { useSendGroupCommand } from '../../api/queries/commands'
import { useApplicationConfig, useUpdateApplicationConfig } from '../../api/queries/commands'
import styles from './ExchangeDetail.module.css'
// ── Helpers ──────────────────────────────────────────────────────────────────
@@ -187,27 +187,35 @@ export default function ExchangeDetail() {
// ── Tracing toggle ──────────────────────────────────────────────────────
const { toast } = useToast()
const tracingStore = useTracingStore()
const sendCommand = useSendGroupCommand()
const app = detail?.applicationName ?? ''
const { data: appConfig } = useApplicationConfig(app || undefined)
const updateConfig = useUpdateApplicationConfig()
// Sync tracing store with server config
useEffect(() => {
if (appConfig?.tracedProcessors && app) {
tracingStore.syncFromServer(app, appConfig.tracedProcessors)
}
}, [appConfig, app])
const handleToggleTracing = useCallback((processorId: string) => {
if (!processorId || !detail?.applicationName) return
if (!processorId || !detail?.applicationName || !appConfig) return
const newMap = tracingStore.toggleProcessor(app, processorId)
sendCommand.mutate({
group: detail.applicationName,
type: 'set-traced-processors',
payload: { processors: newMap },
}, {
onSuccess: (data) => {
const updatedConfig = {
...appConfig,
tracedProcessors: { ...newMap },
}
updateConfig.mutate(updatedConfig, {
onSuccess: (saved) => {
const action = processorId in newMap ? 'enabled' : 'disabled'
toast({ title: `Tracing ${action}`, description: `${processorId}sent to ${data?.targetCount ?? 0} agent(s)`, variant: 'success' })
toast({ title: `Tracing ${action}`, description: `${processorId}config v${saved.version}`, variant: 'success' })
},
onError: () => {
tracingStore.toggleProcessor(app, processorId)
toast({ title: 'Command failed', description: 'Could not send tracing command', variant: 'error' })
toast({ title: 'Config update failed', description: 'Could not save configuration', variant: 'error' })
},
})
}, [detail, app, tracingStore, sendCommand, toast])
}, [detail, app, appConfig, tracingStore, updateConfig, toast])
// Correlation chain
const correlatedExchanges = useMemo(() => {
@@ -372,7 +380,7 @@ export default function ExchangeDetail() {
return [{
label: tracingStore.isTraced(app, pid) ? 'Disable Tracing' : 'Enable Tracing',
onClick: () => handleToggleTracing(pid),
disabled: sendCommand.isPending,
disabled: updateConfig.isPending,
}]
}}
/>
@@ -391,7 +399,7 @@ export default function ExchangeDetail() {
return [{
label: tracingStore.isTraced(app, pid) ? 'Disable Tracing' : 'Enable Tracing',
onClick: () => handleToggleTracing(pid),
disabled: sendCommand.isPending,
disabled: updateConfig.isPending,
}]
}}
/>

View File

@@ -8,6 +8,8 @@ interface TracingState {
isTraced: (app: string, processorId: string) => boolean
/** Toggle processor tracing (BOTH on, remove on off). Returns the full map for the app. */
toggleProcessor: (app: string, processorId: string) => Record<string, CaptureMode>
/** Sync store with server-side config (called when config is fetched). */
syncFromServer: (app: string, tracedProcessors: Record<string, string>) => void
}
export const useTracingStore = create<TracingState>((set, get) => ({
@@ -25,4 +27,14 @@ export const useTracingStore = create<TracingState>((set, get) => ({
}))
return current
},
syncFromServer: (app, serverMap) => {
const mapped: Record<string, CaptureMode> = {}
for (const [k, v] of Object.entries(serverMap)) {
mapped[k] = v as CaptureMode
}
set((state) => ({
tracedProcessors: { ...state.tracedProcessors, [app]: mapped },
}))
},
}))