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:
@@ -70,8 +70,11 @@ public class SearchController {
|
||||
|
||||
@GetMapping("/stats")
|
||||
@Operation(summary = "Aggregate execution stats (P99 latency, active count)")
|
||||
public ResponseEntity<ExecutionStats> stats() {
|
||||
return ResponseEntity.ok(searchService.stats());
|
||||
public ResponseEntity<ExecutionStats> stats(
|
||||
@RequestParam Instant from,
|
||||
@RequestParam(required = false) Instant to) {
|
||||
Instant end = to != null ? to : Instant.now();
|
||||
return ResponseEntity.ok(searchService.stats(from, end));
|
||||
}
|
||||
|
||||
@GetMapping("/stats/timeseries")
|
||||
|
||||
@@ -88,11 +88,11 @@ public class ClickHouseSearchEngine implements SearchEngine {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExecutionStats stats() {
|
||||
public ExecutionStats stats(Instant from, Instant to) {
|
||||
Long p99 = jdbcTemplate.queryForObject(
|
||||
"SELECT quantile(0.99)(duration_ms) FROM route_executions " +
|
||||
"WHERE start_time >= now() - INTERVAL 1 HOUR",
|
||||
Long.class);
|
||||
"WHERE start_time >= ? AND start_time <= ?",
|
||||
Long.class, Timestamp.from(from), Timestamp.from(to));
|
||||
Long active = jdbcTemplate.queryForObject(
|
||||
"SELECT count() FROM route_executions WHERE status = 'RUNNING'",
|
||||
Long.class);
|
||||
|
||||
Reference in New Issue
Block a user