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

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

Constant Summary collapse

LOG_PREFIX =
"[CodeCoverage]"

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Table.



12
13
14
15
16
17
18
# File 'lib/gitlab_quality/test_tooling/code_coverage/click_house/table.rb', line 12

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)


22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/gitlab_quality/test_tooling/code_coverage/click_house/table.rb', line 22

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