Skip to content

Commit

Permalink
Implement job priorities in daily report (#100)
Browse files Browse the repository at this point in the history
* Add first version of job priorities calculation (WIP)

Signed-off-by: Crola1702 <[email protected]>

* Add gazebo jobs priorities

Signed-off-by: Crola1702 <[email protected]>

* Return job priority in known issues section

Signed-off-by: Crola1702 <[email protected]>

* Show formatted priority in a new column

Signed-off-by: Crola1702 <[email protected]>

* Sort known issues by priority

Signed-off-by: Crola1702 <[email protected]>

* Rename sql query for clarity

Signed-off-by: Crola1702 <[email protected]>

* Address PR comments

Signed-off-by: Crola1702 <[email protected]>

---------

Signed-off-by: Crola1702 <[email protected]>
  • Loading branch information
Crola1702 authored Nov 6, 2024
1 parent 377fadf commit 5bba611
Show file tree
Hide file tree
Showing 4 changed files with 383 additions and 3 deletions.
6 changes: 6 additions & 0 deletions database/scripts/get_known_issue_by_url.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
SELECT job_name,
error_name
FROM test_fail_issues
WHERE github_issue = "@param1@"
GROUP BY github_issue,
job_name;
41 changes: 40 additions & 1 deletion database/scripts/lib/buildfarm_tools.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require 'open3'
require 'csv'

module BuildfarmToolsLib
class BuildfarmToolsError < RuntimeError; end
Expand All @@ -15,6 +16,8 @@ class BuildfarmToolsError < RuntimeError; end
FLAKY_BUILDS_DEFAULT_RANGE = '15 days'
WARNING_AGE_CONSTANT = -1

JOB_PRIORITIES = CSV.read('lib/job_priorities.csv', converters: :numeric).to_h

def self.build_regressions_today(filter_known: false)
# Keys: job_name, build_number, build_datetime, failure_reason, last_section
out = run_command('./sql_run.sh builds_failing_today.sql')
Expand Down Expand Up @@ -128,13 +131,49 @@ def self.jobs_last_success_date(older_than_days: 0)
out
end

def self.test_regressions_known
def self.test_regressions_known(sort_by: 'priority')
out = known_issues(status: 'open')
out.concat known_issues(status: 'disabled')
out = out.group_by { |e| e["github_issue"] }.to_a.map { |e| e[1] }
out.each do |error_list|
priority = calculate_issue_priority(error_list.first["github_issue"])
error_list.each do |error|
error["priority"] = priority
end
end

unless sort_by.nil?
out.sort_by! { |r| -r.first['priority'] }
end
out
end

def self.calculate_issue_priority(issue_link)
sql_out = run_command('./sql_run.sh get_known_issue_by_url.sql', args: [issue_link])
errors = sql_out.map {|e| e['error_name']}.uniq
jobs = sql_out.map {|e| e['job_name']}.uniq

error_score_jobs = {}

errors.each do |e|
jobs.each do |job|
flaky_result = run_command('./sql_run.sh calculate_flakiness_jobs.sql', args: [e, FLAKY_BUILDS_DEFAULT_RANGE, job])
next if flaky_result.empty?
# This is not guaranteed to be 'not consistent', we need to re-check if the last 3 builds were failing because of this
flaky_ratio = flaky_result.first['failure_percentage'].to_f/100.0

job_priority = JOB_PRIORITIES[job]
job_priority = job_priority*1.5 if flaky_ratio == 1

error_score_jobs[job] = [] if error_score_jobs[job].nil?
error_score_jobs[job] << (job_priority*flaky_ratio)
end
end

# Get only maximum score for each job
error_score_jobs.each_value.map {|e| e.max}.sum.round(3)
end

def self.run_command(cmd, args: [], keys: [])
cmd += " '#{args.shift}'" until args.empty?
begin
Expand Down
Loading

0 comments on commit 5bba611

Please sign in to comment.