Commit f81dd64f authored by Robert Speicher's avatar Robert Speicher Committed by Ruben Davila

Merge branch 'wall-clock-time-for-showing-pipeline' into 'master'

Show wall-clock time when showing pipeline

Show wall-clock time when showing pipeline instead of cumulative builds time.

Closes #17007

See merge request !5734
parent 9d71605b
...@@ -37,6 +37,7 @@ v 8.11.0 (unreleased) ...@@ -37,6 +37,7 @@ v 8.11.0 (unreleased)
- API: Add deployment endpoints - API: Add deployment endpoints
- API: Add Play endpoint on Builds - API: Add Play endpoint on Builds
- Fix of 'Commits being passed to custom hooks are already reachable when using the UI' - Fix of 'Commits being passed to custom hooks are already reachable when using the UI'
- Show wall clock time when showing a pipeline. !5734
- Show member roles to all users on members page - Show member roles to all users on members page
- Project.visible_to_user is instrumented again - Project.visible_to_user is instrumented again
- Fix awardable button mutuality loading spinners (ClemMakesApps) - Fix awardable button mutuality loading spinners (ClemMakesApps)
......
...@@ -15,20 +15,9 @@ module TimeHelper ...@@ -15,20 +15,9 @@ module TimeHelper
"#{from.to_s(:short)} - #{to.to_s(:short)}" "#{from.to_s(:short)} - #{to.to_s(:short)}"
end end
def duration_in_numbers(finished_at, started_at) def duration_in_numbers(duration)
interval = interval_in_seconds(started_at, finished_at) time_format = duration < 1.hour ? "%M:%S" : "%H:%M:%S"
time_format = interval < 1.hour ? "%M:%S" : "%H:%M:%S"
Time.at(interval).utc.strftime(time_format) Time.at(duration).utc.strftime(time_format)
end
private
def interval_in_seconds(started_at, finished_at = nil)
if started_at && finished_at
finished_at.to_i - started_at.to_i
elsif started_at
Time.now.to_i - started_at.to_i
end
end end
end end
...@@ -72,6 +72,10 @@ module Ci ...@@ -72,6 +72,10 @@ module Ci
CommitStatus.where(pipeline: pluck(:id)).stages CommitStatus.where(pipeline: pluck(:id)).stages
end end
def self.total_duration
where.not(duration: nil).sum(:duration)
end
def stages_with_latest_statuses def stages_with_latest_statuses
statuses.latest.order(:stage_idx).group_by(&:stage) statuses.latest.order(:stage_idx).group_by(&:stage)
end end
...@@ -248,7 +252,7 @@ module Ci ...@@ -248,7 +252,7 @@ module Ci
end end
def update_duration def update_duration
self.duration = statuses.latest.duration self.duration = calculate_duration
end end
private private
......
...@@ -21,6 +21,7 @@ class CommitStatus < ActiveRecord::Base ...@@ -21,6 +21,7 @@ class CommitStatus < ActiveRecord::Base
where(id: max_id.group(:name, :commit_id)) where(id: max_id.group(:name, :commit_id))
end end
scope :retried, -> { where.not(id: latest) } scope :retried, -> { where.not(id: latest) }
scope :ordered, -> { order(:name) } scope :ordered, -> { order(:name) }
scope :ignored, -> { where(allow_failure: true, status: [:failed, :canceled]) } scope :ignored, -> { where(allow_failure: true, status: [:failed, :canceled]) }
...@@ -111,13 +112,7 @@ class CommitStatus < ActiveRecord::Base ...@@ -111,13 +112,7 @@ class CommitStatus < ActiveRecord::Base
end end
def duration def duration
duration = calculate_duration
if started_at && finished_at
finished_at - started_at
elsif started_at
Time.now - started_at
end
duration
end end
def stuck? def stuck?
......
...@@ -35,11 +35,6 @@ module Statuseable ...@@ -35,11 +35,6 @@ module Statuseable
all.pluck(self.status_sql).first all.pluck(self.status_sql).first
end end
def duration
duration_array = all.map(&:duration).compact
duration_array.reduce(:+)
end
def started_at def started_at
all.minimum(:started_at) all.minimum(:started_at)
end end
...@@ -85,4 +80,14 @@ module Statuseable ...@@ -85,4 +80,14 @@ module Statuseable
def complete? def complete?
COMPLETED_STATUSES.include?(status) COMPLETED_STATUSES.include?(status)
end end
private
def calculate_duration
if started_at && finished_at
finished_at - started_at
elsif started_at
Time.now - started_at
end
end
end end
...@@ -51,7 +51,7 @@ ...@@ -51,7 +51,7 @@
- if build.duration - if build.duration
%p.duration %p.duration
= custom_icon("icon_timer") = custom_icon("icon_timer")
= duration_in_numbers(build.finished_at, build.started_at) = duration_in_numbers(build.duration)
- if build.finished_at - if build.finished_at
%p.finished-at %p.finished-at
......
...@@ -63,7 +63,7 @@ ...@@ -63,7 +63,7 @@
- if build.duration - if build.duration
%p.duration %p.duration
= custom_icon("icon_timer") = custom_icon("icon_timer")
= duration_in_numbers(build.finished_at, build.started_at) = duration_in_numbers(build.duration)
- if build.finished_at - if build.finished_at
%p.finished-at %p.finished-at
= icon("calendar") = icon("calendar")
......
...@@ -48,10 +48,10 @@ ...@@ -48,10 +48,10 @@
\- \-
%td %td
- if pipeline.started_at && pipeline.finished_at - if pipeline.duration
%p.duration %p.duration
= custom_icon("icon_timer") = custom_icon("icon_timer")
= duration_in_numbers(pipeline.finished_at, pipeline.started_at) = duration_in_numbers(pipeline.duration)
- if pipeline.finished_at - if pipeline.finished_at
%p.finished-at %p.finished-at
= icon("calendar") = icon("calendar")
......
...@@ -56,10 +56,10 @@ ...@@ -56,10 +56,10 @@
= pluralize(@commit.pipelines.count, 'pipeline') = pluralize(@commit.pipelines.count, 'pipeline')
= link_to builds_namespace_project_commit_path(@project.namespace, @project, @commit.id), class: "ci-status-link ci-status-icon-#{@commit.status}" do = link_to builds_namespace_project_commit_path(@project.namespace, @project, @commit.id), class: "ci-status-link ci-status-icon-#{@commit.status}" do
= ci_icon_for_status(@commit.status) = ci_icon_for_status(@commit.status)
= ci_label_for_status(@commit.status) %span.ci-status-label
- if @commit.pipelines.duration = ci_label_for_status(@commit.status)
in in
= time_interval_in_words @commit.pipelines.duration = time_interval_in_words @commit.pipelines.total_duration
.commit-box.content-block .commit-box.content-block
%h3.commit-title %h3.commit-title
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
= link_to @pipeline.ref, namespace_project_commits_path(@project.namespace, @project, @pipeline.ref), class: "monospace" = link_to @pipeline.ref, namespace_project_commits_path(@project.namespace, @project, @pipeline.ref), class: "monospace"
- if @pipeline.duration - if @pipeline.duration
in in
= time_interval_in_words @pipeline.duration = time_interval_in_words(@pipeline.duration)
.pull-right .pull-right
= link_to namespace_project_pipeline_path(@project.namespace, @project, @pipeline), class: "ci-status ci-#{@pipeline.status}" do = link_to namespace_project_pipeline_path(@project.namespace, @project, @pipeline), class: "ci-status ci-#{@pipeline.status}" do
......
...@@ -7,7 +7,7 @@ module Gitlab ...@@ -7,7 +7,7 @@ module Gitlab
# @param cmd [Array<String>] # @param cmd [Array<String>]
# @return [Boolean] # @return [Boolean]
def system_silent(cmd) def system_silent(cmd)
Popen::popen(cmd).last.zero? Popen.popen(cmd).last.zero?
end end
def force_utf8(str) def force_utf8(str)
......
...@@ -19,16 +19,16 @@ describe TimeHelper do ...@@ -19,16 +19,16 @@ describe TimeHelper do
describe "#duration_in_numbers" do describe "#duration_in_numbers" do
it "returns minutes and seconds" do it "returns minutes and seconds" do
duration_in_numbers = { durations_and_expectations = {
[100, 0] => "01:40", 100 => "01:40",
[121, 0] => "02:01", 121 => "02:01",
[3721, 0] => "01:02:01", 3721 => "01:02:01",
[0, 0] => "00:00", 0 => "00:00",
[nil, Time.now.to_i - 42] => "00:42" 42 => "00:42"
} }
duration_in_numbers.each do |interval, expectation| durations_and_expectations.each do |duration, expectation|
expect(duration_in_numbers(*interval)).to eq(expectation) expect(duration_in_numbers(duration)).to eq(expectation)
end end
end end
end end
......
require 'spec_helper' require 'spec_helper'
describe BroadcastMessage, models: true do describe BroadcastMessage, models: true do
include ActiveSupport::Testing::TimeHelpers
subject { create(:broadcast_message) } subject { create(:broadcast_message) }
it { is_expected.to be_valid } it { is_expected.to be_valid }
......
...@@ -122,17 +122,21 @@ describe Ci::Pipeline, models: true do ...@@ -122,17 +122,21 @@ describe Ci::Pipeline, models: true do
describe 'state machine' do describe 'state machine' do
let(:current) { Time.now.change(usec: 0) } let(:current) { Time.now.change(usec: 0) }
let(:build) { create :ci_build, name: 'build1', pipeline: pipeline, started_at: current - 60, finished_at: current } let(:build) { create :ci_build, name: 'build1', pipeline: pipeline }
let(:build2) { create :ci_build, name: 'build2', pipeline: pipeline, started_at: current - 60, finished_at: current }
describe '#duration' do describe '#duration' do
before do before do
build.skip travel_to(current - 120) do
build2.skip pipeline.run
end
travel_to(current) do
pipeline.succeed
end
end end
it 'matches sum of builds duration' do it 'matches sum of builds duration' do
expect(pipeline.reload.duration).to eq(build.duration + build2.duration) expect(pipeline.reload.duration).to eq(120)
end end
end end
......
...@@ -33,6 +33,7 @@ RSpec.configure do |config| ...@@ -33,6 +33,7 @@ RSpec.configure do |config|
config.include EmailHelpers config.include EmailHelpers
config.include TestEnv config.include TestEnv
config.include ActiveJob::TestHelper config.include ActiveJob::TestHelper
config.include ActiveSupport::Testing::TimeHelpers
config.include StubGitlabCalls config.include StubGitlabCalls
config.include StubGitlabData config.include StubGitlabData
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment