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

Refactor Chargeback data to instance of Chargeback #11925

Merged
merged 7 commits into from
Oct 25, 2016

Conversation

isimluk
Copy link
Member

@isimluk isimluk commented Oct 13, 2016

Chargeback calculation is now set of class methods. Sometimes using class variables. If we convert this to instance methods, we may achieve

  • better structure of the code
  • name things better to reflect meaning
  • achieve performance boost using memoization

This is first step to achieve this. More to came. Many thanks to @lpichler for many consultations!

@miq-bot add_label refactoring, chargeback

@isimluk
Copy link
Member Author

isimluk commented Oct 13, 2016

@miq-bot assign @gtanzillo

@isimluk isimluk changed the title Refacor Chargeback data to instance of Chargeback Refactor Chargeback data to instance of Chargeback Oct 13, 2016

if defined_column_for_report
[metric_key, metric_group_key].each { |col| col_hash[col] = metric }
[cost_key, cost_group_key, 'total_cost'].each { |col| col_hash[col] = cost }
end

col_hash
col_hash.each do |k, val|
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@@ -33,7 +35,7 @@ def self.build_results_for_report_chargeback(options)
base_rollup = base_rollup.select(*rate_cols)

timerange = get_report_time_range(options, interval, tz)
data = {}
cb.data = {}
Copy link
Member

Choose a reason for hiding this comment

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

@isimluk Where does cb get instantiated?

Copy link
Member Author

Choose a reason for hiding this comment

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

Near the method start. It was already there.

@isimluk isimluk force-pushed the refactor-cb-bind-data-to-instance branch from b5208cd to f4d8614 Compare October 19, 2016 11:21
@isimluk
Copy link
Member Author

isimluk commented Oct 19, 2016

@lpichler @gtanzillo I have improved this pr based on what I learned about Chargebacks yesterday.

Also, I've tried to make respective commit messages useful for reviewer.

@miq-bot
Copy link
Member

miq-bot commented Oct 19, 2016

<pr_mergeability_checker />This pull request is not mergeable. Please rebase and repush.

@isimluk isimluk force-pushed the refactor-cb-bind-data-to-instance branch 2 times, most recently from 1b88b32 to 2109ad3 Compare October 20, 2016 14:52
@isimluk
Copy link
Member Author

isimluk commented Oct 20, 2016

Reworked on top of the @lpichler's new calculations.

Ready to be merged!

Copy link
Member

@gtanzillo gtanzillo left a comment

Choose a reason for hiding this comment

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

@isimluk These changes look ok to me 👍 . Can you confirm that there is enough coverage in the existing chargeback tests to test these changes?

calculated_costs['fixed_compute_metric'] = chargeback_fields_present if chargeback_fields_present
def calculate_costs(metric_rollup_records, rates, hours_in_interval)
chargeback_fields_present = metric_rollup_records.count(&:chargeback_fields_present?)
self.fixed_compute_metric = chargeback_fields_present if chargeback_fields_present
Copy link
Member

Choose a reason for hiding this comment

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

This feels a bit weird or fragile because fixed_compute_metric is only defined in the descendant classes and in in the base class.

Copy link
Member Author

Choose a reason for hiding this comment

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

Nod.

Although, I am not bringing the fragility here. I only make changes, that make this easier to spot.

Previously, we have build a hash (was stored in data[key] or calculated_costs), this hash had various keys not defined in Chargeback parent class. Later we passed this hash to new() and hoped for the best. We then modified the code to assume some of the keys are always present, like fixed_compute_metric. Perhaps we can later move cols that are always needed to the Chargeback parent class?

I have noticed, there are other parts of Chargeback class that rely on its descendants to define certain things. For example, get_keys_and_extra_fields, get_rate_parents, report_col_options, report_static_cols, where_clause, and perhaps more. Thus, this pattern is common in this part of the code.

@isimluk
Copy link
Member Author

isimluk commented Oct 24, 2016

Can you confirm that there is enough coverage in the existing chargeback tests to test these changes?

Yep, I feel confident in this regard.

This pr does not bring a change of behavior (output for a given input). It only re-structures some of the code and data during the processing. For such change, I think, tests need to go through all the methods I touched. That is already achieved for each of Chargeback.descendants.

@miq-bot
Copy link
Member

miq-bot commented Oct 24, 2016

<pr_mergeability_checker />This pull request is not mergeable. Please rebase and repush.

@gtanzillo
Copy link
Member

👍 I'm good with this. Will merge once you rebase and eliminate the conflicts.

@isimluk isimluk force-pushed the refactor-cb-bind-data-to-instance branch from 2109ad3 to ec03a76 Compare October 25, 2016 06:19
@isimluk
Copy link
Member Author

isimluk commented Oct 25, 2016

Thanks!!

Conflicts resolved.

@isimluk isimluk force-pushed the refactor-cb-bind-data-to-instance branch from ec03a76 to bc575d3 Compare October 25, 2016 08:32
Do instanciate early in the calculation process.

This will allows us to encapsulate code to these instances.
It only manipulates Chargeback instance based on perf record.
This lowers the indirection and complexity.
As we see, it takes a very long name to describe what it does. Perhaps
we can lower the complexity in future.
@miq-bot
Copy link
Member

miq-bot commented Oct 25, 2016

Checked commits isimluk/manageiq@527712d~...bc575d3 with ruby 2.2.5, rubocop 0.37.2, and haml-lint 0.16.1
1 file checked, 0 offenses detected
Everything looks good. 🏆

@gtanzillo gtanzillo added this to the Sprint 49 Ending Nov 14, 2016 milestone Oct 25, 2016
@gtanzillo gtanzillo merged commit 3676e42 into ManageIQ:master Oct 25, 2016
@simaishi
Copy link
Contributor

Backported to Euwe via #13419

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