From 8c7898b373de9f359c0333afec59a2baf4be21ae Mon Sep 17 00:00:00 2001 From: Crola1702 Date: Mon, 29 Jul 2024 08:32:06 -0500 Subject: [PATCH 1/7] WIP old known issues Signed-off-by: Crola1702 --- database/scripts/get_known_issues.sql | 3 +- database/scripts/get_known_issues_link.sql | 5 +++ database/scripts/get_need_to_close_issues.sh | 34 ++++++++++++++++++++ database/scripts/known_issues_status.rb | 27 ++++++++++++++++ database/scripts/wip_get_closed_issues.sql | 14 ++++++++ 5 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 database/scripts/get_known_issues_link.sql create mode 100755 database/scripts/get_need_to_close_issues.sh create mode 100755 database/scripts/known_issues_status.rb create mode 100644 database/scripts/wip_get_closed_issues.sql diff --git a/database/scripts/get_known_issues.sql b/database/scripts/get_known_issues.sql index d78f708..0b503aa 100644 --- a/database/scripts/get_known_issues.sql +++ b/database/scripts/get_known_issues.sql @@ -2,4 +2,5 @@ SELECT error_name, job_name, github_issue, status -FROM test_fail_issues; \ No newline at end of file +FROM test_fail_issues +WHERE status LIKE "%@param1@%"; diff --git a/database/scripts/get_known_issues_link.sql b/database/scripts/get_known_issues_link.sql new file mode 100644 index 0000000..619b88a --- /dev/null +++ b/database/scripts/get_known_issues_link.sql @@ -0,0 +1,5 @@ +SELECT DISTINCT + github_issue, + status +FROM test_fail_issues +WHERE status LIKE "%@param1@%"; diff --git a/database/scripts/get_need_to_close_issues.sh b/database/scripts/get_need_to_close_issues.sh new file mode 100755 index 0000000..9efebaa --- /dev/null +++ b/database/scripts/get_need_to_close_issues.sh @@ -0,0 +1,34 @@ +#!/bin/bash + +for Line in $(./sql_run.sh get_known_issues_link.sql CLOSED | tail +2) +do + gh_issue=`expr match "$Line" '.*\(https://github.com.*\)|.*'` + gh_type=`expr match "$gh_issue" '.*\(pull\|issue\).*'` + if [ $gh_type = "pull" ] + then + echo "[WARNING] $gh_issue gh_type is Pull request. Change it to issue." + continue + fi + + issue_data=`gh $gh_type view $gh_issue` + issue_status=`python3 -c "import sys; import re; print(re.match(r'[\S\s]*state:[\s](.*?)[\s]', sys.argv[1]).group(1))" "$issue_data"` + + if [ -z $issue_status ] + then + echo "[WARNING] Unknown status for $gh_issue" + echo $issue_data + continue + fi + + if [ $issue_status == "OPEN" ] + then + echo "OPEN issue but CLOSED status for: $gh_issue" + elif [ $issue_status == "CLOSED" ] + then + continue + else + echo "[WARNING] Unknown status $issue_status" + continue + fi + +done diff --git a/database/scripts/known_issues_status.rb b/database/scripts/known_issues_status.rb new file mode 100755 index 0000000..d295ca6 --- /dev/null +++ b/database/scripts/known_issues_status.rb @@ -0,0 +1,27 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +require_relative 'lib/buildfarm_tools' +require 'json' +require 'date' + +known_issues_list = parse_sql_output(%x{./sql_run.sh get_known_issues.sql}, %w[error_name job_name github_issue status]) + +known_issues_list.each do |ki| + gh_info_raw = %x{gh issue view #{ki['github_issue']} --json title,state,updatedAt} + gh_info = JSON.parse(gh_info_raw) + gh_info['updatedAt'] = Date.parse(gh_info['updatedAt']) if gh_info['updatedAt'] + if gh_info['state'] == 'OPEN' and ki['status'] == 'OPEN' and gh_info['updatedAt'] < Date.today - 30 + puts "Issue #{ki['github_issue']} is open and has not been updated in the last 30 days" + elsif gh_info['state'] == 'OPEN' and ki['status'] == 'CLOSED' + last_error_output = %x{./sql_run.sh errors_get_last_ones.sql "#{ki['error_name']}" | grep #{ki['job_name']} | tail -n 1} + _, _, job_name, build_number, last_time, _ = last_error_output.split('|') + puts "Issue #{ki['github_issue']} is open but the last time it happened was #{last_time} in #{job_name}##{build_number}" + elsif gh_info['state'] == 'CLOSED' and gh_info['updatedAt'] < (Date.today - 365) + puts "Issue #{ki['github_issue']} is closed and hasn't been updated in the last year" + end +end + + + + diff --git a/database/scripts/wip_get_closed_issues.sql b/database/scripts/wip_get_closed_issues.sql new file mode 100644 index 0000000..c7f2c97 --- /dev/null +++ b/database/scripts/wip_get_closed_issues.sql @@ -0,0 +1,14 @@ +SELECT test_failures.error_name, + test_failures.job_name, + test_failures.build_number, + test_fail_issues.github_issue, + build_status.build_datetime +FROM test_fail_issues +JOIN test_failures ON + test_fail_issues.error_name == test_failures.error_name AND + test_fail_issues.job_name == test_failures.job_name +JOIN build_status ON + build_status.job_name == test_fail_issues.job_name AND + build_status.build_number == test_failures.build_number +WHERE test_fail_issues.status LIKE "CLOSED" +ORDER BY build_status.build_datetime DESC; From 79da7966781334c31c6249437b0672f1ac553990 Mon Sep 17 00:00:00 2001 From: Crola1702 Date: Tue, 30 Jul 2024 21:11:01 -0500 Subject: [PATCH 2/7] Pass filter issues responsibility to sqlite Signed-off-by: Crola1702 --- database/scripts/close_old_known_issues.sh | 7 +------ database/scripts/generate_report.rb | 4 ++-- database/scripts/lib/buildfarm_tools.rb | 6 ++---- 3 files changed, 5 insertions(+), 12 deletions(-) diff --git a/database/scripts/close_old_known_issues.sh b/database/scripts/close_old_known_issues.sh index 67db85b..317ca08 100755 --- a/database/scripts/close_old_known_issues.sh +++ b/database/scripts/close_old_known_issues.sh @@ -7,14 +7,9 @@ close_issue() { ./sql_run.sh issue_close_by_name.sql "$error_name" "$error_job_name" } -for Line in $(./sql_run.sh get_known_issues.sql) +for Line in $(./sql_run.sh get_known_issues.sql OPEN) do - if [[ $Line =~ "CLOSED" ]] - then - continue - fi - error_name=$(echo $Line | sed 's/|.*//') error_job_name=$(echo $Line | sed 's/^.*|\(.*\)|.*|.*/\1/') diff --git a/database/scripts/generate_report.rb b/database/scripts/generate_report.rb index a57b011..38f4a29 100755 --- a/database/scripts/generate_report.rb +++ b/database/scripts/generate_report.rb @@ -28,8 +28,8 @@ def generate_report(report_name, exclude_set) report = { 'urgent' => { 'build_regressions' => urgent_build_regressions = BuildfarmToolsLib::build_regressions_today(), - 'test_regressions_consecutive' => urgent_consistent_test_regressions = BuildfarmToolsLib::test_regressions_today(only_consistent: true, group_issues: true), - 'test_regressions_flaky' => urgent_flaky_test_regressions = BuildfarmToolsLib::flaky_test_regressions(group_issues: true), + 'test_regressions_consecutive' => urgent_consistent_test_regressions = BuildfarmToolsLib::test_regressions_today(filter_known: true, only_consistent: true, group_issues: true), + 'test_regressions_flaky' => urgent_flaky_test_regressions = BuildfarmToolsLib::flaky_test_regressions(filter_known: true, group_issues: true), }, 'maintenance' => { 'jobs_failing' => [], diff --git a/database/scripts/lib/buildfarm_tools.rb b/database/scripts/lib/buildfarm_tools.rb index 0083057..a7b6f4b 100644 --- a/database/scripts/lib/buildfarm_tools.rb +++ b/database/scripts/lib/buildfarm_tools.rb @@ -22,11 +22,9 @@ def self.build_regressions_today(filter_known: false) out end - def self.known_issues(status: nil) + def self.known_issues(status: '') # Keys: error_name, job_name, github_issue, status - out = run_command('./sql_run.sh get_known_issues.sql') - out.filter! { |e| e['status'] == status.upcase } unless status.nil? - out + run_command("./sql_run.sh get_known_issues.sql #{status.upcase}") end def self.error_appearances_in_job(test_name, job_name) From 72ed919653366c2fd9afa07d8c7dfb7663c79a6d Mon Sep 17 00:00:00 2001 From: Crola1702 Date: Tue, 30 Jul 2024 22:12:20 -0500 Subject: [PATCH 3/7] Add jobs_failing section to lib, report and formatter Signed-off-by: Crola1702 --- database/scripts/format_report.rb | 1 + database/scripts/generate_report.rb | 2 +- database/scripts/jobs_last_success.sql | 9 +++++++++ database/scripts/jobs_never_passed.sql | 11 +++++++++++ database/scripts/lib/buildfarm_tools.rb | 23 +++++++++++++++++++++++ database/scripts/lib/report_formatter.rb | 13 +++++++++++-- 6 files changed, 56 insertions(+), 3 deletions(-) create mode 100644 database/scripts/jobs_last_success.sql create mode 100644 database/scripts/jobs_never_passed.sql diff --git a/database/scripts/format_report.rb b/database/scripts/format_report.rb index 8f40648..4a38b6e 100755 --- a/database/scripts/format_report.rb +++ b/database/scripts/format_report.rb @@ -10,6 +10,7 @@ report['urgent']['build_regressions'] = ReportFormatter::build_regressions(report['urgent']['build_regressions']) report['urgent']['test_regressions_consecutive'] = ReportFormatter::test_regressions_consecutive(report['urgent']['test_regressions_consecutive']) report['urgent']['test_regressions_flaky'] = ReportFormatter::test_regressions_flaky(report['urgent']['test_regressions_flaky']) +report['maintenance']['jobs_failing'] = ReportFormatter::jobs_failing(report['maintenance']['jobs_failing']) # Sample output: # puts report['urgent']['build_regressions'] diff --git a/database/scripts/generate_report.rb b/database/scripts/generate_report.rb index 38f4a29..f5f180f 100755 --- a/database/scripts/generate_report.rb +++ b/database/scripts/generate_report.rb @@ -32,7 +32,7 @@ def generate_report(report_name, exclude_set) 'test_regressions_flaky' => urgent_flaky_test_regressions = BuildfarmToolsLib::flaky_test_regressions(filter_known: true, group_issues: true), }, 'maintenance' => { - 'jobs_failing' => [], + 'jobs_failing' => maintenance_jobs_failing = BuildfarmToolsLib::jobs_failing(days_exclude: 7), 'gh_issues_reported' => [], 'tests_disabled' => [], }, diff --git a/database/scripts/jobs_last_success.sql b/database/scripts/jobs_last_success.sql new file mode 100644 index 0000000..a45e53a --- /dev/null +++ b/database/scripts/jobs_last_success.sql @@ -0,0 +1,9 @@ +SELECT job_name, last_success_time +FROM ( + SELECT bs.job_name, MAX(bs.build_datetime) AS last_success_time + FROM build_status bs + INNER JOIN server_status ss ON bs.job_name = ss.job_name + WHERE bs.status = 'SUCCESS' + GROUP BY bs.job_name +) AS last_success_times +ORDER BY last_success_time ASC; \ No newline at end of file diff --git a/database/scripts/jobs_never_passed.sql b/database/scripts/jobs_never_passed.sql new file mode 100644 index 0000000..efc7f99 --- /dev/null +++ b/database/scripts/jobs_never_passed.sql @@ -0,0 +1,11 @@ +SELECT bs.job_name, + COUNT(*) as failed_build_count +FROM build_status bs +INNER JOIN server_status ss ON bs.job_name = ss.job_name +WHERE bs.job_name NOT IN ( + SELECT job_name + FROM build_status + WHERE status = 'SUCCESS' +) +GROUP BY bs.job_name +ORDER BY failed_build_count DESC; \ No newline at end of file diff --git a/database/scripts/lib/buildfarm_tools.rb b/database/scripts/lib/buildfarm_tools.rb index a7b6f4b..b57f8f0 100644 --- a/database/scripts/lib/buildfarm_tools.rb +++ b/database/scripts/lib/buildfarm_tools.rb @@ -90,6 +90,29 @@ def self.test_regression_reported_issues(error_name, status: nil) is_known_issue.map { |issue| { 'github_issue' => issue['github_issue'], 'status' => issue['status'] } }.uniq end + def self.jobs_last_success + run_command('./sql_run.sh jobs_last_success.sql') + end + + def self.jobs_never_passed + run_command('./sql_run.sh jobs_never_passed.sql') + end + + def self.jobs_failing(days_exclude: 0) + # Keys: job_name, last_success + out = [] + jobs_never_passed.each do |e| + out << {"job_name" => e["job_name"], "last_success" => "Never"} + end + + jobs_last_success.each do |e| + last_success = DateTime.parse(e['last_success_time']) + next if last_success > (Date.today - days_exclude) + out << {"job_name" => e["job_name"], "last_success" => last_success.strftime('%Y-%m-%d')} + end + out + end + def self.run_command(cmd, args: [], keys: []) cmd += " '#{args.shift}'" until args.empty? begin diff --git a/database/scripts/lib/report_formatter.rb b/database/scripts/lib/report_formatter.rb index 7c12e47..93a7a56 100644 --- a/database/scripts/lib/report_formatter.rb +++ b/database/scripts/lib/report_formatter.rb @@ -127,10 +127,19 @@ def self.test_regressions_flaky(tr_array) out += "### Warnings\n#{warnings_table}\n" if warnings_table.count("\n") > 2 out end - + + def self.jobs_failing(job_array) + return "" if job_array.empty? + table = "| Job Name | Last Success |\n| -- | -- |\n" + job_array.each do |job| + table += "| #{job['job_name']} | #{job['last_success']} |\n" + end + table + end def self.format_report(report_hash) # Use
and tags to prevent long reports + details_subcategories = ['test_regressions_flaky', 'jobs_failing'] output_report = "" report_hash.each_pair do |category, subcategory_hash| @@ -140,7 +149,7 @@ def self.format_report(report_hash) subcategory_report_title = "

