Database time metric counts only last query

Created on 8 June 2023, about 1 year ago

Problem/Motivation

Variable $totalTimeInMs in DatabaseCollector::getTotalTimeInMs() gets overwritten on each iteration of the loop, so the method returns time only for the last logged query, and not the total.

Steps to reproduce

  1. Install Prometheus.io Exporter and Prometheus Exporter - Database. It would be better to have some prepopulated site. If you do not have one, install Drupal with Umami demo profile.
  2. Add following buckets to Prometheus Exporter - Database settings: 10, 50, 100. All these values are milliseconds.
  3. Go to /metrics in your installation.
  4. Walk through your site in another tab or window and refresh /metrics page periodically.
  5. See that (almost) all buckets in drupal_database_time_bucket get updated synchronously, indicating suspiciously small database footprint.

Proposed resolution

Sum query times instead of overwriting the total with the latest value.

Remaining tasks

None.

User interface changes

None.

API changes

None.

Data model changes

None.

πŸ› Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

πŸ‡·πŸ‡ΊRussia iamweird

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.69.0 2024