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

Fix max method on empty array in chargeback storage report #16575

Conversation

lpichler
Copy link
Contributor

@lpichler lpichler commented Dec 1, 2017

Issue is that when we have result as empty array(It is because we don't have any VimPerformance yet) of method VimPerformanceStates#sub_metric_rollups then on this empty array can be called method max and then we have nil in value:

[].max => nil

Note: for sum it is ok:

[].sum => 0

Error message

➜  manageiq git:(master) ✗ ./tools/generate_report.rb 'storage-volume'
** override_gem: manageiq-ui-classic, [{:path=>"/Users/liborpichler/manageiq/manageiq-ui-classic"}], caller: /Users/liborpichler/manageiq/manageiq/bundler.d/Gemfile.dev.rb
** Using session_store: ActionDispatch::Session::MemCacheStore
Generating report... storage-volume
/Users/liborpichler/manageiq/manageiq/app/models/chargeback_rate_detail.rb:104:in `block in find_rate': undefined method `*' for nil:NilClass (NoMethodError)
	from /Users/liborpichler/manageiq/manageiq/.bundle/ruby/2.4.0/gems/activerecord-5.0.6/lib/active_record/relation/delegation.rb:38:in `each'
	from /Users/liborpichler/manageiq/manageiq/.bundle/ruby/2.4.0/gems/activerecord-5.0.6/lib/active_record/relation/delegation.rb:38:in `each'
	from /Users/liborpichler/manageiq/manageiq/app/models/chargeback_rate_detail.rb:104:in `detect'
	from /Users/liborpichler/manageiq/manageiq/app/models/chargeback_rate_detail.rb:104:in `find_rate'
	from /Users/liborpichler/manageiq/manageiq/app/models/chargeback_rate_detail.rb:123:in `hourly_cost'
	from /Users/liborpichler/manageiq/manageiq/app/models/chargeback_rate_detail.rb:228:in `metric_and_cost_by'
	from /Users/liborpichler/manageiq/manageiq/app/models/chargeback_rate_detail.rb:90:in `charge'
	from /Users/liborpichler/manageiq/manageiq/app/models/chargeback.rb:137:in `block (2 levels) in calculate_costs'
	from /Users/liborpichler/manageiq/manageiq/app/models/chargeback.rb:136:in `each'
	from /Users/liborpichler/manageiq/manageiq/app/models/chargeback.rb:136:in `block in calculate_costs'
	from /Users/liborpichler/manageiq/manageiq/app/models/chargeback.rb:135:in `each'
	from /Users/liborpichler/manageiq/manageiq/app/models/chargeback.rb:135:in `calculate_costs'
	from /Users/liborpichler/manageiq/manageiq/app/models/chargeback.rb:33:in `block in build_results_for_report_chargeback'
	from /Users/liborpichler/manageiq/manageiq/app/models/chargeback/consumption_history.rb:27:in `block (2 levels) in for_report'
	from /Users/liborpichler/manageiq/manageiq/app/models/chargeback/consumption_history.rb:25:in `each'
	from /Users/liborpichler/manageiq/manageiq/app/models/chargeback/consumption_history.rb:25:in `block in for_report'
	from /Users/liborpichler/manageiq/manageiq/app/models/chargeback/consumption_history.rb:9:in `each'
	from /Users/liborpichler/manageiq/manageiq/app/models/chargeback/consumption_history.rb:9:in `each_cons'
	from /Users/liborpichler/manageiq/manageiq/app/models/chargeback/consumption_history.rb:9:in `for_report'
	from /Users/liborpichler/manageiq/manageiq/app/models/chargeback.rb:20:in `build_results_for_report_chargeback'
	from /Users/liborpichler/manageiq/manageiq/app/models/chargeback_vm.rb:62:in `build_results_for_report_ChargebackVm'
	from /Users/liborpichler/manageiq/manageiq/app/models/miq_report/generator.rb:199:in `_generate_table'
	from /Users/liborpichler/manageiq/manageiq/app/models/miq_report/generator.rb:173:in `block in generate_table'
	from /Users/liborpichler/manageiq/manageiq/app/models/user.rb:246:in `with_user'

Links

@miq-bot assign @gtanzillo

@miq-bot add_label bug, chargeback, blocker

this can happen when method ConsumptionWithRollups#sub_metric_rollups
returns empty array when there are no related VimPerformanceState
records
@miq-bot
Copy link
Member

miq-bot commented Dec 1, 2017

Checked commits lpichler/manageiq@6757fe6~...71d629e with ruby 2.3.3, rubocop 0.47.1, haml-lint 0.20.0, and yamllint 1.10.0
2 files checked, 0 offenses detected
Everything looks fine. 🏆

@lpichler
Copy link
Contributor Author

lpichler commented Dec 1, 2017

@miq-bot add_label gaprindashvili/yes

@gtanzillo gtanzillo added this to the Sprint 75 Ending Dec 11, 2017 milestone Dec 1, 2017
@gtanzillo gtanzillo merged commit a06bd40 into ManageIQ:master Dec 1, 2017
@lpichler lpichler deleted the fix_empty_array_in_chargeback_storage_report branch December 1, 2017 15:39
@lpichler
Copy link
Contributor Author

lpichler commented Dec 1, 2017

@simaishi

simaishi pushed a commit that referenced this pull request Dec 1, 2017
…_storage_report

Fix max method on empty array in chargeback storage report
(cherry picked from commit a06bd40)

https://bugzilla.redhat.com/show_bug.cgi?id=1517956
@simaishi
Copy link
Contributor

simaishi commented Dec 1, 2017

Gaprindashvili backport details:

$ git log -1
commit 1ad25ed36517a2e917365b2b4374ab338d25b77a
Author: Gregg Tanzillo <gtanzill@redhat.com>
Date:   Fri Dec 1 10:37:25 2017 -0500

    Merge pull request #16575 from lpichler/fix_empty_array_in_chargeback_storage_report
    
    Fix max method on empty array in chargeback storage report
    (cherry picked from commit a06bd40f283a83c4d58cf6edf312993158f23e18)
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1517956

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.

4 participants