Make stats endpoint respect selected time window instead of hardcoded last hour
All checks were successful
CI / build (push) Successful in 1m10s
CI / docker (push) Successful in 48s
CI / deploy (push) Successful in 28s

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:
hsiegeln
2026-03-13 22:19:59 +01:00
parent 6794e4c234
commit cdf4c93630
9 changed files with 57 additions and 18 deletions

View File

@@ -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",

View File

@@ -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,
});
}

View File

@@ -97,6 +97,12 @@ export interface paths {
};
'/search/stats': {
get: {
parameters: {
query: {
from: string;
to?: string;
};
};
responses: {
200: {
content: {

View File

@@ -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>