[PoC] Test clickhouse-activerecord gem

What does this MR do and why?

This MR attempts to integrate the clickhouse-activerecord gem with the GitLab application.

Setup

GDK supports ClickHouse but it needs to be installed automatically. The gdk.yml can be used to run the service:

---
clickhouse:
  bin: "/usr/bin/clickhouse"
  data_dir: "/gitlab-development-kit/clickhouse/data"
  dir: "/gitlab-development-kit/clickhouse"
  enabled: true
  http_port: 8123
  interserver_http_port: 9009
  log_dir: "/gitlab-development-kit/clickhouse/log"
  log_level: trace
  max_memory_usage: 1000000000
  max_server_memory_usage: 2000000000
  max_thread_pool_size: 1000
  tcp_port: 9001
gdk:
  experimental:
    ruby_services: true

Running gdk reconfigure will make the clickhouse service available within GDK.

What works

  • Creating and running migrations
  • Tracking schema version
  • Creating AR models
  • Querying the database
  • Inserting to the database

How to test it

This MR includes a test migration that creates the issues table on CH.

  1. Ensure that the Clickhouse DB is runnig.
  2. Configure CH in the config/database.yml file
  3. Run the migration: rails db:migrate:clickhouse_analytics
  4. Start a rails console: rails c
  5. Create a record: Clickhouse::Issue.create!(title: 'My issue', project_id: 15)
  6. Query the record: Clickhouse::Issue.where(project_id: 15)

Identified quirks/issues

  • We patch ActiveRecord::Base a lot. This is not great because we add a lot of PG-specific functionality to the base class which prevents using a different DB adapter.
    • This MR introduces a base class for PG based models, we can apply extensions to this class.
    • Ideally, all models (including external models coming from gems) should inherit from PostgresqlRecord.
  • Query analyzers for cross DB modifications and migrations are off when the adapter is `Clickhouse. Clickhouse queries might not always be parseable by PG.
  • Our Database module contains a lot of PG-specific methods.

MR acceptance checklist

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

Edited by Adam Hegyi

Merge request reports

Loading