Skip to content

Commit

Permalink
#189 use duration
Browse files Browse the repository at this point in the history
  • Loading branch information
Suban05 committed Aug 27, 2024
1 parent 3fe852a commit 337b2e8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
8 changes: 5 additions & 3 deletions judges/quality-of-service/quality-of-service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,17 @@
Fbe.unmask_repos.each do |repo|
Fbe.octo.repository_workflow_runs(repo, created: ">#{f.since.utc.iso8601[0..9]}")[:workflow_runs].each do |json|
workflow_id = json[:workflow_id]
run_duration = (Fbe.octo.workflow_run_usage(repo, json[:id])[:run_duration_ms] || 0) / 1000
completed = json[:run_started_at] + run_duration
if json[:conclusion] == 'failure' && failed[workflow_id].nil?
failed[workflow_id] = json[:updated_at]
failed[workflow_id] = completed
elsif json[:conclusion] == 'success' && failed[workflow_id]
ttrs << (json[:updated_at] - failed[workflow_id]).to_i
ttrs << (completed - failed[workflow_id]).to_i
failed.delete(workflow_id)
end
total += 1
success += json[:conclusion] == 'success' ? 1 : 0
duration += (Fbe.octo.workflow_run_usage(repo, json[:id])[:run_duration_ms] || 0) / 1000
duration += run_duration
end
end
f.average_build_success_rate = total.zero? ? 0 : success.to_f / total
Expand Down
16 changes: 13 additions & 3 deletions test/judges/test-quality-of-service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def test_runs_when_run_duration_ms_is_nil
status: 200,
body: {
workflow_runs: [
{ id: 1 }
{ id: 1, run_started_at: Time.now - rand(10_000) }
]
}.to_json,
headers: {
Expand Down Expand Up @@ -145,6 +145,7 @@ def test_quality_of_service_average_issues
workflow_id: 42,
created_at: Time.now - rand(10_000),
updated_at: Time.now - rand(10_000) + 100,
run_started_at: Time.now - rand(10_000),
repository: {
id: 1, full_name: 'foo/foo', default_branch: 'master', private: false,
owner: { login: 'foo', id: 526_301, site_admin: false },
Expand Down Expand Up @@ -189,6 +190,7 @@ def test_quality_of_service_average_build_mttr
workflow_id: 101,
created_at: '2024-08-07T10:00:00Z',
updated_at: '2024-08-07T10:10:00Z',
run_started_at: '2024-08-07T10:00:00Z',
repository: { full_name: 'foo/foo' }
},
{
Expand All @@ -202,6 +204,7 @@ def test_quality_of_service_average_build_mttr
workflow_id: 101,
created_at: '2024-08-07T11:00:00Z',
updated_at: '2024-08-07T11:15:00Z',
run_started_at: '2024-08-07T11:00:00Z',
repository: { full_name: 'foo/foo' }
},
{
Expand All @@ -215,6 +218,7 @@ def test_quality_of_service_average_build_mttr
workflow_id: 102,
created_at: '2024-08-08T12:00:00Z',
updated_at: '2024-08-08T12:10:00Z',
run_started_at: '2024-08-08T12:00:00Z',
repository: { full_name: 'foo/foo' }
},
{
Expand All @@ -228,6 +232,7 @@ def test_quality_of_service_average_build_mttr
workflow_id: 102,
created_at: '2024-08-08T13:00:00Z',
updated_at: '2024-08-08T13:20:00Z',
run_started_at: '2024-08-08T13:00:00Z',
repository: { full_name: 'foo/foo' }
}
]
Expand All @@ -241,7 +246,7 @@ def test_quality_of_service_average_build_mttr
Time.stub(:now, Time.parse('2024-08-09 21:00:00 UTC')) do
load_it('quality-of-service', fb)
f = fb.query('(eq what "quality-of-service")').each.to_a.first
assert_in_delta((3900 + 4200) / 2.0, f.average_build_mttr)
assert_in_delta(3600, f.average_build_mttr)
end
end

Expand All @@ -261,6 +266,7 @@ def test_quality_of_service_average_build_mttr_when_failure_several_times_in_a_r
workflow_id: 101,
created_at: '2024-08-07T10:00:00Z',
updated_at: '2024-08-07T10:10:00Z',
run_started_at: '2024-08-07T10:00:00Z',
repository: { full_name: 'foo/foo' }
},
{
Expand All @@ -274,6 +280,7 @@ def test_quality_of_service_average_build_mttr_when_failure_several_times_in_a_r
workflow_id: 101,
created_at: '2024-08-07T11:00:00Z',
updated_at: '2024-08-07T11:15:00Z',
run_started_at: '2024-08-07T11:00:00Z',
repository: { full_name: 'foo/foo' }
},
{
Expand All @@ -287,6 +294,7 @@ def test_quality_of_service_average_build_mttr_when_failure_several_times_in_a_r
workflow_id: 101,
created_at: '2024-08-08T12:00:00Z',
updated_at: '2024-08-08T12:10:00Z',
run_started_at: '2024-08-08T12:00:00Z',
repository: { full_name: 'foo/foo' }
},
{
Expand All @@ -300,6 +308,7 @@ def test_quality_of_service_average_build_mttr_when_failure_several_times_in_a_r
workflow_id: 101,
created_at: '2024-08-08T13:00:00Z',
updated_at: '2024-08-08T13:20:00Z',
run_started_at: '2024-08-08T13:00:00Z',
repository: { full_name: 'foo/foo' }
},
{
Expand All @@ -313,6 +322,7 @@ def test_quality_of_service_average_build_mttr_when_failure_several_times_in_a_r
workflow_id: 101,
created_at: '2024-08-08T14:00:00Z',
updated_at: '2024-08-08T14:20:00Z',
run_started_at: '2024-08-08T14:00:00Z',
repository: { full_name: 'foo/foo' }
}
]
Expand All @@ -326,7 +336,7 @@ def test_quality_of_service_average_build_mttr_when_failure_several_times_in_a_r
Time.stub(:now, Time.parse('2024-08-09 21:00:00 UTC')) do
load_it('quality-of-service', fb)
f = fb.query('(eq what "quality-of-service")').each.to_a.first
assert_in_delta(97_500, f.average_build_mttr)
assert_in_delta(97_200, f.average_build_mttr)
end
end

Expand Down

0 comments on commit 337b2e8

Please sign in to comment.