Performance Trends
The trends endpoint provides time-series analysis for key query performance metrics. Each metric can be analyzed at different granularities (hour, day, week) over configurable time periods.
Endpoint
GET /v1/analytics/trends/{metric}Path Parameters
| Parameter | Type | Description |
|---|---|---|
metric | String | Metric name: queryCount, avgLatency, successRate, cacheHitRate |
Query Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
days | int | 7 | Number of days to analyze |
granularity | String | hour | Time granularity: hour, day, week |
Available Metrics
| Metric | Description | Unit |
|---|---|---|
queryCount | Total queries executed per period | count |
avgLatency | Average query execution time | milliseconds |
successRate | Percentage of queries that completed successfully | ratio (0-1) |
cacheHitRate | Percentage of queries served from cache | ratio (0-1) |
curl Examples
# Get query count trend by hour for the last 7 days
curl "http://query-engine:8080/v1/analytics/trends/queryCount?days=7&granularity=hour" \
-H "Authorization: Bearer $JWT_TOKEN"{
"metric": "queryCount",
"granularity": "hour",
"period": "7d",
"dataPoints": [
{"timestamp": "2026-02-05T00:00:00Z", "value": 120},
{"timestamp": "2026-02-05T01:00:00Z", "value": 45},
{"timestamp": "2026-02-05T02:00:00Z", "value": 23}
],
"summary": {
"min": 8,
"max": 3500,
"average": 1250,
"total": 210000,
"trend": "increasing",
"trendPercent": 12.5
}
}# Get average latency trend by day for the last 30 days
curl "http://query-engine:8080/v1/analytics/trends/avgLatency?days=30&granularity=day" \
-H "Authorization: Bearer $JWT_TOKEN"# Get cache hit rate trend
curl "http://query-engine:8080/v1/analytics/trends/cacheHitRate?days=14&granularity=day" \
-H "Authorization: Bearer $JWT_TOKEN"Implementation
The AnalyticsController delegates to the QueryAnalyticsService:
@GetMapping("/trends/{metric}")
public ResponseEntity<QueryTrend> getTrend(
@PathVariable String metric,
@RequestParam(defaultValue = "7") int days,
@RequestParam(defaultValue = "hour") String granularity) {
UUID tenantId = SecurityUtils.getCurrentTenantId();
QueryTrend trend = analyticsService.getTrend(tenantId, metric, days, granularity);
return ResponseEntity.ok(trend);
}The tenant ID is extracted from the JWT security context via SecurityUtils.getCurrentTenantId(), ensuring analytics are always tenant-scoped.