Class: GitlabQuality::TestTooling::CodeCoverage::ClickHouse::CategoryOwnersTable
- Inherits:
-
Table
- Object
- Table
- GitlabQuality::TestTooling::CodeCoverage::ClickHouse::CategoryOwnersTable
- 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
Instance Method Summary collapse
-
#owners(feature_category_name) ⇒ Hash
Owners of particular feature category as group, stage and section.
-
#push(data) ⇒ Object
Insert only new category ownership records that don’t already exist This avoids needing TRUNCATE permission.
Methods inherited from Table
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
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.}") raise end |