gitlab_quality-test_tooling 2.16.0 → 2.20.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-version +1 -1
  3. data/.tool-versions +1 -1
  4. data/Gemfile.lock +30 -28
  5. data/exe/epic-readiness-notification +58 -0
  6. data/exe/relate-failure-issue +5 -0
  7. data/lib/gitlab_quality/test_tooling/click_house/client.rb +85 -0
  8. data/lib/gitlab_quality/test_tooling/feature_readiness/concerns/issue_concern.rb +1 -1
  9. data/lib/gitlab_quality/test_tooling/feature_readiness/concerns/work_item_concern.rb +11 -0
  10. data/lib/gitlab_quality/test_tooling/feature_readiness/epic_readiness_notifier.rb +308 -0
  11. data/lib/gitlab_quality/test_tooling/gcs_tools.rb +49 -0
  12. data/lib/gitlab_quality/test_tooling/gitlab_client/gitlab_client.rb +2 -9
  13. data/lib/gitlab_quality/test_tooling/gitlab_client/group_labels_client.rb +34 -0
  14. data/lib/gitlab_quality/test_tooling/gitlab_client/issues_client.rb +1 -1
  15. data/lib/gitlab_quality/test_tooling/gitlab_client/issues_dry_client.rb +2 -2
  16. data/lib/gitlab_quality/test_tooling/report/failed_test_issue.rb +1 -1
  17. data/lib/gitlab_quality/test_tooling/report/flaky_test_issue.rb +2 -2
  18. data/lib/gitlab_quality/test_tooling/report/generate_test_session.rb +2 -2
  19. data/lib/gitlab_quality/test_tooling/report/group_issues/error_message_normalizer.rb +49 -0
  20. data/lib/gitlab_quality/test_tooling/report/group_issues/error_pattern_matcher.rb +36 -0
  21. data/lib/gitlab_quality/test_tooling/report/group_issues/failure_processor.rb +73 -0
  22. data/lib/gitlab_quality/test_tooling/report/group_issues/group_results_in_issues.rb +48 -0
  23. data/lib/gitlab_quality/test_tooling/report/group_issues/incident_checker.rb +61 -0
  24. data/lib/gitlab_quality/test_tooling/report/group_issues/issue_base.rb +48 -0
  25. data/lib/gitlab_quality/test_tooling/report/group_issues/issue_creator.rb +44 -0
  26. data/lib/gitlab_quality/test_tooling/report/group_issues/issue_finder.rb +79 -0
  27. data/lib/gitlab_quality/test_tooling/report/group_issues/issue_formatter.rb +83 -0
  28. data/lib/gitlab_quality/test_tooling/report/group_issues/issue_manager.rb +33 -0
  29. data/lib/gitlab_quality/test_tooling/report/group_issues/issue_updater.rb +87 -0
  30. data/lib/gitlab_quality/test_tooling/report/health_problem_reporter.rb +3 -3
  31. data/lib/gitlab_quality/test_tooling/report/knapsack_report_issue.rb +1 -1
  32. data/lib/gitlab_quality/test_tooling/report/merge_request_slow_tests_report.rb +2 -6
  33. data/lib/gitlab_quality/test_tooling/report/relate_failure_issue.rb +131 -4
  34. data/lib/gitlab_quality/test_tooling/report/slow_test_issue.rb +2 -1
  35. data/lib/gitlab_quality/test_tooling/runtime/env.rb +9 -4
  36. data/lib/gitlab_quality/test_tooling/system_logs/finders/rails/api_log_finder.rb +1 -1
  37. data/lib/gitlab_quality/test_tooling/system_logs/finders/rails/application_log_finder.rb +1 -1
  38. data/lib/gitlab_quality/test_tooling/system_logs/finders/rails/exception_log_finder.rb +1 -1
  39. data/lib/gitlab_quality/test_tooling/system_logs/finders/rails/graphql_log_finder.rb +1 -1
  40. data/lib/gitlab_quality/test_tooling/test_meta/test_meta_updater.rb +39 -11
  41. data/lib/gitlab_quality/test_tooling/test_metrics_exporter/config.rb +88 -15
  42. data/lib/gitlab_quality/test_tooling/test_metrics_exporter/formatter.rb +71 -34
  43. data/lib/gitlab_quality/test_tooling/test_metrics_exporter/test_metrics.rb +105 -80
  44. data/lib/gitlab_quality/test_tooling/test_result/base_test_result.rb +4 -0
  45. data/lib/gitlab_quality/test_tooling/version.rb +1 -1
  46. data/lib/gitlab_quality/test_tooling.rb +2 -0
  47. metadata +69 -55
  48. data/lib/gitlab_quality/test_tooling/test_metrics_exporter/log_test_metrics.rb +0 -117
  49. data/lib/gitlab_quality/test_tooling/test_metrics_exporter/support/gcs_tools.rb +0 -49
  50. data/lib/gitlab_quality/test_tooling/test_metrics_exporter/support/influxdb_tools.rb +0 -33
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GitlabQuality
4
+ module TestTooling
5
+ module Report
6
+ module GroupIssues
7
+ class IssueManager
8
+ DEFAULT_MAX_AGE_HOURS = 24
9
+ ISSUES_PER_PAGE = 50
10
+ GROUPED_ISSUE_LABELS = Set.new(%w[test failure::test-environment automation:bot-authored type::maintenance]).freeze
11
+
12
+ def initialize(options = {})
13
+ @options = options
14
+ @client = options[:gitlab]
15
+ @issue_finder = IssueFinder.new(@client, @options)
16
+ @issue_updater = IssueUpdater.new(@client, @options)
17
+ @issue_creator = IssueCreator.new(@client, @options)
18
+ end
19
+
20
+ def create_or_update_issue(grouped_failure)
21
+ existing_issue = @issue_finder.find_existing_issue(grouped_failure)
22
+
23
+ if existing_issue
24
+ @issue_updater.update_existing_issue(existing_issue, grouped_failure)
25
+ else
26
+ @issue_creator.create_new_issue(grouped_failure)
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,87 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GitlabQuality
4
+ module TestTooling
5
+ module Report
6
+ module GroupIssues
7
+ class IssueUpdater < IssueBase
8
+ def update_existing_issue(issue, grouped_failure)
9
+ log_issue_update(issue, grouped_failure)
10
+ append_failures_to_issue(issue, grouped_failure[:failures])
11
+ add_update_comment(issue, grouped_failure[:failures].size)
12
+ end
13
+
14
+ private
15
+
16
+ def append_failures_to_issue(issue, failures)
17
+ current_issue = @client.find_issues(iid: issue.iid).first
18
+ return unless current_issue
19
+
20
+ existing_description = current_issue.description
21
+ affected_tests_match = existing_description.match(/### Affected Tests \((\d+) failures?\)/)
22
+ return unless affected_tests_match
23
+
24
+ updated_description = build_updated_description(existing_description, affected_tests_match, failures)
25
+ update_issue_description(issue, updated_description, failures.size)
26
+ end
27
+
28
+ def update_issue_description(issue, updated_description, failure_count)
29
+ handle_gitlab_api_error("updating issue", "##{issue.web_url}") do
30
+ @client.edit_issue(iid: issue.iid, options: { description: updated_description })
31
+ Runtime::Logger.info "Successfully appended #{failure_count} failures to issue #{issue.web_url}"
32
+ true
33
+ end
34
+ end
35
+
36
+ def build_updated_description(existing_description, affected_tests_match, failures)
37
+ current_count = affected_tests_match[1].to_i
38
+ new_count = current_count + failures.size
39
+
40
+ updated_description = existing_description.gsub(
41
+ /### Affected Tests \(\d+ failures?\)/,
42
+ "### Affected Tests (#{new_count} failures)"
43
+ )
44
+ insert_new_failures(updated_description, failures)
45
+ end
46
+
47
+ def insert_new_failures(description, failures)
48
+ formatter = IssueFormatter.new
49
+ new_failure_entries = formatter.format_affected_tests(failures)
50
+
51
+ test_section_end = description.index('### Pipeline Information')
52
+ return description unless test_section_end
53
+
54
+ insertion_point = description.rindex("\n", test_section_end - 1)
55
+ return description unless insertion_point
56
+
57
+ "#{description[0..insertion_point]}#{new_failure_entries}\n#{description[insertion_point + 1..]}"
58
+ end
59
+
60
+ def add_update_comment(issue, failure_count)
61
+ pipeline_url = ENV['CI_PIPELINE_URL'] || "Pipeline #{ENV.fetch('CI_PIPELINE_ID', nil)}"
62
+ comment = build_update_comment(pipeline_url, failure_count)
63
+ add_comment_to_issue(issue, comment)
64
+ end
65
+
66
+ def build_update_comment(pipeline_url, failure_count)
67
+ "🔄 **New failures added from #{pipeline_url}**\n\n" \
68
+ "Added #{failure_count} additional test failures with the same error pattern."
69
+ end
70
+
71
+ def add_comment_to_issue(issue, comment)
72
+ handle_gitlab_api_error("adding comment to issue", issue.web_url) do
73
+ @client.create_issue_note(iid: issue.iid, note: comment)
74
+ Runtime::Logger.info "Comment added successfully to issue #{issue.web_url}"
75
+ true
76
+ end
77
+ end
78
+
79
+ def log_issue_update(issue, grouped_failure)
80
+ pipeline_id = ENV.fetch('CI_PIPELINE_ID', nil)
81
+ Runtime::Logger.info "Updating existing issue ##{issue.iid} with #{grouped_failure[:failures].size} new failures from pipeline #{pipeline_id}"
82
+ end
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end
@@ -15,7 +15,6 @@ module GitlabQuality
15
15
  class HealthProblemReporter < ReportAsIssue
16
16
  include Concerns::GroupAndCategoryLabels
17
17
  include Concerns::IssueReports
18
- include TestMetricsExporter::Support::GcsTools
19
18
 
20
19
  BASE_SEARCH_LABELS = ['test'].freeze
21
20
  FOUND_IN_MR_LABEL = '~"found:in MR"'
@@ -151,7 +150,7 @@ module GitlabQuality
151
150
  def push_test_to_gcs(tests_data, test_results_filename)
152
151
  Runtime::Logger.info "will push the test data to GCS"
153
152
 
154
- gcs_client(project_id: gcs_project_id, credentials: gcs_credentials, dry_run: dry_run).put_object(
153
+ GcsTools.gcs_client(project_id: gcs_project_id, credentials: gcs_credentials, dry_run: dry_run).put_object(
155
154
  gcs_bucket,
156
155
  gcs_metrics_file_name(test_results_filename),
157
156
  tests_data.to_json,
@@ -163,7 +162,7 @@ module GitlabQuality
163
162
  end
164
163
 
165
164
  def gcs_metrics_file_name(test_results_filename)
166
- today = Time.now.strftime('%Y-%m-%d')
165
+ today = Time.now.to_date.iso8601
167
166
 
168
167
  "#{today}-#{test_results_filename}"
169
168
  end
@@ -253,6 +252,7 @@ module GitlabQuality
253
252
  issue_url: issues.first&.web_url,
254
253
  job_id: Runtime::Env.ci_job_id,
255
254
  job_web_url: test.ci_job_url,
255
+ job_status: Runtime::Env.ci_job_status,
256
256
  pipeline_id: Runtime::Env.ci_pipeline_id,
257
257
  pipeline_ref: Runtime::Env.ci_commit_ref_name,
258
258
  pipeline_web_url: Runtime::Env.ci_pipeline_url,
@@ -18,7 +18,7 @@ module GitlabQuality
18
18
 
19
19
  NEW_ISSUE_LABELS = Set.new([
20
20
  'test', 'automation:bot-authored', 'type::maintenance', 'maintenance::performance',
21
- 'priority::3', 'severity::3', 'knapsack_report'
21
+ 'priority::3', 'severity::3', 'knapsack_report', 'suppress-contributor-links'
22
22
  ]).freeze
23
23
  SEARCH_LABELS = %w[test maintenance::performance knapsack_report].freeze
24
24
  JOB_TIMEOUT_EPIC_URL = 'https://gitlab.com/groups/gitlab-org/quality/engineering-productivity/-/epics/19'
@@ -78,13 +78,9 @@ module GitlabQuality
78
78
  end
79
79
 
80
80
  def slow_test_rows(slow_test)
81
- rows = []
82
-
83
- slow_test.each do |test|
84
- rows << slow_test_table_row(test)
81
+ slow_test.map do |test|
82
+ slow_test_table_row(test)
85
83
  end
86
-
87
- rows
88
84
  end
89
85
 
90
86
  def build_note(slow_test)
@@ -3,6 +3,10 @@
3
3
  require 'nokogiri'
4
4
  require 'rubygems/text'
5
5
 
6
+ require_relative 'group_issues/error_pattern_matcher'
7
+ require_relative 'group_issues/error_message_normalizer'
8
+ require_relative 'group_issues/group_results_in_issues'
9
+
6
10
  module GitlabQuality
7
11
  module TestTooling
8
12
  module Report
@@ -12,6 +16,7 @@ module GitlabQuality
12
16
  # - Takes a project where failure issues should be created
13
17
  # - Find issue by title (with test description or test file), then further filter by stack trace, then pick the better-matching one
14
18
  # - Add the failed job to the issue description, and update labels
19
+ # - Can group similar failures together when group_similar option is enabled
15
20
  class RelateFailureIssue < ReportAsIssue
16
21
  include TestTooling::Concerns::FindSetDri
17
22
  include Concerns::GroupAndCategoryLabels
@@ -23,7 +28,7 @@ module GitlabQuality
23
28
  FAILURE_STACKTRACE_REGEX = %r{(?:(?:.*Failure/Error:(?<stacktrace>.+))|(?<stacktrace>.+))}m
24
29
  ISSUE_STACKTRACE_REGEX = /### Stack trace\s*(```)#{FAILURE_STACKTRACE_REGEX}(```)\n*\n###/m
25
30
 
26
- NEW_ISSUE_LABELS = Set.new(%w[test failure::new priority::2 automation:bot-authored type::maintenance]).freeze
31
+ NEW_ISSUE_LABELS = Set.new(%w[test failure::new priority::2 automation:bot-authored type::maintenance suppress-contributor-links]).freeze
27
32
  SCREENSHOT_IGNORED_ERRORS = ['500 Internal Server Error', 'fabricate_via_api!', 'Error Code 500'].freeze
28
33
  FAILURE_ISSUE_GUIDE_URL = "https://handbook.gitlab.com/handbook/engineering/testing/guide-to-e2e-test-failure-issues/"
29
34
  FAILURE_ISSUE_HANDBOOK_GUIDE = "**:rotating_light: [End-to-End Test Failure Issue Debugging Guide](#{FAILURE_ISSUE_GUIDE_URL}) :rotating_light:**\n".freeze
@@ -63,6 +68,7 @@ module GitlabQuality
63
68
  base_issue_labels: nil,
64
69
  exclude_labels_for_search: nil,
65
70
  metrics_files: [],
71
+ group_similar: false,
66
72
  **kwargs)
67
73
  super
68
74
  @max_diff_ratio = max_diff_ratio.to_f
@@ -72,21 +78,112 @@ module GitlabQuality
72
78
  @issue_type = 'issue'
73
79
  @commented_issue_list = Set.new
74
80
  @metrics_files = Array(metrics_files)
81
+ @group_similar = group_similar
75
82
  end
76
83
 
77
84
  private
78
85
 
79
- attr_reader :max_diff_ratio, :system_logs, :base_issue_labels, :exclude_labels_for_search, :metrics_files, :ops_gitlab_client
86
+ attr_reader :max_diff_ratio, :system_logs, :base_issue_labels, :exclude_labels_for_search, :metrics_files, :ops_gitlab_client, :group_similar
80
87
 
81
88
  def run!
82
89
  puts "Reporting test failures in `#{files.join(',')}` as issues in project `#{project}` via the API at `#{Runtime::Env.gitlab_api_base}`."
83
90
 
91
+ run_with_grouping! if group_similar
92
+
93
+ return if similar_issues_grouped?
94
+
84
95
  TestResults::Builder.new(token: token, project: project, file_glob: files).test_results_per_file do |test_results|
85
96
  puts "=> Reporting #{test_results.count} tests in #{test_results.path}"
86
97
  process_test_results(test_results)
87
98
  end
88
99
  end
89
100
 
101
+ def similar_issues_grouped?
102
+ grouper.summary[:grouped_issues].positive?
103
+ end
104
+
105
+ def grouper
106
+ @grouper ||= GitlabQuality::TestTooling::Report::GroupIssues::GroupResultsInIssues.new(
107
+ gitlab: gitlab,
108
+ config: grouper_config
109
+ )
110
+ end
111
+
112
+ def run_with_grouping!
113
+ Runtime::Logger.info "=> Grouping similar failures where possible"
114
+
115
+ all_test_results = collect_all_test_results
116
+ return if all_test_results.empty?
117
+
118
+ Runtime::Logger.info "=> Processing #{all_test_results.count} failures with GroupResultsInIssues"
119
+
120
+ failure_data = convert_test_results_to_failure_data(all_test_results)
121
+
122
+ grouper.process_failures(failure_data)
123
+ grouper.process_issues
124
+ end
125
+
126
+ def collect_all_test_results
127
+ all_test_results = []
128
+
129
+ TestResults::Builder.new(token: token, project: project, file_glob: files).test_results_per_file do |test_results|
130
+ Runtime::Logger.info "=> Collecting #{test_results.count} tests from #{test_results.path}"
131
+ all_test_results.concat(test_results.select(&:failures?))
132
+ end
133
+
134
+ all_test_results
135
+ end
136
+
137
+ def convert_test_results_to_failure_data(test_results)
138
+ test_results.map do |test|
139
+ {
140
+ description: test.name,
141
+ full_description: test.name,
142
+ file_path: test.relative_file,
143
+ line_number: extract_line_number(test),
144
+ exception: extract_exception_data(test),
145
+ ci_job_url: test.ci_job_url,
146
+ testcase: extract_test_id_or_name(test),
147
+ product_group: extract_product_group(test),
148
+ level: extract_level(test)
149
+ }
150
+ end
151
+ end
152
+
153
+ def extract_line_number(test)
154
+ test.respond_to?(:line_number) ? test.line_number : nil
155
+ end
156
+
157
+ def extract_exception_data(test)
158
+ {
159
+ 'message' => test.failures.first&.dig('message') || test.full_stacktrace || 'Unknown error'
160
+ }
161
+ end
162
+
163
+ def extract_product_group(test)
164
+ test.respond_to?(:product_group) ? test.product_group : nil
165
+ end
166
+
167
+ def extract_level(test)
168
+ test.respond_to?(:level) ? test.level : nil
169
+ end
170
+
171
+ def grouper_config
172
+ {
173
+ thresholds: {
174
+ min_failures_to_group: 2
175
+ }
176
+ }
177
+ end
178
+
179
+ def extract_test_id_or_name(test)
180
+ return test.example_id if test.respond_to?(:example_id)
181
+ return test.id if test.respond_to?(:id)
182
+ return test.name if test.respond_to?(:name)
183
+
184
+ "#{test.relative_file}:#{test.respond_to?(:line_number) ? test.line_number : 'unknown'}"
185
+ end
186
+
90
187
  def new_issue_labels(test)
91
188
  up_to_date_labels(test: test, new_labels: NEW_ISSUE_LABELS + group_and_category_labels_for_test(test))
92
189
  end
@@ -469,10 +566,40 @@ module GitlabQuality
469
566
  end
470
567
 
471
568
  def new_issue_assignee_id(test)
472
- return unless test.product_group?
569
+ assignee_id = try_feature_category_assignment(test)
570
+ return assignee_id if assignee_id
571
+
572
+ try_product_group_assignment(test)
573
+ end
574
+
575
+ def try_feature_category_assignment(test)
576
+ unless test.respond_to?(:feature_category) && test.feature_category?
577
+ Runtime::Logger.info("No feature_category found for DRI assignment")
578
+ return
579
+ end
580
+
581
+ labels_inference = GitlabQuality::TestTooling::LabelsInference.new
582
+ product_group = labels_inference.product_group_from_feature_category(test.feature_category)
583
+
584
+ unless product_group
585
+ Runtime::Logger.warn("Could not map feature_category '#{test.feature_category}' to product_group")
586
+ return
587
+ end
588
+
589
+ dri = test_dri(product_group, test.stage, test.section)
590
+ Runtime::Logger.info("Assigning #{dri} as DRI for the issue (via feature_category).")
591
+
592
+ gitlab.find_user_id(username: dri)
593
+ end
594
+
595
+ def try_product_group_assignment(test)
596
+ unless test.respond_to?(:product_group) && test.product_group?
597
+ Runtime::Logger.info("No product_group found for DRI assignment")
598
+ return
599
+ end
473
600
 
474
601
  dri = test_dri(test.product_group, test.stage, test.section)
475
- puts " => Assigning #{dri} as DRI for the issue."
602
+ Runtime::Logger.info("Assigning #{dri} as DRI for the issue (via product_group).")
476
603
 
477
604
  gitlab.find_user_id(username: dri)
478
605
  end
@@ -11,7 +11,8 @@ module GitlabQuality
11
11
  # - Add test metadata, duration to the issue with group and category labels
12
12
  class SlowTestIssue < HealthProblemReporter
13
13
  IDENTITY_LABELS = ['test', 'rspec:slow test', 'test-health:slow', 'rspec profiling', 'automation:bot-authored'].freeze
14
- NEW_ISSUE_LABELS = Set.new(['test', 'type::maintenance', 'maintenance::performance', 'priority::3', 'severity::3', *IDENTITY_LABELS]).freeze
14
+ NEW_ISSUE_LABELS = Set.new(
15
+ ['test', 'type::maintenance', 'maintenance::performance', 'priority::3', 'severity::3', 'suppress-contributor-links', *IDENTITY_LABELS]).freeze
15
16
  REPORT_SECTION_HEADER = '### Slowness reports'
16
17
  REPORTS_DOCUMENTATION = <<~DOC
17
18
  Slow tests were detected, please see the [test speed best practices guide](https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#test-speed)
@@ -15,16 +15,17 @@ module GitlabQuality
15
15
  'CI_JOB_ID' => :ci_job_id,
16
16
  'CI_JOB_NAME' => :ci_job_name,
17
17
  'CI_JOB_URL' => :ci_job_url,
18
+ 'CI_JOB_STATUS' => :ci_job_status,
18
19
  'CI_PIPELINE_ID' => :ci_pipeline_id,
19
20
  'CI_PIPELINE_NAME' => :ci_pipeline_name,
20
21
  'CI_PIPELINE_URL' => :ci_pipeline_url,
21
22
  'CI_PROJECT_ID' => :ci_project_id,
22
23
  'CI_PROJECT_NAME' => :ci_project_name,
23
24
  'CI_PROJECT_PATH' => :ci_project_path,
25
+ 'CI_PIPELINE_CREATED_AT' => :ci_pipeline_created_at,
24
26
  'DEPLOY_VERSION' => :deploy_version,
25
27
  'GITLAB_QA_ISSUE_URL' => :qa_issue_url,
26
- 'QA_GITLAB_CI_TOKEN' => :gitlab_ci_token,
27
- 'SLACK_QA_CHANNEL' => :slack_qa_channel
28
+ 'QA_GITLAB_CI_TOKEN' => :gitlab_ci_token
28
29
  }.freeze
29
30
 
30
31
  ENV_VARIABLES.each do |env_name, method_name|
@@ -61,6 +62,10 @@ module GitlabQuality
61
62
  env_var_value_if_defined('GITLAB_GRAPHQL_API_BASE')
62
63
  end
63
64
 
65
+ def slack_alerts_channel
66
+ env_var_value_if_defined('SLACK_ALERTS_CHANNEL') || 'C09HQ5BN07J' # test-tooling-alerts channel ID
67
+ end
68
+
64
69
  def pipeline_from_project_name
65
70
  %w[gitlab gitaly].any? { |str| ci_project_name.to_s.start_with?(str) } ? default_branch : ci_project_name
66
71
  end
@@ -111,12 +116,12 @@ module GitlabQuality
111
116
  end
112
117
 
113
118
  def env_var_value_if_defined(variable)
114
- return ENV.fetch(variable) if env_var_value_valid?(variable)
119
+ ENV.fetch(variable) if env_var_value_valid?(variable)
115
120
  end
116
121
 
117
122
  def env_var_name_if_defined(variable)
118
123
  # Pass through the variables if they are defined and not empty in the environment
119
- return "$#{variable}" if env_var_value_valid?(variable)
124
+ "$#{variable}" if env_var_value_valid?(variable)
120
125
  end
121
126
  end
122
127
  end
@@ -7,7 +7,7 @@ module GitlabQuality
7
7
  module Rails
8
8
  class ApiLogFinder < JsonLogFinder
9
9
  def initialize(base_path, file_path = 'gitlab-rails/api_json.log')
10
- super(base_path, file_path)
10
+ super
11
11
  end
12
12
 
13
13
  def new_log(data)
@@ -7,7 +7,7 @@ module GitlabQuality
7
7
  module Rails
8
8
  class ApplicationLogFinder < JsonLogFinder
9
9
  def initialize(base_path, file_path = 'gitlab-rails/application_json.log')
10
- super(base_path, file_path)
10
+ super
11
11
  end
12
12
 
13
13
  def new_log(data)
@@ -7,7 +7,7 @@ module GitlabQuality
7
7
  module Rails
8
8
  class ExceptionLogFinder < JsonLogFinder
9
9
  def initialize(base_path, file_path = 'gitlab-rails/exceptions_json.log')
10
- super(base_path, file_path)
10
+ super
11
11
  end
12
12
 
13
13
  def new_log(data)
@@ -7,7 +7,7 @@ module GitlabQuality
7
7
  module Rails
8
8
  class GraphqlLogFinder < JsonLogFinder
9
9
  def initialize(base_path, file_path = 'gitlab-rails/graphql_json.log')
10
- super(base_path, file_path)
10
+ super
11
11
  end
12
12
 
13
13
  def new_log(data)
@@ -8,9 +8,7 @@ module GitlabQuality
8
8
  class TestMetaUpdater
9
9
  include TestTooling::Concerns::FindSetDri
10
10
 
11
- attr_reader :project, :ref, :report_issue, :processed_commits
12
-
13
- TEST_PLATFORM_MAINTAINERS_SLACK_CHANNEL_ID = 'C0437FV9KBN' # test-platform-maintainers
11
+ attr_reader :project, :ref, :report_issue, :processed_commits, :token, :specs_file, :dry_run, :processor
14
12
 
15
13
  def initialize(token:, project:, specs_file:, processor:, ref: 'master', dry_run: false)
16
14
  @specs_file = specs_file
@@ -269,12 +267,15 @@ module GitlabQuality
269
267
  # Fetch the id for the dri of the product group and stage
270
268
  # The first item returned is the id of the assignee and the second item is the handle
271
269
  #
272
- # @param [String] product_group
270
+ # @param [Hash] test object
273
271
  # @param [String] devops_stage
272
+ # @param [String] section
274
273
  # @return [Array<Integer, String>]
275
- def fetch_dri_id(product_group, devops_stage, section)
276
- assignee_handle = ENV.fetch('QA_TEST_DRI_HANDLE', nil) || test_dri(product_group, devops_stage, section)
274
+ def fetch_dri_id(test, devops_stage, section)
275
+ product_group = determine_product_group(test)
276
+ return unless product_group
277
277
 
278
+ assignee_handle = ENV.fetch('QA_TEST_DRI_HANDLE', nil) || test_dri(product_group, devops_stage, section)
278
279
  [user_id_for_username(assignee_handle), assignee_handle]
279
280
  end
280
281
 
@@ -291,7 +292,7 @@ module GitlabQuality
291
292
  # @param [String] message the message to post
292
293
  # @return [HTTP::Response]
293
294
  def post_message_on_slack(message)
294
- channel = ENV.fetch('SLACK_QA_CHANNEL', nil) || TEST_PLATFORM_MAINTAINERS_SLACK_CHANNEL_ID
295
+ channel = Runtime::Env.slack_alerts_channel
295
296
  slack_options = {
296
297
  slack_webhook_url: ENV.fetch('CI_SLACK_WEBHOOK_URL', nil),
297
298
  channel: channel,
@@ -335,6 +336,16 @@ module GitlabQuality
335
336
  label ? %(/label ~"#{label}") : ''
336
337
  end
337
338
 
339
+ # Infers the group label from the provided feature category
340
+ #
341
+ # @param [String] feature_category feature category
342
+ # @return [String]
343
+ def label_from_feature_category(feature_category)
344
+ labels = labels_inference.infer_labels_from_feature_category(feature_category)
345
+ group_label = labels.find { |label| label.start_with?('group::') }
346
+ group_label ? %(/label ~"#{group_label}") : ''
347
+ end
348
+
338
349
  # Returns the link to the Grafana dashboard for single spec metrics
339
350
  #
340
351
  # @param [String] example_name the full example name
@@ -344,10 +355,6 @@ module GitlabQuality
344
355
  base_url + CGI.escape(example_name)
345
356
  end
346
357
 
347
- private
348
-
349
- attr_reader :token, :specs_file, :dry_run, :processor
350
-
351
358
  # Returns any test description string within single or double quotes
352
359
  #
353
360
  # @param [String] line the line to check for any quoted string
@@ -380,6 +387,27 @@ module GitlabQuality
380
387
  def labels_inference
381
388
  @labels_inference ||= GitlabQuality::TestTooling::LabelsInference.new
382
389
  end
390
+
391
+ private
392
+
393
+ def determine_product_group(test)
394
+ return map_feature_category_to_product_group(test) if has_feature_category?(test)
395
+ return test.product_group if has_product_group?(test)
396
+
397
+ nil
398
+ end
399
+
400
+ def has_feature_category?(test)
401
+ test.respond_to?(:feature_category) && test.feature_category?
402
+ end
403
+
404
+ def has_product_group?(test)
405
+ test.respond_to?(:product_group) && test.product_group?
406
+ end
407
+
408
+ def map_feature_category_to_product_group(test)
409
+ labels_inference.product_group_from_feature_category(test.feature_category)
410
+ end
383
411
  end
384
412
  end
385
413
  end