Problem/Motivation

We've had this idea in the past and planned implementing a module for this, but looking at this impressive module I think this would make a lot more sense here!

Of course we're happy to help, if you like the idea below:

Problem

Working on a production Drupal project you may sometimes overlook something important like

  • (re-)enabling the cache
  • disabling error display
  • ...

but you may not look into the audit results or status report.

Proposed resolution

Allow selecting some of these relevant things to check at runtime and show a block in the frontend, for example as block (very flexible) or in the new Navigation module or the admin toolbar or a custom sticky indicator.

Remaining tasks

  1. Discuss a good way to select the audits that should be considered (configuration)
  2. Discuss live validation vs. reports on demand
  3. Discuss a block (or Navigation) display for the indicator in the frontend so that users with the selected roles can see there's something to check in production
  4. Implement
  5. Test
  6. Release

User interface changes

API changes

Data model changes

Issue fork audit-3606303

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

anybody created an issue. See original summary.

anybody’s picture

I'd love to get your feedback on this @trebormc - what do you think? Do you see the problem space?

anybody’s picture

Maybe a good idea is to use the atomic checks from this module and run an important subset live or on cron for this?

trebormc’s picture

I wouldn't run the checks on every request though. I'd compute a critical subset on cron, store a summary (score per category plus an overall status) and have the display just read that precomputed data.

My plan would be to ship it as a permission-gated block first, since that's the most flexible (footer, a region, wherever the theme wants it), probably as an optional submodule. A toolbar/Navigation integration can come on top once the data layer is solid.

The one thing I'm still undecided on is the display: a sticky footer bar with a richer summary, or a compact indicator in the admin toolbar. Do you have a preference from a usability point of view?

anybody’s picture

Thanks @trebormc - I think that makes sense, maybe combined with information that this is not live? Or maybe we can even find a better way to not confuse administrators thinking this is live or needing the current value?

I was thinking about a manual refresh option on top, maybe that helps in cases where it's failed to update the latest state on demand?

The one thing I'm still undecided on is the display: a sticky footer bar with a richer summary, or a compact indicator in the admin toolbar. Do you have a preference from a usability point of view?

I think we should have a regular block first, as you've written.

For these additional things like the sticky indicator or the indicator in the Navigation module I'd say it should be a setting (checkboxes) to opt-in. The block can also be used for custom implementations.

Do you agree?

anybody’s picture

PS: Maybe this all should better go into a submodule "Production checks" or something like that? It's a bit different from the key functionality of this module and might be worth splitting.

ressa’s picture

This would be a great feature, and I would absolutely use it.

Drush support?
For Drush, there are filters like drush audit:run security --filter="severity:error" but I get almost the same amount of output as with drush audit:run security, where I hoped to get a fairly short output back, of only the most serious problems.

So an accompanying new Drush command like drush audit:production-check could similarly to the summary block discussed here produce a short summary of the most important problems. Since it's via the command line, you can quickly check multiple sites, without having to open them in the browser.

Alert
The user could incorporate the Drush command in a script run by Cron once a day, and send out an email alert, if anything serious is found. Or this could even be an option for the summary block itself?

anybody’s picture

Should we maybe start breaking down the options that *really* make sense to base the decision how to solve it technically on it?

For us the primary focus is to not forget things like

  • Enable Caching
  • Enable JS Aggregation
  • Enable CSS Aggregation
  • Disable error display
  • Disable reroute_email
  • Disable shield

Which I think can all be checked at runtime.

Maybe the module could just implement the core ones and add a hook for other (dev) modules to opt-into? Like shield and reroute_email?

trebormc’s picture

I would drop the score summary block. The expensive checks cannot run per request, and if they do not, so we end up with a manual refresh button. No advantage over the audit report page we already have.

