Экспорт метрик в формате Prometheus
This commit is contained in:
1 parent
ed8f753ca1
commit
f82cc5c09d
8 files changed
+129
No files matched your search
@@ -585,6 +585,25 @@ test('api: здоровье отвечает без ключа и разбито
|
||||
assertTrue(isset($payload['checks']['queue']['status']), 'очередь проверяется отдельно');
|
||||
});
|
||||
|
||||
test('api: метрики для Prometheus закрыты списком адресов', function (): void {
|
||||
// Без настройки METRICS_ALLOW эндпоинт не пускает никого — это
|
||||
// недописанная настройка, а не «открыто для всех»
|
||||
withConfig(['metrics.allow' => ''], static function (): void {
|
||||
assertStatus(403, httpRequest('GET', '/metrics'));
|
||||
});
|
||||
|
||||
// В тестах REMOTE_ADDR не задан, Request::ip() отдаёт 'unknown' —
|
||||
// разрешаем ровно его, чтобы проверить сам путь допуска
|
||||
withConfig(['metrics.allow' => 'unknown'], static function (): void {
|
||||
$response = httpRequest('GET', '/metrics');
|
||||
|
||||
assertStatus(200, $response);
|
||||
assertContains('proton_users_total', $response->body());
|
||||
assertContains('proton_queue_jobs{status="', $response->body());
|
||||
assertContains('# TYPE proton_users_total gauge', $response->body());
|
||||
});
|
||||
});
|
||||
|
||||
test('api: ошибки приходят в едином формате', function (): void {
|
||||
$response = httpRequest('GET', '/api/v1/notes');
|
||||
|
||||
|
||||
@@ -50,6 +50,20 @@ test('показатели: снимок отвечает без запущен
|
||||
assertTrue(($snapshot['storage']['var_bytes'] ?? -1) >= 0);
|
||||
});
|
||||
|
||||
test('показатели: тот же снимок читается в формате Prometheus', function (): void {
|
||||
$text = Metrics::prometheus();
|
||||
|
||||
assertMatches('/^# HELP proton_users_total /m', $text);
|
||||
assertMatches('/^# TYPE proton_users_total gauge$/m', $text);
|
||||
assertMatches('/^proton_users_total \d+$/m', $text);
|
||||
|
||||
// Метки берутся из состояний очереди — они всегда на месте, даже пустой
|
||||
assertMatches('/^proton_queue_jobs\{status="queued"\} \d+$/m', $text);
|
||||
|
||||
// Пустой ключ разбивки превращается в «unknown», а не в кавычки без имени
|
||||
assertNotContains('{status=""}', $text);
|
||||
});
|
||||
|
||||
test('присмотр: порог сработал — сообщение уходит один раз за окно', function (): void {
|
||||
Cache::flush();
|
||||
|
||||
|
||||
Reference in new issue
Block a user