Commit 69179973 authored by Adam Hegyi's avatar Adam Hegyi Committed by Vitali Tatarintev

Use aggregated VSA backend in time summary

parent 70667ba9
......@@ -23,6 +23,7 @@ module CycleAnalyticsParams
opts[:from] = params[:from] || start_date(params)
opts[:to] = params[:to] if params[:to]
opts[:end_event_filter] = params[:end_event_filter] if params[:end_event_filter]
opts[:use_aggregated_data_collector] = params[:use_aggregated_data_collector] if params[:use_aggregated_data_collector]
opts.merge!(params.slice(*::Gitlab::Analytics::CycleAnalytics::RequestParams::FINDER_PARAM_NAMES))
opts.merge!(date_range(params))
end
......
......@@ -10,7 +10,7 @@ module Gitlab
@current_user = current_user
@options = options
assign_event_identifiers
assign_stage_metadata
end
def value
......@@ -35,10 +35,20 @@ module Gitlab
private
def assign_event_identifiers
# rubocop: disable CodeReuse/ActiveRecord
def assign_stage_metadata
@stage.start_event_identifier = self.class.start_event_identifier
@stage.end_event_identifier = self.class.end_event_identifier
if @options[:use_aggregated_data_collector]
# Gitlab::Analytics::CycleAnalytics::DistinctStageLoader ensures that we have StageEventHash record
# for the subclasses (LeadTime, CycleTime) however, it is an asynchronous process. There can be a short period
# of time where the query below returns nil. To handle this, we're pre-setting "None" value.
@stage.stage_event_hash_id = ::Analytics::CycleAnalytics::StageEventHash.find_by(hash_sha256: @stage.events_hash_code)&.id
@value = Gitlab::CycleAnalytics::Summary::Value::None.new if @stage.stage_event_hash_id.blank?
end
end
# rubocop: enable CodeReuse/ActiveRecord
def data_collector
Gitlab::Analytics::CycleAnalytics::DataCollector.new(
......@@ -48,7 +58,8 @@ module Gitlab
to: @options[:to] || DateTime.now,
project_ids: @options[:projects],
end_event_filter: @options[:end_event_filter],
current_user: @current_user
current_user: @current_user,
use_aggregated_data_collector: @options[:use_aggregated_data_collector]
}.merge(@options.slice(*::Gitlab::Analytics::CycleAnalytics::RequestParams::FINDER_PARAM_NAMES))
)
end
......
......@@ -4,7 +4,8 @@ require 'spec_helper'
RSpec.describe Projects::Analytics::CycleAnalytics::SummaryController do
let_it_be(:user) { create(:user) }
let_it_be(:project) { create(:project) }
let_it_be(:group) { create(:group) }
let_it_be(:project) { create(:project, group: group) }
let(:params) { { namespace_id: project.namespace.to_param, project_id: project.to_param, created_after: '2010-01-01', created_before: '2020-01-02' } }
......@@ -26,7 +27,9 @@ RSpec.describe Projects::Analytics::CycleAnalytics::SummaryController do
context 'when cycle_analytics_for_projects feature is available' do
before do
stub_licensed_features(cycle_analytics_for_projects: true)
stub_licensed_features(cycle_analytics_for_projects: true, cycle_analytics_for_groups: true)
Analytics::CycleAnalytics::GroupDataLoaderWorker.new.perform(group.id, 'Issue')
project.add_reporter(user)
end
......@@ -45,6 +48,20 @@ RSpec.describe Projects::Analytics::CycleAnalytics::SummaryController do
expect(json_response.last["value"].to_i).to eq(expected_cycle_time)
end
context 'when the use_vsa_aggregated_tables FF is off' do
before do
stub_feature_flags(use_vsa_aggregated_tables: false)
end
it 'returns correct value' do
expected_cycle_time = (closed_at - first_mentioned_in_commit_at).to_i
subject
expect(json_response.last["value"].to_i).to eq(expected_cycle_time)
end
end
context 'when analytics_disabled features are disabled' do
it 'renders 404' do
project.add_reporter(user)
......
......@@ -23,6 +23,35 @@ RSpec.describe Gitlab::Analytics::CycleAnalytics::Summary::StageTimeSummary do
group.add_owner(user)
end
context 'when the use_aggregated_data_collector option is given' do
context 'when aggregated data is available yet' do
it 'shows no value' do
lead_time, cycle_time, * = subject
expect(lead_time[:value]).to eq('-')
expect(cycle_time[:value]).to eq('-')
end
end
context 'when aggregated data is present' do
before do
issue = create(:closed_issue, project: project, created_at: 1.day.ago, closed_at: Time.current)
issue.metrics.update!(first_mentioned_in_commit_at: 2.days.ago)
options[:use_aggregated_data_collector] = true
stub_licensed_features(cycle_analytics_for_groups: true)
Analytics::CycleAnalytics::GroupDataLoaderWorker.new.perform(group.id, 'Issue')
end
it 'loads the lead and cycle time' do
lead_time, cycle_time, * = subject
expect(lead_time[:value]).to eq('1.0')
expect(cycle_time[:value]).to eq('2.0')
end
end
end
describe '#lead_time' do
describe 'issuable filter parameters' do
let_it_be(:label) { create(:group_label, group: group) }
......
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