Class: GitlabQuality::TestTooling::CodeCoverage::ClickHouse::Table

Inherits:
Object
  • Object
show all
Includes:
Client
Defined in:
lib/gitlab_quality/test_tooling/code_coverage/click_house/table.rb

Instance Method Summary collapse

Constructor Details

#initialize(url:, database:, username: nil, password: nil, logger: nil) ⇒ Table

Returns a new instance of Table.



18
19
20
21
22
23
24
# File 'lib/gitlab_quality/test_tooling/code_coverage/click_house/table.rb', line 18

def initialize(url:, database:, username: nil, password: nil, logger: nil)
  @url = url
  @database = database
  @username = username
  @password = password
  @logger = logger || Runtime::Logger.logger
end

Instance Method Details

#push(data) ⇒ nil

Parameters:

  • data (Array<Hash>)

    Code coverage related data to be pushed to ClickHouse

Returns:

  • (nil)


28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/gitlab_quality/test_tooling/code_coverage/click_house/table.rb', line 28

def push(data) # rubocop:disable Metrics/AbcSize
  return logger.warn("#{LOG_PREFIX} No data found, skipping ClickHouse export!") if data.empty?

  logger.debug("#{LOG_PREFIX} Starting data export to ClickHouse")
  sanitized_data = sanitize(data)

  return logger.warn("#{LOG_PREFIX} No valid data found after sanitization, skipping ClickHouse export!") if sanitized_data.empty?

  client.insert_json_data(table_name, sanitized_data)
  logger.info("#{LOG_PREFIX} Successfully pushed #{sanitized_data.size} records to #{full_table_name}!")
rescue StandardError => e
  logger.error("#{LOG_PREFIX} Error occurred while pushing data to #{full_table_name}: #{e.message}")
  raise
end