Comments

Berdir created an issue. See original summary.

ginovski’s picture

Assigned: Unassigned » ginovski
Status: Active » Needs review
StatusFileSize
new6.03 KB

Initial patch, added sensor, default config and basic web test.

Status: Needs review » Needs work

The last submitted patch, 2: support_redirect_404-2836483-2.patch, failed testing.

ginovski’s picture

Status: Needs work » Needs review
StatusFileSize
new896 bytes
new6.17 KB

Adding module dependency for the test

ginovski’s picture

StatusFileSize
new295 bytes

Added test dependency in the monitoring module.

The last submitted patch, 4: support_redirect_404-2836483-4.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 5: redirect_404-test-dependency.patch, failed testing.

  • Berdir committed c51dfd4 on 8.x-1.x authored by Ginovski
    Issue #2836483 by Ginovski: Added redirect_404 as a test dependency
    
berdir’s picture

Committed that. Would be nice if someone would look into those test fails because now you will have to always manually request a test.

berdir’s picture

  1. +++ b/src/Plugin/monitoring/SensorPlugin/Monitoring404SensorPlugin.php
    @@ -0,0 +1,113 @@
    + *
    + * @SensorPlugin(
    + *   id = "monitoring_404",
    + *   provider = "redirect_404",
    + *   label = @Translation("Monitoring 404"),
    

    just like the other is called Dblog404, this should be called redirect_404, the id possibly monitoring_redirect_404, label should also clarify that this the redirect_404 version.

  2. +++ b/src/Plugin/monitoring/SensorPlugin/Monitoring404SensorPlugin.php
    @@ -0,0 +1,113 @@
    +   */
    +  public function getAggregateQuery() {
    +    /* @var \Drupal\Core\Database\Connection $database */
    +    $database = $this->getService('database');
    +    // Get aggregate query for the table.
    +    $query = $database->select($this->sensorConfig->getSetting('table'));
    

    count of just one record does't make sense. just select count as records_count or what it is with addField(). And that should be possibly by just overridig the aggregate method called by the parent.

  3. +++ b/src/Plugin/monitoring/SensorPlugin/Monitoring404SensorPlugin.php
    @@ -0,0 +1,113 @@
    +    $query->orderBy('count', 'DESC');
    +    $query->range(0, 1);
    +    return $query;
    

    additionally select the path field and display that in the message like the other 404 sensor

  4. +++ b/src/Plugin/monitoring/SensorPlugin/Monitoring404SensorPlugin.php
    @@ -0,0 +1,113 @@
    +    $query->orderBy('count', 'DESC');
    +    $query->condition('resolved', 0);
    +    $query->range(0, 10);
    +    return $query;
    

    the aggregate also needs the check on resolve. you could also put that in settigs, then both should respect it.

  5. +++ b/src/Plugin/monitoring/SensorPlugin/Monitoring404SensorPlugin.php
    @@ -0,0 +1,113 @@
    +    parent::runSensor($result);
    +    $query = $this->getQuery();
    +    $this->executedQuery = $query->execute();
    +    $this->fetchedObject = $this->executedQuery->fetchObject();
    +    $count = 0;
    +    if (!empty($this->fetchedObject->count)) {
    +      $count = $this->fetchedObject->count;
    +    }
    +    $result->setValue($count);
    

    if you select it as the right field name, then the parent does this for you, and you just need exactly the same as the other 404 for the path.

  6. +++ b/src/Tests/Monitoring404SensorPluginTest.php
    @@ -0,0 +1,42 @@
    +    ]);
    +    $this->drupalLogin($test_user);
    +    $this->drupalGet('/admin/config/system/monitoring/sensors');
    +    $this->assertText('Monitoring 404');
    +    $this->drupalGet('/admin/config/system/monitoring/sensors/non-existing-sensor');
    +    $this->drupalGet('/admin/config/system/monitoring/sensors/non-existing-sensor');
    +    $this->drupalGet('/admin/reports/monitoring/sensors/monitoring_404');
    +    $this->assertText('/admin/config/system/monitoring/sensors/non-existing-sensor');
    +    $this->assertText('2 404 requests');
    

    extend with checking the patch in the message as well.

    I would actually recommend to insert the rows directly into the database and making this a kernel test. redirect_404 has such a test to test purging of data, you can do it in a similar way. We want records older than one day, records that are resolved and multiple with different counts to make sure we get the right now and test all our coditions.

    Also installing the redirect_404 module can be done in the property now.

ginovski’s picture

StatusFileSize
new5.55 KB

1. Renamed monitoring_404 -> redirect_404
2. Added field count as records_count in the aggregateQuery
3. Added field path in the aggregateQuery
4. Added resolved in the settings, added condition for it in the aggregateQuery and query.
5. Removed the setValue logic from runSensor(), using the records_count instead.
6. Transformed the webtest to kernel, asserting the status message also.
Addressed #10, but it seems like the addField() has some error with the aggregateQuery with the groupBy, I'll fix this asap.

ginovski’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 11: support_redirect_404-2836483-11.patch, failed testing.

berdir’s picture

+++ b/src/Plugin/monitoring/SensorPlugin/Redirect404SensorPlugin.php
@@ -0,0 +1,98 @@
+  public function runSensor(SensorResultInterface $result) {
+    parent::runSensor($result);
+    if (!empty($this->fetchedObject) && !empty($this->fetchedObject->path)) {
+      $result->addStatusMessage($_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'] . $this->fetchedObject->path);
+    }

just the path is enough, we don't need this, it would be wrong anyway on drush and so on.

ginovski’s picture

Status: Needs work » Needs review
StatusFileSize
new2.11 KB
new5.63 KB
new27.03 KB

Changed path and fixed groupBy.
Sensor is working properly when I tried it manually, but kernel test is failing somewhere in the query->execute(), not sure why.

Status: Needs review » Needs work

The last submitted patch, 15: support_redirect_404-2836483-15.patch, failed testing.

ginovski’s picture

Status: Needs work » Needs review
StatusFileSize
new6.82 KB
new8.08 KB

Fixed the query and extended test.

  • Berdir committed 96be896 on 8.x-1.x authored by Ginovski
    Issue #2836483 by Ginovski: Support redirect_404 for 404 request...
berdir’s picture

Status: Needs review » Fixed

Nice, tested that this is created on rebuilding the sensor list and committed.

Status: Fixed » Closed (fixed)

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