Skip to content

Recalculate CI extra minutes when monthly minutes defaults to nil

Fabio Pitino requested to merge fix-ci-extra-minutes-recalculation into master

What does this MR do?

Related to #225813 (closed)

This MR fixes a bug that skipped recalculating CI extra minutes for namespaces having shared_runners_minutes_limit: nil.

More details about this approach available here.

Defaulting to ::Gitlab::CurrentSettings.shared_runners_minutes when not present is already used today to display the CI minutes usage report and to check CI minutes quota prior to assign a job to a Runner.

This MR aligns the actual value of shared_runners_minutes_limit with existing usages.

Query plans

From database-lab: https://gitlab.slack.com/archives/CLJMDRD8C/p1594200447307900

Query plans prior to this change: !29017 (merged)

First run

explain UPDATE namespaces
SET extra_shared_runners_minutes_limit = GREATEST((COALESCE(namespaces.shared_runners_minutes_limit, 2000) + namespaces.extra_shared_runners_minutes_limit) - ROUND(namespace_statistics.shared_runners_seconds / 60.0), 0)
FROM namespace_statistics
WHERE namespaces.id BETWEEN 100001 AND 200000
  AND namespaces.id >= 100001 AND namespaces.id < 101001
  AND (namespaces.extra_shared_runners_minutes_limit > 0)
  AND (COALESCE(namespaces.shared_runners_minutes_limit, 2000) > 0)
  AND (namespace_statistics.namespace_id = namespaces.id)
  AND (namespace_statistics.shared_runners_seconds > (COALESCE(namespaces.shared_runners_minutes_limit, 2000) * 60));
ModifyTable on public.namespaces  (cost=0.86..1457.51 rows=1 width=363) (actual time=509.871..509.871 rows=0 loops=1)
   Buffers: shared hit=108 read=181
   I/O Timings: read=505.731
   ->  Nested Loop  (cost=0.86..1457.51 rows=1 width=363) (actual time=509.844..509.844 rows=0 loops=1)
         Buffers: shared hit=108 read=181
         I/O Timings: read=505.731
         ->  Index Scan using namespaces_pkey on public.namespaces  (cost=0.43..1454.03 rows=1 width=337) (actual time=509.843..509.843 rows=0 loops=1)
               Index Cond: ((namespaces.id >= 100001) AND (namespaces.id <= 200000) AND (namespaces.id >= 100001) AND (namespaces.id < 101001))
               Filter: ((namespaces.extra_shared_runners_minutes_limit > 0) AND (COALESCE(namespaces.shared_runners_minutes_limit, 2000) > 0))
               Rows Removed by Filter: 937
               Buffers: shared hit=108 read=181
               I/O Timings: read=505.731
         ->  Index Scan using index_namespace_statistics_on_namespace_id on public.namespace_statistics  (cost=0.42..3.45 rows=1 width=14) (actual time=0.000..0.000 rows=0 loops=0)
               Index Cond: (namespace_statistics.namespace_id = namespaces.id)
               Filter: (namespace_statistics.shared_runners_seconds > (COALESCE(namespaces.shared_runners_minutes_limit, 2000) * 60))
               Rows Removed by Filter: 0
Time: 510.908 ms
  - planning: 0.845 ms
  - execution: 510.063 ms
    - I/O read: 505.731 ms
    - I/O write: 0.000 ms

Shared buffers:
  - hits: 108 (~864.00 KiB) from the buffer pool
  - reads: 181 (~1.40 MiB) from the OS file cache, including disk I/O
  - dirtied: 0
  - writes: 0

Second run

Time: 2.528 ms
  - planning: 1.043 ms
  - execution: 1.485 ms
    - I/O read: 0.000 ms
    - I/O write: 0.000 ms

Shared buffers:
  - hits: 289 (~2.30 MiB) from the buffer pool
  - reads: 0 from the OS file cache, including disk I/O
  - dirtied: 0
  - writes: 0

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • Label as security and @ mention @gitlab-com/gl-security/appsec
  • The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • Security reports checked/validated by a reviewer from the AppSec team
Edited by Fabio Pitino

Merge request reports