Problem/Motivation

The resultVerbose method does a lot with DatabaseAggregator.
If sensors only want to alter parts such as the unaggregated result table, it needs to reimplement the whole method.

Proposed resolution

Reduce the method and outsource the unaggregated results in a separate method.
A sensor like Watchdog or 404 can then reinvent that method and not call the parent.

Establish the patterns similarly for DB and Entity aggregator.

Do not work with return values. Just call:
$this->verboseResultUnaggregated($output) where output is passed by reference.

Remaining tasks

User interface changes

API changes

Data model changes

Comments

LKS90’s picture

Status: Active » Needs review
StatusFileSize
new3.98 KB

Here is a beginning. I started with a watchdog sensor, if messages and variables are available, I replace the variables and drop the variables field.

LKS90’s picture

Line 195 is a mistake, probably cut instead of copy.

miro_dietiker’s picture

Status: Needs review » Needs work
  1. +++ b/src/Plugin/monitoring/SensorPlugin/DatabaseAggregatorSensorPlugin.php
    @@ -160,6 +160,14 @@ class DatabaseAggregatorSensorPlugin extends DatabaseAggregatorSensorPluginBase
    +   * {@inheritdoc}
    ...
    +  public function verboseResultUnaggregated(array &$output) {
    

    And inherited from what? :-)

  2. +++ b/src/Plugin/monitoring/SensorPlugin/WatchdogAggregatorSensorPlugin.php
    @@ -0,0 +1,84 @@
    +    unset($form['table']);
    

    Are you sure saving the sensor does not lead to deleting the verbose fields?

LKS90’s picture

1. From DatabaseSensorAggregatorPluginBase, but not yet :D.
2. The table field is the database table which will be queried (The watchdog sensor only queries watchdog, so configuring it doesn't make sense), the result is in output_table (tehehe).

miro_dietiker’s picture

2. Still my question: Is the field accidentally emptied when saving (other sensor configuration)? Because it might be needed that you set this a hidden item or just access false instead.

LKS90’s picture

StatusFileSize
new4.73 KB

You were correct, unsetting the fields deleted the sensor config table entry and made life more complicated, changed the fields that shouldn't be changed to be disabled.

miro_dietiker’s picture

Interdiff? :-)

At the same time you now introduce the watchdog plugin. If we are going to do this, then please also update all default configuration for watchdog table sensors to use the new sensor plugin.

Rest looks fine.

+++ b/src/Plugin/monitoring/SensorPlugin/WatchdogAggregatorSensorPlugin.php
@@ -0,0 +1,85 @@
+    $form['table']['#disabled'] = TRUE;

Add a comment why we hide it.

Finally, i think, for the new Watchdog behaviour we really need a tests.

LKS90’s picture

Status: Needs work » Needs review
StatusFileSize
new20.65 KB

Modified configuration of sensors which use the watchdog table to use the watchdog_aggregator plugin, was able to removed sensor specific plugins. Also amended the test with the replaced name. Only tested MonitoringCoreWebTest (which passed).

LKS90’s picture

StatusFileSize
new16.68 KB

Forgot the interdiff again...

LKS90’s picture

StatusFileSize
new20.65 KB
new875 bytes

The patch had one uncommitted change (a space at the end of the user sensor test string).

LKS90’s picture

StatusFileSize
new23 KB
new2.55 KB

Added test for the watchdog sensor and it's functionality.

The last submitted patch, 8: separate_unaggregated-2525426-8.patch, failed testing.

The last submitted patch, 1: separate_unaggregated-2525426-1.patch, failed testing.

The last submitted patch, 1: separate_unaggregated-2525426-1.patch, failed testing.

The last submitted patch, 10: separate_unaggregated-2525426-10.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 11: separate_unaggregated-2525426-11.patch, failed testing.

LKS90’s picture

Status: Needs work » Needs review
StatusFileSize
new9.14 KB

Rebase.
Edit: Actually the wrong issue...

LKS90’s picture

StatusFileSize
new23 KB

Correct patch this time.

Edit: The test fails are all related to the sensors which I removed (and replaced with watchdog).

Status: Needs review » Needs work

The last submitted patch, 18: separate_unaggregated-2525426-18.patch, failed testing.

miro_dietiker’s picture

You are deleting multiple files. Why? .-)

+++ b/config/install/monitoring.sensor_config.user_failed_logins.yml
@@ -2,7 +2,7 @@ id: user_failed_logins
-plugin_id: user_failed_logins

+++ b/config/optional/monitoring.sensor_config.dblog_404.yml
@@ -7,7 +7,7 @@ id: dblog_404
-plugin_id: dblog_404
+plugin_id: watchdog_aggregator

Really switch them to the currentl watchdog sensor? Is the new watchdog sensor providing everything

LKS90’s picture

Status: Needs work » Needs review
StatusFileSize
new14.55 KB

You are deleting multiple files. Why? .-)

I thought it was worth a try :D.

