Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MiqWorkerType model #19536

Merged
merged 6 commits into from
Nov 21, 2019
Merged

Add MiqWorkerType model #19536

merged 6 commits into from
Nov 21, 2019

Conversation

carbonin
Copy link
Member

@carbonin carbonin commented Nov 19, 2019

This adds a model which will replace the worker type constant.
It seeds the table based on the leaf subclasses of MiqWorker
and each worker class needs to define its own attributes, specifically
its priority in the kill order and bundler groups.

This allows new workers to be added by simply adding a new subclass
of MiqWorker rather than maintaining a list of worker classes in the
core repo.

Additionally this brings us closer to the ability to run a separate
process that will access the database and determine which workers
should be running on which servers, all outside of the main application
code-base.

Requires:

@carbonin carbonin changed the title Add MiqWorkerTypes model Add MiqWorkerType model Nov 19, 2019
@carbonin
Copy link
Member Author

Cross repo test ManageIQ/manageiq-cross_repo-tests#15

"#{class_name}::CloudManager::EventCatcher" => %i(manageiq_default),
"#{class_name}::CloudManager::MetricsCollectorWorker" => %i(manageiq_default),
"#{class_name}::CloudManager::RefreshWorker" => %i(manageiq_default),
RB
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1000 ❤️ s!!

@agrare
Copy link
Member

agrare commented Nov 20, 2019

I absolutely love this

@carbonin
Copy link
Member Author

Regarding the kill order priorities, this may be a good time to revisit the list. Here is what I currently have implemented in this PR:

  1. MiqEmsMetricsProcessorWorker
  2. MetricsCollectorWorkers
  3. MiqReportingWorker
  4. MiqSmartProxyWorker
  5. MiqGenericWorker
  6. MiqEventHandler
  7. RefreshWorkers
  8. MiqScheduleWorker
  9. MiqPriorityWorker
  10. MiqWebServiceWorker
  11. MiqEmsRefreshCoreWorker
  12. MiqVimBrokerWorker
  13. EventCatchers
  14. MiqUiWorker
  15. MiqRemoteConsoleWorker
  16. MiqCockpitWsWorker

Which, for completeness, in the database looks like this:

vmdb_development=# select * from miq_worker_types order by kill_priority ;
 id |                                 worker_type                                 |                 bundler_groups                 | kill_priority 
