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

Generate perfomance reports in specific date range #19393

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 10 additions & 5 deletions app/models/miq_report/generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -245,18 +245,25 @@ def generate_performance_results(options = {})
results
end

def performance_report_time_range
if db_options[:custom_time_range]
db_options[:start_date]..db_options[:end_date]
else
Metric::Helper.time_range_from_offset(interval, db_options[:start_offset], db_options[:end_offset], tz)
end
end

# Ad-hoc daily performance reports
# Daily for: Performance - Clusters...
def generate_daily_metric_rollup_results(options = {})
unless conditions.nil?
conditions.preprocess_options = {:vim_performance_daily_adhoc => (time_profile && time_profile.rollup_daily_metrics)}
end

time_range = Metric::Helper.time_range_from_offset(interval, db_options[:start_offset], db_options[:end_offset], tz)
results = Metric::Helper.find_for_interval_name('daily', time_profile || tz, db_klass)
.where(where_clause)
.where(options[:where_clause])
.where(:timestamp => time_range)
.where(:timestamp => performance_report_time_range)
.includes(get_include_for_find)
.references(db_klass.includes_to_references(get_include))
.limit(options[:limit])
Expand All @@ -269,9 +276,7 @@ def generate_daily_metric_rollup_results(options = {})

# Ad-hoc performance reports
def generate_interval_metric_results(options = {})
time_range = Metric::Helper.time_range_from_offset(interval, db_options[:start_offset], db_options[:end_offset])

results = db_klass.with_interval_and_time_range(interval, time_range)
results = db_klass.with_interval_and_time_range(interval, performance_report_time_range)
.where(where_clause)
.where(options[:where_clause])
.includes(get_include_for_find)
Expand Down
59 changes: 50 additions & 9 deletions spec/models/miq_report_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
end

describe MiqReport do
include Spec::Support::ChargebackHelper

context ".for_user" do
let(:my_user) { FactoryBot.create(:user_with_group) }
let(:group_in_my_tenant) { FactoryBot.create(:miq_group, :tenant => my_user.current_tenant) }
Expand Down Expand Up @@ -680,18 +682,21 @@
expect(report.table.data.collect { |rec| rec.data['miq_provision_vms.name'] }).to eq([vm.name])
end

let(:db_options) { {:start_offset => 604_800, :end_offset => 0, :interval => interval} }
let(:report) do
MiqReport.new(
:name => "All Departments with Performance", :title => "All Departments with Performance for last week",
:db => "VmPerformance",
:cols => %w(resource_name max_cpu_usage_rate_average cpu_usage_rate_average),
:col_order => ["ems_cluster.name", "vm.v_annotation", "host.name"],
:headers => ["Cluster", "VM Annotations - Notes", "Host Name"],
:order => "Ascending",
:group => "c",
:db_options => {:start_offset => 604_800, :end_offset => 0, :interval => interval},
:conditions => conditions)
:name => "All Departments with Performance", :title => "All Departments with Performance for last week",
:db => "VmPerformance",
:cols => %w[resource_name max_cpu_usage_rate_average cpu_usage_rate_average timestamp],
:col_order => %w[ems_cluster.name vm.v_annotation host.name"],
:headers => %w[Cluster VM\ Annotations\ -\ Notes Host\ Name],
:order => "Ascending",
:group => "c",
:db_options => db_options,
:conditions => nil
)
end

context "daily reports" do
let(:interval) { "daily" }

Expand All @@ -712,6 +717,42 @@
end.not_to raise_error
end
end

context "with specific timeframe interval" do
let(:vm) { FactoryBot.create(:vm_vmware, :name => "test_vm 2") }

let(:starting_date) { Time.parse('2012-09-01 23:59:59Z').utc }
let(:ts) { starting_date.in_time_zone(Metric::Helper.get_time_zone(:tz => 'UTC')) }
let(:first_rollup_timestamp) { ts.beginning_of_month.utc }
let(:last_rollup_timestamp) { (ts + 1.month).end_of_month.utc }
let(:time_profile) { FactoryBot.create(:time_profile_with_rollup, :profile => {:tz => "UTC", :hours => TimeProfile::ALL_HOURS, :days => TimeProfile::ALL_DAYS}) }
let(:user_admin) { FactoryBot.create(:user_admin) }

before do
EvmSpecHelper.create_guid_miq_server_zone
rollup_params = {:capture_interval_name => 'daily', :time_profile_id => time_profile.id }
add_metric_rollups_for([vm], first_rollup_timestamp...last_rollup_timestamp, 24.hours, rollup_params)
end

let(:reporting_start_day) { ts.beginning_of_day + 5.days }
let(:reporting_end_day) { ts.beginning_of_day + 10.days }

let(:db_options) do
{:custom_time_range => true,
:start_date => reporting_start_day,
:end_date => reporting_end_day,
:interval => interval}
end

it "reports data in specific date range" do
User.with_user(user_admin) do
report.generate_table(:userid => "admin", :mode => "async", :report_source => "Requested by user")
expect(report.table.data.count).to eq((reporting_end_day.end_of_day - reporting_start_day).to_f.ceil / 1.day)
expect(report.table.data.first["timestamp"]).to eq(reporting_start_day)
expect(report.table.data.last["timestamp"]).to eq(reporting_end_day)
end
end
end
end
context "performance reports" do
let(:report) do
Expand Down