-
Notifications
You must be signed in to change notification settings - Fork 900
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
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 |
---|---|---|
|
@@ -116,7 +116,7 @@ def new_chargeback_calculate_costs(consumption, rates) | |
:resource => MiqEnterprise.first) | ||
|
||
data = {} | ||
rate.rate_details_relevant_to(relevant_fields).each do |r| | ||
rate.rate_details_relevant_to(relevant_fields, self.class.attribute_names).each do |r| | ||
r.populate_showback_rate(plan, r, showback_category) | ||
measure = r.chargeable_field.showback_measure | ||
dimension, _, _ = r.chargeable_field.showback_dimension | ||
|
@@ -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 commentThe 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 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 commentThe reason will be displayed to describe this comment to others. Learn more. Unfortunately , it is not same. Originally, And it will meet also But we need to refuse Hopefully, you understand better. And sure we need to do some refactoring here: for example similar condition is also in |
||
r.charge(relevant_fields, consumption, @options).each do |field, value| | ||
next unless self.class.attribute_names.include?(field) | ||
self[field] = self[field].kind_of?(Numeric) ? (self[field] || 0) + value : value | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,9 +35,13 @@ def self.tag_class(klass) | |
super(klass) | ||
end | ||
|
||
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 commentThe 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 commentThe 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. |
||
# we can memoize, as we get the same report_cols through the life of the object | ||
@relevant ||= begin | ||
chargeback_rate_details.select do |r| | ||
r.affects_report_fields(report_cols) && allowed_cols.include?(r.metric_column_key) | ||
end | ||
end | ||
end | ||
|
||
def self.validate_rate_type(type) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. Wait, we still want to delegate 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. No, we need it in |
||
|
||
FORM_ATTRIBUTES = %i(description per_time per_unit metric group source metric chargeable_field_id sub_metric).freeze | ||
PER_TIME_TYPES = { | ||
|
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 columncpu_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-7c998acd3d11c70ed830e216754f4b6bR42if string
cpu_allocated_cost
(from selected fields
) is related tometric_key
which is based fromChargeableField#group and Chargeback#source
.But we have to add exception for
fixed rate detail
because there are two columnsfixed_compute_1_cost
andfixed_compute_1_cost
but related metric field is only one:fixed_compute_metric
and then method ChargeableField#metric_key is not enough (it would producefixed_compute_1_metric
) but we need to base check infixed_compute_metric
(some for storage)so input of this method is
fixed_compute_1_metric
and it should remove_1
(etc.)