-
Notifications
You must be signed in to change notification settings - Fork 897
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
Output constant must match the constantized class name #19400
Conversation
👍 🐉 |
@bdunne @Fryguy @d-m-u what do you think of this? We don't know if the user in the referenced BZ actually added a new worker type for the foreman event catcher without adding the class for it but we definitely see the logs indicating the base manager event catcher started. We should never have gotten to this point... sync_workers should never try to call
|
haha, this is what the logging looks like... I didn't do an miq exception because I think we want the backtrace here:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is probably a good idea regardless, but I'm not sure it's the source of the problem. If you add the same provider type, do you seen the same errors in your logs?
Yes. With just this change: index c692917d17..9e055ee4cd 100644
--- a/lib/workers/miq_worker_types.rb
+++ b/lib/workers/miq_worker_types.rb
@@ -16,6 +16,7 @@ MIQ_WORKER_TYPES = {
"ManageIQ::Providers::AzureStack::CloudManager::RefreshWorker" => %i[manageiq_default],
"ManageIQ::Providers::AzureStack::NetworkManager::RefreshWorker" => %i[manageiq_default],
"ManageIQ::Providers::Foreman::ConfigurationManager::RefreshWorker" => %i(manageiq_default),
+ "ManageIQ::Providers::Foreman::ProvisioningManager::EventCatcher" => %i(manageiq_default),
"ManageIQ::Providers::Foreman::ProvisioningManager::RefreshWorker" => %i(manageiq_default),
"ManageIQ::Providers::Google::CloudManager::EventCatcher" => %i(manageiq_default),
"ManageIQ::Providers::Google::CloudManager::MetricsCollectorWorker" => %i(manageiq_default), rake evm:start logs this branch's error:
|
I'm not sure I like bandaid-ing an issue we don't really understand. This feels like a bug with constantize. How can it resolve an unknown constant? |
Ohhh...it's the 'ol find the constant in the nearest class issue... Similar to 😩 |
2cc0efc
to
e675202
Compare
Constantize can demodulize to an incorrect class, so we should skip any class names that don't constantize to the expected class. In this example, if you do the following in rails console, you'll get the following: Autoload the base manager eventcatcher: ManageIQ::Providers::BaseManager::EventCatcher Try to constantize a non existing event catcher in a valid provider namespace: "ManageIQ::Providers::Foreman::ProvisioningManager::EventCatcher".constantize => ManageIQ::Providers::BaseManager::EventCatcher Seen in the logs for https://bugzilla.redhat.com/show_bug.cgi?id=1759711
e675202
to
afe1f02
Compare
Checked commit jrafanie@afe1f02 with ruby 2.4.6, rubocop 0.69.0, haml-lint 0.20.0, and yamllint 1.10.0 |
So, do we know where the source of this issue is? |
this is great. |
Technically, yes, because autoload uses const_get.
I don't know. I will have to check that out. The problem is const_get . Rails autoload is just a victim of it doing the wrong thing: irb(main):001:0> ManageIQ::Providers::BaseManager::EventCatcher
PostgreSQLAdapter#log_after_checkout, connection_pool: size: 5, connections: 1, in use: 1, waiting_in_queue: 0
=> ManageIQ::Providers::BaseManager::EventCatcher(id: integer, guid: string, status: string, started_on: datetime, stopped_on: datetime, last_heartbeat: datetime, pid: integer, queue_name: string, type: string, percent_memory: float, percent_cpu: float, cpu_time: float, os_priority: integer, memory_usage: decimal, memory_size: decimal, uri: string, miq_server_id: integer, sql_spid: integer, proportional_set_size: decimal, unique_set_size: decimal, href_slug: string, region_number: integer, region_description: string, friendly_name: string, uri_or_queue_name: string)
irb(main):002:0> Object.const_get("ManageIQ::Providers::Foreman::ProvisioningManager::EventCatcher")
=> ManageIQ::Providers::BaseManager::EventCatcher(id: integer, guid: string, status: string, started_on: datetime, stopped_on: datetime, last_heartbeat: datetime, pid: integer, queue_name: string, type: string, percent_memory: float, percent_cpu: float, cpu_time: float, os_priority: integer, memory_usage: decimal, memory_size: decimal, uri: string, miq_server_id: integer, sql_spid: integer, proportional_set_size: decimal, unique_set_size: decimal, href_slug: string, region_number: integer, region_description: string, friendly_name: string, uri_or_queue_name: string) |
Late to the party, but I thought |
even later to the party... yeah, I don't think it matters here if it's uses |
Right...in this case, the constant is always "found" (and thus no NameError nor nil); it just happens to not be the constant you asked for. Example: [1] pry(main)> String.const_get("String")
=> String That being said, I think this is all fixed in newer Rails / Ruby |
There is a second parameter (that defaults to true): String.const_get("String", false) # => NameError I couldn`t find any way to say don't be so liberal but don't freak out |
Constantize can demodulize to an incorrect class, so we should skip any class
names that don't constantize to the expected class.
In this example, if you do the following in rails console, you'll get the
following:
Autoload the base manager eventcatcher:
ManageIQ::Providers::BaseManager::EventCatcher
Try to constantize a non existing event catcher in a valid provider namespace:
"ManageIQ::Providers::Foreman::ProvisioningManager::EventCatcher".constantize
=> ManageIQ::Providers::BaseManager::EventCatcher
Seen in the logs for https://bugzilla.redhat.com/show_bug.cgi?id=1759711