----+-----------------------------------------------------------------------------+------------------------------------------------+---------------
  9 | MiqEmsMetricsProcessorWorker                                                | {manageiq_default}                             |            10
 18 | ManageIQ::Providers::Kubernetes::ContainerManager::MetricsCollectorWorker   | {manageiq_default}                             |            20
 24 | ManageIQ::Providers::Openstack::NetworkManager::MetricsCollectorWorker      | {manageiq_default}                             |            20
 23 | ManageIQ::Providers::Openstack::InfraManager::MetricsCollectorWorker        | {manageiq_default}                             |            20
 22 | ManageIQ::Providers::Openstack::CloudManager::MetricsCollectorWorker        | {manageiq_default}                             |            20
 25 | ManageIQ::Providers::Redhat::NetworkManager::MetricsCollectorWorker         | {manageiq_default}                             |            20
 21 | ManageIQ::Providers::Vmware::InfraManager::MetricsCollectorWorker           | {manageiq_default}                             |            20
 20 | ManageIQ::Providers::Redhat::InfraManager::MetricsCollectorWorker           | {manageiq_default}                             |            20
 16 | ManageIQ::Providers::Azure::CloudManager::MetricsCollectorWorker            | {manageiq_default}                             |            20
 19 | ManageIQ::Providers::Openshift::ContainerManager::MetricsCollectorWorker    | {manageiq_default}                             |            20
 15 | ManageIQ::Providers::Amazon::CloudManager::MetricsCollectorWorker           | {manageiq_default}                             |            20
 17 | ManageIQ::Providers::Google::CloudManager::MetricsCollectorWorker           | {manageiq_default}                             |            20
 13 | MiqReportingWorker                                                          | {manageiq_default}                             |            30
 14 | MiqSmartProxyWorker                                                         | {manageiq_default}                             |            40
 11 | MiqGenericWorker                                                            | {manageiq_default}                             |            50
 10 | MiqEventHandler                                                             | {manageiq_default}                             |            60
 43 | ManageIQ::Providers::Amazon::StorageManager::S3::RefreshWorker              | {manageiq_default}                             |            70
  6 | ManageIQ::Providers::Amazon::AgentCoordinatorWorker                         | {manageiq_default}                             |            70
 26 | ManageIQ::Providers::Amazon::CloudManager::RefreshWorker                    | {manageiq_default}                             |            70
 27 | ManageIQ::Providers::AnsibleTower::AutomationManager::RefreshWorker         | {manageiq_default}                             |            70
 28 | ManageIQ::Providers::Azure::CloudManager::RefreshWorker                     | {manageiq_default}                             |            70
 29 | ManageIQ::Providers::AzureStack::CloudManager::RefreshWorker                | {manageiq_default}                             |            70
 30 | ManageIQ::Providers::Google::CloudManager::RefreshWorker                    | {manageiq_default}                             |            70
 31 | ManageIQ::Providers::Kubernetes::ContainerManager::RefreshWorker            | {manageiq_default}                             |            70
 32 | ManageIQ::Providers::Lenovo::PhysicalInfraManager::RefreshWorker            | {manageiq_default}                             |            70
 33 | ManageIQ::Providers::Openshift::ContainerManager::RefreshWorker             | {manageiq_default}                             |            70
 34 | ManageIQ::Providers::Redhat::InfraManager::RefreshWorker                    | {manageiq_default}                             |            70
 35 | ManageIQ::Providers::Redfish::PhysicalInfraManager::RefreshWorker           | {manageiq_default}                             |            70
 36 | ManageIQ::Providers::Vmware::InfraManager::RefreshWorker                    | {manageiq_default}                             |            70
 37 | ManageIQ::Providers::Nuage::NetworkManager::RefreshWorker                   | {manageiq_default}                             |            70
 38 | ManageIQ::Providers::Openstack::CloudManager::RefreshWorker                 | {manageiq_default}                             |            70
 39 | ManageIQ::Providers::Openstack::InfraManager::RefreshWorker                 | {manageiq_default}                             |            70
 40 | ManageIQ::Providers::Redhat::NetworkManager::RefreshWorker                  | {manageiq_default}                             |            70
 41 | ManageIQ::Providers::Vmware::CloudManager::RefreshWorker                    | {manageiq_default}                             |            70
 42 | ManageIQ::Providers::Kubevirt::InfraManager::RefreshWorker                  | {manageiq_default}                             |            70
 44 | ManageIQ::Providers::AzureStack::NetworkManager::RefreshWorker              | {manageiq_default}                             |            70
 45 | ManageIQ::Providers::Foreman::ConfigurationManager::RefreshWorker           | {manageiq_default}                             |            70
 46 | ManageIQ::Providers::Foreman::ProvisioningManager::RefreshWorker            | {manageiq_default}                             |            70
 47 | ManageIQ::Providers::Google::NetworkManager::RefreshWorker                  | {manageiq_default}                             |            70
 48 | ManageIQ::Providers::Microsoft::InfraManager::RefreshWorker                 | {manageiq_default}                             |            70
 49 | ManageIQ::Providers::Vmware::NetworkManager::RefreshWorker                  | {manageiq_default}                             |            70
  3 | MiqScheduleWorker                                                           | {manageiq_default}                             |            80
 12 | MiqPriorityWorker                                                           | {manageiq_default}                             |            90
  5 | MiqWebServiceWorker                                                         | {manageiq_default,graphql_api}                 |           100
  7 | MiqEmsRefreshCoreWorker                                                     | {manageiq_default}                             |           110
  8 | MiqVimBrokerWorker                                                          | {manageiq_default}                             |           120
 62 | ManageIQ::Providers::Vmware::InfraManager::EventCatcher                     | {manageiq_default}                             |           130
 64 | ManageIQ::Providers::Openstack::CloudManager::EventCatcher                  | {manageiq_default}                             |           130
 65 | ManageIQ::Providers::Openstack::InfraManager::EventCatcher                  | {manageiq_default}                             |           130
 66 | ManageIQ::Providers::Openstack::NetworkManager::EventCatcher                | {manageiq_default}                             |           130
 60 | ManageIQ::Providers::Redhat::InfraManager::EventCatcher                     | {manageiq_default}                             |           130
 61 | ManageIQ::Providers::Redfish::PhysicalInfraManager::EventCatcher            | {manageiq_default}                             |           130
 63 | ManageIQ::Providers::Nuage::NetworkManager::EventCatcher                    | {manageiq_default}                             |           130
 67 | ManageIQ::Providers::Openstack::StorageManager::CinderManager::EventCatcher | {manageiq_default}                             |           130
 68 | ManageIQ::Providers::Redhat::NetworkManager::EventCatcher                   | {manageiq_default}                             |           130
 69 | ManageIQ::Providers::Vmware::CloudManager::EventCatcher                     | {manageiq_default}                             |           130
 50 | ManageIQ::Providers::Amazon::CloudManager::EventCatcher                     | {manageiq_default}                             |           130
 51 | ManageIQ::Providers::AnsibleTower::AutomationManager::EventCatcher          | {manageiq_default}                             |           130
 52 | ManageIQ::Providers::Azure::CloudManager::EventCatcher                      | {manageiq_default}                             |           130
 53 | ManageIQ::Providers::AzureStack::CloudManager::EventCatcher                 | {manageiq_default}                             |           130
 54 | ManageIQ::Providers::Google::CloudManager::EventCatcher                     | {manageiq_default}                             |           130
 55 | ManageIQ::Providers::Kubernetes::ContainerManager::EventCatcher             | {manageiq_default}                             |           130
 56 | ManageIQ::Providers::Kubernetes::MonitoringManager::EventCatcher            | {manageiq_default}                             |           130
 57 | ManageIQ::Providers::Lenovo::PhysicalInfraManager::EventCatcher             | {manageiq_default}                             |           130
 58 | ManageIQ::Providers::Openshift::ContainerManager::EventCatcher              | {manageiq_default}                             |           130
 59 | ManageIQ::Providers::Openshift::MonitoringManager::EventCatcher             | {manageiq_default}                             |           130
  4 | MiqUiWorker                                                                 | {manageiq_default,ui_dependencies,graphql_api} |           140
  2 | MiqRemoteConsoleWorker                                                      | {manageiq_default}                             |           150
  1 | MiqCockpitWsWorker                                                          | {manageiq_default}                             |           160
