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

[EUWE] Chargebacks for SCVMM (rollup-less) #13419

Merged
merged 73 commits into from
Jan 18, 2017
Merged
Changes from 1 commit
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
fc542ae
Set @options only once
isimluk Oct 19, 2016
dfee861
Drop support from start_time and end_time options
isimluk Oct 19, 2016
c10ab4e
Drop chargeback_type option documentation
isimluk Oct 19, 2016
7196894
Use Struct for storing Chargeback calculation options
isimluk Oct 19, 2016
e4ee6ec
Refactor: Extract method: tz
isimluk Oct 20, 2016
67a678f
Default interval should be property of ReportOptions
isimluk Oct 20, 2016
9257725
Refactor: move and rename method: report_time_range
isimluk Oct 20, 2016
46ab551
Refactor: move and rename method: duration_of_report_step
isimluk Oct 20, 2016
6595272
Do not pass interval variable along, use @options
isimluk Oct 20, 2016
24a6c15
Refactor: Extract method: start_of_report_step
isimluk Oct 20, 2016
6b2d5c3
Refactor: Extract method: tag_hash
isimluk Oct 20, 2016
0ad8578
Refactor: Extract method: report_step_range
isimluk Oct 20, 2016
6968a20
Set default :ext_options in Chargeback::ReportOptions
isimluk Oct 20, 2016
19417a7
Be explicit, when creating the report results
isimluk Oct 19, 2016
004f017
Do not instanciate Chargeback at the end of calculation
isimluk Oct 19, 2016
cbf9471
Avoid extra merge, compose hash in situ
isimluk Oct 20, 2016
603b3db
Move calculate_costs method to instance
isimluk Oct 19, 2016
69a26e8
Make reportable_metric_and_cost_fields private instance method
isimluk Oct 19, 2016
a2a41d3
Calculate key/values and report them in a single method
isimluk Oct 19, 2016
4775bfa
Rename method to better reflect what it does
isimluk Oct 19, 2016
419d9b5
Rename cost to hourly_cost
isimluk Oct 25, 2016
ca349ae
Make a part of cb_rate_detail private
isimluk Oct 25, 2016
ec7fc49
Refactor: Extract method: metric_and_cost_by
isimluk Oct 27, 2016
7c2d029
Refactor: Extract methods to tell what the RateDetail affects
isimluk Nov 9, 2016
5845a82
Refactor: Extract method: Relevant fields
isimluk Nov 14, 2016
5ceb42e
Refactor: move charging logic from cb to rate
isimluk Nov 14, 2016
6acb055
Charge only, when it is relevant
isimluk Nov 14, 2016
21951df
Fix fixed-rates calculation when missing cb fields
isimluk Nov 14, 2016
aec4086
Refactor: Move parents_determining_rate to MetricRollup record
isimluk Nov 8, 2016
8d4db4d
Refactor: Extract rates cache to separate class
isimluk Nov 8, 2016
0e052fe
Refactor: Extract consumption to a separate class
isimluk Nov 22, 2016
92bca79
Collect & memoize consumption values only once
isimluk Nov 22, 2016
d056ce9
Instantiate consumption object early, before charging
isimluk Nov 22, 2016
d7173b9
Refactor: Extract variable to memoized method
isimluk Nov 22, 2016
e075f56
Consumption should tell how many hours are in the interval
isimluk Nov 22, 2016
9e756c6
Instantiate Consumption object as early as possible
isimluk Nov 22, 2016
318efe1
If we round to seconds we can be more accurate in fact
isimluk Nov 22, 2016
69df278
Move hours_in_interval method to Consumption
isimluk Nov 22, 2016
b7d4c2b
Refactor: Extract method: classification_for_perf
isimluk Nov 29, 2016
710004f
Split key and extra keys methods
isimluk Nov 29, 2016
ad1f186
Put Report options to chargeback instance
isimluk Nov 29, 2016
c9d8bd2
Expand class method to constructor
isimluk Nov 29, 2016
0c4460a
Drop premature optimization
isimluk Nov 29, 2016
8bd5f7b
Make vms class variable
isimluk Nov 29, 2016
08aa9b2
Use directly the @vms variable to determine applicable rollups
isimluk Nov 29, 2016
5da2a59
Refactor: Extract method: vm_owner
isimluk Nov 29, 2016
d5563de
Refactor: Extract method: vms
isimluk Nov 29, 2016
7ce131e
Refactor: Extract methods: project & image.
isimluk Nov 29, 2016
ddaca81
Refactor: Expand date_fields class method to constructor
isimluk Nov 29, 2016
a1e465f
Refactor: expand method: get_tag_fields
isimluk Nov 29, 2016
9b9f26b
Refactor: this class method should be private instance method
isimluk Nov 30, 2016
68c689c
Replace inject by map
lpichler Nov 16, 2016
3355fda
Move tag prefix method to Metric::ChargebackHelper
lpichler Nov 16, 2016
2d1a365
Add prefixes to on one place
lpichler Nov 16, 2016
0dd2f0d
Use kind_of? for checking type and remove unnecessary var
lpichler Nov 16, 2016
edcdcc8
Refactor: Extract method: base_rollup_scope
isimluk Dec 16, 2016
c92740e
Refactor: Extract method: for_report
isimluk Dec 16, 2016
08ed2d9
Refactor: Extract method: key()
isimluk Dec 16, 2016
30e1d71
Extract method: first_metric_rollup_record
isimluk Dec 16, 2016
f1db045
Do not pass metric_rollup to main loop of chargeback
isimluk Dec 16, 2016
2251ed1
RatesCache should operate over Consumption not metric_rollup
isimluk Dec 16, 2016
73351ff
Initialize chargeback instances with consumption
isimluk Dec 16, 2016
41fed0b
init_extra_fields should depend only on consumption object
isimluk Dec 16, 2016
558f335
report_row_key should take just consumption class
isimluk Dec 16, 2016
cacd635
classification_for should not depend on metric_rollup
isimluk Dec 16, 2016
e9fd562
default_key should not depend on metric_rollup
isimluk Dec 16, 2016
6153c73
RatesCaches should not depend on metric_rollups
isimluk Dec 16, 2016
d5bfb46
Make first_metric_rollup_private
isimluk Dec 16, 2016
456486a
Extract child class: ConsumptionWithRollups
isimluk Dec 16, 2016
ab596a1
Chargebacks for Hyper-V without rollups
isimluk Dec 16, 2016
215a225
Spec for Hyper-V fixed charges.
isimluk Dec 19, 2016
57e4f1c
Charge allocation of hyperv instances without rollups
isimluk Dec 20, 2016
44aa15b
Unit test for ConsumptionWithoutRollups
isimluk Jan 2, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Refactor: move charging logic from cb to rate
(cherry picked from commit d714d67)
  • Loading branch information
