Skip to content

POC Sync and query user seat assignment historical data on CH

Felipe Cardozo requested to merge issue_490932-proof_of_concept into master

What does this MR do and why?

Setup paper_trail gem to store historical user add-on seat assignment data on PG. The data is then sent to CH using the write buffer strategy and stored into a ReplacingMerge tree table.

How to reproduce

  1. Run rails db:migrate
  2. bundle exec rake gitlab:clickhouse:migrate
  3. Run the seed script bundle exec rake db:seed_fu FILTER=seat_assignments COUNT=100 (default count is 50) to create seat assignments in a time range
  4. Now sync data to CH using rails console ClickHouse::DumpWriteBufferWorker.new.perform('add_on_assignment_events')
  5. Run the following queries on your local ClickHouse client

Sample queries

Adjust start-date and end-date according to the time you ran the script.

How many assignments happened for a given period

SELECT COUNT(*) AS total_assignments
FROM add_on_assignment_events FINAL
WHERE assigned_at >= '2024-10-01 00:00:00' AND assigned_at <= '2024-10-30 00:00:00';

How many assignments were active in a given period

SELECT COUNT(*) AS total_active_assignments
FROM add_on_assignment_events FINAL
WHERE assigned_at >= '2024-10-01 00:00:00' AND assigned_at <= '2024-10-30 00:00:00'
  AND (revoked_at IS NULL OR revoked_at > '2024-10-30 00:00:00');

How many unassignments happened in a given period

SELECT COUNT(*) AS total_unassignments
FROM add_on_assignment_events 
WHERE revoked_at >= '2024-10-01 00:00:00' AND revoked_at <= '2024-10-30 00:00:00'
Edited by Felipe Cardozo

Merge request reports

Loading