Skip to content

Use EXTRACT(EPOCH) when calculating durations

Adam Hegyi requested to merge 346761-fix-vsa-durations into master

What does this MR do and why?

Note: the bug is not visible to end-users because the aggregated VSA feature is not released yet. The FF is enabled for gitlab-org group.

This MR fixes a configuration issue that only happens on PRD. The symptoms are described in the issue: #346761 (closed)

How to see the box:

  1. Go to VSA
  2. See the time column.
  3. Click the "issue" button a few times.
  4. At some point you should see different values (0) for the same rows.

Why does this happening?

It looks like the interval_style config is misconfigured on some of our replicas:

[ gprd ] production> 10.times { puts ActiveRecord::Base.connection.execute("show intervalstyle").to_a }
{"IntervalStyle"=>"iso_8601"}
{"IntervalStyle"=>"iso_8601"}
{"IntervalStyle"=>"iso_8601"}
{"IntervalStyle"=>"postgres"}
{"IntervalStyle"=>"iso_8601"}
{"IntervalStyle"=>"postgres"}
{"IntervalStyle"=>"postgres"}
{"IntervalStyle"=>"iso_8601"}
{"IntervalStyle"=>"iso_8601"}
{"IntervalStyle"=>"postgres"}

How to fix it?

I notified the DB team about the misconfiguration. This MR fixes the queries to use EXTRACT(epoch ...) so the queries will always return the duration in seconds. This is the same way as we calculate durations in the old value stream analytics backend.

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Related to #346761 (closed)

Edited by Adam Hegyi

Merge request reports