add consul failsafes to several request-critical paths
Change-Id: I8d81da166a2d7fb79da1e722135d59b18b6e7825 Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/270783 Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com> Reviewed-by: Jacob Burroughs <jburroughs@instructure.com> QA-Review: Cody Cutrer <cody@instructure.com> Product-Review: Cody Cutrer <cody@instructure.com>
This commit is contained in:
parent
99f5db6a61
commit
c6054e8308
|
@ -2786,7 +2786,7 @@ class ApplicationController < ActionController::Base
|
|||
false
|
||||
else
|
||||
return value_to_boolean(params[:force_stream]) if params.key?(:force_stream)
|
||||
::Canvas::DynamicSettings.find(tree: :private)["enable_template_streaming"] &&
|
||||
::Canvas::DynamicSettings.find(tree: :private)["enable_template_streaming", failsafe: false] &&
|
||||
Setting.get("disable_template_streaming_for_#{controller_name}/#{action_name}", "false") != "true"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -67,7 +67,7 @@ module DatadogRumHelper
|
|||
end
|
||||
|
||||
def sample_rate
|
||||
datadog_rum_config[:sample_rate_percentage].to_f / 100
|
||||
datadog_rum_config[:sample_rate_percentage, failsafe: 0.0].to_f / 100
|
||||
end
|
||||
|
||||
def datadog_rum_config
|
||||
|
@ -76,7 +76,7 @@ module DatadogRumHelper
|
|||
|
||||
def complete_config?
|
||||
%i[client_token application_id sample_rate_percentage].all? do |key|
|
||||
datadog_rum_config[key].present?
|
||||
datadog_rum_config[key, failsafe: nil].present?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -28,13 +28,13 @@ module FullStoryHelper
|
|||
return if session.key?(:fullstory_enabled)
|
||||
|
||||
fsconfig = Canvas::DynamicSettings.find('fullstory', tree: 'config', service: 'canvas')
|
||||
rate = fsconfig[:sampling_rate].to_f
|
||||
rate = fsconfig[:sampling_rate, failsafe: 0.0].to_f
|
||||
sample = rand()
|
||||
session[:fullstory_enabled] = rate >= 0.0 && rate <= 1.0 && sample < rate
|
||||
end
|
||||
|
||||
def fullstory_app_key
|
||||
Canvas::DynamicSettings.find('fullstory', tree: 'config', service: 'canvas')[:app_key] rescue nil
|
||||
Canvas::DynamicSettings.find('fullstory', tree: 'config', service: 'canvas')[:app_key, failsafe: nil]
|
||||
end
|
||||
|
||||
def fullstory_enabled_for_session?(session)
|
||||
|
|
|
@ -195,7 +195,7 @@ class RequestThrottle
|
|||
end
|
||||
|
||||
def self.dynamic_settings
|
||||
@dynamic_settings ||= YAML.safe_load(Canvas::DynamicSettings.find(tree: :private)['request_throttle.yml'] || '') || {}
|
||||
@dynamic_settings ||= YAML.safe_load(Canvas::DynamicSettings.find(tree: :private)['request_throttle.yml', failsafe: ''] || '') || {}
|
||||
end
|
||||
|
||||
def rate_limit_exceeded
|
||||
|
|
|
@ -282,7 +282,7 @@ module UserLearningObjectScopes
|
|||
|
||||
# opts forwaded to course_ids_for_todo_lists
|
||||
def submissions_needing_grading_count(**opts)
|
||||
if ::Canvas::DynamicSettings.find(tree: :private, cluster: Shard.current.database_server.id)["disable_needs_grading_queries"]
|
||||
if ::Canvas::DynamicSettings.find(tree: :private, cluster: Shard.current.database_server.id)["disable_needs_grading_queries", failsafe: false]
|
||||
return 0
|
||||
end
|
||||
course_ids = course_ids_for_todo_lists(:manage_grades, **opts)
|
||||
|
|
|
@ -159,10 +159,10 @@ module CanvasRails
|
|||
|
||||
config.middleware.use Rack::Chunked
|
||||
config.middleware.use Rack::Deflater, if: -> (*) {
|
||||
::Canvas::DynamicSettings.find(tree: :private)["enable_rack_deflation"]
|
||||
::Canvas::DynamicSettings.find(tree: :private)["enable_rack_deflation", failsafe: true]
|
||||
}
|
||||
config.middleware.use Rack::Brotli, if: -> (*) {
|
||||
::Canvas::DynamicSettings.find(tree: :private)["enable_rack_brotli"]
|
||||
::Canvas::DynamicSettings.find(tree: :private)["enable_rack_brotli", failsafe: true]
|
||||
}
|
||||
|
||||
config.i18n.load_path << Rails.root.join('config', 'locales', 'locales.yml')
|
||||
|
|
|
@ -24,11 +24,11 @@ describe DatadogRumHelper do
|
|||
include ApplicationHelper
|
||||
|
||||
let(:datadog_rum_config) do
|
||||
{
|
||||
DynamicSettings::FallbackProxy.new(
|
||||
application_id: "27627d1e-8a4f-4645-b390-bb396fc83c81",
|
||||
client_token: "a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r",
|
||||
sample_rate_percentage: 100.0
|
||||
}
|
||||
)
|
||||
end
|
||||
|
||||
describe "#include_datadog_rum_js?" do
|
||||
|
@ -50,33 +50,33 @@ describe DatadogRumHelper do
|
|||
end
|
||||
|
||||
it "returns true when the random value is below the sample rate" do
|
||||
datadog_rum_config[:sample_rate_percentage] = 50.0001
|
||||
datadog_rum_config.data[:sample_rate_percentage] = 50.0001
|
||||
expect(include_datadog_rum_js?).to be(true)
|
||||
end
|
||||
|
||||
it "returns true when the random value matches the sample rate" do
|
||||
datadog_rum_config[:sample_rate_percentage] = 50.0
|
||||
datadog_rum_config.data[:sample_rate_percentage] = 50.0
|
||||
expect(include_datadog_rum_js?).to be(true)
|
||||
end
|
||||
|
||||
it "returns false when the random value is above the sample rate" do
|
||||
datadog_rum_config[:sample_rate_percentage] = 49.9999
|
||||
datadog_rum_config.data[:sample_rate_percentage] = 49.9999
|
||||
expect(include_datadog_rum_js?).to be(false)
|
||||
end
|
||||
|
||||
it "returns true when the sample rate percentage is 100%" do
|
||||
datadog_rum_config[:sample_rate_percentage] = 100.0
|
||||
datadog_rum_config.data[:sample_rate_percentage] = 100.0
|
||||
expect(include_datadog_rum_js?).to be(true)
|
||||
end
|
||||
|
||||
it "returns false when the sample rate percentage is 0%" do
|
||||
allow(self).to receive(:random).and_return(0.0)
|
||||
datadog_rum_config[:sample_rate_percentage] = 0.0
|
||||
datadog_rum_config.data[:sample_rate_percentage] = 0.0
|
||||
expect(include_datadog_rum_js?).to be(false)
|
||||
end
|
||||
|
||||
it "returns false consistently when called multiple times" do
|
||||
datadog_rum_config[:sample_rate_percentage] = 50.0
|
||||
datadog_rum_config.data[:sample_rate_percentage] = 50.0
|
||||
allow(self).to receive(:random).and_return(0.6)
|
||||
expect(include_datadog_rum_js?).to be(false)
|
||||
allow(self).to receive(:random).and_return(0.4)
|
||||
|
@ -84,7 +84,7 @@ describe DatadogRumHelper do
|
|||
end
|
||||
|
||||
it "returns true consistently when called multiple times" do
|
||||
datadog_rum_config[:sample_rate_percentage] = 50.0
|
||||
datadog_rum_config.data[:sample_rate_percentage] = 50.0
|
||||
allow(self).to receive(:random).and_return(0.4)
|
||||
expect(include_datadog_rum_js?).to be(true)
|
||||
allow(self).to receive(:random).and_return(0.6)
|
||||
|
@ -105,7 +105,7 @@ describe DatadogRumHelper do
|
|||
|
||||
it "returns false when the sample rate percentage is 0.0" do
|
||||
request_datadog_rum_js
|
||||
datadog_rum_config[:sample_rate_percentage] = 0.0
|
||||
datadog_rum_config.data[:sample_rate_percentage] = 0.0
|
||||
expect(include_datadog_rum_js?).to be(false)
|
||||
end
|
||||
|
||||
|
@ -122,19 +122,19 @@ describe DatadogRumHelper do
|
|||
|
||||
it "returns false when the configuration is missing :application_id" do
|
||||
opt_in_datadog_rum_js
|
||||
datadog_rum_config.delete(:application_id)
|
||||
datadog_rum_config.data.delete(:application_id)
|
||||
expect(include_datadog_rum_js?).to be(false)
|
||||
end
|
||||
|
||||
it "returns false when the configuration is missing :client_token" do
|
||||
opt_in_datadog_rum_js
|
||||
datadog_rum_config.delete(:client_token)
|
||||
datadog_rum_config.data.delete(:client_token)
|
||||
expect(include_datadog_rum_js?).to be(false)
|
||||
end
|
||||
|
||||
it "returns false when the configuration is missing :sample_rate_percentage" do
|
||||
opt_in_datadog_rum_js
|
||||
datadog_rum_config.delete(:sample_rate_percentage)
|
||||
datadog_rum_config.data.delete(:sample_rate_percentage)
|
||||
expect(include_datadog_rum_js?).to be(false)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue