Commit 86b70ec8 authored by James Fargher's avatar James Fargher

Merge branch 'sh-ensure-fresh-project-settings' into 'master'

Ensure freshness of settings with project creation

Closes gitaly#2147

See merge request gitlab-org/gitlab!27156
parents d0290377 33fa698e
...@@ -66,7 +66,13 @@ class Project < ApplicationRecord ...@@ -66,7 +66,13 @@ class Project < ApplicationRecord
default_value_for :archived, false default_value_for :archived, false
default_value_for :resolve_outdated_diff_discussions, false default_value_for :resolve_outdated_diff_discussions, false
default_value_for :container_registry_enabled, gitlab_config_features.container_registry default_value_for :container_registry_enabled, gitlab_config_features.container_registry
default_value_for(:repository_storage) { Gitlab::CurrentSettings.pick_repository_storage } default_value_for(:repository_storage) do
# We need to ensure application settings are fresh when we pick
# a repository storage to use.
Gitlab::CurrentSettings.expire_current_application_settings
Gitlab::CurrentSettings.pick_repository_storage
end
default_value_for(:shared_runners_enabled) { Gitlab::CurrentSettings.shared_runners_enabled } default_value_for(:shared_runners_enabled) { Gitlab::CurrentSettings.shared_runners_enabled }
default_value_for :issues_enabled, gitlab_config_features.issues default_value_for :issues_enabled, gitlab_config_features.issues
default_value_for :merge_requests_enabled, gitlab_config_features.merge_requests default_value_for :merge_requests_enabled, gitlab_config_features.merge_requests
......
---
title: Ensure freshness of settings with project creation
merge_request: 27156
author:
type: fixed
...@@ -50,7 +50,7 @@ describe Gitlab::DatabaseImporters::SelfMonitoring::Project::CreateService do ...@@ -50,7 +50,7 @@ describe Gitlab::DatabaseImporters::SelfMonitoring::Project::CreateService do
end end
end end
context 'with application settings and admin users' do context 'with application settings and admin users', :request_store do
let(:project) { result[:project] } let(:project) { result[:project] }
let(:group) { result[:group] } let(:group) { result[:group] }
let(:application_setting) { Gitlab::CurrentSettings.current_application_settings } let(:application_setting) { Gitlab::CurrentSettings.current_application_settings }
...@@ -58,8 +58,9 @@ describe Gitlab::DatabaseImporters::SelfMonitoring::Project::CreateService do ...@@ -58,8 +58,9 @@ describe Gitlab::DatabaseImporters::SelfMonitoring::Project::CreateService do
let!(:user) { create(:user, :admin) } let!(:user) { create(:user, :admin) }
before do before do
allow(ApplicationSetting).to receive(:current_without_cache) { application_setting } stub_env('IN_MEMORY_APPLICATION_SETTINGS', 'false')
application_setting.allow_local_requests_from_web_hooks_and_services = true
application_setting.update(allow_local_requests_from_web_hooks_and_services: true)
end end
shared_examples 'has prometheus service' do |listen_address| shared_examples 'has prometheus service' do |listen_address|
...@@ -130,12 +131,17 @@ describe Gitlab::DatabaseImporters::SelfMonitoring::Project::CreateService do ...@@ -130,12 +131,17 @@ describe Gitlab::DatabaseImporters::SelfMonitoring::Project::CreateService do
it 'saves the project id' do it 'saves the project id' do
expect(result[:status]).to eq(:success) expect(result[:status]).to eq(:success)
expect(application_setting.self_monitoring_project_id).to eq(project.id) expect(application_setting.reload.self_monitoring_project_id).to eq(project.id)
end end
it 'expires application_setting cache' do it 'creates a Prometheus service' do
expect(Gitlab::CurrentSettings).to receive(:expire_current_application_settings)
expect(result[:status]).to eq(:success) expect(result[:status]).to eq(:success)
services = result[:project].reload.services
expect(services.count).to eq(1)
# Ensures PrometheusService#self_monitoring_project? is true
expect(services.first.allow_local_api_url?).to be_truthy
end end
it 'creates an environment for the project' do it 'creates an environment for the project' do
...@@ -158,8 +164,8 @@ describe Gitlab::DatabaseImporters::SelfMonitoring::Project::CreateService do ...@@ -158,8 +164,8 @@ describe Gitlab::DatabaseImporters::SelfMonitoring::Project::CreateService do
end end
it 'returns error when saving project ID fails' do it 'returns error when saving project ID fails' do
allow(application_setting).to receive(:update).and_call_original allow(subject.application_settings).to receive(:update).and_call_original
allow(application_setting).to receive(:update) allow(subject.application_settings).to receive(:update)
.with(self_monitoring_project_id: anything) .with(self_monitoring_project_id: anything)
.and_return(false) .and_return(false)
...@@ -175,8 +181,8 @@ describe Gitlab::DatabaseImporters::SelfMonitoring::Project::CreateService do ...@@ -175,8 +181,8 @@ describe Gitlab::DatabaseImporters::SelfMonitoring::Project::CreateService do
let(:existing_project) { create(:project, namespace: existing_group) } let(:existing_project) { create(:project, namespace: existing_group) }
before do before do
application_setting.instance_administrators_group_id = existing_group.id application_setting.update(instance_administrators_group_id: existing_group.id,
application_setting.self_monitoring_project_id = existing_project.id self_monitoring_project_id: existing_project.id)
end end
it 'returns success' do it 'returns success' do
...@@ -189,7 +195,7 @@ describe Gitlab::DatabaseImporters::SelfMonitoring::Project::CreateService do ...@@ -189,7 +195,7 @@ describe Gitlab::DatabaseImporters::SelfMonitoring::Project::CreateService do
context 'when local requests from hooks and services are not allowed' do context 'when local requests from hooks and services are not allowed' do
before do before do
application_setting.allow_local_requests_from_web_hooks_and_services = false application_setting.update(allow_local_requests_from_web_hooks_and_services: false)
end end
it_behaves_like 'has prometheus service', 'http://localhost:9090' it_behaves_like 'has prometheus service', 'http://localhost:9090'
......
...@@ -1401,6 +1401,22 @@ describe Project do ...@@ -1401,6 +1401,22 @@ describe Project do
expect(project.repository_storage).to eq('picked') expect(project.repository_storage).to eq('picked')
end end
it 'picks from the latest available storage', :request_store do
stub_env('IN_MEMORY_APPLICATION_SETTINGS', 'false')
Gitlab::CurrentSettings.current_application_settings
settings = ApplicationSetting.last
settings.repository_storages = %w(picked)
settings.save!
expect(Gitlab::CurrentSettings.repository_storages).to eq(%w(default))
project
expect(project.repository.storage).to eq('picked')
expect(Gitlab::CurrentSettings.repository_storages).to eq(%w(picked))
end
end end
context 'shared runners by default' do context 'shared runners by default' do
......
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