diff options
Diffstat (limited to 'config/initializers/click_house.rb')
-rw-r--r-- | config/initializers/click_house.rb | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/config/initializers/click_house.rb b/config/initializers/click_house.rb new file mode 100644 index 00000000000..c1bec683c6b --- /dev/null +++ b/config/initializers/click_house.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +return unless File.exist?(Rails.root.join('config/click_house.yml')) + +raw_config = Rails.application.config_for(:click_house) + +return if raw_config.blank? + +ClickHouse::Client.configure do |config| + raw_config.each do |database_identifier, db_config| + config.register_database(database_identifier, + database: db_config[:database], + url: db_config[:url], + username: db_config[:username], + password: db_config[:password], + variables: db_config[:variables] || {} + ) + end + + config.json_parser = Gitlab::Json + config.http_post_proc = ->(url, headers, body) do + options = { + headers: headers, + body: body, + allow_local_requests: Rails.env.development? || Rails.env.test? + } + + response = Gitlab::HTTP.post(url, options) + ClickHouse::Client::Response.new(response.body, response.code) + end +end |