Files
cameleer-server/ui/src/api/queries/executions.ts

161 lines
5.5 KiB
TypeScript
Raw Normal View History

import { useQuery } from '@tanstack/react-query';
import { api } from '../client';
feat!: move query/logs/routes/diagram/agent-view endpoints under /environments/{envSlug}/ P3C — the last data/query wave of the taxonomy migration. Every user- facing read endpoint that was keyed on env-as-query-param is now under the env-scoped URL, making env impossible to omit and unambiguous in server-side tenant+env filtering. Server: - SearchController: /api/v1/search/** → /api/v1/environments/{envSlug}/... Endpoints: /executions (GET), /executions/search (POST), /stats, /stats/timeseries, /stats/timeseries/by-app, /stats/timeseries/by-route, /stats/punchcard, /attributes/keys, /errors/top. Env comes from path. - LogQueryController: /api/v1/logs → /api/v1/environments/{envSlug}/logs. - RouteCatalogController: /api/v1/routes/catalog → /api/v1/environments/ {envSlug}/routes. Env filter unconditional (path). - RouteMetricsController: /api/v1/routes/metrics → /api/v1/environments/{envSlug}/routes/metrics (and /metrics/processors). - DiagramRenderController: /{contentHash}/render stays flat (hashes are globally unique). Find-by-route moved to /api/v1/environments/{envSlug}/ apps/{appSlug}/routes/{routeId}/diagram — the old GET /diagrams?... handler is removed. - Agent views split cleanly: - AgentListController (new): /api/v1/environments/{envSlug}/agents - AgentEventsController: /api/v1/environments/{envSlug}/agents/events - AgentMetricsController: /api/v1/environments/{envSlug}/agents/ {agentId}/metrics — now also rejects cross-env agents (404) as a defense-in-depth check, fulfilling B3. Agent self-service endpoints (register/refresh/heartbeat/deregister) remain flat at /api/v1/agents/** — JWT-authoritative. SPA: - queries/agents.ts, agent-metrics.ts, logs.ts, catalog.ts (route metrics only; /catalog stays flat), processor-metrics.ts, executions.ts (attributes/keys, stats, timeseries, search), dashboard.ts (all stats/errors/punchcard), correlation.ts, diagrams.ts (by-route) — all rewritten to env-scoped URLs. - Hooks now either read env from useEnvironmentStore internally or require it as an argument. Query keys include env so switching env invalidates caches. - useAgents/useAgentEvents signature simplified — env is no longer a parameter; it's read from the store. Callers (LayoutShell, AgentHealth, AgentInstance) updated accordingly. - LogTab and useStartupLogs thread env through to useLogs. - envFetch helper introduced in executions.ts for env-prefixed raw fetch until schema.d.ts is regenerated against the new backend. BREAKING CHANGE: All these flat paths are removed: /api/v1/search/**, /api/v1/logs, /api/v1/routes/catalog, /api/v1/routes/metrics (and /processors), /api/v1/diagrams (lookup), /api/v1/agents (list), /api/v1/agents/events-log, /api/v1/agents/{id}/metrics, /api/v1/agent-events. Clients must use the /api/v1/environments/{envSlug}/... equivalents. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-16 23:48:25 +02:00
import { config as appConfig } from '../../config';
import { useAuthStore } from '../../auth/auth-store';
fix!: require environment on diagram lookup and attribute keys queries Closes two cross-env data leakage paths. Both endpoints previously returned data aggregated across all environments, so a diagram or attribute key from dev could appear in a prod UI query (and vice versa). B1: GET /api/v1/diagrams?application=&routeId= now requires ?environment= and resolves agents via registryService.findByApplicationAndEnvironment instead of findByApplication. Prevents serving a dev diagram for a prod route. B2: GET /api/v1/search/attributes/keys now requires ?environment=. SearchIndex.distinctAttributeKeys gains an environment parameter and the ClickHouse query adds the env filter alongside the existing tenant_id filter. Prevents prod attribute names leaking into dev autocompletion (and vice versa). SPA hooks updated to thread environment through from useEnvironmentStore; query keys include environment so React Query re-fetches on env switch. No call-site changes needed — hook signatures unchanged. B3 (AgentMetricsController env scope) deferred to P3C: agent-env is effectively 1:1 today via the instance_id naming ({envSlug}-{appSlug}-{replicaIndex}), and the URL migration in P3C to /api/v1/environments/{env}/agents/{agentId}/metrics naturally introduces env from path. A minimal P1 fix would regress the "view metrics of a killed agent" case. BREAKING CHANGE: Both endpoints now require ?environment= (slug). Clients omitting the parameter receive 400. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-16 23:19:55 +02:00
import { useEnvironmentStore } from '../environment-store';
feat!: move query/logs/routes/diagram/agent-view endpoints under /environments/{envSlug}/ P3C — the last data/query wave of the taxonomy migration. Every user- facing read endpoint that was keyed on env-as-query-param is now under the env-scoped URL, making env impossible to omit and unambiguous in server-side tenant+env filtering. Server: - SearchController: /api/v1/search/** → /api/v1/environments/{envSlug}/... Endpoints: /executions (GET), /executions/search (POST), /stats, /stats/timeseries, /stats/timeseries/by-app, /stats/timeseries/by-route, /stats/punchcard, /attributes/keys, /errors/top. Env comes from path. - LogQueryController: /api/v1/logs → /api/v1/environments/{envSlug}/logs. - RouteCatalogController: /api/v1/routes/catalog → /api/v1/environments/ {envSlug}/routes. Env filter unconditional (path). - RouteMetricsController: /api/v1/routes/metrics → /api/v1/environments/{envSlug}/routes/metrics (and /metrics/processors). - DiagramRenderController: /{contentHash}/render stays flat (hashes are globally unique). Find-by-route moved to /api/v1/environments/{envSlug}/ apps/{appSlug}/routes/{routeId}/diagram — the old GET /diagrams?... handler is removed. - Agent views split cleanly: - AgentListController (new): /api/v1/environments/{envSlug}/agents - AgentEventsController: /api/v1/environments/{envSlug}/agents/events - AgentMetricsController: /api/v1/environments/{envSlug}/agents/ {agentId}/metrics — now also rejects cross-env agents (404) as a defense-in-depth check, fulfilling B3. Agent self-service endpoints (register/refresh/heartbeat/deregister) remain flat at /api/v1/agents/** — JWT-authoritative. SPA: - queries/agents.ts, agent-metrics.ts, logs.ts, catalog.ts (route metrics only; /catalog stays flat), processor-metrics.ts, executions.ts (attributes/keys, stats, timeseries, search), dashboard.ts (all stats/errors/punchcard), correlation.ts, diagrams.ts (by-route) — all rewritten to env-scoped URLs. - Hooks now either read env from useEnvironmentStore internally or require it as an argument. Query keys include env so switching env invalidates caches. - useAgents/useAgentEvents signature simplified — env is no longer a parameter; it's read from the store. Callers (LayoutShell, AgentHealth, AgentInstance) updated accordingly. - LogTab and useStartupLogs thread env through to useLogs. - envFetch helper introduced in executions.ts for env-prefixed raw fetch until schema.d.ts is regenerated against the new backend. BREAKING CHANGE: All these flat paths are removed: /api/v1/search/**, /api/v1/logs, /api/v1/routes/catalog, /api/v1/routes/metrics (and /processors), /api/v1/diagrams (lookup), /api/v1/agents (list), /api/v1/agents/events-log, /api/v1/agents/{id}/metrics, /api/v1/agent-events. Clients must use the /api/v1/environments/{envSlug}/... equivalents. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-16 23:48:25 +02:00
import type { components } from '../schema';
import type { SearchRequest } from '../types';
import { useLiveQuery } from './use-refresh-interval';
feat!: move query/logs/routes/diagram/agent-view endpoints under /environments/{envSlug}/ P3C — the last data/query wave of the taxonomy migration. Every user- facing read endpoint that was keyed on env-as-query-param is now under the env-scoped URL, making env impossible to omit and unambiguous in server-side tenant+env filtering. Server: - SearchController: /api/v1/search/** → /api/v1/environments/{envSlug}/... Endpoints: /executions (GET), /executions/search (POST), /stats, /stats/timeseries, /stats/timeseries/by-app, /stats/timeseries/by-route, /stats/punchcard, /attributes/keys, /errors/top. Env comes from path. - LogQueryController: /api/v1/logs → /api/v1/environments/{envSlug}/logs. - RouteCatalogController: /api/v1/routes/catalog → /api/v1/environments/ {envSlug}/routes. Env filter unconditional (path). - RouteMetricsController: /api/v1/routes/metrics → /api/v1/environments/{envSlug}/routes/metrics (and /metrics/processors). - DiagramRenderController: /{contentHash}/render stays flat (hashes are globally unique). Find-by-route moved to /api/v1/environments/{envSlug}/ apps/{appSlug}/routes/{routeId}/diagram — the old GET /diagrams?... handler is removed. - Agent views split cleanly: - AgentListController (new): /api/v1/environments/{envSlug}/agents - AgentEventsController: /api/v1/environments/{envSlug}/agents/events - AgentMetricsController: /api/v1/environments/{envSlug}/agents/ {agentId}/metrics — now also rejects cross-env agents (404) as a defense-in-depth check, fulfilling B3. Agent self-service endpoints (register/refresh/heartbeat/deregister) remain flat at /api/v1/agents/** — JWT-authoritative. SPA: - queries/agents.ts, agent-metrics.ts, logs.ts, catalog.ts (route metrics only; /catalog stays flat), processor-metrics.ts, executions.ts (attributes/keys, stats, timeseries, search), dashboard.ts (all stats/errors/punchcard), correlation.ts, diagrams.ts (by-route) — all rewritten to env-scoped URLs. - Hooks now either read env from useEnvironmentStore internally or require it as an argument. Query keys include env so switching env invalidates caches. - useAgents/useAgentEvents signature simplified — env is no longer a parameter; it's read from the store. Callers (LayoutShell, AgentHealth, AgentInstance) updated accordingly. - LogTab and useStartupLogs thread env through to useLogs. - envFetch helper introduced in executions.ts for env-prefixed raw fetch until schema.d.ts is regenerated against the new backend. BREAKING CHANGE: All these flat paths are removed: /api/v1/search/**, /api/v1/logs, /api/v1/routes/catalog, /api/v1/routes/metrics (and /processors), /api/v1/diagrams (lookup), /api/v1/agents (list), /api/v1/agents/events-log, /api/v1/agents/{id}/metrics, /api/v1/agent-events. Clients must use the /api/v1/environments/{envSlug}/... equivalents. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-16 23:48:25 +02:00
type ExecutionStats = components['schemas']['ExecutionStats'];
type StatsTimeseries = components['schemas']['StatsTimeseries'];
type SearchResultSummary = components['schemas']['SearchResultExecutionSummary'];
// Raw authenticated fetch — used for env-scoped endpoints where the
// generated openapi schema is still on the old flat shape. Switch back to
// api.GET once the schema is regenerated against a running P3-era backend.
async function envFetch<T>(envSlug: string, path: string, init?: RequestInit): Promise<T> {
const token = useAuthStore.getState().accessToken;
const res = await fetch(
`${appConfig.apiBaseUrl}/environments/${encodeURIComponent(envSlug)}${path}`, {
...init,
headers: {
'Content-Type': 'application/json',
...(token ? { Authorization: `Bearer ${token}` } : {}),
'X-Cameleer-Protocol-Version': '1',
...init?.headers,
},
});
if (!res.ok) throw new Error(`API error: ${res.status}`);
return res.json() as Promise<T>;
}
export function useExecutionStats(
timeFrom: string | undefined,
timeTo: string | undefined,
routeId?: string,
application?: string,
environment?: string,
) {
const live = useLiveQuery(10_000);
return useQuery({
feat!: move query/logs/routes/diagram/agent-view endpoints under /environments/{envSlug}/ P3C — the last data/query wave of the taxonomy migration. Every user- facing read endpoint that was keyed on env-as-query-param is now under the env-scoped URL, making env impossible to omit and unambiguous in server-side tenant+env filtering. Server: - SearchController: /api/v1/search/** → /api/v1/environments/{envSlug}/... Endpoints: /executions (GET), /executions/search (POST), /stats, /stats/timeseries, /stats/timeseries/by-app, /stats/timeseries/by-route, /stats/punchcard, /attributes/keys, /errors/top. Env comes from path. - LogQueryController: /api/v1/logs → /api/v1/environments/{envSlug}/logs. - RouteCatalogController: /api/v1/routes/catalog → /api/v1/environments/ {envSlug}/routes. Env filter unconditional (path). - RouteMetricsController: /api/v1/routes/metrics → /api/v1/environments/{envSlug}/routes/metrics (and /metrics/processors). - DiagramRenderController: /{contentHash}/render stays flat (hashes are globally unique). Find-by-route moved to /api/v1/environments/{envSlug}/ apps/{appSlug}/routes/{routeId}/diagram — the old GET /diagrams?... handler is removed. - Agent views split cleanly: - AgentListController (new): /api/v1/environments/{envSlug}/agents - AgentEventsController: /api/v1/environments/{envSlug}/agents/events - AgentMetricsController: /api/v1/environments/{envSlug}/agents/ {agentId}/metrics — now also rejects cross-env agents (404) as a defense-in-depth check, fulfilling B3. Agent self-service endpoints (register/refresh/heartbeat/deregister) remain flat at /api/v1/agents/** — JWT-authoritative. SPA: - queries/agents.ts, agent-metrics.ts, logs.ts, catalog.ts (route metrics only; /catalog stays flat), processor-metrics.ts, executions.ts (attributes/keys, stats, timeseries, search), dashboard.ts (all stats/errors/punchcard), correlation.ts, diagrams.ts (by-route) — all rewritten to env-scoped URLs. - Hooks now either read env from useEnvironmentStore internally or require it as an argument. Query keys include env so switching env invalidates caches. - useAgents/useAgentEvents signature simplified — env is no longer a parameter; it's read from the store. Callers (LayoutShell, AgentHealth, AgentInstance) updated accordingly. - LogTab and useStartupLogs thread env through to useLogs. - envFetch helper introduced in executions.ts for env-prefixed raw fetch until schema.d.ts is regenerated against the new backend. BREAKING CHANGE: All these flat paths are removed: /api/v1/search/**, /api/v1/logs, /api/v1/routes/catalog, /api/v1/routes/metrics (and /processors), /api/v1/diagrams (lookup), /api/v1/agents (list), /api/v1/agents/events-log, /api/v1/agents/{id}/metrics, /api/v1/agent-events. Clients must use the /api/v1/environments/{envSlug}/... equivalents. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-16 23:48:25 +02:00
queryKey: ['executions', 'stats', environment, timeFrom, timeTo, routeId, application],
queryFn: async () => {
feat!: move query/logs/routes/diagram/agent-view endpoints under /environments/{envSlug}/ P3C — the last data/query wave of the taxonomy migration. Every user- facing read endpoint that was keyed on env-as-query-param is now under the env-scoped URL, making env impossible to omit and unambiguous in server-side tenant+env filtering. Server: - SearchController: /api/v1/search/** → /api/v1/environments/{envSlug}/... Endpoints: /executions (GET), /executions/search (POST), /stats, /stats/timeseries, /stats/timeseries/by-app, /stats/timeseries/by-route, /stats/punchcard, /attributes/keys, /errors/top. Env comes from path. - LogQueryController: /api/v1/logs → /api/v1/environments/{envSlug}/logs. - RouteCatalogController: /api/v1/routes/catalog → /api/v1/environments/ {envSlug}/routes. Env filter unconditional (path). - RouteMetricsController: /api/v1/routes/metrics → /api/v1/environments/{envSlug}/routes/metrics (and /metrics/processors). - DiagramRenderController: /{contentHash}/render stays flat (hashes are globally unique). Find-by-route moved to /api/v1/environments/{envSlug}/ apps/{appSlug}/routes/{routeId}/diagram — the old GET /diagrams?... handler is removed. - Agent views split cleanly: - AgentListController (new): /api/v1/environments/{envSlug}/agents - AgentEventsController: /api/v1/environments/{envSlug}/agents/events - AgentMetricsController: /api/v1/environments/{envSlug}/agents/ {agentId}/metrics — now also rejects cross-env agents (404) as a defense-in-depth check, fulfilling B3. Agent self-service endpoints (register/refresh/heartbeat/deregister) remain flat at /api/v1/agents/** — JWT-authoritative. SPA: - queries/agents.ts, agent-metrics.ts, logs.ts, catalog.ts (route metrics only; /catalog stays flat), processor-metrics.ts, executions.ts (attributes/keys, stats, timeseries, search), dashboard.ts (all stats/errors/punchcard), correlation.ts, diagrams.ts (by-route) — all rewritten to env-scoped URLs. - Hooks now either read env from useEnvironmentStore internally or require it as an argument. Query keys include env so switching env invalidates caches. - useAgents/useAgentEvents signature simplified — env is no longer a parameter; it's read from the store. Callers (LayoutShell, AgentHealth, AgentInstance) updated accordingly. - LogTab and useStartupLogs thread env through to useLogs. - envFetch helper introduced in executions.ts for env-prefixed raw fetch until schema.d.ts is regenerated against the new backend. BREAKING CHANGE: All these flat paths are removed: /api/v1/search/**, /api/v1/logs, /api/v1/routes/catalog, /api/v1/routes/metrics (and /processors), /api/v1/diagrams (lookup), /api/v1/agents (list), /api/v1/agents/events-log, /api/v1/agents/{id}/metrics, /api/v1/agent-events. Clients must use the /api/v1/environments/{envSlug}/... equivalents. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-16 23:48:25 +02:00
const params = new URLSearchParams({ from: timeFrom! });
if (timeTo) params.set('to', timeTo);
if (routeId) params.set('routeId', routeId);
if (application) params.set('application', application);
return envFetch<ExecutionStats>(environment!, `/stats?${params}`);
},
feat!: move query/logs/routes/diagram/agent-view endpoints under /environments/{envSlug}/ P3C — the last data/query wave of the taxonomy migration. Every user- facing read endpoint that was keyed on env-as-query-param is now under the env-scoped URL, making env impossible to omit and unambiguous in server-side tenant+env filtering. Server: - SearchController: /api/v1/search/** → /api/v1/environments/{envSlug}/... Endpoints: /executions (GET), /executions/search (POST), /stats, /stats/timeseries, /stats/timeseries/by-app, /stats/timeseries/by-route, /stats/punchcard, /attributes/keys, /errors/top. Env comes from path. - LogQueryController: /api/v1/logs → /api/v1/environments/{envSlug}/logs. - RouteCatalogController: /api/v1/routes/catalog → /api/v1/environments/ {envSlug}/routes. Env filter unconditional (path). - RouteMetricsController: /api/v1/routes/metrics → /api/v1/environments/{envSlug}/routes/metrics (and /metrics/processors). - DiagramRenderController: /{contentHash}/render stays flat (hashes are globally unique). Find-by-route moved to /api/v1/environments/{envSlug}/ apps/{appSlug}/routes/{routeId}/diagram — the old GET /diagrams?... handler is removed. - Agent views split cleanly: - AgentListController (new): /api/v1/environments/{envSlug}/agents - AgentEventsController: /api/v1/environments/{envSlug}/agents/events - AgentMetricsController: /api/v1/environments/{envSlug}/agents/ {agentId}/metrics — now also rejects cross-env agents (404) as a defense-in-depth check, fulfilling B3. Agent self-service endpoints (register/refresh/heartbeat/deregister) remain flat at /api/v1/agents/** — JWT-authoritative. SPA: - queries/agents.ts, agent-metrics.ts, logs.ts, catalog.ts (route metrics only; /catalog stays flat), processor-metrics.ts, executions.ts (attributes/keys, stats, timeseries, search), dashboard.ts (all stats/errors/punchcard), correlation.ts, diagrams.ts (by-route) — all rewritten to env-scoped URLs. - Hooks now either read env from useEnvironmentStore internally or require it as an argument. Query keys include env so switching env invalidates caches. - useAgents/useAgentEvents signature simplified — env is no longer a parameter; it's read from the store. Callers (LayoutShell, AgentHealth, AgentInstance) updated accordingly. - LogTab and useStartupLogs thread env through to useLogs. - envFetch helper introduced in executions.ts for env-prefixed raw fetch until schema.d.ts is regenerated against the new backend. BREAKING CHANGE: All these flat paths are removed: /api/v1/search/**, /api/v1/logs, /api/v1/routes/catalog, /api/v1/routes/metrics (and /processors), /api/v1/diagrams (lookup), /api/v1/agents (list), /api/v1/agents/events-log, /api/v1/agents/{id}/metrics, /api/v1/agent-events. Clients must use the /api/v1/environments/{envSlug}/... equivalents. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-16 23:48:25 +02:00
enabled: !!timeFrom && !!environment && live.enabled,
placeholderData: (prev) => prev,
refetchInterval: live.refetchInterval,
});
}
export function useAttributeKeys() {
fix!: require environment on diagram lookup and attribute keys queries Closes two cross-env data leakage paths. Both endpoints previously returned data aggregated across all environments, so a diagram or attribute key from dev could appear in a prod UI query (and vice versa). B1: GET /api/v1/diagrams?application=&routeId= now requires ?environment= and resolves agents via registryService.findByApplicationAndEnvironment instead of findByApplication. Prevents serving a dev diagram for a prod route. B2: GET /api/v1/search/attributes/keys now requires ?environment=. SearchIndex.distinctAttributeKeys gains an environment parameter and the ClickHouse query adds the env filter alongside the existing tenant_id filter. Prevents prod attribute names leaking into dev autocompletion (and vice versa). SPA hooks updated to thread environment through from useEnvironmentStore; query keys include environment so React Query re-fetches on env switch. No call-site changes needed — hook signatures unchanged. B3 (AgentMetricsController env scope) deferred to P3C: agent-env is effectively 1:1 today via the instance_id naming ({envSlug}-{appSlug}-{replicaIndex}), and the URL migration in P3C to /api/v1/environments/{env}/agents/{agentId}/metrics naturally introduces env from path. A minimal P1 fix would regress the "view metrics of a killed agent" case. BREAKING CHANGE: Both endpoints now require ?environment= (slug). Clients omitting the parameter receive 400. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-16 23:19:55 +02:00
const environment = useEnvironmentStore((s) => s.environment);
return useQuery({
fix!: require environment on diagram lookup and attribute keys queries Closes two cross-env data leakage paths. Both endpoints previously returned data aggregated across all environments, so a diagram or attribute key from dev could appear in a prod UI query (and vice versa). B1: GET /api/v1/diagrams?application=&routeId= now requires ?environment= and resolves agents via registryService.findByApplicationAndEnvironment instead of findByApplication. Prevents serving a dev diagram for a prod route. B2: GET /api/v1/search/attributes/keys now requires ?environment=. SearchIndex.distinctAttributeKeys gains an environment parameter and the ClickHouse query adds the env filter alongside the existing tenant_id filter. Prevents prod attribute names leaking into dev autocompletion (and vice versa). SPA hooks updated to thread environment through from useEnvironmentStore; query keys include environment so React Query re-fetches on env switch. No call-site changes needed — hook signatures unchanged. B3 (AgentMetricsController env scope) deferred to P3C: agent-env is effectively 1:1 today via the instance_id naming ({envSlug}-{appSlug}-{replicaIndex}), and the URL migration in P3C to /api/v1/environments/{env}/agents/{agentId}/metrics naturally introduces env from path. A minimal P1 fix would regress the "view metrics of a killed agent" case. BREAKING CHANGE: Both endpoints now require ?environment= (slug). Clients omitting the parameter receive 400. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-16 23:19:55 +02:00
queryKey: ['search', 'attribute-keys', environment],
feat!: move query/logs/routes/diagram/agent-view endpoints under /environments/{envSlug}/ P3C — the last data/query wave of the taxonomy migration. Every user- facing read endpoint that was keyed on env-as-query-param is now under the env-scoped URL, making env impossible to omit and unambiguous in server-side tenant+env filtering. Server: - SearchController: /api/v1/search/** → /api/v1/environments/{envSlug}/... Endpoints: /executions (GET), /executions/search (POST), /stats, /stats/timeseries, /stats/timeseries/by-app, /stats/timeseries/by-route, /stats/punchcard, /attributes/keys, /errors/top. Env comes from path. - LogQueryController: /api/v1/logs → /api/v1/environments/{envSlug}/logs. - RouteCatalogController: /api/v1/routes/catalog → /api/v1/environments/ {envSlug}/routes. Env filter unconditional (path). - RouteMetricsController: /api/v1/routes/metrics → /api/v1/environments/{envSlug}/routes/metrics (and /metrics/processors). - DiagramRenderController: /{contentHash}/render stays flat (hashes are globally unique). Find-by-route moved to /api/v1/environments/{envSlug}/ apps/{appSlug}/routes/{routeId}/diagram — the old GET /diagrams?... handler is removed. - Agent views split cleanly: - AgentListController (new): /api/v1/environments/{envSlug}/agents - AgentEventsController: /api/v1/environments/{envSlug}/agents/events - AgentMetricsController: /api/v1/environments/{envSlug}/agents/ {agentId}/metrics — now also rejects cross-env agents (404) as a defense-in-depth check, fulfilling B3. Agent self-service endpoints (register/refresh/heartbeat/deregister) remain flat at /api/v1/agents/** — JWT-authoritative. SPA: - queries/agents.ts, agent-metrics.ts, logs.ts, catalog.ts (route metrics only; /catalog stays flat), processor-metrics.ts, executions.ts (attributes/keys, stats, timeseries, search), dashboard.ts (all stats/errors/punchcard), correlation.ts, diagrams.ts (by-route) — all rewritten to env-scoped URLs. - Hooks now either read env from useEnvironmentStore internally or require it as an argument. Query keys include env so switching env invalidates caches. - useAgents/useAgentEvents signature simplified — env is no longer a parameter; it's read from the store. Callers (LayoutShell, AgentHealth, AgentInstance) updated accordingly. - LogTab and useStartupLogs thread env through to useLogs. - envFetch helper introduced in executions.ts for env-prefixed raw fetch until schema.d.ts is regenerated against the new backend. BREAKING CHANGE: All these flat paths are removed: /api/v1/search/**, /api/v1/logs, /api/v1/routes/catalog, /api/v1/routes/metrics (and /processors), /api/v1/diagrams (lookup), /api/v1/agents (list), /api/v1/agents/events-log, /api/v1/agents/{id}/metrics, /api/v1/agent-events. Clients must use the /api/v1/environments/{envSlug}/... equivalents. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-16 23:48:25 +02:00
queryFn: () => envFetch<string[]>(environment!, '/attributes/keys'),
fix!: require environment on diagram lookup and attribute keys queries Closes two cross-env data leakage paths. Both endpoints previously returned data aggregated across all environments, so a diagram or attribute key from dev could appear in a prod UI query (and vice versa). B1: GET /api/v1/diagrams?application=&routeId= now requires ?environment= and resolves agents via registryService.findByApplicationAndEnvironment instead of findByApplication. Prevents serving a dev diagram for a prod route. B2: GET /api/v1/search/attributes/keys now requires ?environment=. SearchIndex.distinctAttributeKeys gains an environment parameter and the ClickHouse query adds the env filter alongside the existing tenant_id filter. Prevents prod attribute names leaking into dev autocompletion (and vice versa). SPA hooks updated to thread environment through from useEnvironmentStore; query keys include environment so React Query re-fetches on env switch. No call-site changes needed — hook signatures unchanged. B3 (AgentMetricsController env scope) deferred to P3C: agent-env is effectively 1:1 today via the instance_id naming ({envSlug}-{appSlug}-{replicaIndex}), and the URL migration in P3C to /api/v1/environments/{env}/agents/{agentId}/metrics naturally introduces env from path. A minimal P1 fix would regress the "view metrics of a killed agent" case. BREAKING CHANGE: Both endpoints now require ?environment= (slug). Clients omitting the parameter receive 400. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-16 23:19:55 +02:00
enabled: !!environment,
staleTime: 60_000,
});
}
export function useSearchExecutions(filters: SearchRequest, live = false) {
feat!: move query/logs/routes/diagram/agent-view endpoints under /environments/{envSlug}/ P3C — the last data/query wave of the taxonomy migration. Every user- facing read endpoint that was keyed on env-as-query-param is now under the env-scoped URL, making env impossible to omit and unambiguous in server-side tenant+env filtering. Server: - SearchController: /api/v1/search/** → /api/v1/environments/{envSlug}/... Endpoints: /executions (GET), /executions/search (POST), /stats, /stats/timeseries, /stats/timeseries/by-app, /stats/timeseries/by-route, /stats/punchcard, /attributes/keys, /errors/top. Env comes from path. - LogQueryController: /api/v1/logs → /api/v1/environments/{envSlug}/logs. - RouteCatalogController: /api/v1/routes/catalog → /api/v1/environments/ {envSlug}/routes. Env filter unconditional (path). - RouteMetricsController: /api/v1/routes/metrics → /api/v1/environments/{envSlug}/routes/metrics (and /metrics/processors). - DiagramRenderController: /{contentHash}/render stays flat (hashes are globally unique). Find-by-route moved to /api/v1/environments/{envSlug}/ apps/{appSlug}/routes/{routeId}/diagram — the old GET /diagrams?... handler is removed. - Agent views split cleanly: - AgentListController (new): /api/v1/environments/{envSlug}/agents - AgentEventsController: /api/v1/environments/{envSlug}/agents/events - AgentMetricsController: /api/v1/environments/{envSlug}/agents/ {agentId}/metrics — now also rejects cross-env agents (404) as a defense-in-depth check, fulfilling B3. Agent self-service endpoints (register/refresh/heartbeat/deregister) remain flat at /api/v1/agents/** — JWT-authoritative. SPA: - queries/agents.ts, agent-metrics.ts, logs.ts, catalog.ts (route metrics only; /catalog stays flat), processor-metrics.ts, executions.ts (attributes/keys, stats, timeseries, search), dashboard.ts (all stats/errors/punchcard), correlation.ts, diagrams.ts (by-route) — all rewritten to env-scoped URLs. - Hooks now either read env from useEnvironmentStore internally or require it as an argument. Query keys include env so switching env invalidates caches. - useAgents/useAgentEvents signature simplified — env is no longer a parameter; it's read from the store. Callers (LayoutShell, AgentHealth, AgentInstance) updated accordingly. - LogTab and useStartupLogs thread env through to useLogs. - envFetch helper introduced in executions.ts for env-prefixed raw fetch until schema.d.ts is regenerated against the new backend. BREAKING CHANGE: All these flat paths are removed: /api/v1/search/**, /api/v1/logs, /api/v1/routes/catalog, /api/v1/routes/metrics (and /processors), /api/v1/diagrams (lookup), /api/v1/agents (list), /api/v1/agents/events-log, /api/v1/agents/{id}/metrics, /api/v1/agent-events. Clients must use the /api/v1/environments/{envSlug}/... equivalents. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-16 23:48:25 +02:00
const environment = useEnvironmentStore((s) => s.environment);
const liveQuery = useLiveQuery(5_000);
return useQuery({
feat!: move query/logs/routes/diagram/agent-view endpoints under /environments/{envSlug}/ P3C — the last data/query wave of the taxonomy migration. Every user- facing read endpoint that was keyed on env-as-query-param is now under the env-scoped URL, making env impossible to omit and unambiguous in server-side tenant+env filtering. Server: - SearchController: /api/v1/search/** → /api/v1/environments/{envSlug}/... Endpoints: /executions (GET), /executions/search (POST), /stats, /stats/timeseries, /stats/timeseries/by-app, /stats/timeseries/by-route, /stats/punchcard, /attributes/keys, /errors/top. Env comes from path. - LogQueryController: /api/v1/logs → /api/v1/environments/{envSlug}/logs. - RouteCatalogController: /api/v1/routes/catalog → /api/v1/environments/ {envSlug}/routes. Env filter unconditional (path). - RouteMetricsController: /api/v1/routes/metrics → /api/v1/environments/{envSlug}/routes/metrics (and /metrics/processors). - DiagramRenderController: /{contentHash}/render stays flat (hashes are globally unique). Find-by-route moved to /api/v1/environments/{envSlug}/ apps/{appSlug}/routes/{routeId}/diagram — the old GET /diagrams?... handler is removed. - Agent views split cleanly: - AgentListController (new): /api/v1/environments/{envSlug}/agents - AgentEventsController: /api/v1/environments/{envSlug}/agents/events - AgentMetricsController: /api/v1/environments/{envSlug}/agents/ {agentId}/metrics — now also rejects cross-env agents (404) as a defense-in-depth check, fulfilling B3. Agent self-service endpoints (register/refresh/heartbeat/deregister) remain flat at /api/v1/agents/** — JWT-authoritative. SPA: - queries/agents.ts, agent-metrics.ts, logs.ts, catalog.ts (route metrics only; /catalog stays flat), processor-metrics.ts, executions.ts (attributes/keys, stats, timeseries, search), dashboard.ts (all stats/errors/punchcard), correlation.ts, diagrams.ts (by-route) — all rewritten to env-scoped URLs. - Hooks now either read env from useEnvironmentStore internally or require it as an argument. Query keys include env so switching env invalidates caches. - useAgents/useAgentEvents signature simplified — env is no longer a parameter; it's read from the store. Callers (LayoutShell, AgentHealth, AgentInstance) updated accordingly. - LogTab and useStartupLogs thread env through to useLogs. - envFetch helper introduced in executions.ts for env-prefixed raw fetch until schema.d.ts is regenerated against the new backend. BREAKING CHANGE: All these flat paths are removed: /api/v1/search/**, /api/v1/logs, /api/v1/routes/catalog, /api/v1/routes/metrics (and /processors), /api/v1/diagrams (lookup), /api/v1/agents (list), /api/v1/agents/events-log, /api/v1/agents/{id}/metrics, /api/v1/agent-events. Clients must use the /api/v1/environments/{envSlug}/... equivalents. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-16 23:48:25 +02:00
queryKey: ['executions', 'search', environment, filters],
queryFn: () => envFetch<SearchResultSummary>(environment!, '/executions/search', {
method: 'POST',
body: JSON.stringify(filters),
}),
placeholderData: (prev) => prev,
feat!: move query/logs/routes/diagram/agent-view endpoints under /environments/{envSlug}/ P3C — the last data/query wave of the taxonomy migration. Every user- facing read endpoint that was keyed on env-as-query-param is now under the env-scoped URL, making env impossible to omit and unambiguous in server-side tenant+env filtering. Server: - SearchController: /api/v1/search/** → /api/v1/environments/{envSlug}/... Endpoints: /executions (GET), /executions/search (POST), /stats, /stats/timeseries, /stats/timeseries/by-app, /stats/timeseries/by-route, /stats/punchcard, /attributes/keys, /errors/top. Env comes from path. - LogQueryController: /api/v1/logs → /api/v1/environments/{envSlug}/logs. - RouteCatalogController: /api/v1/routes/catalog → /api/v1/environments/ {envSlug}/routes. Env filter unconditional (path). - RouteMetricsController: /api/v1/routes/metrics → /api/v1/environments/{envSlug}/routes/metrics (and /metrics/processors). - DiagramRenderController: /{contentHash}/render stays flat (hashes are globally unique). Find-by-route moved to /api/v1/environments/{envSlug}/ apps/{appSlug}/routes/{routeId}/diagram — the old GET /diagrams?... handler is removed. - Agent views split cleanly: - AgentListController (new): /api/v1/environments/{envSlug}/agents - AgentEventsController: /api/v1/environments/{envSlug}/agents/events - AgentMetricsController: /api/v1/environments/{envSlug}/agents/ {agentId}/metrics — now also rejects cross-env agents (404) as a defense-in-depth check, fulfilling B3. Agent self-service endpoints (register/refresh/heartbeat/deregister) remain flat at /api/v1/agents/** — JWT-authoritative. SPA: - queries/agents.ts, agent-metrics.ts, logs.ts, catalog.ts (route metrics only; /catalog stays flat), processor-metrics.ts, executions.ts (attributes/keys, stats, timeseries, search), dashboard.ts (all stats/errors/punchcard), correlation.ts, diagrams.ts (by-route) — all rewritten to env-scoped URLs. - Hooks now either read env from useEnvironmentStore internally or require it as an argument. Query keys include env so switching env invalidates caches. - useAgents/useAgentEvents signature simplified — env is no longer a parameter; it's read from the store. Callers (LayoutShell, AgentHealth, AgentInstance) updated accordingly. - LogTab and useStartupLogs thread env through to useLogs. - envFetch helper introduced in executions.ts for env-prefixed raw fetch until schema.d.ts is regenerated against the new backend. BREAKING CHANGE: All these flat paths are removed: /api/v1/search/**, /api/v1/logs, /api/v1/routes/catalog, /api/v1/routes/metrics (and /processors), /api/v1/diagrams (lookup), /api/v1/agents (list), /api/v1/agents/events-log, /api/v1/agents/{id}/metrics, /api/v1/agent-events. Clients must use the /api/v1/environments/{envSlug}/... equivalents. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-16 23:48:25 +02:00
enabled: !!environment && (live ? liveQuery.enabled : true),
refetchInterval: live ? liveQuery.refetchInterval : false,
});
}
export function useStatsTimeseries(
timeFrom: string | undefined,
timeTo: string | undefined,
routeId?: string,
application?: string,
environment?: string,
) {
const live = useLiveQuery(30_000);
return useQuery({
feat!: move query/logs/routes/diagram/agent-view endpoints under /environments/{envSlug}/ P3C — the last data/query wave of the taxonomy migration. Every user- facing read endpoint that was keyed on env-as-query-param is now under the env-scoped URL, making env impossible to omit and unambiguous in server-side tenant+env filtering. Server: - SearchController: /api/v1/search/** → /api/v1/environments/{envSlug}/... Endpoints: /executions (GET), /executions/search (POST), /stats, /stats/timeseries, /stats/timeseries/by-app, /stats/timeseries/by-route, /stats/punchcard, /attributes/keys, /errors/top. Env comes from path. - LogQueryController: /api/v1/logs → /api/v1/environments/{envSlug}/logs. - RouteCatalogController: /api/v1/routes/catalog → /api/v1/environments/ {envSlug}/routes. Env filter unconditional (path). - RouteMetricsController: /api/v1/routes/metrics → /api/v1/environments/{envSlug}/routes/metrics (and /metrics/processors). - DiagramRenderController: /{contentHash}/render stays flat (hashes are globally unique). Find-by-route moved to /api/v1/environments/{envSlug}/ apps/{appSlug}/routes/{routeId}/diagram — the old GET /diagrams?... handler is removed. - Agent views split cleanly: - AgentListController (new): /api/v1/environments/{envSlug}/agents - AgentEventsController: /api/v1/environments/{envSlug}/agents/events - AgentMetricsController: /api/v1/environments/{envSlug}/agents/ {agentId}/metrics — now also rejects cross-env agents (404) as a defense-in-depth check, fulfilling B3. Agent self-service endpoints (register/refresh/heartbeat/deregister) remain flat at /api/v1/agents/** — JWT-authoritative. SPA: - queries/agents.ts, agent-metrics.ts, logs.ts, catalog.ts (route metrics only; /catalog stays flat), processor-metrics.ts, executions.ts (attributes/keys, stats, timeseries, search), dashboard.ts (all stats/errors/punchcard), correlation.ts, diagrams.ts (by-route) — all rewritten to env-scoped URLs. - Hooks now either read env from useEnvironmentStore internally or require it as an argument. Query keys include env so switching env invalidates caches. - useAgents/useAgentEvents signature simplified — env is no longer a parameter; it's read from the store. Callers (LayoutShell, AgentHealth, AgentInstance) updated accordingly. - LogTab and useStartupLogs thread env through to useLogs. - envFetch helper introduced in executions.ts for env-prefixed raw fetch until schema.d.ts is regenerated against the new backend. BREAKING CHANGE: All these flat paths are removed: /api/v1/search/**, /api/v1/logs, /api/v1/routes/catalog, /api/v1/routes/metrics (and /processors), /api/v1/diagrams (lookup), /api/v1/agents (list), /api/v1/agents/events-log, /api/v1/agents/{id}/metrics, /api/v1/agent-events. Clients must use the /api/v1/environments/{envSlug}/... equivalents. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-16 23:48:25 +02:00
queryKey: ['executions', 'timeseries', environment, timeFrom, timeTo, routeId, application],
queryFn: async () => {
feat!: move query/logs/routes/diagram/agent-view endpoints under /environments/{envSlug}/ P3C — the last data/query wave of the taxonomy migration. Every user- facing read endpoint that was keyed on env-as-query-param is now under the env-scoped URL, making env impossible to omit and unambiguous in server-side tenant+env filtering. Server: - SearchController: /api/v1/search/** → /api/v1/environments/{envSlug}/... Endpoints: /executions (GET), /executions/search (POST), /stats, /stats/timeseries, /stats/timeseries/by-app, /stats/timeseries/by-route, /stats/punchcard, /attributes/keys, /errors/top. Env comes from path. - LogQueryController: /api/v1/logs → /api/v1/environments/{envSlug}/logs. - RouteCatalogController: /api/v1/routes/catalog → /api/v1/environments/ {envSlug}/routes. Env filter unconditional (path). - RouteMetricsController: /api/v1/routes/metrics → /api/v1/environments/{envSlug}/routes/metrics (and /metrics/processors). - DiagramRenderController: /{contentHash}/render stays flat (hashes are globally unique). Find-by-route moved to /api/v1/environments/{envSlug}/ apps/{appSlug}/routes/{routeId}/diagram — the old GET /diagrams?... handler is removed. - Agent views split cleanly: - AgentListController (new): /api/v1/environments/{envSlug}/agents - AgentEventsController: /api/v1/environments/{envSlug}/agents/events - AgentMetricsController: /api/v1/environments/{envSlug}/agents/ {agentId}/metrics — now also rejects cross-env agents (404) as a defense-in-depth check, fulfilling B3. Agent self-service endpoints (register/refresh/heartbeat/deregister) remain flat at /api/v1/agents/** — JWT-authoritative. SPA: - queries/agents.ts, agent-metrics.ts, logs.ts, catalog.ts (route metrics only; /catalog stays flat), processor-metrics.ts, executions.ts (attributes/keys, stats, timeseries, search), dashboard.ts (all stats/errors/punchcard), correlation.ts, diagrams.ts (by-route) — all rewritten to env-scoped URLs. - Hooks now either read env from useEnvironmentStore internally or require it as an argument. Query keys include env so switching env invalidates caches. - useAgents/useAgentEvents signature simplified — env is no longer a parameter; it's read from the store. Callers (LayoutShell, AgentHealth, AgentInstance) updated accordingly. - LogTab and useStartupLogs thread env through to useLogs. - envFetch helper introduced in executions.ts for env-prefixed raw fetch until schema.d.ts is regenerated against the new backend. BREAKING CHANGE: All these flat paths are removed: /api/v1/search/**, /api/v1/logs, /api/v1/routes/catalog, /api/v1/routes/metrics (and /processors), /api/v1/diagrams (lookup), /api/v1/agents (list), /api/v1/agents/events-log, /api/v1/agents/{id}/metrics, /api/v1/agent-events. Clients must use the /api/v1/environments/{envSlug}/... equivalents. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-16 23:48:25 +02:00
const params = new URLSearchParams({ from: timeFrom!, buckets: '24' });
if (timeTo) params.set('to', timeTo);
if (routeId) params.set('routeId', routeId);
if (application) params.set('application', application);
return envFetch<StatsTimeseries>(environment!, `/stats/timeseries?${params}`);
},
feat!: move query/logs/routes/diagram/agent-view endpoints under /environments/{envSlug}/ P3C — the last data/query wave of the taxonomy migration. Every user- facing read endpoint that was keyed on env-as-query-param is now under the env-scoped URL, making env impossible to omit and unambiguous in server-side tenant+env filtering. Server: - SearchController: /api/v1/search/** → /api/v1/environments/{envSlug}/... Endpoints: /executions (GET), /executions/search (POST), /stats, /stats/timeseries, /stats/timeseries/by-app, /stats/timeseries/by-route, /stats/punchcard, /attributes/keys, /errors/top. Env comes from path. - LogQueryController: /api/v1/logs → /api/v1/environments/{envSlug}/logs. - RouteCatalogController: /api/v1/routes/catalog → /api/v1/environments/ {envSlug}/routes. Env filter unconditional (path). - RouteMetricsController: /api/v1/routes/metrics → /api/v1/environments/{envSlug}/routes/metrics (and /metrics/processors). - DiagramRenderController: /{contentHash}/render stays flat (hashes are globally unique). Find-by-route moved to /api/v1/environments/{envSlug}/ apps/{appSlug}/routes/{routeId}/diagram — the old GET /diagrams?... handler is removed. - Agent views split cleanly: - AgentListController (new): /api/v1/environments/{envSlug}/agents - AgentEventsController: /api/v1/environments/{envSlug}/agents/events - AgentMetricsController: /api/v1/environments/{envSlug}/agents/ {agentId}/metrics — now also rejects cross-env agents (404) as a defense-in-depth check, fulfilling B3. Agent self-service endpoints (register/refresh/heartbeat/deregister) remain flat at /api/v1/agents/** — JWT-authoritative. SPA: - queries/agents.ts, agent-metrics.ts, logs.ts, catalog.ts (route metrics only; /catalog stays flat), processor-metrics.ts, executions.ts (attributes/keys, stats, timeseries, search), dashboard.ts (all stats/errors/punchcard), correlation.ts, diagrams.ts (by-route) — all rewritten to env-scoped URLs. - Hooks now either read env from useEnvironmentStore internally or require it as an argument. Query keys include env so switching env invalidates caches. - useAgents/useAgentEvents signature simplified — env is no longer a parameter; it's read from the store. Callers (LayoutShell, AgentHealth, AgentInstance) updated accordingly. - LogTab and useStartupLogs thread env through to useLogs. - envFetch helper introduced in executions.ts for env-prefixed raw fetch until schema.d.ts is regenerated against the new backend. BREAKING CHANGE: All these flat paths are removed: /api/v1/search/**, /api/v1/logs, /api/v1/routes/catalog, /api/v1/routes/metrics (and /processors), /api/v1/diagrams (lookup), /api/v1/agents (list), /api/v1/agents/events-log, /api/v1/agents/{id}/metrics, /api/v1/agent-events. Clients must use the /api/v1/environments/{envSlug}/... equivalents. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-16 23:48:25 +02:00
enabled: !!timeFrom && !!environment && live.enabled,
placeholderData: (prev) => prev,
refetchInterval: live.refetchInterval,
});
}
export function useExecutionDetail(executionId: string | null) {
return useQuery({
queryKey: ['executions', 'detail', executionId],
queryFn: async () => {
const { data, error } = await api.GET('/executions/{executionId}', {
params: { path: { executionId: executionId! } },
});
if (error) throw new Error('Failed to load execution detail');
return data!;
},
enabled: !!executionId,
});
}
export function useProcessorSnapshot(
executionId: string | null,
index: number | null,
) {
return useQuery({
queryKey: ['executions', 'snapshot', executionId, index],
queryFn: async () => {
const { data, error } = await api.GET(
'/executions/{executionId}/processors/{index}/snapshot',
{
params: {
path: { executionId: executionId!, index: index! },
},
},
);
if (error) throw new Error('Failed to load snapshot');
return data!;
},
enabled: !!executionId && index !== null,
});
}
export function useProcessorSnapshotById(
executionId: string | null,
processorId: string | null,
) {
return useQuery({
queryKey: ['executions', 'snapshot-by-id', executionId, processorId],
queryFn: async () => {
const { data, error } = await api.GET(
'/executions/{executionId}/processors/by-id/{processorId}/snapshot',
{
params: {
path: { executionId: executionId!, processorId: processorId! },
},
},
);
if (error) throw new Error('Failed to load snapshot');
return data!;
},
enabled: !!executionId && !!processorId,
});
}