Commit de8d9965 authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Merge branch 'clean-up-query_deploymenys_via_finished_at_in_vsa-ff' into 'master'

Remove VSA deployment query feature flag [RUN ALL RSPEC] [RUN AS-IF-FOSS]

See merge request gitlab-org/gitlab!54823
parents 528e71ae 6ef9a91d
---
name: query_deploymenys_via_finished_at_in_vsa
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/53050
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/300649
milestone: '13.9'
type: development
group: group::optimize
default_enabled: true
......@@ -20,19 +20,13 @@ module Gitlab
# rubocop: disable CodeReuse/ActiveRecord
def deployments_count
@deployments_count ||= if Feature.enabled?(:query_deploymenys_via_finished_at_in_vsa, default_enabled: :yaml)
@deployments_count ||= begin
deployments = DeploymentsFinder
.new(group: group, finished_after: options[:from], finished_before: options[:to], status: :success)
.execute
deployments = deployments.where(project_id: options[:projects]) if options[:projects].present?
deployments.count
else
deployments = Deployment.joins(:project).merge(Project.inside_path(group.full_path))
deployments = deployments.where(projects: { id: options[:projects] }) if options[:projects].present?
deployments = deployments.where("deployments.created_at > ?", options[:from])
deployments = deployments.where("deployments.created_at < ?", options[:to]) if options[:to]
deployments.success.count
end
end
# rubocop: enable CodeReuse/ActiveRecord
......
......@@ -127,71 +127,69 @@ RSpec.describe Gitlab::Analytics::CycleAnalytics::Summary::Group::StageSummary d
end
end
shared_examples 'shared examples for #deploys' do
describe "#deploys" do
context 'with from date' do
before do
travel_to(5.days.ago) { create(:deployment, :success, project: project, finished_at: Time.zone.now) }
travel_to(5.days.from_now) { create(:deployment, :success, project: project, finished_at: Time.zone.now) }
travel_to(5.days.ago) { create(:deployment, :success, project: project_2, finished_at: Time.zone.now) }
travel_to(5.days.from_now) { create(:deployment, :success, project: project_2, finished_at: Time.zone.now) }
end
describe "#deploys" do
context 'with from date' do
before do
travel_to(5.days.ago) { create(:deployment, :success, project: project, finished_at: Time.zone.now) }
travel_to(5.days.from_now) { create(:deployment, :success, project: project, finished_at: Time.zone.now) }
travel_to(5.days.ago) { create(:deployment, :success, project: project_2, finished_at: Time.zone.now) }
travel_to(5.days.from_now) { create(:deployment, :success, project: project_2, finished_at: Time.zone.now) }
end
it "finds the number of deploys made created after it" do
expect(subject.second[:value]).to eq('2')
end
it "finds the number of deploys made created after it" do
expect(subject.second[:value]).to eq('2')
end
it 'returns the localized title' do
Gitlab::I18n.with_locale(:ru) do
expect(subject.second[:title]).to eq(n_('Deploy', 'Deploys', 2))
end
it 'returns the localized title' do
Gitlab::I18n.with_locale(:ru) do
expect(subject.second[:title]).to eq(n_('Deploy', 'Deploys', 2))
end
end
context 'with subgroups' do
before do
travel_to(5.days.from_now) do
create(:deployment, :success, finished_at: Time.zone.now, project: create(:project, :repository, namespace: create(:group, parent: group)))
end
context 'with subgroups' do
before do
travel_to(5.days.from_now) do
create(:deployment, :success, finished_at: Time.zone.now, project: create(:project, :repository, namespace: create(:group, parent: group)))
end
end
it "finds deploys from them" do
expect(subject.second[:value]).to eq('3')
end
it "finds deploys from them" do
expect(subject.second[:value]).to eq('3')
end
end
context 'with projects specified in options' do
before do
travel_to(5.days.from_now) do
create(:deployment, :success, finished_at: Time.zone.now, project: create(:project, :repository, namespace: group, name: 'not_applicable'))
end
context 'with projects specified in options' do
before do
travel_to(5.days.from_now) do
create(:deployment, :success, finished_at: Time.zone.now, project: create(:project, :repository, namespace: group, name: 'not_applicable'))
end
end
subject { described_class.new(group, options: { from: Time.now, current_user: user, projects: [project.id, project_2.id] }).data }
subject { described_class.new(group, options: { from: Time.now, current_user: user, projects: [project.id, project_2.id] }).data }
it 'shows deploys from those projects' do
expect(subject.second[:value]).to eq('2')
end
it 'shows deploys from those projects' do
expect(subject.second[:value]).to eq('2')
end
end
context 'when `from` and `to` parameters are provided' do
subject { described_class.new(group, options: { from: 10.days.ago, to: Time.now, current_user: user }).data }
context 'when `from` and `to` parameters are provided' do
subject { described_class.new(group, options: { from: 10.days.ago, to: Time.now, current_user: user }).data }
it 'finds deployments from 5 days ago' do
expect(subject.second[:value]).to eq('2')
end
it 'finds deployments from 5 days ago' do
expect(subject.second[:value]).to eq('2')
end
end
end
context 'with other projects' do
before do
travel_to(5.days.from_now) do
create(:deployment, :success, finished_at: Time.zone.now, project: create(:project, :repository, namespace: create(:group)))
end
context 'with other projects' do
before do
travel_to(5.days.from_now) do
create(:deployment, :success, finished_at: Time.zone.now, project: create(:project, :repository, namespace: create(:group)))
end
end
it "doesn't find deploys from them" do
expect(subject.second[:value]).to eq('-')
end
it "doesn't find deploys from them" do
expect(subject.second[:value]).to eq('-')
end
end
......@@ -241,20 +239,4 @@ RSpec.describe Gitlab::Analytics::CycleAnalytics::Summary::Group::StageSummary d
end
end
end
context 'when query_deploymenys_via_finished_at_in_vsa feature flag is enabled' do
before do
stub_feature_flags(query_deploymenys_via_finished_at_in_vsa: true)
end
it_behaves_like 'shared examples for #deploys'
end
context 'when query_deploymenys_via_finished_at_in_vsa feature flag is disabled' do
before do
stub_feature_flags(query_deploymenys_via_finished_at_in_vsa: false)
end
it_behaves_like 'shared examples for #deploys'
end
end
......@@ -15,16 +15,10 @@ module Gitlab
private
def deployments_count
if Feature.enabled?(:query_deploymenys_via_finished_at_in_vsa, default_enabled: :yaml)
DeploymentsFinder
.new(project: @project, finished_after: @from, finished_before: @to, status: :success)
.execute
.count
else
query = @project.deployments.success.where("created_at >= ?", @from)
query = query.where("created_at <= ?", @to) if @to
query.count
end
DeploymentsFinder
.new(project: @project, finished_after: @from, finished_before: @to, status: :success)
.execute
.count
end
end
end
......
......@@ -230,34 +230,13 @@ RSpec.describe Gitlab::CycleAnalytics::StageSummary do
end
context 'when `from` and `to` are within a day' do
context 'when query_deploymenys_via_finished_at_in_vsa feature flag is off' do
before do
stub_feature_flags(query_deploymenys_via_finished_at_in_vsa: false)
end
it 'returns the number of deployments made on that day' do
freeze_time do
create(:deployment, :success, project: project)
options[:from] = options[:to] = Time.zone.now
expect(subject).to eq('1')
end
end
end
context 'when query_deploymenys_via_finished_at_in_vsa feature flag is off' do
before do
stub_feature_flags(query_deploymenys_via_finished_at_in_vsa: true)
end
it 'returns the number of deployments made on that day' do
freeze_time do
create(:deployment, :success, project: project, finished_at: Time.zone.now)
options[:from] = Time.zone.now.at_beginning_of_day
options[:to] = Time.zone.now.at_end_of_day
it 'returns the number of deployments made on that day' do
freeze_time do
create(:deployment, :success, project: project, finished_at: Time.zone.now)
options[:from] = Time.zone.now.at_beginning_of_day
options[:to] = Time.zone.now.at_end_of_day
expect(subject).to eq('1')
end
expect(subject).to eq('1')
end
end
end
......
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