(69 rows)

As a simple start I would move the web service worker toward to bottom because you can't log in without the API, and move the cockpit and remote console workers up, maybe before refresh because those are not always being used.

Does the VMware event catcher use the vim broker? If it does I think we should move the broker after the event catchers. Also not sure about the relative position of the event handler and the event catchers.

Does it make sense to move the ems refresh core worker closer to the other refresh workers?

@carbonin
Copy link
Member Author

Also unless we get the list down to a more manageable size, I'm not sure we can name all of the priorities @Fryguy, right now we have 16 levels (I used 10 to 160 to allow for new groupings between existing ones).

@carbonin
Copy link
Member Author

@agrare what do you think about the provider worker priorities?

@Fryguy
Copy link
Member

Fryguy commented Nov 20, 2019

I would leave them as close to default for this PR, then have a separate PR for reordering. Once the constants are in place, it's a simple matter of just changing them.

@Fryguy
Copy link
Member

Fryguy commented Nov 20, 2019

Also unless we get the list down to a more manageable size, I'm not sure we can name all of the priorities @Fryguy, right now we have 16 levels (I used 10 to 160 to allow for new groupings between existing ones).

16 doesn't feel all that bad...I'd go for it 😄

@agrare
Copy link
Member

agrare commented Nov 20, 2019

Does the VMware event catcher use the vim broker?

No, it uses the VMwareWebService gem but it doesn't rely on the MiqVimBrokerWorker running

This adds a model which will replace the worker type constant.
It seeds the table based on the leaf subclasses of MiqWorker
and each worker class needs to define its own attributes, specifically
its priority in the kill order and bundler groups.

This allows new workers to be added by simply adding a new subclass
of MiqWorker rather than maintaining a list of worker classes in the
core repo.

Additionally this brings us closer to the ability to run a separate
process that will access the database and determine which workers
should be running on which servers, all outside of the main application
code-base.
@carbonin
Copy link
Member Author

16 doesn't feel all that bad...I'd go for it

Did the best I could, but only came up with 15:

MAXIMUM
EXTREMELY_HIGH
VERY_HIGH
HIGH
HIGH_HIGH_MEDIUM
HIGH_MEDIUM
MEDIUM_HIGH_MEDIUM
MEDIUM
MEDIUM_LOW_MEDIUM
LOW_MEDIUM
LOW_LOW_MEDIUM
LOW
VERY_LOW
EXTREMELY_LOW
MINIMUM

Pretty sure I'd still rather just have numbers 😆

@carbonin
Copy link
Member Author

Assuming we're not defining 15 constants for priorities this will be good to go once the provider and schema PRs are merged.

@Fryguy
Copy link
Member

Fryguy commented Nov 20, 2019

Did the best I could, but only came up with 15:

OHHHHH I totally wasn't expecting that at all... I was thinking more like in core we do:

