Add OpenTelemetry Application Performance Monitoring to core performance tests

Created on 5 April 2023, over 1 year ago
Updated 5 December 2023, 12 months ago

Problem/Motivation

Postponed on โœจ Add PerformanceTestBase for allowing browser performance assertions within FunctionalJavaScriptTests Fixed and ๐Ÿ“Œ Add open-telemetry/sdk and open-telemetry/exporter-otlp as dev dependencies Active .

See ๐ŸŒฑ Automated performance testing for core Active for rationale.

We're not able to easily see changes on core backend and frontend performance over time, this MR adds the capability to display graphs in a grafana/tempo instance as well as browse individual traces to see what's different.

Steps to reproduce

Proposed resolution

โœจ Add PerformanceTestBase for allowing browser performance assertions within FunctionalJavaScriptTests Fixed gives us the ability to pass or fail tests based on certain performance characteristics, but this only works for things you can count.

For things that can't be counted but only timed (like how long a request takes from first byte to first paint), we could instead look at graphing these over time and flagging changes.

Open Telemetry is a suite of tools that will allow us to do this via adding some development dependencies, and setting up a 'collector' on Drupal.org infrastructure.

We can add the capability to PerformanceTestBase to send traces to OpenTelemetry, these can then be made available for browsing in signoz. signoz will show both trends over time and allow you to drill down into individual traces. See the screenshot for a proof of concept.

Traces are currently using data from the performance navigation API: https://developer.mozilla.org/en-US/docs/Web/API/PerformanceNavigationTi... via executeScript() - this lets us log this information without running any extra JavaScript on the tested site.

Note that the MR doesn't include the OpenTelemetry collector or the configuration to enable this, that will have to be handled on the infrastructure side. However there is a test repo using this patch that gives you a full end-to-end installation via ddev. https://github.com/tag1consulting/google-drupal

Remaining tasks

Once we have the initial framework for sending traces, we can add more tests, and more data to traces.

โœจ Add authenticated user telemetry tests Active
๐Ÿ“Œ Add database query spans to otel traces Needs review
โœจ Support 'interaction to next paint' (or close equivalent) in performance testing Active
โœจ Add script, style, image HTTP requests to otel traces Active
๐Ÿ“Œ Add the commit hash to OpenTelemetry traces Active
๐Ÿ“Œ Optimize PerformanceTestBase largest contentful paint detection Active
๐Ÿ› Figure out cold start issue with chromedriver performance logs Active

User interface changes

API changes

A new PerformanceTestTrait is added, it is included in the existing PerformanceTestBase.

A PerformanceData value object has been added in the Drupal\Tests namespace, this is only used by PerformanceTestTrait.

To get performance data to assert on within a test:

Before:

  $this->drupalGet('node/1');
  $this->assertSame(2, $this->styleSheetCount);
  $this->assertSame(2, $this->scriptCount);

After, to record performance data to assert on, explicitly enable profiling via calling the 'collectPerformanceData()' method, which takes a callable.

    $performance_data = $this->collectPerformanceData(function () {
      $this->drupalGet('node/1');
    });
    $this->assertSame(2, $performance_data->getStylesheetCount());
    $this->assertSame(1, $performance_data->getScriptCount());

The former behaviour of always recording performance data and adding information on PerformanceTestBase properties is removed, but is not in a tagged release yet, so no bc is provided, just existing tests updated:

To log telemetry to open telemetry, call the new ::logTelemetry() method, API is otherwise the same as ::collectPerformancedata(), so it's possible to combine both telemetry logging but also assert on PerformanceData from the same request.

    $this->logTelemetry('umamiFrontPageWarmCache', function () {
      $this->drupalGet('<front>');
    });

Data model changes

Release notes snippet

Tests extending PerformanceTestBase can now additionally send OpenTelemetry traces to an open telemetry endpoint, but setting the OTEL_COLLECTORenvironment variable. An OpenTelemetry collecter must be accessible from the environment running the test.

โœจ Feature request
Status

Fixed

Version

11.0 ๐Ÿ”ฅ

Component
PHPUnitย  โ†’

Last updated about 1 hour ago

Created by

๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom catch

Live updates comments and jobs are added and updated live.
  • Performance

    It affects performance. It is often combined with the Needs profiling tag.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024