-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Enhanced Prometheus metrics and health checks (#212) #269
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: development
Are you sure you want to change the base?
Changes from all commits
8526148
ce9ae98
906b2da
926e739
b1d5b24
19bc8bd
7671595
d6622b2
05f2903
235b3bd
b599bc6
568da8c
42c842e
09aef01
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,6 +33,8 @@ | |
| /** | ||
| * Controller for health check endpoints. | ||
| * | ||
| * @spec openspec/changes/prometheus-metrics/tasks.md#task-4 | ||
| * | ||
| * @psalm-suppress UnusedClass | ||
| */ | ||
| class HealthController extends Controller | ||
|
|
@@ -57,6 +59,8 @@ public function __construct( | |
| /** | ||
| * Health check endpoint. | ||
| * | ||
| * @spec openspec/changes/prometheus-metrics/tasks.md#task-4 | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [unfixed: no container write access; also requires SEC-01/@publicpage fix first] Rule: CWE-209 / OWASP A05:2021 — Three exception messages returned verbatim in health response (lines 123, 147, 170). checkDatabase() at line 123 returns |
||
| * | ||
| * @NoCSRFRequired | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [unfixed: no container write access to root-owned repo files] Rule: OWASP A01:2021 — Missing @publicpage annotation on HealthController::index(). Without @publicpage, Nextcloud's auth middleware intercepts all unauthenticated requests (container health probes) with a 302 redirect to the login page, making the endpoint non-functional. Fix: add |
||
| * | ||
| * @return JSONResponse Health status | ||
|
|
@@ -126,6 +130,8 @@ private function checkDatabase(): string | |
| * OpenRegister is a hard dependency for Procest. If it is not enabled, | ||
| * the overall health status MUST be "error". | ||
| * | ||
| * @spec openspec/changes/prometheus-metrics/tasks.md#task-4 | ||
| * | ||
| * @return string 'ok' or error message | ||
| */ | ||
| private function checkOpenRegister(): string | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,6 +33,10 @@ | |
| /** | ||
| * Controller for exposing Prometheus metrics. | ||
| * | ||
| * @spec openspec/changes/prometheus-metrics/tasks.md#task-1 | ||
| * @spec openspec/changes/prometheus-metrics/tasks.md#task-2 | ||
| * @spec openspec/changes/prometheus-metrics/tasks.md#task-3 | ||
| * | ||
| * @psalm-suppress UnusedClass | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [fixed: added class-level @SPEC tags + index() @SPEC + moved @SPEC after @param in getCached()] Rule: ADR-003 — class docblock missing @SPEC (SpecTagSniff WARNING); index() missing @SPEC (SpecTagSniff WARNING); getCached() had @SPEC before @param violating PEAR.Commenting.FunctionComment order (phpcs ERROR). |
||
| */ | ||
| class MetricsController extends Controller | ||
|
|
@@ -67,6 +71,10 @@ public function __construct( | |
| /** | ||
| * Return Prometheus metrics in text exposition format. | ||
| * | ||
| * @spec openspec/changes/prometheus-metrics/tasks.md#task-1 | ||
| * @spec openspec/changes/prometheus-metrics/tasks.md#task-2 | ||
| * @spec openspec/changes/prometheus-metrics/tasks.md#task-3 | ||
| * | ||
| * @NoCSRFRequired | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [unfixed: no container write access to root-owned repo files] Rule: OWASP A01:2021 — Missing @publicpage annotation on MetricsController::index(). Without @publicpage, Nextcloud's auth middleware blocks all unauthenticated Prometheus scrape requests with a 302 redirect. The /api/metrics endpoint is non-functional for external scrapers. Fix: add |
||
| * | ||
| * @return TextPlainResponse Prometheus-formatted metrics | ||
|
|
@@ -83,6 +91,10 @@ public function index(): TextPlainResponse | |
| /** | ||
| * Collect all metrics and format as Prometheus text. | ||
| * | ||
| * @spec openspec/changes/prometheus-metrics/tasks.md#task-1 | ||
| * @spec openspec/changes/prometheus-metrics/tasks.md#task-2 | ||
| * @spec openspec/changes/prometheus-metrics/tasks.md#task-3 | ||
| * | ||
| * @return string Prometheus exposition format text | ||
| */ | ||
| private function collectMetrics(): string | ||
|
|
@@ -200,6 +212,8 @@ private function collectMetrics(): string | |
| * @param callable $compute Callable that computes the value on cache miss | ||
| * | ||
| * @return mixed The cached or freshly computed value | ||
| * | ||
| * @spec openspec/changes/prometheus-metrics/tasks.md#task-3 | ||
| */ | ||
| private function getCached(string $key, int $ttl, callable $compute): mixed | ||
| { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[fixed: added class-level @SPEC tag] Rule: ADR-003 — Class docblock must carry @SPEC traceability tag linking to openspec tasks. Sniff: SpecTagSniff WARNING on HealthController class at line 38.