Skip to content

Commit 260f08f

Browse files
balasankarcv-sh
andcommitted
Merge branch 'vshushlin/clickhouse-databases' into 'master'
Add support for ClickHouse databases See merge request https://gitlab.com/gitlab-org/omnibus-gitlab/-/merge_requests/7179 Merged-by: Balasankar 'Balu' C <[email protected]> Approved-by: Adam Hegyi <[email protected]> Approved-by: Clemens Beck <[email protected]> Approved-by: Balasankar 'Balu' C <[email protected]> Reviewed-by: Balasankar 'Balu' C <[email protected]> Reviewed-by: Vladimir Shushlin <[email protected]> Reviewed-by: Clemens Beck <[email protected]> Co-authored-by: Vladimir Shushlin <[email protected]>
2 parents 19bce79 + fcaa2ca commit 260f08f

File tree

5 files changed

+107
-0
lines changed

5 files changed

+107
-0
lines changed

files/gitlab-config-template/gitlab.rb.template

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -765,6 +765,13 @@ external_url 'GENERATED_EXTERNAL_URL'
765765
# gitlab_rails['databases']['ci']['db_database'] = 'gitlabhq_production'
766766
# gitlab_rails['databases']['ci']['database_tasks'] = false
767767

768+
### GitLab ClickHouse connection settings
769+
###! EXPERIMENTAL
770+
# gitlab_rails['clickhouse_databases']['main']['database'] = 'dbname'
771+
# gitlab_rails['clickhouse_databases']['main']['url'] = 'https://example.com/path'
772+
# gitlab_rails['clickhouse_databases']['main']['username'] = 'gitlab'
773+
# gitlab_rails['clickhouse_databases']['main']['password'] = 'password'
774+
768775
### GitLab Redis settings
769776
###! Connect to your own Redis instance
770777
###! Docs: https://docs.gitlab.com/omnibus/settings/redis.html

files/gitlab-cookbooks/gitlab/attributes/default.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,7 @@
427427
default['gitlab']['gitlab_rails']['db_application_name'] = nil
428428

429429
default['gitlab']['gitlab_rails']['databases'] = {}
430+
default['gitlab']['gitlab_rails']['clickhouse_databases'] = {}
430431

431432
# Automatic Database Reindexing
432433
# See https://docs.gitlab.com/omnibus/settings/database.html#automatic-database-reindexing

files/gitlab-cookbooks/gitlab/recipes/gitlab-rails.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,18 @@
196196
sensitive true
197197
end
198198

199+
templatesymlink "Create a clickhouse.yml and create a symlink to Rails root" do
200+
link_from File.join(gitlab_rails_source_dir, "config/click_house.yml")
201+
link_to File.join(gitlab_rails_etc_dir, "click_house.yml")
202+
source "click_house.yml.erb"
203+
owner "root"
204+
group gitlab_group
205+
mode "0640"
206+
variables node['gitlab']['gitlab_rails'].to_hash
207+
dependent_services.each { |svc| notifies :restart, svc }
208+
sensitive true
209+
end
210+
199211
redis_url = redis_helper.redis_url
200212
redis_sentinels = node['gitlab']['gitlab_rails']['redis_sentinels']
201213
redis_sentinels_password = node['gitlab']['gitlab_rails']['redis_sentinels_password']
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# This file is managed by gitlab-ctl. Manual changes will be
2+
# erased! To change the contents below, edit /etc/gitlab/gitlab.rb
3+
# and run `sudo gitlab-ctl reconfigure`.
4+
5+
production:
6+
<% @clickhouse_databases.each do |database, attributes| %>
7+
<%= database %>:
8+
database: <%= quote(attributes['database']) %>
9+
url: <%= quote(attributes['url']) %>
10+
username: <%= quote(attributes['username']) %>
11+
password: <%= quote(attributes['password']) %>
12+
variables:
13+
enable_http_compression: 1
14+
date_time_input_format: basic # needed for CH cloud
15+
<% end %>
16+
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
require 'chef_helper'
2+
3+
RSpec.describe 'gitlab::gitlab-rails' do
4+
describe 'ClickHouse database settings' do
5+
let(:chef_run) { ChefSpec::SoloRunner.new(step_into: 'templatesymlink').converge('gitlab::default') }
6+
let(:clickhouse_yml_template) { chef_run.template('/var/opt/gitlab/gitlab-rails/etc/click_house.yml') }
7+
let(:clickhouse_yml_file_content) { ChefSpec::Renderer.new(chef_run, clickhouse_yml_template).content }
8+
let(:clickhouse_yml) { YAML.safe_load(clickhouse_yml_file_content, [], [], true, symbolize_names: true) }
9+
10+
before do
11+
allow(Gitlab).to receive(:[]).and_call_original
12+
allow(File).to receive(:symlink?).and_call_original
13+
end
14+
15+
context 'with default settings' do
16+
it 'renders empty clickhouse.yml' do
17+
expect(clickhouse_yml[:production]).to eq(nil)
18+
end
19+
end
20+
21+
context 'with databases setup' do
22+
before do
23+
stub_gitlab_rb(
24+
gitlab_rails: {
25+
clickhouse_databases: {
26+
main: {
27+
database: 'production',
28+
url: 'https://example.com/path',
29+
username: 'gitlab',
30+
password: 'password'
31+
},
32+
main2: {
33+
database: 'production2',
34+
url: 'https://example.com/path2',
35+
username: 'gitlab2',
36+
password: 'password2'
37+
}
38+
}
39+
}
40+
)
41+
end
42+
43+
it 'renders clickhouse.yml using these settings' do
44+
expect(clickhouse_yml[:production]).to eq(
45+
{
46+
main: {
47+
database: 'production',
48+
url: 'https://example.com/path',
49+
username: 'gitlab',
50+
password: 'password',
51+
variables: {
52+
enable_http_compression: 1,
53+
date_time_input_format: "basic"
54+
}
55+
},
56+
main2: {
57+
database: 'production2',
58+
url: 'https://example.com/path2',
59+
username: 'gitlab2',
60+
password: 'password2',
61+
variables: {
62+
enable_http_compression: 1,
63+
date_time_input_format: "basic"
64+
}
65+
}
66+
}
67+
)
68+
end
69+
end
70+
end
71+
end

0 commit comments

Comments
 (0)