Draft: Add Clickhouse support to GitLab
What does this MR do and why?
This adds ActiveRecord support for Clickhouse with Rails' multiple database support. Load balancing needs to be disabled since Clickhouse doesn't use the PostgreSQL adapter.
Note that because Clickhouse is a columnar store, the schema used for error tracking needs to be changed to take advantage of this. That means we should probably have:
- A partitioned table that holds all raw events (no JOIN needed between
error_tracking_errorsanderror_tracking_error_events). - A materialized view that aggregates the events.
Addresses: #356481 (closed)
Screenshots or screen recordings
These are strongly recommended to assist reviewers and reduce the time to merge your change.
How to set up and validate locally
Testing locally
config/database.yml
development:
...
clickhouse:
adapter: clickhouse
database: gitlabhq_clickhouse_development
host: localhost
port: 8123
username: default
password:
ssl: false # optional for using ssl connection
debug: true # use for showing in to log technical information
migrations_paths: db/clickhouse/migrate # optional, default: db/migrate_clickhouse
# cluster_name: 'cluster_name' # optional for creating tables in cluster
# replica_name: '{replica}' # replica macros name, optional for creating replicated tables
test: &test
...
clickhouse:
adapter: clickhouse
database: gitlabhq_clickhouse_test
host: localhost
port: 8123
username: default
password:
ssl: false # optional for using ssl connection
debug: true # use for showing in to log technical information
migrations_paths: db/clickhouse/migrate # optional, default: db/migrate_clickhouse
# cluster_name: 'cluster_name' # optional for creating tables in cluster
# replica_name: '{replica}' # replica macros name, optional for creating replicated tables
Start clickhouse server via Docker
In GDK root (../gitlab)
docker run -d -p 8123:8123 --name gdk-clickhouse --ulimit nofile=262144:262144 --volume=`pwd`/clickhouse:/var/lib/clickhouse clickhouse/clickhouse-server
clickhouse/ is owned by root on Linux
Migration and testing
rake db:create
rake db:migrate
bin/rails console
payload = JSON.parse(File.read("spec/fixtures/error_tracking/parsed_event.json"))
ErrorTracking::ErrorEvent.create!(payload: json, description: "first", occurred_at: Time.now, actor: "foo", platform: "bar", name: "baz");
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 Peter Leitzen