Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 25
0.00% covered (danger)
0.00%
0 / 7
CRAP
0.00% covered (danger)
0.00%
0 / 1
ObservabilityController
0.00% covered (danger)
0.00%
0 / 25
0.00% covered (danger)
0.00%
0 / 7
56
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 percentiles
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 slowest
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
2
 byEndpoint
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 statusCodes
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 timeseries
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
2
 alertImpact
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace App\Http\Controllers;
4
5use App\Services\TimingsAggregator;
6use Illuminate\Http\JsonResponse;
7use Illuminate\Http\Request;
8
9/**
10 * FIRE-1197: admin-only observability endpoints. Thin wrappers around
11 * App\Services\TimingsAggregator — the controller just unpacks query params
12 * and the aggregator does the file parsing + percentile maths.
13 *
14 * All endpoints live under the `auth.token + require.admin` group in
15 * routes/api.php so the gate is `role_id = 1` ("Admin").
16 */
17class ObservabilityController extends Controller
18{
19    public function __construct(private readonly TimingsAggregator $aggregator) {}
20
21    public function percentiles(Request $request): JsonResponse
22    {
23        return response()->json(
24            $this->aggregator->percentiles($request->query('window', '5m')),
25        );
26    }
27
28    public function slowest(Request $request): JsonResponse
29    {
30        return response()->json(
31            $this->aggregator->slowest(
32                $request->query('window', '24h'),
33                (int) $request->query('limit', 10),
34            ),
35        );
36    }
37
38    public function byEndpoint(Request $request): JsonResponse
39    {
40        return response()->json(
41            $this->aggregator->byEndpoint($request->query('window', '24h')),
42        );
43    }
44
45    public function statusCodes(Request $request): JsonResponse
46    {
47        return response()->json(
48            $this->aggregator->statusCodes($request->query('window', '1h')),
49        );
50    }
51
52    public function timeseries(Request $request): JsonResponse
53    {
54        return response()->json(
55            $this->aggregator->timeseries(
56                $request->query('metric', 'p95'),
57                $request->query('window', '24h'),
58            ),
59        );
60    }
61
62    /**
63     * FIRE-1275: per-alert impact — one call returns the counts the
64     * observability banner needs to render "N of M requests" and
65     * "A of B users affected" for each red-bucket alert. Same window is
66     * used for both numerator and denominator inside the aggregator.
67     */
68    public function alertImpact(Request $request): JsonResponse
69    {
70        return response()->json(
71            $this->aggregator->alertImpact($request->query('window', '5m')),
72        );
73    }
74}