MATIH Platform is in active MVP development. Documentation reflects current implementation status.
9. Query Engine & SQL
Query Analytics
Performance Trends

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

ParameterTypeDescription
metricStringMetric name: queryCount, avgLatency, successRate, cacheHitRate

Query Parameters

ParameterTypeDefaultDescription
daysint7Number of days to analyze
granularityStringhourTime granularity: hour, day, week

Available Metrics

MetricDescriptionUnit
queryCountTotal queries executed per periodcount
avgLatencyAverage query execution timemilliseconds
successRatePercentage of queries that completed successfullyratio (0-1)
cacheHitRatePercentage of queries served from cacheratio (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.