Problem/Motivation

Sometimes user's may want to know when certain KPIs fall outside of an expected range (e.g. If fully loaded page time takes longer than 8 seconds, send an email or whatever).

Proposed resolution

After #3072581: Configurable KPIs is completed, add configurable thresholds to the performance_budget_kpi_group config entities. And then when a capture is performed broadcast a custom event, the other modules can subscribe to.

Accessible Scanner also needs the means for notifications (See #3043963: Notification System). As such, we could maybe combine some of the need there by adding the notification functionality into the Web Page Archive module itself. It would make sense for that module to handle all of the notification events/subscribers and then performance budget could just trigger the event.

Remaining tasks

TBD

User interface changes

TBD

API changes

TBD

Data model changes

TBD

Release notes snippet

TBD

Comments

WidgetsBurritos created an issue. See original summary.

WidgetsBurritos’s picture

Status: Postponed » Active

Unblocking this task as the dependency is complete.

WidgetsBurritos’s picture

Status: Active » Postponed
WidgetsBurritos’s picture

Status: Postponed » Needs work
StatusFileSize
new7.34 KB

This is dependent on WIP in #3074051: Notification System. Merely posting this as a POC. This doesn't have the threshold monitoring yet, but does have the email alerts setup. You simply use this template:

<ul>
<li>URL: @url</li>
<li>Load Time: @pb_wpt__standard_page_load_kpis__average__first_view__load_time</li>
<li>Fully Loaded: @pb_wpt__standard_page_load_kpis__average__first_view__fully_loaded</li>
<li>TTFB: @pb_wpt__standard_page_load_kpis__average__first_view__ttfb</li>
<li>Render: @pb_wpt__standard_page_load_kpis__average__first_view__start_render</li>
</ul>
<a href="@wpa_run_url">See more information here</a>

That all seems to be working as expected. So basically we just need to generate a new context that happens when thresholds are met, and then send email.

WidgetsBurritos’s picture

Status: Needs work » Needs review
StatusFileSize
new36.48 KB
new36.55 KB

Okay, this is still dependent on #3074051: Notification System going in, but this basically has everything we want in it. The only caveat is we don't have great test coverage around the actual capturing functionality. In the functional test, we "simulate" it. I probably need a way to mock that service in the future, but for now, I think this is fine to consider moving forward.

Although we may want to set a minimum module compatibility version or something once WPA is updated.

WidgetsBurritos’s picture

Status: Needs review » Needs work

Per review session with @vessel_adrift:

  1. +++ b/config/schema/wpt_kpi.schema.yml
    @@ -14,35 +14,72 @@ performance_budget.wpt_kpi.*:
    +      type: float
    

    Change these all back to integer

  2. +++ b/src/Entity/WebPageTestKpiListBuilder.php
    @@ -61,15 +61,32 @@ class WebPageTestKpiListBuilder extends ConfigEntityListBuilder {
    +            if (!empty($kpi_details['has_minimum']) && !empty($kpi_details['minimum'])) {
    +              $minimum = $kpi_details['minimum'];
    +              $threshold[] = $this->t('- Minimum value: @minimum', ['@minimum' => $minimum]);
    +            }
    +            if (!empty($kpi_details['has_maximum']) && !empty($kpi_details['maximum'])) {
    +              $maximum = $kpi_details['maximum'];
    +              $threshold[] = $this->t('- Maximum value: @maximum', ['@maximum' => $maximum]);
    +            }
    
    if (!empty($kpi_details['has_minimum']) && !empty($kpi_details['minimum'])) {
    

    probably should be

    if (!empty($kpi_details['has_minimum']) && isset($kpi_details['minimum'])) {
    

    Because the minimum could feasibly be set to the value of zero. None of the metrics that I know of can return negative values, but I don't want to be surprised by this in the future.

    Same with the maximu

  3. +++ b/src/Form/WebPageTestKpiForm.php
    @@ -47,13 +47,70 @@ class WebPageTestKpiForm extends EntityForm {
    +      $minimum = !empty($defaults[$average][$view]["{$kpi}_threshold"]['minimum']) ? $defaults[$average][$view]["{$kpi}_threshold"]['minimum'] : NULL;
    

    Should be isset instead of !empty in case value is zero.

  4. +++ b/src/Plugin/CaptureResponse/WebPageTestCaptureResponse.php
    @@ -114,6 +116,29 @@ class WebPageTestCaptureResponse extends UriCaptureResponse {
    +  /**
    +   * Retrieves the messenger service.
    +   *
    +   * @return \Drupal\Core\Messenger\MessengerInterface
    +   *   The messenger service.
    +   */
    +  protected function getMessenger() {
    +    if (!isset($this->messenger)) {
    +      $this->messenger = \Drupal::service('messenger');
    +    }
    +    return $this->messenger;
    +  }
    +
    +  /**
    +   * Sets the messenger service.
    +   *
    +   * @param \Drupal\Core\Messenger\MessengerInterface $messenger
    +   *   The messenger service.
    +   */
    +  public function setMessenger(MessengerInterface $messenger) {
    +    $this->messenger = $messenger;
    +  }
    +
    

    We are no longer using the messenger service here. We can kill this.

  5. +++ b/src/Plugin/CaptureResponse/WebPageTestCaptureResponse.php
    @@ -138,11 +163,12 @@ class WebPageTestCaptureResponse extends UriCaptureResponse {
    +    $kpis = $this->parseKpis($run, $contents, FALSE);
         $render = [
           '#theme' => 'pb-wpt-preview',
           '#url' => $this->captureUrl,
           '#from' => isset($contents['from']) ? strip_tags($contents['from']) : $this->t('Unknown')->render(),
    -      '#kpis' => $this->parseKpis($run, $contents, FALSE),
    +      '#kpis' => $kpis,
    

    We don't need this refactor here after all as we're not using $kpis in this method.

  6. +++ b/src/Plugin/CaptureResponse/WebPageTestCaptureResponse.php
    @@ -368,11 +394,57 @@ class WebPageTestCaptureResponse extends UriCaptureResponse {
    +              $actual = isset($content[$average][$view][$kpi]) ? $content[$average][$view][$kpi] : FALSE;
    +
    +              if ($actual && !empty($kpi_details['has_minimum']) && !empty($kpi_details['minimum'])) {
    

    Could $actual ever be zero here?
    Also $kpi_details['minimum'] could also be zero?

  7. +++ b/src/Plugin/CaptureResponse/WebPageTestCaptureResponse.php
    @@ -391,4 +463,57 @@ class WebPageTestCaptureResponse extends UriCaptureResponse {
    +    $kpis = $this->parseKpis($run_entity);
    +    return $kpis['#threshold_violations'];
    

    This should check for the existence of #threshold_violations as it's not always set, if there are none.

  8. +++ b/src/Plugin/QueueWorker/AggregateRunDataQueueWorker.php
    @@ -114,7 +114,7 @@ class AggregateRunDataQueueWorker extends QueueWorkerBase implements ContainerFa
    -            else {
    +            elseif ($group != '#threshold_violations') {
    

    For now I don't care about violations cumulatively. We may in a future task, and should create an issue for that specific context if we do.

WidgetsBurritos’s picture

Status: Needs work » Needs review
StatusFileSize
new35.5 KB
new9.69 KB

Items #7.1 - #7.7 have been addressed.

#7.8 is more of a commentary than anything. We can potentially add another ticket for this later.

WidgetsBurritos’s picture

StatusFileSize
new35.37 KB
new3.59 KB

Minor formatting change.

vessel_adrift’s picture

Status: Needs review » Reviewed & tested by the community

+1 rtbc

WidgetsBurritos’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new36.08 KB
new730 bytes

Okay now that WPA is merged and the version is bumped, changing the version of WPA we look at here.

WidgetsBurritos’s picture

+++ b/composer.json
@@ -16,7 +16,7 @@
-        "drupal/web_page_archive": "^2.13"
+        "drupal/web_page_archive": "3.x-dev"

At some point this will need to change to an actual release. This is just temporary at this point.

WidgetsBurritos’s picture

Status: Needs review » Reviewed & tested by the community

Okay confirmed tests are passing as expected with new versions. Going to go ahead and create a new alpha release. Before we can move this module to beta, we'll need to get WPA 3.0 release launched.

  • WidgetsBurritos committed 0502d85 on 8.x-1.x
    Issue #3074048 by WidgetsBurritos, vessel_adrift, bighappyface, pobster...
WidgetsBurritos’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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