Skip to content

Commit

Permalink
Merge pull request #17552 from lpichler/get_rid_off_big_query
Browse files Browse the repository at this point in the history
Get rid off query "All in One" in Chargeback
(cherry picked from commit 019d2ad)

https://bugzilla.redhat.com/show_bug.cgi?id=1591939
  • Loading branch information
gtanzillo authored and simaishi committed Jun 15, 2018
1 parent 9310fad commit d3719f3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 18 deletions.
13 changes: 2 additions & 11 deletions app/models/chargeback/consumption_history.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,13 @@ def self.for_report(cb_class, options)
end

def self.base_rollup_scope
base_rollup = MetricRollup.includes(
:resource => [:hardware, :tenant, :tags, :vim_performance_states, :custom_attributes,
{:container_image => :custom_attributes}],
:parent_host => :tags,
:parent_ems_cluster => :tags,
:parent_storage => :tags,
:parent_ems => :tags)
.select(*Metric::BASE_COLS).order('resource_id, timestamp')

base_rollup.select(*ChargeableField.chargeable_cols_on_metric_rollup).with_resource
MetricRollup.select(*(Metric::BASE_COLS + ChargeableField.chargeable_cols_on_metric_rollup))
end

private_class_method :base_rollup_scope

def self.uniq_timestamp_record_map(report_scope, group_by_tenant = false)
main_select = MetricRollup.select(:id, :resource_id).arel.ast.to_sql
main_select = MetricRollup.select(:id, :resource_id).with_resource.arel.ast.to_sql
.gsub("SELECT", "DISTINCT ON (resource_type, resource_id, timestamp)")
.gsub(/ FROM.*$/, '')

Expand Down
15 changes: 8 additions & 7 deletions spec/models/chargeback_vm_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,7 @@ def result_row_for_vm(vm)
let(:report_options) { Chargeback::ReportOptions.new }
let(:timestamp_key) { 'Fri, 13 May 2016 10:40:00 UTC +00:00' }
let(:beginning_of_day) { timestamp_key.in_time_zone.beginning_of_day }
let(:metric_rollup) { FactoryGirl.build(:metric_rollup_vm_hr, :timestamp => timestamp_key, :resource => @vm1) }
let(:metric_rollup) { FactoryGirl.create(:metric_rollup_vm_hr, :timestamp => timestamp_key, :resource => @vm1) }
let(:consumption) { Chargeback::ConsumptionWithRollups.new([metric_rollup], nil, nil) }
subject { described_class.report_row_key(consumption) }
before do
Expand All @@ -844,7 +844,7 @@ def result_row_for_vm(vm)

context 'with parent ems' do
let(:metric_rollup) do
FactoryGirl.build(:metric_rollup_vm_hr, :tag_names => 'environment/prod',
FactoryGirl.create(:metric_rollup_vm_hr, :tag_names => 'environment/prod',
:parent_host_id => @host1.id, :parent_ems_cluster_id => @ems_cluster.id,
:parent_ems_id => ems.id, :parent_storage_id => @storage.id,
:resource => @vm1, :resource_name => @vm1.name)
Expand All @@ -857,7 +857,7 @@ def result_row_for_vm(vm)

context 'when parent ems is missing' do
let(:metric_rollup) do
FactoryGirl.build(:metric_rollup_vm_hr, :tag_names => 'environment/prod',
FactoryGirl.create(:metric_rollup_vm_hr, :tag_names => 'environment/prod',
:parent_host_id => @host1.id, :parent_ems_cluster_id => @ems_cluster.id,
:parent_storage_id => @storage.id,
:resource => @vm1, :resource_name => @vm1.name)
Expand Down Expand Up @@ -887,7 +887,6 @@ def result_row_for_vm(vm)
:parent_ems_id => ems.id, :parent_storage_id => @storage.id,
:resource => @vm)
end
let(:consumption) { Chargeback::ConsumptionWithRollups.new([metric_rollup], nil, nil) }

before do
@storage.tag_with([classification_1.tag.name, classification_2.tag.name], :ns => '*')
Expand All @@ -899,9 +898,11 @@ def result_row_for_vm(vm)
skip('this feature needs to be added to new chargeback') if Settings.new_chargeback

[rate_assignment_options_1, rate_assignment_options_2].each do |rate_assignment|
metric_rollup.tag_names = rate_assignment[:tag].first.tag.send(:name_path)
metric_rollup.update_attributes!(:tag_names => rate_assignment[:tag].first.tag.send(:name_path))
@vm.tag_with(["/managed/#{metric_rollup.tag_names}"], :ns => '*')
@vm.reload

consumption = Chargeback::ConsumptionWithRollups.new([metric_rollup], nil, nil)
uniq_rates = Chargeback::RatesCache.new.get(consumption)
consumption.instance_variable_set(:@tag_names, nil)
consumption.instance_variable_set(:@hash_features_affecting_rate, nil)
Expand Down Expand Up @@ -935,10 +936,10 @@ def result_row_for_vm(vm)
let(:metering_used_hours) { 24 }

let(:hardware) do
FactoryGirl.build(:hardware,
FactoryGirl.create(:hardware,
:cpu_total_cores => cores,
:memory_mb => mem_mb,
:disks => [FactoryGirl.build(:disk, :size => disk_b)])
:disks => [FactoryGirl.create(:disk, :size => disk_b)])
end

let(:fixed_cost) { hourly_rate * 24 }
Expand Down

0 comments on commit d3719f3

Please sign in to comment.