Commit 541e6c24 authored by Adam Hegyi's avatar Adam Hegyi

Fix VSA code stage query

Fix VSA code stage query with GROUP BY clause when multiple labels are
given as filter parameter.
parent 67a0b331
...@@ -24,6 +24,7 @@ module Gitlab ...@@ -24,6 +24,7 @@ module Gitlab
Arel.sql("#{join_expression_name}.created_at") Arel.sql("#{join_expression_name}.created_at")
end end
override :column_list
def column_list def column_list
[timestamp_projection] [timestamp_projection]
end end
......
...@@ -19,7 +19,8 @@ RSpec.describe Gitlab::Analytics::CycleAnalytics::DataCollector do ...@@ -19,7 +19,8 @@ RSpec.describe Gitlab::Analytics::CycleAnalytics::DataCollector do
# `create_data_for_end_event`. For each stage we create 3 records with a fixed # `create_data_for_end_event`. For each stage we create 3 records with a fixed
# durations (10, 5, 15 days) in order to easily generalize the test cases. # durations (10, 5, 15 days) in order to easily generalize the test cases.
shared_examples 'custom cycle analytics stage' do shared_examples 'custom cycle analytics stage' do
let(:data_collector) { described_class.new(stage: stage, params: { from: Time.new(2019), to: Time.new(2020), current_user: user }) } let(:params) { { from: Time.new(2019), to: Time.new(2020), current_user: user } }
let(:data_collector) { described_class.new(stage: stage, params: params) }
before do before do
# takes 10 days # takes 10 days
...@@ -87,7 +88,7 @@ RSpec.describe Gitlab::Analytics::CycleAnalytics::DataCollector do ...@@ -87,7 +88,7 @@ RSpec.describe Gitlab::Analytics::CycleAnalytics::DataCollector do
it_behaves_like 'custom cycle analytics stage' it_behaves_like 'custom cycle analytics stage'
end end
describe 'between issue creation time and closing time' do context 'between issue creation time and closing time' do
let(:start_event_identifier) { :issue_created } let(:start_event_identifier) { :issue_created }
let(:end_event_identifier) { :issue_closed } let(:end_event_identifier) { :issue_closed }
...@@ -102,7 +103,7 @@ RSpec.describe Gitlab::Analytics::CycleAnalytics::DataCollector do ...@@ -102,7 +103,7 @@ RSpec.describe Gitlab::Analytics::CycleAnalytics::DataCollector do
it_behaves_like 'custom cycle analytics stage' it_behaves_like 'custom cycle analytics stage'
end end
describe 'between issue first mentioned in commit and first associated with milestone time' do context 'between issue first mentioned in commit and first associated with milestone time' do
let(:start_event_identifier) { :issue_first_mentioned_in_commit } let(:start_event_identifier) { :issue_first_mentioned_in_commit }
let(:end_event_identifier) { :issue_first_associated_with_milestone } let(:end_event_identifier) { :issue_first_associated_with_milestone }
...@@ -119,7 +120,7 @@ RSpec.describe Gitlab::Analytics::CycleAnalytics::DataCollector do ...@@ -119,7 +120,7 @@ RSpec.describe Gitlab::Analytics::CycleAnalytics::DataCollector do
it_behaves_like 'custom cycle analytics stage' it_behaves_like 'custom cycle analytics stage'
end end
describe 'between issue creation time and first added to board time' do context 'between issue creation time and first added to board time' do
let(:start_event_identifier) { :issue_created } let(:start_event_identifier) { :issue_created }
let(:end_event_identifier) { :issue_first_added_to_board } let(:end_event_identifier) { :issue_first_added_to_board }
...@@ -134,7 +135,7 @@ RSpec.describe Gitlab::Analytics::CycleAnalytics::DataCollector do ...@@ -134,7 +135,7 @@ RSpec.describe Gitlab::Analytics::CycleAnalytics::DataCollector do
it_behaves_like 'custom cycle analytics stage' it_behaves_like 'custom cycle analytics stage'
end end
describe 'between issue creation time and last edit time' do context 'between issue creation time and last edit time' do
let(:start_event_identifier) { :issue_created } let(:start_event_identifier) { :issue_created }
let(:end_event_identifier) { :issue_last_edited } let(:end_event_identifier) { :issue_last_edited }
...@@ -149,7 +150,7 @@ RSpec.describe Gitlab::Analytics::CycleAnalytics::DataCollector do ...@@ -149,7 +150,7 @@ RSpec.describe Gitlab::Analytics::CycleAnalytics::DataCollector do
it_behaves_like 'custom cycle analytics stage' it_behaves_like 'custom cycle analytics stage'
end end
describe 'between issue label added time and label removed time' do context 'between issue label added time and label removed time' do
let(:start_event_identifier) { :issue_label_added } let(:start_event_identifier) { :issue_label_added }
let(:end_event_identifier) { :issue_label_removed } let(:end_event_identifier) { :issue_label_removed }
...@@ -181,7 +182,7 @@ RSpec.describe Gitlab::Analytics::CycleAnalytics::DataCollector do ...@@ -181,7 +182,7 @@ RSpec.describe Gitlab::Analytics::CycleAnalytics::DataCollector do
it_behaves_like 'custom cycle analytics stage' it_behaves_like 'custom cycle analytics stage'
end end
describe 'between issue label added time and another issue label added time' do context 'between issue label added time and another issue label added time' do
let(:start_event_identifier) { :issue_label_added } let(:start_event_identifier) { :issue_label_added }
let(:end_event_identifier) { :issue_label_added } let(:end_event_identifier) { :issue_label_added }
...@@ -230,7 +231,7 @@ RSpec.describe Gitlab::Analytics::CycleAnalytics::DataCollector do ...@@ -230,7 +231,7 @@ RSpec.describe Gitlab::Analytics::CycleAnalytics::DataCollector do
end end
end end
describe 'between issue creation time and issue label added time' do context 'between issue creation time and issue label added time' do
let(:start_event_identifier) { :issue_created } let(:start_event_identifier) { :issue_created }
let(:end_event_identifier) { :issue_label_added } let(:end_event_identifier) { :issue_label_added }
...@@ -304,7 +305,7 @@ RSpec.describe Gitlab::Analytics::CycleAnalytics::DataCollector do ...@@ -304,7 +305,7 @@ RSpec.describe Gitlab::Analytics::CycleAnalytics::DataCollector do
it_behaves_like 'custom cycle analytics stage' it_behaves_like 'custom cycle analytics stage'
end end
describe 'between merge request creation time and close time' do context 'between merge request creation time and close time' do
let(:start_event_identifier) { :merge_request_created } let(:start_event_identifier) { :merge_request_created }
let(:end_event_identifier) { :merge_request_closed } let(:end_event_identifier) { :merge_request_closed }
...@@ -319,7 +320,7 @@ RSpec.describe Gitlab::Analytics::CycleAnalytics::DataCollector do ...@@ -319,7 +320,7 @@ RSpec.describe Gitlab::Analytics::CycleAnalytics::DataCollector do
it_behaves_like 'custom cycle analytics stage' it_behaves_like 'custom cycle analytics stage'
end end
describe 'between merge request creation time and last edit time' do context 'between merge request creation time and last edit time' do
let(:start_event_identifier) { :merge_request_created } let(:start_event_identifier) { :merge_request_created }
let(:end_event_identifier) { :merge_request_last_edited } let(:end_event_identifier) { :merge_request_last_edited }
...@@ -334,7 +335,7 @@ RSpec.describe Gitlab::Analytics::CycleAnalytics::DataCollector do ...@@ -334,7 +335,7 @@ RSpec.describe Gitlab::Analytics::CycleAnalytics::DataCollector do
it_behaves_like 'custom cycle analytics stage' it_behaves_like 'custom cycle analytics stage'
end end
describe 'between merge request label added time and label removed time' do context 'between merge request label added time and label removed time' do
let(:start_event_identifier) { :merge_request_label_added } let(:start_event_identifier) { :merge_request_label_added }
let(:end_event_identifier) { :merge_request_label_removed } let(:end_event_identifier) { :merge_request_label_removed }
...@@ -365,6 +366,41 @@ RSpec.describe Gitlab::Analytics::CycleAnalytics::DataCollector do ...@@ -365,6 +366,41 @@ RSpec.describe Gitlab::Analytics::CycleAnalytics::DataCollector do
it_behaves_like 'custom cycle analytics stage' it_behaves_like 'custom cycle analytics stage'
end end
context 'between code stage start time and merge request created time with label filter' do
let(:start_event_identifier) { :code_stage_start }
let(:end_event_identifier) { :merge_request_created }
before do
params[:label_name] = [label.name, other_label.name]
end
def create_data_for_start_event(example_class)
issue = create(:issue, project: example_class.project)
issue.metrics.update!(first_mentioned_in_commit_at: Time.zone.now)
mr = create(:merge_request, {
source_project: example_class.project,
target_branch: example_class.project.default_branch,
description: "Description\n\nclosing #{issue.to_reference}",
allow_broken: true
})
MergeRequests::UpdateService.new(
example_class.project,
user,
label_ids: [label.id, other_label.id]
).execute(mr)
mr
end
def create_data_for_end_event(mr, example_class)
mr.update!(created_at: Time.zone.now)
end
it_behaves_like 'custom cycle analytics stage'
end
end end
end end
......
...@@ -21,6 +21,11 @@ module Gitlab ...@@ -21,6 +21,11 @@ module Gitlab
issue_metrics_table[:first_mentioned_in_commit_at] issue_metrics_table[:first_mentioned_in_commit_at]
end end
override :column_list
def column_list
[timestamp_projection]
end
# rubocop: disable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord
def apply_query_customization(query) def apply_query_customization(query)
issue_metrics_join = mr_closing_issues_table issue_metrics_join = mr_closing_issues_table
......
...@@ -21,6 +21,7 @@ module Gitlab ...@@ -21,6 +21,7 @@ module Gitlab
Arel::Nodes::NamedFunction.new('COALESCE', column_list) Arel::Nodes::NamedFunction.new('COALESCE', column_list)
end end
override :column_list
def column_list def column_list
[ [
issue_metrics_table[:first_associated_with_milestone_at], issue_metrics_table[:first_associated_with_milestone_at],
......
...@@ -11,6 +11,7 @@ module Gitlab ...@@ -11,6 +11,7 @@ module Gitlab
end end
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
override :column_list
def column_list def column_list
[timestamp_projection] [timestamp_projection]
end end
......
...@@ -21,6 +21,7 @@ module Gitlab ...@@ -21,6 +21,7 @@ module Gitlab
Arel::Nodes::NamedFunction.new('COALESCE', column_list) Arel::Nodes::NamedFunction.new('COALESCE', column_list)
end end
override :column_list
def column_list def column_list
[ [
issue_metrics_table[:first_associated_with_milestone_at], issue_metrics_table[:first_associated_with_milestone_at],
......
...@@ -21,6 +21,7 @@ module Gitlab ...@@ -21,6 +21,7 @@ module Gitlab
mr_metrics_table[:first_deployed_to_production_at] mr_metrics_table[:first_deployed_to_production_at]
end end
override :column_list
def column_list def column_list
[timestamp_projection] [timestamp_projection]
end end
......
...@@ -7,6 +7,7 @@ module Gitlab ...@@ -7,6 +7,7 @@ module Gitlab
# Base class for expressing an event that can be used for a stage. # Base class for expressing an event that can be used for a stage.
class StageEvent class StageEvent
include Gitlab::CycleAnalytics::MetricsTables include Gitlab::CycleAnalytics::MetricsTables
extend Gitlab::Utils::Override
delegate :label_based?, to: :class delegate :label_based?, to: :class
......
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