-
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
Filter relevant fields also according to chargeback class in Chargeback #17414
Filter relevant fields also according to chargeback class in Chargeback #17414
Conversation
@miq-bot add_label chargeback |
Checked commit lpichler@213289c with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0 |
@@ -152,7 +152,7 @@ def calculate_costs(consumption, rates) | |||
self.class.try(:refresh_dynamic_metric_columns) | |||
|
|||
rates.each do |rate| | |||
rate.rate_details_relevant_to(relevant_fields).each do |r| | |||
rate.rate_details_relevant_to(relevant_fields, self.class.attribute_names).each do |r| |
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.
It feels like this should be a method... I believe you're doing a set intersection of relevant_fields
and self.class.attribute_names)
in rate_details_relevant_to
below, right?
def calculate_costs(consumption, rates)
self.fixed_compute_metric = consumption.chargeback_fields_present if consumption.chargeback_fields_present
self.class.try(:refresh_dynamic_metric_columns)
rates.each do |rate|
rate.rate_details_relevant_to(relevant_fields & self.class.attribute_names).each do |r|
Either that or move the set intersection into the method below.
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.
Unfortunately , it is not same.
Originally,
method rate_details_relevant_to
is going thru all rate chargeback details
and it is basically asking each rate detail chargeback
- Does your cost calculation affect a selected report fields(report_cols) ?
And it will meet also rate detail chargeback with derived_vm_numvcpu_cores
.
But if you have only total_cost on report - this total value are affecting all columns - derived_vm_numvcpu_cores included.
But we need to refuse derived_vm_numvcpu_cores
for chargeback vm.
Hopefully, you understand better.
And sure we need to do some refactoring here: for example similar condition is also in ChargebackRateDetail#charge:97
method, I will do it in folluw up PR
def rate_details_relevant_to(report_cols) | ||
# we can memoize, as we get the same report_cols thrrough the life of the object | ||
@relevant ||= chargeback_rate_details.select { |r| r.affects_report_fields(report_cols) } | ||
def rate_details_relevant_to(report_cols, allowed_cols) |
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.
We probably don't want to change this method signature if we don't have to.
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.
yes we don't want but it is necessary here. But we can improve with some unification because similar condition is also in ChargebackRateDetail#charge:97 method,as I mentioned above.
@@ -12,7 +12,7 @@ class ChargebackRateDetail < ApplicationRecord | |||
|
|||
delegate :rate_type, :to => :chargeback_rate, :allow_nil => true | |||
|
|||
delegate :metric_key, :cost_keys, :rate_key, :to => :chargeable_field | |||
delegate :metric_column_key, :metric_key, :cost_keys, :rate_key, :to => :chargeable_field |
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.
Wait, we still want to delegate metric_key
, don't we?
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.
No, we need it in ChargebackRateDetail#charge
method
# fixed_compute_metric is used in report and calculations | ||
# TODO: remove and unify with metric_key | ||
def metric_column_key | ||
fixed? ? metric_key.gsub(/\_1|\_2/, '') : metric_key |
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'm not sure what this is doing
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.
It is hack,
we have chargeback_rate_details and each detail is representing metric column na cost column.
For example:
�CPU Allocated Cost has metric column: cpu_allocated_metric
and cost column cpu_allocated_cost
so when we are checking if cpu_allocated_cost
is allowed to report, we are asking here https://github.com/ManageIQ/manageiq/pull/17414/files/213289cd034ea8054bbb9a30c80d229cd776c049#diff-7c998acd3d11c70ed830e216754f4b6bR42
if string cpu_allocated_cost
(from selected fields
) is related to metric_key
which is based from ChargeableField#group and Chargeback#source
.
But we have to add exception for fixed rate detail
because there are two columns
fixed_compute_1_cost
and fixed_compute_1_cost
but related metric field is only one: fixed_compute_metric
and then method ChargeableField#metric_key is not enough (it would produce fixed_compute_1_metric
) but we need to base check in fixed_compute_metric
(some for storage)
so input of this method is fixed_compute_1_metric
and it should remove _1
(etc.)
@lpichler I'll merge this for now to fix the issue. Can you do your suggested improvements in a followup PR? Thanks! |
sure @jrafanie, thanks! |
Backported to Gaprindashvili via #17639 |
Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1580543
This bug has been discovered after this fix and unfortunately chargeback report is broken with mentioned PR.
Error msg (during generation report for VMs)
Note:
derived_vm_numvcpu_cores
is related only to chargeback for chargeback for containers.Why?
Chargeback rates contain chargeback rate details (
ChargebackRateDetail
) for all types of chargeback (VMs, ContainerProjects, ContainerImages).In calculation we are cycling thru all rate details independently on chargeback type and then irrelevant fields should be skipped for certain chargeback type. It was basically accidentally skipped before this recent fix and now after the fix, relevant field is ( for example
cpu core allocated
) not skipped for certain chargeback type(example: for Chargeback for VM - even field is related only for chargeback for containers) because of eventual participation on calculation oftotal_cost
column done in fix.Fix
Now column represented by chargeback detail rate has to be present as attribute in related chargeback class.
cc @gtanzillo
@miq-bot assign @jrafanie
@miq-bot add_label gaprindashvili/yes