Skip to content

Add basic test cases for ClickHouse

Adam Hegyi requested to merge 414588-test-cases-for-ch into master

What does this MR do and why?

This MR adds a few test cases for ClickHouse which are depending on the defined DB schema (1 table):

  • Insert some rows
  • Query the inserted rows
  • Delete rows

The MR also introduces RSpec hooks for cleaning up the tables before each run. ClickHouse does not support transactions so there is no easy way to clean up the created rows (truncate the tables one by one). Maybe https://clickhouse.com/docs/en/guides/developer/transactional could help at some point.

Note about the schema

In ClickHouse there is no such thing as schema dump, besides the HTTP interface allows only one statement per call thus each table definition will be located in a new schema file.

We started prepending the timestamp before the schema file name similar to the migration framework in Rails, however we're not implementing schema management yet. This is strictly for the test environment.

For production environments (SaaS), we'll manage the schema manually for now until we gain experience with CH schema management.

How to set up and validate locally

Setup ClickHouse server on your local and create a database:

  1. Set up a ClickHouse server and a user with password: https://clickhouse.com/docs/en/install
  2. Start a console: clickhouse-client --password
  3. Create a new database: create database gitlab_clickhouse_test;

Configure the config/click_house.yml YAML file :

test:
  main:
    database: gitlab_clickhouse_test
    url: 'http://localhost:8123'
    username: default
    password: clickhouse

Run the tests:

bundle exec rspec spec/lib/gitlab/database/click_house_client_spec.rb --tag click_house

MR acceptance checklist

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

Related to #414588 (closed)

Edited by charlie ablett

Merge request reports