Add comparison stats: failure rate %, vs-yesterday change, today total
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user