Add comparison stats: failure rate %, vs-yesterday change, today total
All checks were successful
CI / build (push) Successful in 1m11s
CI / docker (push) Successful in 48s
CI / deploy (push) Successful in 37s

Stats endpoint now returns current + previous period (24h shift) values
plus today's total count. UI shows:
- Total Matches: "of 12.3K today"
- Avg Duration: arrow + % vs yesterday
- Failure Rate: percentage of errors vs total, arrow + % vs yesterday
- P99 Latency: arrow + % vs yesterday
- In-Flight: unchanged (running executions)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
hsiegeln
2026-03-14 09:29:14 +01:00
parent 7c2058ecb2
commit 3641dffecc
5 changed files with 106 additions and 15 deletions

View File

@@ -89,18 +89,48 @@ public class ClickHouseSearchEngine implements SearchEngine {
@Override
public ExecutionStats stats(Instant from, Instant to) {
return jdbcTemplate.queryForObject(
"SELECT countIf(status = 'FAILED') AS failed_count, " +
String aggregateSql = "SELECT count() AS total_count, " +
"countIf(status = 'FAILED') AS failed_count, " +
"toInt64(avg(duration_ms)) AS avg_duration_ms, " +
"toInt64(quantile(0.99)(duration_ms)) AS p99_duration_ms, " +
"countIf(status = 'RUNNING') AS active_count " +
"FROM route_executions WHERE start_time >= ? AND start_time <= ?",
(rs, rowNum) -> new ExecutionStats(
"FROM route_executions WHERE start_time >= ? AND start_time <= ?";
// Current period
record PeriodStats(long totalCount, long failedCount, long avgDurationMs, long p99LatencyMs, long activeCount) {}
PeriodStats current = jdbcTemplate.queryForObject(aggregateSql,
(rs, rowNum) -> new PeriodStats(
rs.getLong("total_count"),
rs.getLong("failed_count"),
rs.getLong("avg_duration_ms"),
rs.getLong("p99_duration_ms"),
rs.getLong("active_count")),
Timestamp.from(from), Timestamp.from(to));
// Previous period (same window shifted back 24h)
Duration window = Duration.between(from, to);
Instant prevFrom = from.minus(Duration.ofHours(24));
Instant prevTo = prevFrom.plus(window);
PeriodStats prev = jdbcTemplate.queryForObject(aggregateSql,
(rs, rowNum) -> new PeriodStats(
rs.getLong("total_count"),
rs.getLong("failed_count"),
rs.getLong("avg_duration_ms"),
rs.getLong("p99_duration_ms"),
rs.getLong("active_count")),
Timestamp.from(prevFrom), Timestamp.from(prevTo));
// Today total (midnight UTC to now)
Instant todayStart = Instant.now().truncatedTo(java.time.temporal.ChronoUnit.DAYS);
Long totalToday = jdbcTemplate.queryForObject(
"SELECT count() FROM route_executions WHERE start_time >= ?",
Long.class, Timestamp.from(todayStart));
return new ExecutionStats(
current.totalCount, current.failedCount, current.avgDurationMs,
current.p99LatencyMs, current.activeCount,
totalToday != null ? totalToday : 0L,
prev.totalCount, prev.failedCount, prev.avgDurationMs, prev.p99LatencyMs);
}
@Override