Skip to content

Commit

Permalink
Merge pull request #17620 from lpichler/fix_ordering_metric_rollups_i…
Browse files Browse the repository at this point in the history
…n_consumption_history

Fix ordering of metric rollups in consumption history
  • Loading branch information
gtanzillo committed Jun 27, 2018
2 parents 2bd1fed + 85da8cd commit d35b051
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions app/models/chargeback/consumption_history.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ def self.for_report(cb_class, options, region)

# we are building hash with grouped calculated values
# values are grouped by resource_id and timestamp (query_start_time...query_end_time)

records.each_value do |rollup_record_ids|
metric_rollup_records = MetricRollup.where(:id => rollup_record_ids).pluck(*ChargeableField.cols_on_metric_rollup)
metric_rollup_records = MetricRollup.where(:id => rollup_record_ids).order(:resource_type, :resource_id, :timestamp).pluck(*ChargeableField.cols_on_metric_rollup)
consumption = ConsumptionWithRollups.new(metric_rollup_records, query_start_time, query_end_time)
yield(consumption) unless consumption.consumed_hours_in_interval.zero?
end
Expand All @@ -43,9 +42,7 @@ def self.uniq_timestamp_record_map(report_scope, group_by_tenant = false)
.gsub("SELECT", "DISTINCT ON (resource_type, resource_id, timestamp)")
.gsub(/ FROM.*$/, '')

query = report_scope.select(main_select)
.order(:resource_type, :resource_id, :timestamp)
.order("created_on DESC")
query = report_scope.select(main_select).order(:resource_type, :resource_id, :timestamp)

rows = ActiveRecord::Base.connection.select_rows(query.to_sql)

Expand Down

0 comments on commit d35b051

Please sign in to comment.