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.

CommentFileSizeAuthor
database-time-fix.patch1.03 KBiamweird

Comments

iamweird created an issue. See original summary.

iamweird’s picture

Title: Database time metric counts only last call » Database time metric counts only last query

  • iamweird authored 5af2ccfd on 2.x
    Issue #3365615 by iamweird: Database time metric counts only last query
    
grota’s picture

Status: Active » Fixed

Thanks @iamweird, I applied your patch and gave you credit in the commit!
I will release a new rc release for 2.x.

  • iamweird authored eda4492e on 8.x-1.x
    Issue #3365615 by iamweird: Database time metric counts only last query
    

Status: Fixed » Closed (fixed)

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