Skip to content

Commit

Permalink
Allow for setting custom worker memory thresholds under advanced sett…
Browse files Browse the repository at this point in the history
  • Loading branch information
bmclaughlin committed Jun 28, 2019
1 parent 9be69cb commit fedd06d
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
19 changes: 19 additions & 0 deletions app/controllers/ops_controller/settings/common.rb
Expand Up @@ -1013,12 +1013,14 @@ def settings_set_form_vars_workers
w[:memory_threshold] = get_worker_setting(@edit[:current], MiqGenericWorker, :memory_threshold) || 400.megabytes
@sb[:generic_threshold] = []
@sb[:generic_threshold] = copy_array(@sb[:threshold])
insert_custom_threshold_value(@sb[:generic_threshold], w[:memory_threshold])

w = (qwb[:priority_worker] ||= {})
w[:count] = get_worker_setting(@edit[:current], MiqPriorityWorker, :count) || 2
w[:memory_threshold] = get_worker_setting(@edit[:current], MiqPriorityWorker, :memory_threshold) || 200.megabytes
@sb[:priority_threshold] = []
@sb[:priority_threshold] = copy_array(@sb[:threshold])
insert_custom_threshold_value(@sb[:priority_threshold], w[:memory_threshold])

qwb[:ems_metrics_collector_worker] ||= {}
qwb[:ems_metrics_collector_worker][:defaults] ||= {}
Expand All @@ -1027,19 +1029,22 @@ def settings_set_form_vars_workers
w[:memory_threshold] = get_worker_setting(@edit[:current], MiqEmsMetricsCollectorWorker, :defaults, :memory_threshold) || 400.megabytes
@sb[:ems_metrics_collector_threshold] = []
@sb[:ems_metrics_collector_threshold] = copy_array(@sb[:threshold])
insert_custom_threshold_value(@sb[:ems_metrics_collector_threshold], w[:memory_threshold])

w = (qwb[:ems_metrics_processor_worker] ||= {})
w[:count] = get_worker_setting(@edit[:current], MiqEmsMetricsProcessorWorker, :count) || 2
w[:memory_threshold] = get_worker_setting(@edit[:current], MiqEmsMetricsProcessorWorker, :memory_threshold) || 200.megabytes
@sb[:ems_metrics_processor_threshold] = []
@sb[:ems_metrics_processor_threshold] = copy_array(@sb[:threshold])
insert_custom_threshold_value(@sb[:ems_metrics_processor_threshold], w[:memory_threshold])

w = (qwb[:smart_proxy_worker] ||= {})
w[:count] = get_worker_setting(@edit[:current], MiqSmartProxyWorker, :count) || 3
w[:memory_threshold] = get_worker_setting(@edit[:current], MiqSmartProxyWorker, :memory_threshold) || 400.megabytes
@sb[:smart_proxy_threshold] = []
@sb[:smart_proxy_threshold] = copy_array(@sb[:threshold])
(1.gigabytes..2.9.gigabytes).step(0.1.gigabyte) { |x| @sb[:smart_proxy_threshold] << [number_to_human_size(x, :significant => false), x.to_i] }
insert_custom_threshold_value(@sb[:smart_proxy_threshold], w[:memory_threshold])

qwb[:ems_refresh_worker] ||= {}
qwb[:ems_refresh_worker][:defaults] ||= {}
Expand All @@ -1050,6 +1055,7 @@ def settings_set_form_vars_workers
(600.megabytes..900.megabytes).step(100.megabytes) { |x| @sb[:ems_refresh_threshold] << [number_to_human_size(x, :significant => false), x] }
(1.gigabytes..2.9.gigabytes).step(0.1.gigabyte) { |x| @sb[:ems_refresh_threshold] << [number_to_human_size(x, :significant => false), x.to_i] }
(3.gigabytes..10.gigabytes).step(512.megabytes) { |x| @sb[:ems_refresh_threshold] << [number_to_human_size(x, :significant => false), x.to_i] }
insert_custom_threshold_value(@sb[:ems_refresh_threshold], w[:memory_threshold])

wb = @edit[:current].config[:workers][:worker_base]
w = (wb[:event_catcher] ||= {})
Expand All @@ -1058,13 +1064,15 @@ def settings_set_form_vars_workers
(500.megabytes...1000.megabytes).step(100.megabytes) { |x| @sb[:event_catcher_threshold] << [number_to_human_size(x, :significant => false), x] }
(1.gigabytes..2.9.gigabytes).step(0.1.gigabyte) { |x| @sb[:event_catcher_threshold] << [number_to_human_size(x, :significant => false), x.to_i] }
(3.gigabytes..10.gigabytes).step(512.megabytes) { |x| @sb[:event_catcher_threshold] << [number_to_human_size(x, :significant => false), x.to_i] }
insert_custom_threshold_value(@sb[:event_catcher_threshold], w[:memory_threshold])

