Problem/Motivation
PHP notices are a sign for bad code, they fill the logs and are usually very easy to fix.
Proposed resolution
Add a sensor similar to 404, count of PHP notices, with output of most frequent php notice, group on variables.
Debug output with php notices.
Warning > 10 by default, no error threshold.
Remaining tasks
User interface changes
API changes
| Comment | File | Size | Author |
|---|---|---|---|
| #54 | interdiff-2495613-52.54.txt | 5.13 KB | johnchque |
| #54 | sensor_for_php_notices-2495613-54.patch | 5.31 KB | johnchque |
| #52 | interdiff-2495613-50-52.txt | 2.78 KB | johnchque |
| #52 | sensor_for_php_notices-2495613-52.patch | 7.24 KB | johnchque |
| #50 | sensor_for_php_notices-2495613-50.patch | 6.46 KB | johnchque |
Comments
Comment #1
LKS90 commentedHere is a patch that provides the sensor. Ordering is broken, but that's a general DatabaseAggregatorSensorPlugin problem.
Comment #3
miro_dietikerThis is mostly duplicate code from Watchdog issue.
Either postpone this issue immediately and wait for the Watchdog plugin... Or just reduce this issue to just provide default sensor configuration for the database aggregator sensor.. (and later switch to the Watchdog sensor.)
Comment #4
LKS90 commentedPostponed until watchdog sensor is committed (some code from here should be implemented over there, the replacement is more functional in this version). #2525426: Separate unaggregated results method
Comment #5
miro_dietikerUnpostponing since we have now the Watchdog aggregator.
Comment #6
LKS90 commentedHere is the sensor. It still has a custom SensorPlugin (because the sensor message is kind of custom) but it extends the watchdog sensor. Also has a test.
Comment #7
LKS90 commentedSomehow added the runSesnsor() to the watchdog aggregator as well, unneeded.
Comment #8
LKS90 commentedInterdiff for the removal.
Comment #11
berdirCan you post a screenshot of the verbose output?
I don't think that already looks like I'd expect it to
This should be hardcoded, the sensors makes no sense for anything else.
one class description is enough ;)
this is not a notice ;)
Maybe the sensor should be called PhpErrors, not sure.
Comment #12
LKS90 commentedAlright, here is the latest version. Looks rather good, but actually doesn't work as intended yet.
Problems:
I had to go through some hoops to get it working (making slight changes to the parent class WatchdogAggregatorSensorPlugin), so some review before continuing would be useful. The default value for table and aggregation are definitely missing at the moment (creating a new watchdog sensor via UI is impossible).
By the way, I haven't changed the test yet, I don't expect it to pass (if it does, yay! :D).
Screenshot of the verbose result (and the query):

