[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.
- Ensure that the Clickhouse DB is runnig.
- Configure CH in the
config/database.ymlfile - Run the migration:
rails db:migrate:clickhouse_analytics - Start a rails console:
rails c - Create a record:
Clickhouse::Issue.create!(title: 'My issue', project_id: 15) - Query the record:
Clickhouse::Issue.where(project_id: 15)
Identified quirks/issues
- We patch
ActiveRecord::Basea 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
Databasemodule 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.
-
I have evaluated the MR acceptance checklist for this MR.
Edited by Adam Hegyi