w = (wb[:vim_broker_worker] ||= {})
w[:memory_threshold] = get_worker_setting(@edit[:current], MiqVimBrokerWorker, :memory_threshold) || 1.gigabytes
@sb[:vim_broker_threshold] = []
(500.megabytes..900.megabytes).step(100.megabytes) { |x| @sb[:vim_broker_threshold] << [number_to_human_size(x, :significant => false), x] }
(1.gigabytes..2.9.gigabytes).step(0.1.gigabyte) { |x| @sb[:vim_broker_threshold] << [number_to_human_size(x, :significant => false), x.to_i] }
(3.gigabytes..10.gigabytes).step(512.megabytes) { |x| @sb[:vim_broker_threshold] << [number_to_human_size(x, :significant => false), x.to_i] }
insert_custom_threshold_value(@sb[:vim_broker_threshold], w[:memory_threshold])

w = (wb[:ui_worker] ||= {})
w[:count] = get_worker_setting(@edit[:current], MiqUiWorker, :count) || 2
Expand All @@ -1074,12 +1082,14 @@ def settings_set_form_vars_workers
w[:memory_threshold] = get_worker_setting(@edit[:current], MiqReportingWorker, :memory_threshold) || 400.megabytes
@sb[:reporting_threshold] = []
@sb[:reporting_threshold] = copy_array(@sb[:threshold])
insert_custom_threshold_value(@sb[:reporting_threshold], w[:memory_threshold])

w = (wb[:web_service_worker] ||= {})
w[:count] = get_worker_setting(@edit[:current], MiqWebServiceWorker, :count) || 2
w[:memory_threshold] = get_worker_setting(@edit[:current], MiqWebServiceWorker, :memory_threshold) || 400.megabytes
@sb[:web_service_threshold] = []
@sb[:web_service_threshold] = copy_array(@sb[:threshold])
insert_custom_threshold_value(@sb[:web_service_threshold], w[:memory_threshold])

w = (wb[:websocket_worker] ||= {})
w[:count] = get_worker_setting(@edit[:current], MiqWebsocketWorker, :count) || 2
Expand All @@ -1089,6 +1099,15 @@ def settings_set_form_vars_workers
@in_a_form = true
end

def insert_custom_threshold_value(threshold, value)
# insert custom value entered from Advanced tab into Worker threshold select options if needed
value_exists = false
threshold.each do |x|
value_exists = true if x.include?(value)
end
threshold << ["#{number_to_human_size(value, :significant => false)} (Custom Value)", value.to_i] unless value_exists
end

private def get_worker_setting(config, klass, *setting)
settings = klass.worker_settings(:config => config, :raw => true)
setting.empty? ? settings : settings.fetch_path(setting).to_i_with_method
Expand Down
46 changes: 46 additions & 0 deletions spec/controllers/ops_controller/settings/common_spec.rb
Expand Up @@ -482,6 +482,52 @@
proxy_worker_threshold_human_size = number_to_human_size(proxy_worker_threshold, :significant => false)
expect(assigns(:sb)[:smart_proxy_threshold]).to include([proxy_worker_threshold_human_size, proxy_worker_threshold])
end

it "gets custom worker setting and makes sure it exists in threshold array so correct value can be selected in drop down" do
Vmdb::Settings.save!(
@miq_server,
:workers => {
:worker_base => {
:queue_worker_base => {
:generic_worker => {
:memory_threshold => 2.5.gigabytes
}
}
}
}
)
controller.send(:settings_set_form_vars_workers)
generic_worker_threshold = controller.send(:get_worker_setting, assigns(:edit)[:current], MiqGenericWorker, :memory_threshold)
generic_worker_threshold_human_size = number_to_human_size(generic_worker_threshold, :significant => false)
expect(assigns(:sb)[:generic_threshold]).to include(["#{generic_worker_threshold_human_size} (Custom Value)", generic_worker_threshold])
end
end
end

describe '#insert_custom_threshold_value' do
include ActionView::Helpers::NumberHelper
before do
@miq_server = FactoryBot.create(:miq_server)
threshold = []
(200.megabytes...500.megabytes).step(100.megabytes) do |x|
threshold << [number_to_human_size(x, :significant => false), x]
end
generic_threshold = copy_array(threshold)
controller.instance_variable_set(:@sb,
:selected_server_id => @miq_server.id,
:threshold => threshold,
:generic_threshold => generic_threshold)
end

it "does not insert an existing value into a threshold array" do
original_generic_threshold = copy_array(assigns(:sb)[:generic_threshold])
controller.send(:insert_custom_threshold_value, assigns(:sb)[:generic_threshold], 200.megabytes)
expect(assigns(:sb)[:generic_threshold]).to eq(original_generic_threshold)
end

it "inserts a custom value into a threshold array" do
controller.send(:insert_custom_threshold_value, assigns(:sb)[:generic_threshold], 2.gigabytes)
expect(assigns(:sb)[:generic_threshold]).to include(["2 GB (Custom Value)", 2.gigabytes.to_i])
end
end
end
Expand Down

0 comments on commit fedd06d

Please sign in to comment.