Comment #14
miro_dietikerYeah that's a common problem with tables and fine as a starting point.
We can consider an alternative table display (like responsive table that does a vertical display) but that's a different issue.
Huh... No the Unaggregated is already called in DatabaseAggregatorSensorPlugin::verboseResult().
Don't call it a second time.
Other than tht, didn't check in much detail.
Comment #15
LKS90 commentedOrdering works now, removed the unnecessary call to unaggregatedResultVerbose.
Comment #17
LKS90 commentedFixed the test fails.
(Moved the sensor to optional because of dblog dependency)
(updated tests with new sensor message)
Comment #18
berdirLooks pretty nice :)
We usually prefix sensors with a module name.. probably dblog_ in this case.
Since we already have watchdog in the category, what about adding something more useful as the description?
What about "Monitors and displays the most frequent PHP notices and errors"?
Why hardcode this as the default here?
Still that double-description thing, one (above the annotation) is enough.
SafeMarkup() already marks a string as safe, xssFilter() should not be needed?
Maybe what you want to do instead is filter the message?
Why range(0, 10) if we only display the first?
This is the one that should have a range.. maybe 20? A site could have a hundred or more different php notices.
Do we translate the headers elsewhere? we don't translate messages, so actually not sure if we should here or not.. but it should be consistent.. looks like no other table has anything that *could* be translated? but entity aggregate I guess will at it and that will be translated.
This is not doing anything anymore?
Wondering if there is a use case for not having a time interval field. I guess this is fine, you can always set the time to a high value.
Verbose output test would be nice, since that's about the most complicated thing the sensor does now ;)
Comment #19
miro_dietikerBerdir 2.) "Monitors and displays the " sounds like a lot redundancy?
5. XssFilter is exactly what we needed to add since the usa if "!" makes it mark the contant as unsafe and everything is escaped afterwards...
10. Monitoring has this problem with providing more specific sensors that things are configurable (from a base sensor) but should not be editable anymore... That's only one particular case. This problem is mostly unresolved in the UI yet. In this particular case i would expect that a time interval of 0 is like not applying a time interval...
11. I would prefer to have a table with individual columns:
- Type
- Date
- File
- Line
- Message
And yeah, please check the verbose output based on some real data, including the double encoding problem above (5).
Comment #20
LKS90 commentedHere is the latest version, now with a count for each row and a generally better table building structure in DatabaseAggregatorSensorPlugin. The watchdog aggregator still works as usual.
Comment #23
LKS90 commentedThe test for the dblog_php_notices sensor was not updated, the other exception will be gone when issue #2525432: Separate text fields per verbose extra field is committed.
Comment #24
LKS90 commentedComment #26
mbovan commentedWhen I apply the patch (#23) I get:
"Warning: implode(): Invalid arguments passed in Drupal\monitoring\Plugin\monitoring\SensorPlugin\DatabaseAggregatorSensorPlugin->buildConfigurationForm() (line 309 of /usr/local/var/www/d8.dev/www/modules/monitoring/src/Plugin/monitoring/SensorPlugin/DatabaseAggregatorSensorPlugin.php).".
Is it because #2525432: Separate text fields per verbose extra field is not committed yet?
$rows => rows
A blank line here?
Comment #27
LKS90 commentedI amended the comment so the $ is gone and it's more explanatory.
Also added the new line, didn't know that, thanks!
Yes, the exception will be gone when #2525432: Separate text fields per verbose extra field is committed, the imploding/exploding is only done because of the text area to enter keys/verbose_fields (the new name) and causes some problems if the input NULL.
Comment #28
mbovan commentedOh, I thought a blank line between class and method doc comment.
Comment #32
berdirTook this on a bit.
The split for the verbose stuff was pretty good, but you still executed the query in there, so a subclass couldn't get to the values. I moved the query out and instead I'm passing the results in.
Also a number of small improvements, like shortening the file name.
Seems like we have no test coverage for the verbose output.
Let's add a new test class for that that looks at the verbose output with those notices.
Comment #34
LKS90 commentedFixed some test fails for the Kernel test, moved the
$this->verboseResultUnaggregated($output);call. (The output was completely missing, this fixes that) and added test coverage for the verbose output in the WebTest.Comment #36
LKS90 commentedCouldn't reproduce the error after moving the unaggregatedResultVerbose method call anymore...
The foreach exception we saw once is easily fixed by removing the fields validation from the validation method. Since we can't configure the fields for the output, validating them is wrong anyway. The previous test failed with my xpath queries, so I left the debug in this path to take a look.
Comment #37
LKS90 commentedComment #39
LKS90 commentedReadded validation + a stub method for PHP sensor.
Last version, if the xpath still fails, I'll have to find another solution.
Also fixed some more exceptions/error which resulted from parent methods validating/expecting fields/conditions which aren't used for the php sensor.
Comment #41
LKS90 commentedUhhm, ignore the patch above.
Comment #42
LKS90 commentedComment #44
LKS90 commentedAdded debugs for the two arrays that are compared, locally the test passes, so 'm kind of debugging the testbot.
Comment #46
LKS90 commentedI think this one should pass local tests and the testbot's test, I changed the logged error message's file path to use DRUPAL_ROOT as well, so the test works locally and on the testbot and the filename shortening is tested. I also changed one test to only assert the existence of a variable, instead of checking the value as well. The count changed with every minor change and the assert was not meant for that anyway.
Comment #47
berdirCommitted, working on a follow-up to clean some things up; #2543886: Allow database sensor plugins to control which configuration elements are shown.
Comment #49
johnchqueLet's backport this.
Comment #50
johnchqueEarly patch, still didn't find the FormatableMarkup d7 replace. Also mixed the verboseResultUnaggregated method appending the other ones in one single method.
Comment #52
johnchqueChanged a bit, fixed those FormattableMarkup thingys. Also added it to be listed on the sensors page.
Comment #54
johnchqueNew patch, now should work better, still working on tests.