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

[Bug] Cannot eagerly load the polymorphic association :resource in performance report #19664

Closed
lpichler opened this issue Dec 19, 2019 · 13 comments
Assignees
Labels

Comments

@lpichler
Copy link
Contributor

Reproducer:

replace context "performance reports" in
./spec/models/miq_report_spec.rb

   context "performance reports" do
      let(:report) do
        MiqReport.new(
            :title   => "vim_perf_daily.yaml",
            :db      => "VimPerformanceDaily",
            :cols    => %w(timestamp cpu_usagemhz_rate_average max_derived_cpu_available resource.derived_memory_used_low_over_time_period),
            :include => {"resource" => {"columms" => 'derived_memory_used_low_over_time_period'}})
      end

      before do
        EvmSpecHelper.local_miq_server
        ems = FactoryBot.create(:ems_vmware)
        vm = FactoryBot.create(:vm_vmware, :ext_management_system => ems)
        time_profile = FactoryBot.create(:time_profile_utc)
        FactoryBot.create(:metric_rollup_vm_daily, :resource => vm, :time_profile => time_profile)
      end

      it "runs report" do
        report.generate_table(:userid => "admin")
      end
    end

run and then you will get error message:
polymorphic association :resource in performance report

this error is also in UI(toolbar button Monitoring -> Utilization on VM summary screen) when those yaml are used:

➜  manageiq git:(master) ✗ ag 'resource:' ./ --yaml
Thu Dec 19 16:13:43 CET 2019
product/charts/miq_reports/vim_perf_daily.yaml
80:  resource:

product/charts/miq_reports/vim_perf_daily_cloud.yaml
78:  resource:

Caused by

most likely by #19127
and issue is only on upstream (no on ivanchuck, no on hammer )

I am not sure about proper fix but it looks we need to somehow include this condition
https://github.com/ManageIQ/manageiq/pull/19127/files#diff-8d948055de14ced0e63abf9637a9a788L415

Feel free to use my spec in your PR.

@kbrock as you author of the #19127 maybe you will know better how to fix it.

cc @NickLaMuro

thanks !

@lpichler
Copy link
Contributor Author

@miq-bot add_label bug

@miq-bot miq-bot added the bug label Dec 19, 2019
@kbrock kbrock self-assigned this Dec 19, 2019
@chessbyte chessbyte changed the title Cannot eagerly load the polymorphic association :resource in performance report [Bug] Cannot eagerly load the polymorphic association :resource in performance report Jan 3, 2020
@kbrock
Copy link
Member

kbrock commented Jan 7, 2020

fun stuff:

# fails
MetricRollup.includes(:resource, :time_profile).references("time_profiles").first
# works
MetricRollup.preload(:resource).includes(:time_profile).references("time_profiles").first
MetricRollup.includes(:resource).first
MetricRollup.includes(:time_profile).references("time_profiles").first
MetricRollup.preload(:resource, :time_profile).includes(:time_profile).references("time_profiles").first

# NEW:
# works
MetricRollup.preload(:resource, :time_profile).eager_load(:time_profile).first

reproducer coded up in master...kbrock:polymorphic_through

kbrock added a commit to kbrock/manageiq that referenced this issue Jan 7, 2020
@martinpovolny
Copy link
Member

Similar problem from the UI side.

Go to Compute --> Infra --> VMs
Select a VM, go to details.
Then in the menu choose (toolbar) Monitoring --> Utilization)

A task is fired at this point through the queue. And the task will fail with a stacktrace in the EVM log. Unfortunately there's no error handling for the failed task so the UI will end up in an infinite busy-wait loop.

