Problem/Motivation
Based on #3606303: Add a summary block / indicator for the frontend in production I just had the idea if it would make sense to expose the result as health-check value similar to what
https://www.drupal.org/project/health_check does.
And I think this module is already more powerful, so the additional module should not be needed.
I'm not yet totally sure how it makes most sense and what of it should be configurable:
Technically it's just a route which should be possible to be switched on / off, eventually by setting or permission ("Access health check at ...")
Functionally the health check might be expected to fail if the result of #3606303: Add a summary block / indicator for the frontend in production is a fail?
Or should it have dedicated conditions?
Let's start a discussion...
Comments
Comment #2
anybodyComment #3
trebormcThanks @anybody, I like the idea and I think it makes sense here. It shouldn't be enabled by default though: I'd go for a checkbox in the audit settings that exposes the route, so whoever needs it turns it on and points their monitoring service at it.
I'd rather postpone this until #3606303 is merged. The health check should just read that value and return an error when the audit isn't fully green (or above whatever threshold we end up making configurable), not calculate anything on its own.
One thing I'm clear about for the implementation: the route itself must not be cached, no page cache and no dynamic page cache, because the point is to verify the request actually reaches Drupal. The audit result behind it should come from cache though, we already invalidate it in #3606303 when any of the affected config changes. health_check is a good reference for the route part, it shouldn't be much work.
Comment #4
anybodyThank YOU @trebormc! :) That sounds great!
I agree in all points. The setting and functionality goes into the
audit_config_checkssubmodule then? That would make most sense to me.Exactly - regarding caching!
Maybe have a closer look into the https://www.drupal.org/project/health_check module before the final implementation to see what they do and why. The module page says:
but I'm unsure if the timestamp is what you want and if it's best practice. If yes, let's do the same.
I don't think the functionality from https://www.drupal.org/project/health_check_url to change the URL is needed?
But what I think would make sense is offering the option to enter a secret URL parameter like
?secret=xyzmaybe so the route is not public to anyone? If it's defined (maybe initialized with a random value), the route should return a 404 not found, like the rout did not exist, so it can't be guessed easily?Or would you like to use a custom URL? In my eyes that might be more confusing?
Anything else I might have missed?
Yes, let's postpone this on the other issue, but also add it to the submodule description (and maybe name) to make it visible, once this is implemented.
Thank you once again!! This is huge :)
Comment #9
trebormcI've implemented this as a new submodule, Audit: Health Check (
audit_health_check), instead of adding it to the config checks. Enabling the submodule is what creates the endpoint, and it's built so other audits can be added later. It isn't part of Audit: All, so nobody gets a new URL without enabling it explicitly.The endpoint is
/audit/health. It answers200 OKwhen everything passes and503 FAILotherwise, so monitors and load balancers only need the status code. It currently checks:Each check can be turned off in the audit settings page, under "Health check endpoint", which also shows the full URL to give to the monitor. Two more checkboxes control the answer: the time it was generated (on by default, handy to spot a CDN or proxy caching it) and one line per check with OK/FAIL and a short detail such as the score against its minimum (off by default, meant for debugging). The details never say which setting or module is wrong; the audit report does.
For privacy and security, the endpoint always requires a secret passed as
?secret=.... It's generated on install, can't be left empty, and any request without the right secret gets a 404, as if the route didn't exist. The response is never cached, by Drupal or by external caches. It also keeps answering in maintenance mode, so a load balancer doesn't drop every instance during a deployment, and it isn't redirected by the Redirect module.This is already in the development branch (1.x-dev), so I'm marking the issue as Fixed. It will be included in the next stable release.
Comment #11
anybodyWhao that looks super nice, I'll also give it a try and see how we can include that into our monitoring. Great work!