Skip to content
Snippets Groups Projects
Commit b50c5c72 authored by Adam Hegyi's avatar Adam Hegyi
Browse files

Merge branch '361746-vsa-lead-and-cycle-times-time-series-data' into 'master'

Add cycle and lead times time series endpoint

See merge request !91029
parents 82dc78dc 29ca7c54
No related branches found
No related tags found
1 merge request!91029Add cycle and lead times time series endpoint
Pipeline #577859596 passed
......@@ -21,6 +21,16 @@ def time_summary
render json: group_level.time_summary
end
def lead_times
data_collector = data_collector_for(::Gitlab::Analytics::CycleAnalytics::Summary::LeadTime)
render json: ::Analytics::CycleAnalytics::DurationChartAverageItemEntity.represent(data_collector.duration_chart_average_data)
end
def cycle_times
data_collector = data_collector_for(::Gitlab::Analytics::CycleAnalytics::Summary::CycleTime)
render json: ::Analytics::CycleAnalytics::DurationChartAverageItemEntity.represent(data_collector.duration_chart_average_data)
end
private
def group_level
......@@ -35,6 +45,17 @@ def authorize_access
def all_cycle_analytics_params
super.merge({ group: @group })
end
def data_collector_for(summary_class)
group_stage = ::Analytics::CycleAnalytics::GroupStage.new(group: @group)
all_params = request_params.to_data_collector_params
group_stage_with_metadata = summary_class.new(stage: group_stage, current_user: current_user, options: all_params).stage
Gitlab::Analytics::CycleAnalytics::DataCollector.new(
stage: group_stage_with_metadata,
params: all_params
)
end
end
end
end
......
......@@ -53,6 +53,8 @@
end
resource :summary, controller: :summary, only: :show
get '/time_summary' => 'summary#time_summary'
get '/lead_times' => 'summary#lead_times'
get '/cycle_times' => 'summary#cycle_times'
end
get '/cycle_analytics', to: redirect('-/analytics/value_stream_analytics')
......
......@@ -7,6 +7,8 @@ module Summary
class BaseTime
include Gitlab::CycleAnalytics::Summary::Defaults
attr_reader :stage
def initialize(stage:, current_user:, options:)
@stage = stage
@current_user = current_user
......
......@@ -69,4 +69,55 @@
expect(response).to be_successful
end
end
describe 'time series endpoints' do
let(:params) { { group_id: group.full_path, created_after: 15.days.ago.to_date } }
let_it_be(:created_at1) { 5.days.ago }
let_it_be(:created_at2) { 10.days.ago }
let_it_be(:project) { create(:project, group: group) }
let_it_be(:issue1) { create(:issue, project: project, created_at: created_at1, closed_at: created_at1 + 3.days) }
let_it_be(:issue2) { create(:issue, project: project, created_at: created_at2, closed_at: created_at2 + 8.days) }
before(:context) do
issue1.metrics.update!(first_mentioned_in_commit_at: created_at1 + 2.days)
issue2.metrics.update!(first_mentioned_in_commit_at: created_at2 + 7.days)
end
before do
Analytics::CycleAnalytics::DataLoaderService.new(group: group, model: Issue).execute
end
describe 'GET "lead_times"' do
subject { get :lead_times, params: params }
it_behaves_like 'summary endpoint'
it 'returns the daily average durations' do
subject
# duration between created_at and closed_at
expect(json_response).to eq([{
'average_duration_in_seconds' => (3.days.seconds + 8.days.seconds).fdiv(2),
'date' => issue1.closed_at.to_date.to_s
}])
end
end
describe 'GET "cycle_times"' do
subject { get :cycle_times, params: params }
it_behaves_like 'summary endpoint'
it 'returns the daily average durations' do
subject
# duration between first_mentioned_in_commit_at and closed_at
expect(json_response).to eq([{
'average_duration_in_seconds' => 2.days.seconds.fdiv(2),
'date' => issue1.closed_at.to_date.to_s
}])
end
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment