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 =
Every owner a category has ever had, including ones it has moved off, one row per distinct owner and in no particular order. Only
pushreads this, to skip rows it has already stored. Deduping to one row per category here would make it re-insert old owners on every run. <<~SQL SELECT category, group, stage, section FROM ( SELECT category, group, stage, section, ROW_NUMBER() OVER (PARTITION BY category, group, stage, section ORDER BY timestamp DESC) as rn FROM %{table_name} ) WHERE rn = 1 SQL
- LATEST_OWNERS_QUERY =
The current owner of each category, one row per category, which is what
ownersandowner_recordsserve to callers. The table keeps every past owner as well, so the newest timestamp is what picks the current one. The owner columns after the timestamp in the ORDER BY break ties, so two rows sharing a category's newest timestamp always resolve the same way. <<~SQL SELECT category, group, stage, section FROM %{table_name} ORDER BY category, timestamp DESC, group, stage, section LIMIT 1 BY category SQL
Instance Method Summary collapse
-
#owner_records ⇒ Hash
Raw category owner data.
-
#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
#owner_records ⇒ Hash
Raw category owner data
81 82 83 |
# File 'lib/gitlab_quality/test_tooling/code_coverage/click_house/category_owners_table.rb', line 81 def owner_records records.deep_dup end |
#owners(feature_category_name) ⇒ Hash
Owners of particular feature category as group, stage and section
65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/gitlab_quality/test_tooling/code_coverage/click_house/category_owners_table.rb', line 65 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
46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/gitlab_quality/test_tooling/code_coverage/click_house/category_owners_table.rb', line 46 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 |