#{subcategory.gsub('_', ' ').capitalize}

\n" subcategory_report_str = "#{subcategory_report_title}\n#{subcategory_report}\n" - subcategory_report_str = "
#{subcategory_report_title}\n\n#{subcategory_report}
\n" if subcategory == 'test_regressions_flaky' + subcategory_report_str = "
#{subcategory_report_title}\n\n#{subcategory_report}
\n" if details_subcategories.include? subcategory output_report += subcategory_report_str end end From bafda2a63fb8050e93bf3692338d148eca5efe5c Mon Sep 17 00:00:00 2001 From: Crola1702 Date: Tue, 30 Jul 2024 22:12:30 -0500 Subject: [PATCH 4/7] Remove unused code Signed-off-by: Crola1702 --- database/scripts/get_known_issues_link.sql | 5 --- database/scripts/get_need_to_close_issues.sh | 34 -------------------- database/scripts/known_issues_status.rb | 27 ---------------- 3 files changed, 66 deletions(-) delete mode 100644 database/scripts/get_known_issues_link.sql delete mode 100755 database/scripts/get_need_to_close_issues.sh delete mode 100755 database/scripts/known_issues_status.rb diff --git a/database/scripts/get_known_issues_link.sql b/database/scripts/get_known_issues_link.sql deleted file mode 100644 index 619b88a..0000000 --- a/database/scripts/get_known_issues_link.sql +++ /dev/null @@ -1,5 +0,0 @@ -SELECT DISTINCT - github_issue, - status -FROM test_fail_issues -WHERE status LIKE "%@param1@%"; diff --git a/database/scripts/get_need_to_close_issues.sh b/database/scripts/get_need_to_close_issues.sh deleted file mode 100755 index 9efebaa..0000000 --- a/database/scripts/get_need_to_close_issues.sh +++ /dev/null @@ -1,34 +0,0 @@ -#!/bin/bash - -for Line in $(./sql_run.sh get_known_issues_link.sql CLOSED | tail +2) -do - gh_issue=`expr match "$Line" '.*\(https://github.com.*\)|.*'` - gh_type=`expr match "$gh_issue" '.*\(pull\|issue\).*'` - if [ $gh_type = "pull" ] - then - echo "[WARNING] $gh_issue gh_type is Pull request. Change it to issue." - continue - fi - - issue_data=`gh $gh_type view $gh_issue` - issue_status=`python3 -c "import sys; import re; print(re.match(r'[\S\s]*state:[\s](.*?)[\s]', sys.argv[1]).group(1))" "$issue_data"` - - if [ -z $issue_status ] - then - echo "[WARNING] Unknown status for $gh_issue" - echo $issue_data - continue - fi - - if [ $issue_status == "OPEN" ] - then - echo "OPEN issue but CLOSED status for: $gh_issue" - elif [ $issue_status == "CLOSED" ] - then - continue - else - echo "[WARNING] Unknown status $issue_status" - continue - fi - -done diff --git a/database/scripts/known_issues_status.rb b/database/scripts/known_issues_status.rb deleted file mode 100755 index d295ca6..0000000 --- a/database/scripts/known_issues_status.rb +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/env ruby -# frozen_string_literal: true - -require_relative 'lib/buildfarm_tools' -require 'json' -require 'date' - -known_issues_list = parse_sql_output(%x{./sql_run.sh get_known_issues.sql}, %w[error_name job_name github_issue status]) - -known_issues_list.each do |ki| - gh_info_raw = %x{gh issue view #{ki['github_issue']} --json title,state,updatedAt} - gh_info = JSON.parse(gh_info_raw) - gh_info['updatedAt'] = Date.parse(gh_info['updatedAt']) if gh_info['updatedAt'] - if gh_info['state'] == 'OPEN' and ki['status'] == 'OPEN' and gh_info['updatedAt'] < Date.today - 30 - puts "Issue #{ki['github_issue']} is open and has not been updated in the last 30 days" - elsif gh_info['state'] == 'OPEN' and ki['status'] == 'CLOSED' - last_error_output = %x{./sql_run.sh errors_get_last_ones.sql "#{ki['error_name']}" | grep #{ki['job_name']} | tail -n 1} - _, _, job_name, build_number, last_time, _ = last_error_output.split('|') - puts "Issue #{ki['github_issue']} is open but the last time it happened was #{last_time} in #{job_name}##{build_number}" - elsif gh_info['state'] == 'CLOSED' and gh_info['updatedAt'] < (Date.today - 365) - puts "Issue #{ki['github_issue']} is closed and hasn't been updated in the last year" - end -end - - - - From 261f764998ac5ccec291a6f4a31afab368acfc41 Mon Sep 17 00:00:00 2001 From: Crola1702 Date: Tue, 30 Jul 2024 22:24:29 -0500 Subject: [PATCH 5/7] Remove filter_known Signed-off-by: Crola1702 --- database/scripts/generate_report.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/database/scripts/generate_report.rb b/database/scripts/generate_report.rb index f5f180f..303e4d3 100755 --- a/database/scripts/generate_report.rb +++ b/database/scripts/generate_report.rb @@ -28,8 +28,8 @@ def generate_report(report_name, exclude_set) report = { 'urgent' => { 'build_regressions' => urgent_build_regressions = BuildfarmToolsLib::build_regressions_today(), - 'test_regressions_consecutive' => urgent_consistent_test_regressions = BuildfarmToolsLib::test_regressions_today(filter_known: true, only_consistent: true, group_issues: true), - 'test_regressions_flaky' => urgent_flaky_test_regressions = BuildfarmToolsLib::flaky_test_regressions(filter_known: true, group_issues: true), + 'test_regressions_consecutive' => urgent_consistent_test_regressions = BuildfarmToolsLib::test_regressions_today(only_consistent: true, group_issues: true), + 'test_regressions_flaky' => urgent_flaky_test_regressions = BuildfarmToolsLib::flaky_test_regressions(group_issues: true), }, 'maintenance' => { 'jobs_failing' => maintenance_jobs_failing = BuildfarmToolsLib::jobs_failing(days_exclude: 7), From 5b5f47ae545fbcacb79a53218ebb6406f1ab3de3 Mon Sep 17 00:00:00 2001 From: Crola1702 Date: Tue, 30 Jul 2024 22:28:00 -0500 Subject: [PATCH 6/7] Refactor to use args Signed-off-by: Crola1702 --- database/scripts/lib/buildfarm_tools.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/database/scripts/lib/buildfarm_tools.rb b/database/scripts/lib/buildfarm_tools.rb index b57f8f0..8028ae5 100644 --- a/database/scripts/lib/buildfarm_tools.rb +++ b/database/scripts/lib/buildfarm_tools.rb @@ -24,7 +24,7 @@ def self.build_regressions_today(filter_known: false) def self.known_issues(status: '') # Keys: error_name, job_name, github_issue, status - run_command("./sql_run.sh get_known_issues.sql #{status.upcase}") + run_command("./sql_run.sh get_known_issues.sql", args: [status.upcase]) end def self.error_appearances_in_job(test_name, job_name) From 52210f88fc1eef6fa5ba305e52f709e73b8666da Mon Sep 17 00:00:00 2001 From: Crola1702 Date: Tue, 30 Jul 2024 22:34:48 -0500 Subject: [PATCH 7/7] Remove unused code Signed-off-by: Crola1702 --- database/scripts/wip_get_closed_issues.sql | 14 -------------- 1 file changed, 14 deletions(-) delete mode 100644 database/scripts/wip_get_closed_issues.sql diff --git a/database/scripts/wip_get_closed_issues.sql b/database/scripts/wip_get_closed_issues.sql deleted file mode 100644 index c7f2c97..0000000 --- a/database/scripts/wip_get_closed_issues.sql +++ /dev/null @@ -1,14 +0,0 @@ -SELECT test_failures.error_name, - test_failures.job_name, - test_failures.build_number, - test_fail_issues.github_issue, - build_status.build_datetime -FROM test_fail_issues -JOIN test_failures ON - test_fail_issues.error_name == test_failures.error_name AND - test_fail_issues.job_name == test_failures.job_name -JOIN build_status ON - build_status.job_name == test_fail_issues.job_name AND - build_status.build_number == test_failures.build_number -WHERE test_fail_issues.status LIKE "CLOSED" -ORDER BY build_status.build_datetime DESC;