Skip to content

Commit

Permalink
Default interval should be property of ReportOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
isimluk committed Oct 24, 2016
1 parent 7e72957 commit e0ecace
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
9 changes: 4 additions & 5 deletions app/models/chargeback.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ def self.build_results_for_report_chargeback(options)
_log.info("Calculating chargeback costs...")
@options = options = ReportOptions.new_from_h(options)

interval = options[:interval] || "daily"
cb = new

options[:ext_options] ||= {}
Expand All @@ -34,10 +33,10 @@ def self.build_results_for_report_chargeback(options)
rate_cols.map! { |x| VIRTUAL_COL_USES.include?(x) ? VIRTUAL_COL_USES[x] : x }.flatten!
base_rollup = base_rollup.select(*rate_cols)

timerange = get_report_time_range(options, interval)
timerange = get_report_time_range(options, options.interval)
data = {}

interval_duration = interval_to_duration(interval)
interval_duration = interval_to_duration(options.interval)

timerange.step_value(interval_duration).each_cons(2) do |query_start_time, query_end_time|
records = base_rollup.where(:timestamp => query_start_time...query_end_time, :capture_interval_name => "hourly")
Expand All @@ -46,7 +45,7 @@ def self.build_results_for_report_chargeback(options)
next if records.empty?
_log.info("Found #{records.length} records for time range #{[query_start_time, query_end_time].inspect}")

hours_in_interval = hours_in_interval(query_start_time, query_end_time, interval)
hours_in_interval = hours_in_interval(query_start_time, query_end_time, options.interval)

# we are building hash with grouped calculated values
# values are grouped by resource_id and timestamp (query_start_time...query_end_time)
Expand All @@ -62,7 +61,7 @@ def self.build_results_for_report_chargeback(options)
# key contains resource_id and timestamp (query_start_time...query_end_time)
# extra_fields there some extra field like resource name and
# some of them are related to specific chargeback (ChargebackVm, ChargebackContainer,...)
key, extra_fields = key_and_fields(metric_rollup_record, interval)
key, extra_fields = key_and_fields(metric_rollup_record, options.interval)
data[key] ||= extra_fields

chargeback_rates = data[key]["chargeback_rates"].split(', ') + rates_to_apply.collect(&:description)
Expand Down
5 changes: 5 additions & 0 deletions app/models/chargeback/report_options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ def self.new_from_h(hash)
new(*hash.values_at(*members))
end

def initialize(*)
super
self.interval ||= 'daily'
end

def tz
# TODO: Support time profiles via options[:ext_options][:time_profile]
@tz ||= Metric::Helper.get_time_zone(ext_options)
Expand Down

0 comments on commit e0ecace

Please sign in to comment.