They are missing some things when using the WatchdogSensor. Dblog404 and UserFailedLogin just have custom messages, the ImageMissingStyleSensor is a little more complicated (loads file results and adds information [listUsage($file)] to the message). Here is a patch that simply readds them.

miro_dietiker’s picture

Status: Needs review » Needs work

just have custom messages

Because we want NICE messages. That's the whole point of monitoring.
Fine if you want to subclass the watchdog sensor in case it makes sense. Dunno. Can be a followup.

  1. +++ b/src/Plugin/monitoring/SensorPlugin/DatabaseAggregatorSensorPlugin.php
    @@ -160,6 +160,14 @@ class DatabaseAggregatorSensorPlugin extends DatabaseAggregatorSensorPluginBase
    +    $this->verboseResultUnaggregated($output);
    
    +++ b/src/SensorPlugin/DatabaseAggregatorSensorPluginBase.php
    @@ -124,6 +124,15 @@ abstract class DatabaseAggregatorSensorPluginBase extends SensorPluginBase {
    +  public function verboseResultUnaggregated(array &$output) {
    

    Hm, The DatabaseAggregatorSensorPluginBase is not really an interface definition. It provides default implementations for database aggregators. By adding a stub here, we won't gain anything. Just add it on DatabaseAggregatorSensorPlugin and move it up once there is a common part... If anything it would be extending the Interface where resultVerbose originates (ExtendedInfoSensorPluginInterface) but that's a different story. For now we shouls just improve again and again our verbose outputs until we know how to better define an "extended info" interface. ;-)

  2. +++ b/src/Plugin/monitoring/SensorPlugin/WatchdogAggregatorSensorPlugin.php
    @@ -0,0 +1,86 @@
    + * Simple database aggregator able to query a single db table.
    

    Try harder.

  3. +++ b/src/Plugin/monitoring/SensorPlugin/WatchdogAggregatorSensorPlugin.php
    @@ -0,0 +1,86 @@
    +    foreach ($query_result as $record) {
    ...
    +      if (array_key_exists('message', $row)) {
    +        if (array_key_exists('variables', $row)) {
    +          $row['message'] = SafeMarkup::format($row['message'], unserialize($row['variables']));
    +          unset($row['variables']);
    

    You could just call parent verboseResultUnaggregated() and then alter the rows in 'result'. You repeat too much code.

  4. +++ b/src/SensorPlugin/DatabaseAggregatorSensorPluginBase.php
    @@ -124,6 +124,15 @@ abstract class DatabaseAggregatorSensorPluginBase extends SensorPluginBase {
    +   * Adds verbose result to the render array $output.
    

    Missing "unaggregated". Too much copy paste.

  5. +++ b/src/Tests/MonitoringCoreWebTest.php
    @@ -26,6 +26,43 @@ class MonitoringCoreWebTest extends MonitoringTestBase {
    +   * Tests active session count through db aggregator sensor.
    

    Active session count?

LKS90’s picture

Status: Needs work » Needs review

New version, moved the resultVerboseUnaggregated down to the DatabaseAggregatorSensorPlugin, shortened the watchdog resultVerboseUnaggregated by editing the parent output, changed the comments as requested.

LKS90’s picture

StatusFileSize
new33.54 KB
new4.34 KB

The patch...

miro_dietiker’s picture

Status: Needs review » Needs work

Plz pull / rebase...

LKS90’s picture

Status: Needs work » Needs review
StatusFileSize
new13.64 KB
new4.34 KB

Rebased, 20KB of breaking HEAD are gone.

The last submitted patch, 24: separate_unaggregated-2525426-23.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 26: separate_unaggregated-2525426-26.patch, failed testing.

miro_dietiker’s picture

+++ b/src/Plugin/monitoring/SensorPlugin/WatchdogAggregatorSensorPlugin.php
@@ -0,0 +1,61 @@
+ * More specific database aggregator for querying the watchdog table.
...
+ *   description = @Translation("Simple aggregator able to query the watchdog table."),

Those are summaries. Be specific in what specificity is provided or don't mention it. You might want to mention the variable handling.

LKS90’s picture

Status: Needs work » Needs review
StatusFileSize
new13.73 KB
new2.11 KB

Changed the description, mentioning the variables replacement in messages. Also added a check to make sure there actually are messages to replace (the exception in the test above).

LKS90’s picture

Status: Needs review » Needs work

Some of the code from #2495613: Sensor for php notices should be ported here. In case the variables have HTML tags/the string isn't marked safe, this version has ugly results.

miro_dietiker’s picture

EDIT: Discussed, reviewed...

miro_dietiker’s picture

Status: Needs work » Needs review
StatusFileSize
new13.94 KB
new2.5 KB

Looks good, but providing some cleanup. Hope it passes then i can commit.

miro_dietiker’s picture

Status: Needs review » Fixed

Yay! committed.

  • miro_dietiker committed e6d7648 on 8.x-1.x
    Issue #2525426 by LKS90, miro_dietiker: Separate unaggregated results...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.