Problem/Motivation
The effort of #2401463: Make dblog entities introduces an interesting problem. If log entries are content, the Database Logging module cannot be uninstalled without deleting the logs first. This is a general rule for all content entries.
The problem is, log entries are not something someones creates on purpose, they are created from external events. So uninstalling the dblog module in a production site can be very difficult if there are a lot of logs created every minute.
Proposed resolution
There are two possible scenarios to fix this problem.
- Modify how ContentUninstallerValidator works, to make an exception for dblog entries. Something that makes sense from an UX point of view, but introduces some of potential edge cases in the future that we want to avoid. See why the validator was created on the first place: #2278017: When a content entity type providing module is uninstalled, the entities are not fully deleted, leaving broken reference
- Allow to pause the creation of logs entries via the user interface, so logs can be deleted safely.
The goal of this issue is provide a solution for approach 2. Without introducing a performance impact of checking the config values every time a log is created. We don't want to touch the current Drupal\dblog\Logger\Dblog class at all.
Remaining tasks
- Add a checkbox in
/admin/config/development/loggingto pause creation of new logs. Checkdblog_form_system_logging_settings_alterto see where put this value. - Save the new configs as part of
dblog_logging_settings_submit - Create a new class that implements
LoggerInterfacebut does nothing on the log method.dblog/src/Logger/Disabled.phpcould be a good place to put this file. - Write a new DblogServiceProvider following these instructions to swap the
logger.dblogservice with the one created in step 2 that does not insert a log into the database. Only when the checkbox from step 1 is enabled. - Create a new implementation of
hook_requirementsthat checks$phase == 'runtime'and returns a warning if the logger collection is disabled. - Write test for the disabled logging functionality. Check the
core/modules/dblog/tests/src/Kernel/DbLogTest.phpas inspiration of how to create log entries, and change the configuration using code.
User interface changes
- A new checkbox to disable log creation in the dblog ui.
- A new warning in the status report page if the logger collection is disabled.
API changes
None.
Data model changes
None.
Release notes snippet
| Comment | File | Size | Author |
|---|---|---|---|
| #17 | Screenshot_2023-12-05_17-15-21.png | 32.47 KB | dagmar |
| #16 | Screenshot_2023-11-01_08-20-05.png | 30 KB | dagmar |
Issue fork drupal-3354081
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
Comment #2
dagmarTagging this with Novice as the instructions to proceed are well defined. I'm here to review and provide guidance if needed.
Comment #4
elberI will take a look on it
Comment #6
petiar commentedSorry guys, I may have cause some chaos with the 3354081-drupal-11 branch. Anyway, the code for review should be in the
3354081-provide-a-waybranch. The only thing missing is the test, which I will write as soon as I will manage to run PHPUnit tests in my lando docker machine.Comment #7
dagmarAwesome @petiar! Many thanks.
Comment #9
smustgrave commentedThink we will need a CR for the change to the UI.
https://git.drupalcode.org/project/drupal/-/merge_requests/4375 didn't do a full review since it was in draft.
Comment #10
dagmarThere are a few coding standards that needs to be fixed, but those are irrelevant for now. The only thing that is not 100% clear to me right now is how to make the DblogServiceProvider::alter code run as soon the Dblog Form is submitted.
I'm not sure if
\Drupal::service('kernel')->rebuildContainer();is the way to go, or if there is something less aggressive. I was not able to find something in core that does this already. All the calls to rebuildContainer I found are part of tests.Comment #11
dagmarI've been trying this today. It seems the approach to alter the service is not actually necessary. Dblog can provide the service using by DblogServiceProvider::register and provide the regular logger only when the config is not available.
The only example in core I found doing something kind of similar is the Drupal\language\LanguageServiceProvider.
The logic then would be something like this:
\Drupal::configFactory() wont work at this register phase I'm afraid. But again LanguageServiceProvider provides some clues how what to do.
Comment #12
imustakim commentedComment #13
imustakim commentedMR updated.
Please review.
Comment #14
poker10 commentedThanks for working on this! Tagging this with Usability tag as there are changes to the UI (new checkbox).
I would personally prefer to have a Usability review here as well, because the two proposed solutions (see the IS) can be evaluated from different point of views:
1) as a developer
I would agree that introducing an exception for dblog entries when uninstalling is not a great thing.
2) as a website admin
Currently you can uninstall the module in one click, without need to care about anything. But instead of one click, now you will need to do (at least) two more steps (2 + 3):
Isn't it possible that it will get too complicated for normal use? I know that uninstalling this module is not something, that is done on a daily basis, but even so.. We can argue that it is needed for all modules using content enties, but I still consider dblog entries as something different like a real content (for me these are just logs).
The MR is in a draft state (so the tests did not go through) and has codestyle issues, so moving to NW.
Comment #15
mfbMy patch at #3103620: Dependency on config storage causes circular reference in service container has a pattern that might be useful for dblog module as well: A config subscriber checks if the config changed and if so, invalidates the container.
Comment #16
dagmar@poker10 I think you pointed out some valid inputs. I had the same thoughts as well and this is why I tried to avoid this in the first place while coding #2401463: Make dblog entities
Unfortunately I don't see an easy way to avoid this, at least without not touching a lot of content related stuff involved with content deletion.
The way I see it, dblog entries will be the same than Comments now. If you have a non public site, deleting the logs will be enough to not need to pause them.
I'm thinking maybe we can avoid this and improve the UX at the same time to allow you to block temporally log entries while you are deleting them.
I think we can also play with
?redirect=toin the url to make this as simple as possible.Eventually most developers will use drush to uninstall dblog, so I think we can provide a patch to make this in one go if we need to.
Comment #17
dagmarAnother interesting approach to analyze is the UI provided by the paragraph module. As it allows you to delete the content "on the fly" when deleting a paragraph type.
Comment #18
dagmar@poker10 I found a way to not need this to implement #2401463: Make dblog entities
I will keep this issue open in case someone else want to work on this, but the original problem described in the issue is not a problem anymore.
Comment #19
smustgrave commentedDoesn't seem like a novice level issue