isimluk committed Jan 10, 2017
commit 5ceb42ed2146cc1829bc0bb38f5f2b7e7b008a1a
27 changes: 3 additions & 24 deletions app/models/chargeback.rb
Original file line number Diff line number Diff line change
@@ -134,35 +134,14 @@ def calculate_costs(metric_rollup_records, rates, hours_in_interval)

rates.each do |rate|
rate.chargeback_rate_details.each do |r|
if !chargeback_fields_present && r.fixed?
cost = 0
else
metric_value, cost = r.metric_and_cost_by(metric_rollup_records, hours_in_interval)
r.charge(relevant_fields, chargeback_fields_present, metric_rollup_records, hours_in_interval).each do |field, value|
next unless self.class.attribute_names.include?(field)
self[field] = (self[field] || 0) + value
end

accumulate_metrics_and_costs_per_rate(r, metric_value, cost)
end
end
end

def accumulate_metrics_and_costs_per_rate(rate, metric, cost)
col_hash = {}

defined_column_for_report = (relevant_fields & [rate.metric_keys[0], rate.cost_keys[0]]).present?

if defined_column_for_report
rate.metric_keys.each { |col| col_hash[col] = metric }
rate.cost_keys.each { |col| col_hash[col] = cost }
end

col_hash.each do |k, val|
next unless self.class.attribute_names.include?(k)
self[k] ||= 0
self[k] += val
end
end
private :accumulate_metrics_and_costs_per_rate

def self.report_cb_model(model)
model.gsub(/^Chargeback/, "")
end
19 changes: 17 additions & 2 deletions app/models/chargeback_rate_detail.rb
Original file line number Diff line number Diff line change
@@ -19,6 +19,21 @@ class ChargebackRateDetail < ApplicationRecord

attr_accessor :hours_in_interval

def charge(relevant_fields, chargeback_fields_present, metric_rollup_records, hours_in_interval)
if !chargeback_fields_present && fixed?
cost = 0
else
metric_value, cost = metric_and_cost_by(metric_rollup_records, hours_in_interval)
end

result = {}
if (relevant_fields & [metric_keys[0], cost_keys[0]]).present?
metric_keys.each { |field| result[field] = metric_value }
cost_keys.each { |field| result[field] = cost }
end
result
end

def max_of_metric_from(metric_rollup_records)
metric_rollup_records.map(&metric.to_sym).max
end
@@ -213,6 +228,8 @@ def contiguous_tiers?
!error
end

private

def metric_keys
["#{rate_name}_metric", # metric value (e.g. Storage [Used|Allocated|Fixed])
"#{group}_metric"] # total of metric's group (e.g. Storage Total)
@@ -230,8 +247,6 @@ def metric_and_cost_by(metric_rollup_records, hours_in_interval)
[metric_value, hourly_cost(metric_value) * hours_in_interval]
end

private

def first_tier?(tier,tiers)
tier == tiers.first
end