-
Notifications
You must be signed in to change notification settings - Fork 899
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
Use foreign_key on the base model's name if ems_events association doesn't exist #23296
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,7 +63,7 @@ def find_one_event(assoc, order) | |
|
||
module ClassMethods | ||
def ems_event_filter_column | ||
@ems_event_filter_column ||= reflect_on_association(:ems_events).try(:foreign_key) || name.foreign_key | ||
@ems_event_filter_column ||= reflect_on_association(:ems_events).try(:foreign_key) || base_model.name.foreign_key | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a reason why the UPDATE: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see the other discussion, they should be fixed but not here. |
||
end | ||
|
||
def miq_event_filter_column | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,26 +46,46 @@ def event_where_clause(assoc) | |
# 2) EmsCluster#event_where_clause does an OR: ems_cluster_id OR (host_id in ? OR dest_host_id IN ?) OR (vm_or_template in ? OR dest_vm_or_template_id in ?) (for now we just do ems_cluster_id in ems_event_filter) | ||
# 3) Host#event_where_clause does an OR: host_id OR dest_host_id... right now we only do host_id in ems_event_filter | ||
# 4) VmOrTemplate#event_where_clause does an OR: vm_or_template_id OR dest_vm_or_template_id, we only do vm_or_template_id in ems_event_filter | ||
# 5) The following are tested below in the custom behavior section because they have different setup: | ||
# Container container_id | ||
# ContainerGroup container_group_id | ||
# ContainerNode container_node_id | ||
# ContainerProject container_project_id | ||
# ContainerReplicator container_replicator_id | ||
# The following classes are missing the event_where_clause and their _id column isn't in event_streams table... fix this by removing event mixin or making it work by adding the column. | ||
not_implemented = %w[HostAggregate PhysicalServerProfile] | ||
%w[ | ||
AvailabilityZone availability_zone_id | ||
EmsCluster ems_cluster_id | ||
ExtManagementSystem ems_id | ||
Host host_id | ||
HostAggregate host_aggregate_id | ||
PhysicalChassis physical_chassis_id | ||
PhysicalServer physical_server_id | ||
PhysicalServerProfile physical_server_profile_id | ||
PhysicalStorage physical_storage_id | ||
PhysicalSwitch physical_switch_id | ||
VmOrTemplate vm_or_template_id | ||
Vm vm_or_template_id | ||
].each_slice(2) do |klass, column| | ||
it "#{klass} uses #{column} and target_id and target_type" do | ||
obj = FactoryBot.create(klass.tableize.singularize) | ||
expect(obj.event_stream_filters["EmsEvent"]).to eq(column => obj.id) | ||
expect(obj.event_stream_filters.dig("MiqEvent", "target_id")).to eq(obj.id) | ||
expect(obj.event_stream_filters.dig("MiqEvent", "target_type")).to eq(obj.class.base_class.name) | ||
skip = not_implemented.include?(klass) | ||
klasses = klass.constantize.descendants.collect(&:name).unshift(klass) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note, EmsCluster does the right thing, but subclasses weren't. This test recreated reported issue so the fix above can verify the problem is addressed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FYI, without the code change, the test fails for each ems cluster subclass like below: 1) EventMixin event_stream_filters ManageIQ::Providers::InfraManager::Cluster uses ems_cluster_id and target_id and target_type
Failure/Error: expect(obj.event_stream_filters["EmsEvent"]).to eq(column => obj.id)
expected: {"ems_cluster_id"=>nil}
got: {"cluster_id"=>nil}
(compared using ==)
Diff:
@@ -1 +1 @@
-"ems_cluster_id" => nil,
+"cluster_id" => nil, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ASIDE: Really wish we were going away from This error suggests there is a problem with We used to use string keys instead of symbol keys because it fixed foreign keys while building sql in a generic way. Wonder if a newer version of rails changed that behavior. (it is also possible that I'm spouting a random and unrelated fact) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This particular code is just building a spec for each of the descendant classes - this seems like an appropriate use of descendants. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
To be fair, some event_where_clause are completely unusable in UI timelines as they do more complex joins on possibly multiple tables such as showing events for all objects under the cluster (host, vm, templates, etc.) as opposed to just events for the cluster. The first cut of |
||
klasses.each do |klass| | ||
it "#{klass} uses #{column} and target_id and target_type" do | ||
skip("Class: #{klass} hasn't fully implemented timeline events") if skip | ||
begin | ||
obj = FactoryBot.build(klass.tableize.singularize, :name => "test") | ||
rescue NameError | ||
skip "Unable to build factory from name: #{klass}, possibly due to inflections" | ||
end | ||
expect(obj.event_stream_filters["EmsEvent"]).to eq(column => obj.id) | ||
expect(obj.event_stream_filters.dig("MiqEvent", "target_id")).to eq(obj.id) | ||
expect(obj.event_stream_filters.dig("MiqEvent", "target_type")).to eq(obj.class.base_class.name) | ||
end | ||
end | ||
|
||
it "#{klass} behaves like event_where_clause for ems_events" do | ||
skip("Class: #{klass} hasn't implemented timeline events. This could be due to no event_where_clause, ems_events association, and/or _id column in event_streams") if skip | ||
obj = FactoryBot.create(klass.tableize.singularize) | ||
event = FactoryBot.create(:event_stream, column => obj.id) | ||
FactoryBot.create(:event_stream) | ||
|
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.
@agrare Do you know if HostAggregates can have events associated with them?
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.
See also the same question below in other models.
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.
HostAggregates are an openstack thing, I only see vm, host (like InfraManager::Host), and availability_zone in the openstack event parser
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.
The only model which does have events that was touched in this PR is PhysicalSwitch
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.
Do you have any idea why event mixin was included in host aggregates?
That's ultimately the problem. I'm trying to fix a bug in an unrelated model and the inconsistency in these other models becomes readily apparent when I try to expand the tests to cover the other models that pull in the event mixin so I can cover the failure with EmsCluster subclasses. These others don't behave like the other event mixin types. I hope it's a deletion but will need to dig into that in a followup.
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.
Honestly if I had to guess, they copied another model as the basis for the HostAggregate class.
The include went all the way back to the first commit in this model
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.
Are we good with a TODO to kick the can down the road?
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.
yeah, TODO is probably fine - no need to fix it all at once. That being said, I still want to discuss because I still don't understand the overall issue nor the fix.
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.
I would think we'd unwind event_mixin inclusion in models that shouldn't need it.