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
default_value_for :archived, false
default_value_for :resolve_outdated_diff_discussions, false
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 :issues_enabled, gitlab_config_features.issues
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
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(:group) { result[:group] }
let(:application_setting) { Gitlab::CurrentSettings.current_application_settings }
......@@ -58,8 +58,9 @@ describe Gitlab::DatabaseImporters::SelfMonitoring::Project::CreateService do
let!(:user) { create(:user, :admin) }
before do
allow(ApplicationSetting).to receive(:current_without_cache) { application_setting }
application_setting.allow_local_requests_from_web_hooks_and_services = true
stub_env('IN_MEMORY_APPLICATION_SETTINGS', 'false')
application_setting.update(allow_local_requests_from_web_hooks_and_services: true)
end
shared_examples 'has prometheus service' do |listen_address|
......@@ -130,12 +131,17 @@ describe Gitlab::DatabaseImporters::SelfMonitoring::Project::CreateService do
it 'saves the project id' do
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
it 'expires application_setting cache' do
expect(Gitlab::CurrentSettings).to receive(:expire_current_application_settings)
it 'creates a Prometheus service' do
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
it 'creates an environment for the project' do
......@@ -158,8 +164,8 @@ describe Gitlab::DatabaseImporters::SelfMonitoring::Project::CreateService do
end
it 'returns error when saving project ID fails' do
allow(application_setting).to receive(:update).and_call_original
allow(application_setting).to receive(:update)
allow(subject.application_settings).to receive(:update).and_call_original
allow(subject.application_settings).to receive(:update)
.with(self_monitoring_project_id: anything)
.and_return(false)
......@@ -175,8 +181,8 @@ describe Gitlab::DatabaseImporters::SelfMonitoring::Project::CreateService do
let(:existing_project) { create(:project, namespace: existing_group) }
before do
application_setting.instance_administrators_group_id = existing_group.id
application_setting.self_monitoring_project_id = existing_project.id
application_setting.update(instance_administrators_group_id: existing_group.id,
self_monitoring_project_id: existing_project.id)
end
it 'returns success' do
......@@ -189,7 +195,7 @@ describe Gitlab::DatabaseImporters::SelfMonitoring::Project::CreateService do
context 'when local requests from hooks and services are not allowed' 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
it_behaves_like 'has prometheus service', 'http://localhost:9090'
......
......@@ -1401,6 +1401,22 @@ describe Project do
expect(project.repository_storage).to eq('picked')
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
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