Make stats endpoint respect selected time window instead of hardcoded last hour
P99 latency and active count now use the same from/to parameters as the timeseries sparklines, so all stat cards are consistent with the user's selected time range. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -664,6 +664,26 @@
|
||||
],
|
||||
"summary": "Aggregate execution stats (P99 latency, active count)",
|
||||
"operationId": "stats",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "from",
|
||||
"in": "query",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"type": "string",
|
||||
"format": "date-time"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "to",
|
||||
"in": "query",
|
||||
"required": false,
|
||||
"schema": {
|
||||
"type": "string",
|
||||
"format": "date-time"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
|
||||
@@ -2,14 +2,23 @@ import { useQuery } from '@tanstack/react-query';
|
||||
import { api } from '../client';
|
||||
import type { SearchRequest } from '../schema';
|
||||
|
||||
export function useExecutionStats() {
|
||||
export function useExecutionStats(timeFrom: string | undefined, timeTo: string | undefined) {
|
||||
return useQuery({
|
||||
queryKey: ['executions', 'stats'],
|
||||
queryKey: ['executions', 'stats', timeFrom, timeTo],
|
||||
queryFn: async () => {
|
||||
const { data, error } = await api.GET('/search/stats');
|
||||
const { data, error } = await api.GET('/search/stats', {
|
||||
params: {
|
||||
query: {
|
||||
from: timeFrom!,
|
||||
to: timeTo || undefined,
|
||||
},
|
||||
},
|
||||
});
|
||||
if (error) throw new Error('Failed to load stats');
|
||||
return data!;
|
||||
},
|
||||
enabled: !!timeFrom,
|
||||
placeholderData: (prev) => prev,
|
||||
refetchInterval: 10_000,
|
||||
});
|
||||
}
|
||||
|
||||
6
ui/src/api/schema.d.ts
vendored
6
ui/src/api/schema.d.ts
vendored
@@ -97,6 +97,12 @@ export interface paths {
|
||||
};
|
||||
'/search/stats': {
|
||||
get: {
|
||||
parameters: {
|
||||
query: {
|
||||
from: string;
|
||||
to?: string;
|
||||
};
|
||||
};
|
||||
responses: {
|
||||
200: {
|
||||
content: {
|
||||
|
||||
@@ -10,11 +10,10 @@ export function ExecutionExplorer() {
|
||||
const { toSearchRequest, offset, limit, setOffset, live, toggleLive } = useExecutionSearch();
|
||||
const searchRequest = toSearchRequest();
|
||||
const { data, isLoading, isFetching } = useSearchExecutions(searchRequest, live);
|
||||
const { data: stats } = useExecutionStats();
|
||||
const { data: timeseries } = useStatsTimeseries(
|
||||
searchRequest.timeFrom ?? undefined,
|
||||
searchRequest.timeTo ?? undefined,
|
||||
);
|
||||
const timeFrom = searchRequest.timeFrom ?? undefined;
|
||||
const timeTo = searchRequest.timeTo ?? undefined;
|
||||
const { data: stats } = useExecutionStats(timeFrom, timeTo);
|
||||
const { data: timeseries } = useStatsTimeseries(timeFrom, timeTo);
|
||||
|
||||
const sparkTotal = timeseries?.buckets.map((b) => b.totalCount) ?? [];
|
||||
const sparkFailed = timeseries?.buckets.map((b) => b.failedCount) ?? [];
|
||||
@@ -53,7 +52,7 @@ export function ExecutionExplorer() {
|
||||
<StatCard label="Total Matches" value={total.toLocaleString()} accent="amber" change={`from current search`} sparkData={sparkTotal} />
|
||||
<StatCard label="Avg Duration" value={`${avgDuration}ms`} accent="cyan" sparkData={sparkAvgDuration} />
|
||||
<StatCard label="Failed (page)" value={failedCount.toString()} accent="rose" sparkData={sparkFailed} />
|
||||
<StatCard label="P99 Latency" value={stats ? `${stats.p99LatencyMs}ms` : '--'} accent="green" change="last hour" sparkData={sparkP99} />
|
||||
<StatCard label="P99 Latency" value={stats ? `${stats.p99LatencyMs}ms` : '--'} accent="green" sparkData={sparkP99} />
|
||||
<StatCard label="In-Flight" value={stats ? stats.activeCount.toString() : '--'} accent="blue" change="running executions" sparkData={sparkActive} />
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user