gitlab_quality-test_tooling 2.16.0 → 2.25.1

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 (67) 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/README.md +1 -1
  6. data/exe/epic-readiness-notification +58 -0
  7. data/exe/post-to-slack +4 -0
  8. data/exe/relate-failure-issue +9 -0
  9. data/exe/test-coverage +113 -0
  10. data/lib/gitlab_quality/test_tooling/click_house/client.rb +111 -0
  11. data/lib/gitlab_quality/test_tooling/code_coverage/artifacts.rb +77 -0
  12. data/lib/gitlab_quality/test_tooling/code_coverage/category_owners.rb +158 -0
  13. data/lib/gitlab_quality/test_tooling/code_coverage/click_house/category_owners_table.rb +62 -0
  14. data/lib/gitlab_quality/test_tooling/code_coverage/click_house/coverage_metrics_table.rb +109 -0
  15. data/lib/gitlab_quality/test_tooling/code_coverage/click_house/table.rb +73 -0
  16. data/lib/gitlab_quality/test_tooling/code_coverage/coverage_data.rb +82 -0
  17. data/lib/gitlab_quality/test_tooling/code_coverage/lcov_file.rb +91 -0
  18. data/lib/gitlab_quality/test_tooling/code_coverage/rspec_report.rb +43 -0
  19. data/lib/gitlab_quality/test_tooling/code_coverage/test_map.rb +93 -0
  20. data/lib/gitlab_quality/test_tooling/code_coverage/utils.rb +18 -0
  21. data/lib/gitlab_quality/test_tooling/feature_readiness/concerns/issue_concern.rb +1 -1
  22. data/lib/gitlab_quality/test_tooling/feature_readiness/concerns/work_item_concern.rb +11 -0
  23. data/lib/gitlab_quality/test_tooling/feature_readiness/epic_readiness_notifier.rb +308 -0
  24. data/lib/gitlab_quality/test_tooling/gcs_tools.rb +49 -0
  25. data/lib/gitlab_quality/test_tooling/gitlab_client/gitlab_client.rb +2 -9
  26. data/lib/gitlab_quality/test_tooling/gitlab_client/group_labels_client.rb +34 -0
  27. data/lib/gitlab_quality/test_tooling/gitlab_client/issues_client.rb +1 -1
  28. data/lib/gitlab_quality/test_tooling/gitlab_client/issues_dry_client.rb +2 -2
  29. data/lib/gitlab_quality/test_tooling/report/concerns/results_reporter.rb +1 -1
  30. data/lib/gitlab_quality/test_tooling/report/failed_test_issue.rb +1 -1
  31. data/lib/gitlab_quality/test_tooling/report/flaky_test_issue.rb +2 -2
  32. data/lib/gitlab_quality/test_tooling/report/generate_test_session.rb +2 -2
  33. data/lib/gitlab_quality/test_tooling/report/group_issues/error_message_normalizer.rb +49 -0
  34. data/lib/gitlab_quality/test_tooling/report/group_issues/error_pattern_matcher.rb +36 -0
  35. data/lib/gitlab_quality/test_tooling/report/group_issues/failure_processor.rb +73 -0
  36. data/lib/gitlab_quality/test_tooling/report/group_issues/group_results_in_issues.rb +48 -0
  37. data/lib/gitlab_quality/test_tooling/report/group_issues/incident_checker.rb +61 -0
  38. data/lib/gitlab_quality/test_tooling/report/group_issues/issue_base.rb +48 -0
  39. data/lib/gitlab_quality/test_tooling/report/group_issues/issue_creator.rb +44 -0
  40. data/lib/gitlab_quality/test_tooling/report/group_issues/issue_finder.rb +81 -0
  41. data/lib/gitlab_quality/test_tooling/report/group_issues/issue_formatter.rb +83 -0
  42. data/lib/gitlab_quality/test_tooling/report/group_issues/issue_manager.rb +33 -0
  43. data/lib/gitlab_quality/test_tooling/report/group_issues/issue_updater.rb +87 -0
  44. data/lib/gitlab_quality/test_tooling/report/health_problem_reporter.rb +6 -3
  45. data/lib/gitlab_quality/test_tooling/report/knapsack_report_issue.rb +1 -1
  46. data/lib/gitlab_quality/test_tooling/report/merge_request_slow_tests_report.rb +2 -6
  47. data/lib/gitlab_quality/test_tooling/report/relate_failure_issue.rb +176 -5
  48. data/lib/gitlab_quality/test_tooling/report/report_as_issue.rb +0 -1
  49. data/lib/gitlab_quality/test_tooling/report/slow_test_issue.rb +2 -1
  50. data/lib/gitlab_quality/test_tooling/runtime/env.rb +9 -4
  51. data/lib/gitlab_quality/test_tooling/slack/post_to_slack.rb +103 -3
  52. data/lib/gitlab_quality/test_tooling/system_logs/finders/rails/api_log_finder.rb +1 -1
  53. data/lib/gitlab_quality/test_tooling/system_logs/finders/rails/application_log_finder.rb +1 -1
  54. data/lib/gitlab_quality/test_tooling/system_logs/finders/rails/exception_log_finder.rb +1 -1
  55. data/lib/gitlab_quality/test_tooling/system_logs/finders/rails/graphql_log_finder.rb +1 -1
  56. data/lib/gitlab_quality/test_tooling/test_meta/test_meta_updater.rb +39 -11
  57. data/lib/gitlab_quality/test_tooling/test_metrics_exporter/config.rb +115 -15
  58. data/lib/gitlab_quality/test_tooling/test_metrics_exporter/formatter.rb +61 -36
  59. data/lib/gitlab_quality/test_tooling/test_metrics_exporter/test_metrics.rb +125 -80
  60. data/lib/gitlab_quality/test_tooling/test_metrics_exporter/utils.rb +95 -0
  61. data/lib/gitlab_quality/test_tooling/test_result/base_test_result.rb +6 -2
  62. data/lib/gitlab_quality/test_tooling/version.rb +1 -1
  63. data/lib/gitlab_quality/test_tooling.rb +3 -0
  64. metadata +82 -55
  65. data/lib/gitlab_quality/test_tooling/test_metrics_exporter/log_test_metrics.rb +0 -117
  66. data/lib/gitlab_quality/test_tooling/test_metrics_exporter/support/gcs_tools.rb +0 -49
  67. data/lib/gitlab_quality/test_tooling/test_metrics_exporter/support/influxdb_tools.rb +0 -33
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GitlabQuality
4
+ module TestTooling
5
+ module Report
6
+ module GroupIssues
7
+ class ErrorPatternMatcher
8
+ ENVIRONMENT_ERROR_PATTERNS = [
9
+ { name: "http_500_api_fabrication", pattern: /Fabrication of .+ using the API failed \(500\)/i },
10
+ { name: "http_500_internal_server", pattern: /(500 Internal Server Error|request returned \(500\)|Expected \(200\), request returned \(500\))/i },
11
+ { name: "http_400_backend_failing", pattern: /failed \(400\) with.+connections to all backends failing/i },
12
+ { name: "http_503_service_unavailable", pattern: /Unexpected status code 503/i },
13
+ { name: "pipeline_creation_timeout", pattern: /Wait for pipeline to be created failed after \d+ seconds/i },
14
+ { name: "event_timeout", pattern: /(Timed out waiting for event|EventNotFoundError: Timed out waiting)/i },
15
+ { name: "git_rpc_failure", pattern: /error: RPC failed; HTTP 500/i },
16
+ { name: "repository_fabricate_error", pattern: /Repository fabricate/i }
17
+ ].freeze
18
+
19
+ def match(error_message)
20
+ return nil if error_message.nil? || error_message.empty?
21
+
22
+ ENVIRONMENT_ERROR_PATTERNS.find { |pattern_def| error_message.match?(pattern_def[:pattern]) }
23
+ end
24
+
25
+ def environment_error?(error_message)
26
+ !match(error_message).nil?
27
+ end
28
+
29
+ def pattern_name(error_message)
30
+ match(error_message)&.dig(:name)
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,73 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GitlabQuality
4
+ module TestTooling
5
+ module Report
6
+ module GroupIssues
7
+ class FailureProcessor
8
+ DEFAULT_MIN_FAILURES = 2
9
+
10
+ def initialize(options = {})
11
+ @options = options
12
+ @pattern_matcher = options[:pattern_matcher] || ErrorPatternMatcher.new
13
+ @normalizer = options[:normalizer] || ErrorMessageNormalizer.new
14
+ @config = options[:config] || {}
15
+ end
16
+
17
+ def process_failures(failures, &)
18
+ Runtime::Logger.info "Processing #{failures.size} failures for grouping..."
19
+ grouped_failures = {}
20
+
21
+ failures.each do |failure|
22
+ process_single_failure(failure, grouped_failures)
23
+ end
24
+
25
+ Runtime::Logger.info "Found #{grouped_failures.size} groups before filtering"
26
+ grouped_failures.each_value(&)
27
+ end
28
+
29
+ def filter_groups_by_threshold(grouped_failures)
30
+ min_failures = @config.dig(:thresholds, :min_failures_to_group) || DEFAULT_MIN_FAILURES
31
+
32
+ grouped_failures.select! do |_fingerprint, grouped_failure|
33
+ grouped_failure[:failures].size >= min_failures
34
+ end
35
+
36
+ Runtime::Logger.info "Found #{grouped_failures.size} groups after filtering"
37
+ end
38
+
39
+ private
40
+
41
+ def process_single_failure(failure, grouped_failures)
42
+ error_message = failure.dig(:exception, 'message') || failure.dig(:exceptions, 0, 'message')
43
+ Runtime::Logger.info "Processing failure: #{failure[:description]}"
44
+ Runtime::Logger.info "Error message: #{error_message[0..100]}..." if error_message
45
+
46
+ return unless error_message && @pattern_matcher.environment_error?(error_message)
47
+
48
+ Runtime::Logger.info "Identified as environment error"
49
+ group_environment_failure(failure, error_message, grouped_failures)
50
+ end
51
+
52
+ def group_environment_failure(failure, error_message, grouped_failures)
53
+ normalized_message = @normalizer.normalize(error_message)
54
+ fingerprint = @normalizer.create_fingerprint(normalized_message)
55
+ pattern_name = @pattern_matcher.pattern_name(error_message)
56
+
57
+ grouped_failures[fingerprint] ||= build_grouped_failure(fingerprint, pattern_name, normalized_message)
58
+ grouped_failures[fingerprint][:failures] << failure
59
+ end
60
+
61
+ def build_grouped_failure(fingerprint, pattern_name, normalized_message)
62
+ {
63
+ fingerprint: fingerprint,
64
+ pattern_name: pattern_name,
65
+ normalized_message: normalized_message,
66
+ failures: []
67
+ }
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'gitlab'
4
+ require 'time'
5
+ require_relative 'error_pattern_matcher'
6
+ require_relative 'error_message_normalizer'
7
+ require_relative 'incident_checker'
8
+
9
+ module GitlabQuality
10
+ module TestTooling
11
+ module Report
12
+ module GroupIssues
13
+ class GroupResultsInIssues
14
+ attr_reader :grouped_failures
15
+
16
+ def initialize(options = {})
17
+ @options = options
18
+ @failure_processor = FailureProcessor.new(options)
19
+ @issue_manager = IssueManager.new(options)
20
+ @grouped_failures = {}
21
+ end
22
+
23
+ def process_failures(failures)
24
+ @failure_processor.process_failures(failures) do |grouped_failure|
25
+ fingerprint = grouped_failure[:fingerprint]
26
+ @grouped_failures[fingerprint] = grouped_failure
27
+ end
28
+
29
+ @failure_processor.filter_groups_by_threshold(@grouped_failures)
30
+ end
31
+
32
+ def process_issues
33
+ @grouped_failures.each_value do |grouped_failure|
34
+ @issue_manager.create_or_update_issue(grouped_failure)
35
+ end
36
+ end
37
+
38
+ def summary
39
+ {
40
+ grouped_issues: @grouped_failures.size,
41
+ total_grouped_failures: @grouped_failures.values.sum { |group| group[:failures].size }
42
+ }
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'gitlab'
4
+
5
+ module GitlabQuality
6
+ module TestTooling
7
+ module Report
8
+ module GroupIssues
9
+ class IncidentChecker
10
+ GITLAB_PRODUCTION_PROJECT_ID = '7444821' # gitlab-com/gl-infra/production
11
+
12
+ def self.get_active_incidents(token: nil, gitlab_url: 'https://gitlab.com')
13
+ return [] unless token
14
+
15
+ begin
16
+ client = GitlabClient::IssuesClient.new(token: token, endpoint: "#{gitlab_url}/api/v4", project: GITLAB_PRODUCTION_PROJECT_ID)
17
+
18
+ issues = client.find_issues(options: {
19
+ labels: 'Incident::Active',
20
+ state: 'opened',
21
+ per_page: 10,
22
+ order_by: 'created_at',
23
+ sort: 'desc'
24
+ })
25
+
26
+ issues.map do |issue|
27
+ {
28
+ title: issue.title,
29
+ url: issue.web_url
30
+ }
31
+ end
32
+
33
+ rescue Gitlab::Error::Error => e
34
+ Runtime::Logger.error "GitLab API error fetching incidents: #{e.message}"
35
+ []
36
+ rescue StandardError => e
37
+ Runtime::Logger.error "Warning: Could not fetch active incidents: #{e.message}"
38
+ []
39
+ end
40
+ end
41
+
42
+ def self.format_incidents_for_issue(incidents)
43
+ return "" if incidents.empty?
44
+
45
+ incident_list = incidents.map { |inc| "- [#{inc[:title]}](#{inc[:url]})" }.join("\n")
46
+
47
+ <<~MARKDOWN
48
+
49
+ ### Related GitLab Incidents
50
+ The following active incidents may be related to these test failures:
51
+
52
+ #{incident_list}
53
+
54
+ Check the [GitLab Production Issues](https://gitlab.com/gitlab-com/gl-infra/production/-/issues/?label_name%5B%5D=Incident%3A%3AActive) for updates.
55
+ MARKDOWN
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GitlabQuality
4
+ module TestTooling
5
+ module Report
6
+ module GroupIssues
7
+ class IssueBase
8
+ def initialize(client, options = {})
9
+ @client = client
10
+ @options = options
11
+ @gitlab_url = ENV.fetch('CI_SERVER_URL', 'https://gitlab.com')
12
+ @project_id = options[:target_project] || ENV['RESULTS_ISSUE_PROJECT'] || ENV.fetch('CI_PROJECT_ID', nil)
13
+ @token = options[:token]
14
+ end
15
+
16
+ private
17
+
18
+ def handle_gitlab_api_error(operation, context = nil)
19
+ yield
20
+ rescue Gitlab::Error::Error => e
21
+ log_gitlab_error(operation, context, e)
22
+ nil
23
+ rescue StandardError => e
24
+ log_standard_error(operation, context, e)
25
+ nil
26
+ end
27
+
28
+ def log_gitlab_error(operation, context, error)
29
+ context_info = context ? " #{context}" : ""
30
+ Runtime::Logger.error "GitLab API error #{operation}#{context_info}: #{error.message}"
31
+ end
32
+
33
+ def log_standard_error(operation, context, error)
34
+ context_info = context ? " #{context}" : ""
35
+ Runtime::Logger.error "Error #{operation}#{context_info}: #{error.message}"
36
+ end
37
+
38
+ def display_description_preview(description, title = "Description preview:")
39
+ Runtime::Logger.info title
40
+ lines = description.split("\n")
41
+ Runtime::Logger.info lines.first(15).join("\n")
42
+ Runtime::Logger.info "..." if lines.length > 15
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GitlabQuality
4
+ module TestTooling
5
+ module Report
6
+ module GroupIssues
7
+ class IssueCreator < IssueBase
8
+ GROUPED_ISSUE_LABELS = Set.new(%w[test failure::test-environment automation:bot-authored type::maintenance]).freeze
9
+
10
+ def initialize(client, options = {})
11
+ super
12
+ @formatter = IssueFormatter.new
13
+ end
14
+
15
+ def create_new_issue(grouped_failure)
16
+ title = @formatter.generate_issue_title(grouped_failure)
17
+ description = @formatter.generate_issue_description(grouped_failure, @options)
18
+ labels = GROUPED_ISSUE_LABELS
19
+
20
+ Runtime::Logger.info "Creating new grouped issue: #{title} (#{grouped_failure[:failures].size} failures)"
21
+
22
+ create_issue(
23
+ title: title,
24
+ description: description,
25
+ labels: labels,
26
+ failures: grouped_failure[:failures]
27
+ )
28
+ end
29
+
30
+ private
31
+
32
+ def create_issue(title:, description:, labels:, failures:)
33
+ Runtime::Logger.info "Creating issue: #{title} with #{failures.size} failures"
34
+
35
+ handle_gitlab_api_error("creating issue") do
36
+ issue = @client.create_issue(title: title, description: description, labels: labels.join(','))
37
+ Runtime::Logger.info "Issue created successfully: #{issue.web_url}" if issue&.web_url
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,81 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'time'
4
+
5
+ module GitlabQuality
6
+ module TestTooling
7
+ module Report
8
+ module GroupIssues
9
+ class IssueFinder
10
+ DEFAULT_MAX_AGE_HOURS = 24
11
+ ISSUES_PER_PAGE = 50
12
+
13
+ def initialize(client, options = {})
14
+ @client = client
15
+ @options = options
16
+ @token = options[:token]
17
+ @project_id = options[:target_project] || ENV['RESULTS_ISSUE_PROJECT'] || ENV.fetch('CI_PROJECT_ID', nil)
18
+ end
19
+
20
+ def find_existing_issue(grouped_failure)
21
+ find_related_issue_by_fingerprint(
22
+ fingerprint: grouped_failure[:fingerprint],
23
+ max_age_hours: DEFAULT_MAX_AGE_HOURS
24
+ )
25
+ end
26
+
27
+ private
28
+
29
+ def find_related_issue_by_fingerprint(fingerprint:, max_age_hours:)
30
+ Runtime::Logger.info "Searching for existing issue with fingerprint: #{fingerprint}"
31
+
32
+ begin
33
+ issues = fetch_recent_open_issues(max_age_hours)
34
+ matching_issue = find_issue_with_fingerprint(issues, fingerprint)
35
+ if matching_issue
36
+ Runtime::Logger.info "Found existing issue: ##{matching_issue.iid} - #{matching_issue.title}"
37
+ convert_to_struct(matching_issue)
38
+ end
39
+ rescue Gitlab::Error::Error => e
40
+ Runtime::Logger.error "GitLab API error searching for issues: #{e.message}"
41
+ nil
42
+ rescue StandardError => e
43
+ Runtime::Logger.error "Error searching for existing issues: #{e.message}"
44
+ nil
45
+ end
46
+ end
47
+
48
+ def fetch_recent_open_issues(max_age_hours)
49
+ cutoff_time = Time.now - (max_age_hours * 3600)
50
+
51
+ @client.find_issues(options: {
52
+ state: 'opened',
53
+ created_after: cutoff_time.utc.iso8601,
54
+ per_page: ISSUES_PER_PAGE,
55
+ order_by: 'created_at',
56
+ sort: 'desc'
57
+ })
58
+ end
59
+
60
+ def find_issue_with_fingerprint(issues, fingerprint)
61
+ fingerprint_tag = "grouped-failure-fingerprint:#{fingerprint}"
62
+ issues.find { |issue| issue.description&.include?(fingerprint_tag) }
63
+ end
64
+
65
+ def convert_to_struct(obj)
66
+ return obj unless obj.is_a?(Hash)
67
+
68
+ struct_class = Struct.new(*obj.keys.map(&:to_sym))
69
+ struct = struct_class.new
70
+
71
+ obj.each do |key, value|
72
+ struct[key.to_sym] = value.is_a?(Hash) ? convert_to_struct(value) : value
73
+ end
74
+
75
+ struct
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,83 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GitlabQuality
4
+ module TestTooling
5
+ module Report
6
+ module GroupIssues
7
+ class IssueFormatter
8
+ def generate_issue_title(grouped_failure)
9
+ case grouped_failure[:pattern_name]
10
+ when /http_500/ then "Environment Issue: HTTP 500 Internal Server Errors"
11
+ when /http_400/ then "Environment Issue: Backend Connection Failures"
12
+ when /http_503/ then "Environment Issue: Service Unavailable (503)"
13
+ when /timeout/ then "Environment Issue: Timeout Failures"
14
+ when /git_rpc|repository/ then "Environment Issue: Repository/Git Operation Failures"
15
+ else "Environment Issue: Multiple Similar Failures"
16
+ end
17
+ end
18
+
19
+ def generate_issue_description(grouped_failure, options = {})
20
+ active_incidents = IncidentChecker.get_active_incidents(token: options[:token])
21
+ incident_section = IncidentChecker.format_incidents_for_issue(active_incidents)
22
+
23
+ <<~MARKDOWN
24
+ ## Environment Issue: #{grouped_failure[:pattern_name]}
25
+
26
+ Multiple tests have failed with similar error patterns, indicating an environment-related issue affecting multiple test cases.
27
+
28
+ ### Error Pattern
29
+ ```
30
+ #{grouped_failure[:normalized_message]}
31
+ ```
32
+
33
+ ### Affected Tests (#{grouped_failure[:failures].size} failures)
34
+ #{format_affected_tests(grouped_failure[:failures])}
35
+
36
+ ### Pipeline Information
37
+ #{format_pipeline_info(grouped_failure[:failures].first)}
38
+
39
+ ### Recommended Actions
40
+ #{generate_recommended_actions(grouped_failure)}
41
+
42
+ #{incident_section}
43
+ ---
44
+ <!-- grouped-failure-fingerprint:#{grouped_failure[:fingerprint]} -->
45
+ MARKDOWN
46
+ end
47
+
48
+ def format_affected_tests(failures)
49
+ failures.map do |failure|
50
+ job_name = failure[:ci_job_url] || failure.dig(:ci_job, :name) || 'unknown_job'
51
+ spec_file = failure[:file_path] || failure[:file] || 'unknown_spec'
52
+ line_number = failure[:line_number] || failure[:line]
53
+ test_name = failure[:description] || failure[:test_name] || 'Unknown test'
54
+
55
+ spec_with_line = line_number.to_s.empty? ? spec_file : "#{spec_file}:#{line_number}"
56
+ "- **#{test_name}** (Job: `#{job_name}`, Spec: `#{spec_with_line}`)"
57
+ end.join("\n")
58
+ end
59
+
60
+ def format_pipeline_info(failure)
61
+ pipeline_url = ENV['CI_PIPELINE_URL'] || "Pipeline #{ENV.fetch('CI_PIPELINE_ID', 'unknown')}"
62
+ job_url = failure[:ci_job_url] || 'Unknown job'
63
+
64
+ "- **Pipeline**: #{pipeline_url}\n- **Job**: #{job_url}"
65
+ end
66
+
67
+ def generate_recommended_actions(grouped_failure)
68
+ case grouped_failure[:pattern_name]
69
+ when /http_500/
70
+ "1. Check GitLab instance status and logs\n2. Verify database connectivity\n3. Review application server health"
71
+ when /timeout/
72
+ "1. Check network connectivity\n2. Review timeout configurations\n3. Monitor system resources"
73
+ when /git_rpc|repository/
74
+ "1. Verify Git repository accessibility\n2. Check Gitaly service status\n3. Review storage capacity"
75
+ else
76
+ "1. Check if there are ongoing incidents affecting the GitLab instance\n2. Verify API endpoints are responding correctly\n3. Review system logs for related errors"
77
+ end
78
+ end
79
+ end
80
+ end
81
+ end
82
+ end
83
+ end
@@ -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
@@ -1,5 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'date'
4
+ require 'time'
5
+
3
6
  module GitlabQuality
4
7
  module TestTooling
5
8
  module Report
@@ -15,7 +18,6 @@ module GitlabQuality
15
18
  class HealthProblemReporter < ReportAsIssue
16
19
  include Concerns::GroupAndCategoryLabels
17
20
  include Concerns::IssueReports
18
- include TestMetricsExporter::Support::GcsTools
19
21
 
20
22
  BASE_SEARCH_LABELS = ['test'].freeze
21
23
  FOUND_IN_MR_LABEL = '~"found:in MR"'
@@ -151,7 +153,7 @@ module GitlabQuality
151
153
  def push_test_to_gcs(tests_data, test_results_filename)
152
154
  Runtime::Logger.info "will push the test data to GCS"
153
155
 
154
- gcs_client(project_id: gcs_project_id, credentials: gcs_credentials, dry_run: dry_run).put_object(
156
+ GcsTools.gcs_client(project_id: gcs_project_id, credentials: gcs_credentials, dry_run: dry_run).put_object(
155
157
  gcs_bucket,
156
158
  gcs_metrics_file_name(test_results_filename),
157
159
  tests_data.to_json,
@@ -163,7 +165,7 @@ module GitlabQuality
163
165
  end
164
166
 
165
167
  def gcs_metrics_file_name(test_results_filename)
166
- today = Time.now.strftime('%Y-%m-%d')
168
+ today = Time.now.to_date.iso8601
167
169
 
168
170
  "#{today}-#{test_results_filename}"
169
171
  end
@@ -253,6 +255,7 @@ module GitlabQuality
253
255
  issue_url: issues.first&.web_url,
254
256
  job_id: Runtime::Env.ci_job_id,
255
257
  job_web_url: test.ci_job_url,
258
+ job_status: Runtime::Env.ci_job_status,
256
259
  pipeline_id: Runtime::Env.ci_pipeline_id,
257
260
  pipeline_ref: Runtime::Env.ci_commit_ref_name,
258
261
  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)