Class: GitlabQuality::TestTooling::CodeCoverage::ClickHouse::CategoryOwnersTable

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

Constant Summary collapse

TABLE_NAME =
"category_owners"
MissingMappingError =
Class.new(StandardError)
KNOWN_UNOWNED =
%w[shared not_owned tooling].freeze
LATEST_RECORDS_QUERY =

SQL query to get the latest ownership record for each category Uses window function to avoid loading entire table history

<<~SQL
  SELECT category, group, stage, section
  FROM (
    SELECT category, group, stage, section,
           ROW_NUMBER() OVER (PARTITION BY category ORDER BY timestamp DESC) as rn
    FROM %{table_name}
  )
  WHERE rn = 1
SQL

Constants inherited from Table

Table::LOG_PREFIX

Instance Method Summary collapse

Methods inherited from Table

#initialize

Constructor Details

This class inherits a constructor from GitlabQuality::TestTooling::CodeCoverage::ClickHouse::Table

Instance Method Details

#owners(feature_category_name) ⇒ Hash

Owners of particular feature category as group, stage and section

Parameters:

  • feature_category_name (String)

    the feature_category name

Returns:

  • (Hash)


49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/gitlab_quality/test_tooling/code_coverage/click_house/category_owners_table.rb', line 49

def owners(feature_category_name)
  if KNOWN_UNOWNED.include?(feature_category_name)
    logger.info(
      "#{LOG_PREFIX} #{feature_category_name} is a known feature category without owner..."
    )
    return {}
  end

  records.fetch(feature_category_name)
rescue KeyError
  raise(MissingMappingError, "Feature category '#{feature_category_name}' not found in table '#{table_name}'")
end

#push(data) ⇒ Object

Insert only new category ownership records that don’t already exist This avoids needing TRUNCATE permission



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

def push(data)
  return logger.warn("#{LOG_PREFIX} No data found, skipping insert!") if data.empty?

  sanitized_data = sanitize_and_filter_data(data)
  return if sanitized_data.empty?

  new_records = filter_new_records(sanitized_data)
  return if new_records.empty?

  insert_new_records(new_records, sanitized_data.size)
rescue StandardError => e
  logger.error("#{LOG_PREFIX} Error occurred while pushing data to #{full_table_name}: #{e.message}")
  raise
end