[----] E, [2020-01-22T15:53:45.501409 #467320:da85e0] ERROR -- : [ActiveRecord::EagerLoadPolymorphicError]: Cannot eagerly load the polymorphic association :resource  Method:[block (2 levels) in <class:LogProxy>
]
[----] E, [2020-01-22T15:53:45.501573 #467320:da85e0] ERROR -- : /home/martin/.rvm/gems/ruby-2.5.5/gems/activerecord-5.1.7/lib/active_record/associations/join_dependency.rb:244:in `block in build'
/home/martin/.rvm/gems/ruby-2.5.5/gems/activerecord-5.1.7/lib/active_record/associations/join_dependency.rb:237:in `each'
/home/martin/.rvm/gems/ruby-2.5.5/gems/activerecord-5.1.7/lib/active_record/associations/join_dependency.rb:237:in `map'
/home/martin/.rvm/gems/ruby-2.5.5/gems/activerecord-5.1.7/lib/active_record/associations/join_dependency.rb:237:in `build'
/home/martin/.rvm/gems/ruby-2.5.5/gems/activerecord-5.1.7/lib/active_record/associations/join_dependency.rb:99:in `initialize'
/home/martin/.rvm/gems/ruby-2.5.5/gems/activerecord-5.1.7/lib/active_record/relation/finder_methods.rb:392:in `new'
/home/martin/.rvm/gems/ruby-2.5.5/gems/activerecord-5.1.7/lib/active_record/relation/finder_methods.rb:392:in `construct_join_dependency'
/home/martin/.rvm/gems/ruby-2.5.5/gems/activerecord-5.1.7/lib/active_record/relation/finder_methods.rb:368:in `find_with_associations'
/home/martin/.rvm/gems/ruby-2.5.5/gems/activerecord-virtual_attributes-1.5.0/lib/active_record/virtual_attributes/virtual_fields.rb:311:in `find_with_associations'
/home/martin/.rvm/gems/ruby-2.5.5/gems/activerecord-virtual_attributes-1.5.0/lib/active_record/virtual_attributes/virtual_fields.rb:313:in `find_with_associations'
/home/martin/.rvm/gems/ruby-2.5.5/gems/activerecord-5.1.7/lib/active_record/relation.rb:669:in `exec_queries'
/home/martin/.rvm/gems/ruby-2.5.5/gems/activerecord-5.1.7/lib/active_record/relation.rb:546:in `load'
/home/martin/.rvm/gems/ruby-2.5.5/gems/activerecord-5.1.7/lib/active_record/relation.rb:255:in `records'
/home/martin/.rvm/gems/ruby-2.5.5/gems/activerecord-5.1.7/lib/active_record/relation/delegation.rb:39:in `each'
/home/martin/Projects/manageiq/app/models/metric/helper.rb:129:in `sort_by'
/home/martin/Projects/manageiq/app/models/metric/helper.rb:129:in `remove_duplicate_timestamps'
/home/martin/Projects/manageiq/app/models/miq_report/generator.rb:330:in `generate_basic_results'
/home/martin/Projects/manageiq/app/models/miq_report/generator.rb:204:in `_generate_table'
/home/martin/Projects/manageiq/app/models/miq_report/generator.rb:185:in `block in generate_table'
/home/martin/Projects/manageiq/app/models/user.rb:295:in `with_user'
/home/martin/Projects/manageiq/app/models/miq_report/generator.rb:185:in `generate_table'
/home/martin/Projects/manageiq/app/models/miq_report/generator/async.rb:33:in `block in _async_generate_tables'
/home/martin/Projects/manageiq/app/models/miq_report/generator/async.rb:32:in `each'
/home/martin/Projects/manageiq/app/models/miq_report/generator/async.rb:32:in `each_with_index'


@skateman
Copy link
Member

@kbrock I'm kinda blocked by this 😕 in resolving ManageIQ/manageiq-ui-classic#6534

kbrock added a commit to kbrock/manageiq that referenced this issue Jan 29, 2020
kbrock added a commit to kbrock/manageiq that referenced this issue Jan 29, 2020
@chessbyte
Copy link
Member

@kbrock @NickLaMuro what is the status of this issue?

@NickLaMuro
Copy link
Member

@chessbyte sorry for the lack of a follow up on here, but #19804 should have fixed this issue.

@chessbyte
Copy link
Member

chessbyte commented Feb 13, 2020

@NickLaMuro can you validate the reproducer here is addressed.

@NickLaMuro
Copy link
Member

@kbrock
Copy link
Member

kbrock commented Feb 14, 2020

@chessbyte @NickLaMuro Yes, The report spec is the reproducer from Libor.

@chessbyte
Copy link
Member

@kbrock @NickLaMuro so can this issue be closed as resolved?

@chessbyte
Copy link
Member

@lpichler is this issue fixed?

@NickLaMuro
Copy link
Member

@kbrock @NickLaMuro so can this issue be closed as resolved?

@chessbyte For what it is worth, I have asked David to test it out in gitter:

https://gitter.im/ManageIQ/manageiq?at=5e3c3b58dc52c34ace4d01f2

And he said that it fixed his issue as well.

@skateman
Copy link
Member

skateman commented Feb 14, 2020

It fixed the issue I was experiencing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants