Skip to content

Send add-on metrics during seat link sync

This is part of customers-gitlab-com#9364 (closed).

This is a follow-up to https://gitlab.com/gitlab-org/customers-gitlab-com/-/merge_requests/10750, https://gitlab.com/gitlab-org/customers-gitlab-com/-/merge_requests/10845, and https://gitlab.com/gitlab-org/customers-gitlab-com/-/merge_requests/10866.

Depends on https://gitlab.com/gitlab-org/customers-gitlab-com/-/merge_requests/10866.

What does this MR do and why?

This MR includes additional add-on metrics in the payload sent by SM instances during the seat link sync.

For more context, please refer to customers-gitlab-com#9364 (closed) and the linked MRs.

Raw SQL

SELECT subscription_add_on_purchases.quantity, subscription_add_on_purchases.subscription_add_on_id, COUNT(subscription_user_add_on_assignments.id) AS assigned_users_count, subscription_add_on_purchases.id AS t0_r0, subscription_add_ons.id AS t1_r0, subscription_add_ons.created_at AS t1_r1, subscription_add_ons.updated_at AS t1_r2, subscription_add_ons.name AS t1_r3, subscription_add_ons.description AS t1_r4 
FROM subscription_add_on_purchases 
LEFT OUTER JOIN subscription_user_add_on_assignments ON subscription_user_add_on_assignments.add_on_purchase_id = subscription_add_on_purchases.id 
LEFT OUTER JOIN subscription_add_ons ON subscription_add_ons.id = subscription_add_on_purchases.subscription_add_on_id 
WHERE (started_at IS NULL OR started_at <= '2024-09-19') AND ('2024-09-19' < expires_on) AND subscription_add_on_purchases.namespace_id IS NULL 
GROUP BY subscription_add_on_purchases.id, subscription_add_ons.id

Query plan

                                                                            QUERY PLAN
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
 GroupAggregate  (cost=4.27..4.29 rows=1 width=86) (actual time=0.037..0.038 rows=1 loops=1)
   Group Key: subscription_add_on_purchases.id, subscription_add_ons.id
   ->  Sort  (cost=4.27..4.27 rows=1 width=86) (actual time=0.031..0.033 rows=2 loops=1)
         Sort Key: subscription_add_on_purchases.id, subscription_add_ons.id
         Sort Method: quicksort  Memory: 25kB
         ->  Nested Loop Left Join  (cost=0.15..4.26 rows=1 width=86) (actual time=0.021..0.025 rows=2 loops=1)
               ->  Nested Loop Left Join  (cost=0.00..2.09 rows=1 width=28) (actual time=0.016..0.018 rows=2 loops=1)
                     Join Filter: (subscription_user_add_on_assignments.add_on_purchase_id = subscription_add_on_purchases.id)
                     ->  Seq Scan on subscription_add_on_purchases  (cost=0.00..1.07 rows=1 width=20) (actual time=0.011..0.012 rows=1 loops=1)
                           Filter: ((namespace_id IS NULL) AND ((started_at IS NULL) OR (started_at <= '2024-09-19'::date)) AND ('2024-09-19'::date < expires_on))
                           Rows Removed by Filter: 5
                     ->  Seq Scan on subscription_user_add_on_assignments  (cost=0.00..1.00 rows=1 width=16) (actual time=0.003..0.003 rows=2 loops=1)
               ->  Index Scan using subscription_add_ons_pkey on subscription_add_ons  (cost=0.15..2.17 rows=1 width=58) (actual time=0.002..0.002 rows=1 loops=2)
                     Index Cond: (id = subscription_add_on_purchases.subscription_add_on_id)
 Planning Time: 0.261 ms
 Execution Time: 0.091 ms
(16 rows)

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Screenshots or screen recordings

N/A

How to set up and validate locally

  1. Start GDK on self-managed mode and pointing to CustomersDot staging (i.e. GITLAB_SIMULATE_SAAS=0 and CUSTOMER_PORTAL_URL=https://customers.staging.gitlab.com/)
  2. Apply a staging license with Duo Pro/Enterprise included in the subscription
  3. Open a Rails console, and do the following:
SyncSeatLinkWorker.new.perform
  1. Check for a new record at https://customers.staging.gitlab.com/admin/license_seat_link and/or verify on the console that a new LicenseSeatLink record was created with the add_on_metrics field included => I can help you with that in case you don't have access
Edited by Paulo Barros

Merge request reports

Loading