KILL_PRIORITY_METRICS_PROCESSOR_WORKERS = 10
KILL_PRIORITY_METRICS_COLLECTOR_WORKERS = 20
KILL_PRIORITY_REPORTING_WORKERS         = 30
KILL_PRIORITY_SMART_PROXY_WORKERS       = 40
KILL_PRIORITY_GENERIC_WORKERS           = 50
KILL_PRIORITY_EVENT_HANDLERS            = 60
KILL_PRIORITY_REFRESH_WORKERS           = 70
KILL_PRIORITY_SCHEDULE_WORKERS          = 80
KILL_PRIORITY_PRIORITY_WORKERS          = 90
KILL_PRIORITY_WEB_SERVICE_WORKERS       = 100
KILL_PRIORITY_REFRESH_CORE_WORKERS      = 110
KILL_PRIORITY_VIM_BROKER_WORKERS        = 120
KILL_PRIORITY_EVENT_CATCHERS            = 130
KILL_PRIORITY_UI_WORKERS                = 140
KILL_PRIORITY_REMOTE_CONSOLE_WORKERS    = 150
KILL_PRIORITY_COCKPIT_WS_WORKERS        = 160

Then in a worker you do:

# app/models/manageiq/providers/base_manager/event_catcher.rb

  def self.kill_priority
    KILL_PRIORITY_EVENT_CATCHERS
  end

Seeding will just use those values so we can change them at any time and they should update.

For pluggability, eventually something like the VimBrokerWorker, which is vmware specific, can do something like the following (and we would remove KILL_PRIORITY_VIM_BROKER_WORKERS)

  def self.kill_priority
    KILL_PRIORITY_WEB_SERVICE_WORKERS + 5
  end

which allows them to insert themselves in the list relative to other items in the list.

@carbonin
Copy link
Member Author

ahahaha okay that makes a ton more sense @Fryguy I'll go that way.

STDERR.puts "ERR: `#{worker_class}` WORKER CLASS NOT FOUND! Please run with `-l` to see possible worker class names."
exit 1
end

# Skip heartbeating with single worker
ENV["DISABLE_MIQ_WORKER_HEARTBEAT"] ||= options[:heartbeat] ? nil : '1'
ENV["BUNDLER_GROUPS"] = MIQ_WORKER_TYPES[worker_class].join(',')
ENV["BUNDLER_GROUPS"] = worker_type.bundler_groups.join(',')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commenting regarding discussion we had in person... because line 63 loads environment which will have already read and used the BUNDLER_GROUPS env var from application.rb here, this manipulation will be too late.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this I moved the bundler groups envvar to the caller of run_single_worker.rb.

The logic was that we would either take the caller's env var if it was set and have some default in this script, but since that exact logic is already taken care of in application.rb, I didn't think it made sense to duplicate it here.

The only thing we lose with this approach is getting the correct bundler groups when someone runs run_single_worker.rb from the command line, but I would argue that if that person wants bundler groups, they will know to set the environment variable.

end

private_class_method def self.classes_for_seed
@classes_for_seed ||= MiqWorker.descendants.select { |w| w.subclasses.empty? } - EXCLUDED_CLASS_NAMES.map(&:constantize)
Copy link
Member

@jrafanie jrafanie Nov 20, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forget, will this autoload all workers in subclasses in external repos such as provider workers?

I wonder what will happen here when/if we dissect bundler groups into small components and therefore won't have all the worker classes. But that's for another day.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it will autoload all the provider subclasses.

If we split out the bundler groups for providers I would imagine the server would need all of the groups to be able to deal with provider constants, right? I don't think any of the workers with pared down bundler groups would be calling this method.

The caller will set the bundler groups outside of the worker
entrypoint. This also prevents the chicken-and-egg problem of needing
to get the bundler groups from the database before loading the environment
@miq-bot
Copy link
Member

miq-bot commented Nov 20, 2019

Some comments on commits carbonin/manageiq@2947aac~...5c9469f

lib/workers/bin/run_single_worker.rb

  • ⚠️ - 66 - Detected puts. Remove all debugging statements.

@miq-bot
Copy link
Member

miq-bot commented Nov 20, 2019

Checked commits carbonin/manageiq@2947aac~...5c9469f with ruby 2.5.5, rubocop 0.69.0, haml-lint 0.20.0, and yamllint 1.10.0
31 files checked, 1 offense detected

spec/models/miq_server/worker_management/monitor_spec.rb

@Fryguy Fryguy closed this Nov 21, 2019
@Fryguy Fryguy reopened this Nov 21, 2019
@Fryguy
Copy link
Member

Fryguy commented Nov 21, 2019

cross_repo tests were green, so merging.

@Fryguy Fryguy merged commit f75eb39 into ManageIQ:master Nov 21, 2019
@Fryguy Fryguy added this to the Sprint 125 Ending Nov 25, 2019 milestone Nov 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants