diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-08-07 18:09:47 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-08-07 18:09:47 +0300 |
commit | 33c86930e0a657e1519082a9a00faae260a44882 (patch) | |
tree | 4d65ae193c2c92826a8fc659345e2bb83e101999 /gems | |
parent | 28f0cd8e0725320c294f9dbf74c698ee727de594 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'gems')
5 files changed, 31 insertions, 35 deletions
diff --git a/gems/click_house-client/lib/click_house/client.rb b/gems/click_house-client/lib/click_house/client.rb index 579413640b1..abc54f2bce0 100644 --- a/gems/click_house-client/lib/click_house/client.rb +++ b/gems/click_house-client/lib/click_house/client.rb @@ -28,17 +28,7 @@ module ClickHouse # Executes a SELECT database query def self.select(query, database, configuration = self.configuration) - db = lookup_database(configuration, database) - - ActiveSupport::Notifications.instrument('sql.click_house', { query: query, database: database }) do |instrument| - response = configuration.http_post_proc.call( - db.uri.to_s, - db.headers, - "#{query} FORMAT JSON" # always return JSON - ) - - raise DatabaseError, response.body unless response.success? - + instrumented_execute(query, database, configuration) do |response, instrument| parsed_response = configuration.json_parser.parse(response.body) instrument[:statistics] = parsed_response['statistics']&.symbolize_keys @@ -49,17 +39,7 @@ module ClickHouse # Executes any kinds of database query without returning any data (INSERT, DELETE) def self.execute(query, database, configuration = self.configuration) - db = lookup_database(configuration, database) - - ActiveSupport::Notifications.instrument('sql.click_house', { query: query, database: database }) do |instrument| - response = configuration.http_post_proc.call( - db.uri.to_s, - db.headers, - query - ) - - raise DatabaseError, response.body unless response.success? - + instrumented_execute(query, database, configuration) do |response, instrument| if response.headers['x-clickhouse-summary'] instrument[:statistics] = Gitlab::Json.parse(response.headers['x-clickhouse-summary']).symbolize_keys @@ -74,5 +54,21 @@ module ClickHouse raise ConfigurationError, "The database '#{database}' is not configured" unless db end end + + private_class_method def self.instrumented_execute(query, database, configuration) + db = lookup_database(configuration, database) + + ActiveSupport::Notifications.instrument('sql.click_house', { query: query, database: database }) do |instrument| + response = configuration.http_post_proc.call( + db.uri.to_s, + db.headers, + query + ) + + raise DatabaseError, response.body unless response.success? + + yield response, instrument + end + end end end diff --git a/gems/click_house-client/lib/click_house/client/database.rb b/gems/click_house-client/lib/click_house/client/database.rb index beeb2a8cbd6..faf5a953a12 100644 --- a/gems/click_house-client/lib/click_house/client/database.rb +++ b/gems/click_house-client/lib/click_house/client/database.rb @@ -10,7 +10,10 @@ module ClickHouse @url = url @username = username @password = password - @variables = variables.merge(database: database).freeze + @variables = { + database: database, + enable_http_compression: 1 # enable HTTP compression by default + }.merge(variables).freeze end def uri @@ -24,7 +27,9 @@ module ClickHouse def headers @headers ||= { 'X-ClickHouse-User' => @username, - 'X-ClickHouse-Key' => @password + 'X-ClickHouse-Key' => @password, + 'X-ClickHouse-Format' => 'JSON', # always return JSON data + 'Content-Encoding' => 'gzip' # tell the server that we send compressed data }.freeze end end diff --git a/gems/click_house-client/spec/click_house/client/configuration_spec.rb b/gems/click_house-client/spec/click_house/client/configuration_spec.rb index 8cbd64ca650..c6bd2974b7e 100644 --- a/gems/click_house-client/spec/click_house/client/configuration_spec.rb +++ b/gems/click_house-client/spec/click_house/client/configuration_spec.rb @@ -29,7 +29,7 @@ RSpec.describe ClickHouse::Client::Configuration do expect(configuration.databases.size).to eq(1) database = configuration.databases[:my_db] - expect(database.uri.to_s).to eq('http://localhost:3333?database=test_db&join_use_nulls=1') + expect(database.uri.to_s).to eq('http://localhost:3333?database=test_db&enable_http_compression=1&join_use_nulls=1') end context 'when adding the same DB multiple times' do diff --git a/gems/click_house-client/spec/click_house/client/database_spec.rb b/gems/click_house-client/spec/click_house/client/database_spec.rb index 112b2ee12b1..a74d4a119a4 100644 --- a/gems/click_house-client/spec/click_house/client/database_spec.rb +++ b/gems/click_house-client/spec/click_house/client/database_spec.rb @@ -17,13 +17,15 @@ RSpec.describe ClickHouse::Client::Database do describe '#uri' do it 'builds the correct URL' do - expect(database.uri.to_s).to eq('http://localhost:3333?database=test_db&join_use_nulls=1') + expect(database.uri.to_s).to eq('http://localhost:3333?database=test_db&enable_http_compression=1&join_use_nulls=1') end end describe '#headers' do it 'returns the correct headers' do expect(database.headers).to eq({ + "Content-Encoding" => "gzip", + "X-ClickHouse-Format" => "JSON", 'X-ClickHouse-User' => 'user', 'X-ClickHouse-Key' => 'pass' }) diff --git a/gems/gem.gitlab-ci.yml b/gems/gem.gitlab-ci.yml index 107164d0b78..4e91f0cbe44 100644 --- a/gems/gem.gitlab-ci.yml +++ b/gems/gem.gitlab-ci.yml @@ -11,16 +11,9 @@ spec: default: "gems/" --- workflow: - name: '$PIPELINE_NAME' + name: '[$[[inputs.gem_name]] gem] Ruby $RUBY_VERSION pipeline' rules: - - if: '$CI_MERGE_REQUEST_EVENT_TYPE == "merged_result" || $CI_MERGE_REQUEST_EVENT_TYPE == "detached"' - variables: - PIPELINE_NAME: '[$[[inputs.gem_name]] gem] Ruby $RUBY_VERSION $CI_MERGE_REQUEST_EVENT_TYPE MR pipeline' - # CI_PIPELINE_SOURCE will always be "parent_pipeline" since this is a child pipeline - # document this here to avoid confusion and to define the default value for PIPELINE_NAME - - if: '$CI_PIPELINE_SOURCE == "parent_pipeline"' - variables: - PIPELINE_NAME: '[$[[inputs.gem_name]] gem] Ruby $RUBY_VERSION default pipeline' + - when: always variables: BUNDLE_PATH: "vendor" |