The other idea (#8) I like, framed as a submodule inside audit for a user defined audit. Settings page with two lists:

  1. Config keys and their expected values (page cache max-age, CSS/JS aggregation, error display, whatever the project cares about).
  2. Modules and whether they must be installed or not, which covers shield, reroute_email, devel, kint.

Everything it checks is configuration, so it is fast and fully cacheable. The block attaches the cache tags of the config it reads plus core.extension. Computed once, shown on every page, and as soon as someone changes one of those settings or installs a module the tag invalidates and the next page load shows the new value. Effectively real time while browsing, with no per request cost.

Since the expectations are config themselves, each environment can have its own. CSS aggregation expected on in production and off in development, devel required locally and forbidden in production, and so on. That makes it adaptable to any project instead of us guessing a fixed list.

Still undecided on the display: a plain block the user places wherever they want, or a fixed footer/header indicator so it works right after install with no block placement.

@ressa, the same data can be exposed as a Drush command so CI can run exactly what the block shows.
And for the cron plus alerting part, what you describe is basically what I built at https://druscan.com, which integrates with this module and centralises the scores of several projects in one place. Worth a look, the free tier may already cover your use case.

anybody’s picture

Thanks @trebormc good points!

Still undecided on the display: a plain block the user places wherever they want, or a fixed footer/header indicator so it works right after install with no block placement.

I'd say both:

  1. A block that can be placed flexibly if needed
  2. An integration into the new navigation module - I think these are also blocks.

For visual presentation we could maybe use a closed details element with color indicator? So if it's green, all is fine. If it's red you can expand it and look at the details? Maybe with a link to the status and to the report page?

Maybe we should give it a first shot in a feature branch to try it out?

trebormc’s picture

Sounds good, let me try to get a first version out this weekend or the next one.

Plan is to start with the simple block so people can place it wherever they want, and then look at how the Navigation module expects things to be integrated. I have not built anything for it yet, so I need to check whether it is blocks or something else there.

On the visual side, what I have in mind is the typical score circle with a colour, and clicking it takes you to the summary page with the list of what is failing. Possibly a tooltip too, so hovering already shows you the failing items without leaving the page. Your closed details idea works as well, I need to try a couple of approaches and see which one behaves properly in every theme, which is usually the tricky part.

I will push a first MVP to a branch so you can try it and we iterate from there.

anybody’s picture

Thanks @trebormc yes my idea with the details element was to keep things as simple as possible and use existing core elements.

Regarding Navigation: It seems quite simple: https://git.drupalcode.org/project/drupal/-/blob/main/core/modules/navig...

Maybe this example is helpful: #3535874: Add Core Navigation integration

ressa’s picture

Thanks @trebormc, I like your thoughts about the solution choices, and optimising performance up front.

I am glad to hear that a Drush command might be possible, to allow easily checking multiple sites from CLI, and I am ready to check it out, as well as the block option in the UI, when there is an MR ready for testing.

About the indicator in the Navigation, I just had a look at #3535874: Add Core Navigation integration, and my suggestion would be to place it above "Help" in the standard (left side) Navigation. This would place it right before "Help" in the alternative top placed Admin Navigation module, which would also work really well.

It's great that there is a service, thanks for sharing, and I wish you success with it! It is a really powerful and convenient option for those with a sizeable budget, allowing them to monitor multiple sites that way. I do hope that a simple email alert option is possible, so that users on a tighter budget can enter their email address in a "Send email alert if there is an error"-field, but I also understand if it requires a bit too much work.

trebormc’s picture

Status: Active » Needs review

Everything is pushed to the issue branch:

https://git.drupalcode.org/issue/audit-3606303/-/compare/1.x...3606303-a...

@anybody, @ressa, could you give it a try before I merge? I would like to know if it behaves as you expected, or if you see anything worth improving.

If nothing comes up, I will merge it into 1.x in a few days.

ressa’s picture

Wow that was fast! It's a very impressive solution you built, and it surpasses my expectations. I really like how (like you write) the checks don't require any database lookups, so the result is instantaneous. So if you add the block to the front page, and hit refresh -- you get the feedback immediately.

You have written an amazingly well-rounded README, documenting perfectly the usage and options of the feature.

The Drush command also works flawlessly, and it could definitely work in a script, for email alerts. Simply set the desired checks up in Audit, and if none of them are allowed to fail, send an email if "score": 100, is not returned when running this command:

$ drush audit:run config_checks | grep '"score": 100'
 [notice] Running audit analyzer: config_checks...
                "score": 100,

I do still hope that an "Email alert" option could at some point be added under the "Config Checks Audit" settings at /admin/reports/audit/settings, so that the user can enter their email in a field, and get an alert in case the score is not 100, which could be checked once a day via cron.

I must also commend you on the user interfaces, they are beautifully laid out, and the typography and colors convey the results efficiently, and are at the same time very aesthetically pleasing.

I must admit that I haven't yet actually used the module in production, since I am in the middle of upgrading my projects to Drupal 11, and my focus in on that. But when that is done, I am definitely going to dive into all the options the Audit module offers, and add it to my sites.

I only found two things, which may need some work. One was the Navigation integration. It seems like the Audit Config Checks block should be placed automatically. But to show it, I had to "Enable edit mode" under "Navigations blocks"/"Edit layout for Navigation layout" (/admin/config/user-interface/navigation-block) and click "Add block", etc. to place it somewhere in the Navigation menu.

Also, if I use the https://www.drupal.org/project/admin_navigation module and place Navigation menu horizontally at the top, the "1 error" text is missing, it only shows "93". It could be because it is using the "collapsed" display?

The other thing is a detail, but the new module is not yet listed as a dependency in the audit_all submodule :)