Init consul before the shard cache
Change-Id: Ib01900d93d89527e1a9d8d5b3b1502d884fe3915 Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/242729 Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com> Reviewed-by: Cody Cutrer <cody@instructure.com> QA-Review: Jacob Burroughs <jburroughs@instructure.com> Product-Review: Jacob Burroughs <jburroughs@instructure.com>
This commit is contained in:
parent
ff78f2bf0b
commit
6af6d1bc34
|
@ -277,6 +277,17 @@ module CanvasRails
|
|||
# don't care about secret_key_base
|
||||
end
|
||||
|
||||
initializer "canvas.init_dynamic_settings", before: "canvas.extend_shard" do
|
||||
settings = ConfigFile.load("consul")
|
||||
if settings.present?
|
||||
begin
|
||||
Canvas::DynamicSettings.config = settings_hash
|
||||
rescue Imperium::UnableToConnectError
|
||||
Rails.logger.warn("INITIALIZATION: can't reach consul, attempts to load DynamicSettings will fail")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
initializer "canvas.extend_shard", before: "active_record.initialize_database" do
|
||||
# have to do this before the default shard loads
|
||||
Switchman::Shard.serialize :settings, Hash
|
||||
|
|
|
@ -15,25 +15,6 @@
|
|||
# You should have received a copy of the GNU Affero General Public License along
|
||||
# with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
# this is named _consul.rb so that other initializers (cache_store.rb in particular)
|
||||
# can talk to Consul
|
||||
|
||||
module ConsulInitializer
|
||||
def self.configure_with(settings_hash, logger=Rails.logger)
|
||||
if settings_hash.present?
|
||||
begin
|
||||
Canvas::DynamicSettings.config = settings_hash
|
||||
rescue Imperium::UnableToConnectError
|
||||
logger.warn("INITIALIZATION: can't reach consul, attempts to load DynamicSettings will fail")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
settings = ConfigFile.load("consul")
|
||||
ConsulInitializer.configure_with(settings)
|
||||
|
||||
handle_fallbacks = -> do
|
||||
Canvas::DynamicSettings.reset_cache!
|
||||
end
|
|
@ -1,66 +0,0 @@
|
|||
#
|
||||
# Copyright (C) 2015 - present Instructure, Inc.
|
||||
#
|
||||
# This file is part of Canvas.
|
||||
#
|
||||
# Canvas is free software: you can redistribute it and/or modify it under
|
||||
# the terms of the GNU Affero General Public License as published by the Free
|
||||
# Software Foundation, version 3 of the License.
|
||||
#
|
||||
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
||||
# details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License along
|
||||
# with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
require_relative '../spec_helper'
|
||||
require_relative '../../config/initializers/_consul'
|
||||
|
||||
describe ConsulInitializer do
|
||||
after(:each) do
|
||||
Canvas::DynamicSettings.config = nil
|
||||
Canvas::DynamicSettings.reset_cache!
|
||||
Canvas::DynamicSettings.fallback_data = nil
|
||||
end
|
||||
|
||||
class FakeLogger
|
||||
attr_reader :messages
|
||||
def initialize
|
||||
@messages = []
|
||||
end
|
||||
|
||||
def warn(message)
|
||||
messages << message
|
||||
end
|
||||
end
|
||||
|
||||
describe ".configure_with" do
|
||||
include WebMock::API
|
||||
|
||||
it "passes provided config info to DynamicSettings" do
|
||||
config_hash = {hi: "ho", host: "localhost", port: 80}
|
||||
ConsulInitializer.configure_with(config_hash.with_indifferent_access)
|
||||
expect(Canvas::DynamicSettings.config[:hi]).to eq("ho")
|
||||
end
|
||||
|
||||
it "logs nothing if there's no config file" do
|
||||
logger = FakeLogger.new
|
||||
ConsulInitializer.configure_with(nil, logger)
|
||||
expect(logger.messages).to eq([])
|
||||
end
|
||||
end
|
||||
|
||||
describe "just from loading" do
|
||||
it "clears the DynamicSettings cache on reload" do
|
||||
Canvas::DynamicSettings.reset_cache!
|
||||
LocalCache.write(Canvas::DynamicSettings::CACHE_KEY_PREFIX + 'service/key', 'value')
|
||||
imperium = double('imperium', get: nil)
|
||||
allow(Canvas::DynamicSettings).to receive(:kv_client).and_return(imperium)
|
||||
expect(Canvas::DynamicSettings.find(tree: nil, service: 'service')['key']).to eq("value")
|
||||
Canvas::Reloader.reload!
|
||||
expect(LocalCache.read(Canvas::DynamicSettings::CACHE_KEY_PREFIX + 'service/key')).to eq(nil)
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue