From 4381f67e2b0cb14d2fb9cdd5e9b4550b6101eb23 Mon Sep 17 00:00:00 2001 From: James Wong Date: Wed, 2 May 2018 09:03:10 -0400 Subject: [PATCH] NOR covers 30 days fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1501996 --- app/models/metric/long_term_averages.rb | 3 ++- app/models/vm_or_template/right_sizing.rb | 12 ++++++++---- spec/models/metric_spec.rb | 5 +++-- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/app/models/metric/long_term_averages.rb b/app/models/metric/long_term_averages.rb index 098b53e304d0..b10a7adad18f 100644 --- a/app/models/metric/long_term_averages.rb +++ b/app/models/metric/long_term_averages.rb @@ -40,7 +40,8 @@ def self.get_averages_over_time_period(obj, options = {}) avg_cols = options[:avg_cols] || AVG_COLS ext_options = ext_options.merge(:only_cols => avg_cols) - perfs = VimPerformanceAnalysis.find_perf_for_time_period(obj, "daily", :end_date => Time.now.utc, :days => avg_days, :ext_options => ext_options) + end_date = Time.now.utc.beginning_of_day - 1 + perfs = VimPerformanceAnalysis.find_perf_for_time_period(obj, "daily", :end_date => end_date, :days => avg_days, :ext_options => ext_options) perfs.each do |p| if ext_options[:time_profile] && !ext_options[:time_profile].ts_day_in_profile?(p.timestamp.in_time_zone(tz)) next diff --git a/app/models/vm_or_template/right_sizing.rb b/app/models/vm_or_template/right_sizing.rb index e82cddadca1a..fdc44f2f999c 100644 --- a/app/models/vm_or_template/right_sizing.rb +++ b/app/models/vm_or_template/right_sizing.rb @@ -149,7 +149,8 @@ def mem_recommendation_minimum alias_method :overallocated_mem_pct, :aggressive_mem_recommended_change_pct def max_cpu_usage_rate_average_max_over_time_period - perfs = VimPerformanceAnalysis.find_perf_for_time_period(self, "daily", :end_date => Time.now.utc, :days => Metric::LongTermAverages::AVG_DAYS) + end_date = Time.now.utc.beginning_of_day - 1 + perfs = VimPerformanceAnalysis.find_perf_for_time_period(self, "daily", :end_date => end_date, :days => Metric::LongTermAverages::AVG_DAYS) perfs.collect do |p| # Ignore any CPU bursts to 100% 15 minutes after VM booted next if (p.abs_max_cpu_usage_rate_average_value == 100.0) && boot_time && (p.abs_max_cpu_usage_rate_average_timestamp <= (boot_time + 15.minutes)) @@ -158,17 +159,20 @@ def max_cpu_usage_rate_average_max_over_time_period end def max_mem_usage_absolute_average_max_over_time_period - perfs = VimPerformanceAnalysis.find_perf_for_time_period(self, "daily", :end_date => Time.now.utc, :days => Metric::LongTermAverages::AVG_DAYS) + end_date = Time.now.utc.beginning_of_day - 1 + perfs = VimPerformanceAnalysis.find_perf_for_time_period(self, "daily", :end_date => end_date, :days => Metric::LongTermAverages::AVG_DAYS) perfs.collect(&:abs_max_mem_usage_absolute_average_value).compact.max end def cpu_usagemhz_rate_average_max_over_time_period - perfs = VimPerformanceAnalysis.find_perf_for_time_period(self, "daily", :end_date => Time.now.utc, :days => Metric::LongTermAverages::AVG_DAYS) + end_date = Time.now.utc.beginning_of_day - 1 + perfs = VimPerformanceAnalysis.find_perf_for_time_period(self, "daily", :end_date => end_date, :days => Metric::LongTermAverages::AVG_DAYS) perfs.collect(&:abs_max_cpu_usagemhz_rate_average_value).compact.max end def derived_memory_used_max_over_time_period - perfs = VimPerformanceAnalysis.find_perf_for_time_period(self, "daily", :end_date => Time.now.utc, :days => Metric::LongTermAverages::AVG_DAYS) + end_date = Time.now.utc.beginning_of_day - 1 + perfs = VimPerformanceAnalysis.find_perf_for_time_period(self, "daily", :end_date => end_date, :days => Metric::LongTermAverages::AVG_DAYS) perfs.collect(&:abs_max_derived_memory_used_value).compact.max end diff --git a/spec/models/metric_spec.rb b/spec/models/metric_spec.rb index cbfb6fa4f695..dec1075f4f1d 100644 --- a/spec/models/metric_spec.rb +++ b/spec/models/metric_spec.rb @@ -638,6 +638,7 @@ before do Timecop.travel(Time.parse("2010-05-01T00:00:00Z")) cases = [ + "2010-04-01T00:00:00Z", 9.14, 32.85, "2010-04-13T21:00:00Z", 9.14, 32.85, "2010-04-14T18:00:00Z", 10.23, 28.76, "2010-04-14T19:00:00Z", 18.92, 39.11, @@ -669,8 +670,8 @@ it "should calculate the correct normal operating range values" do @vm1.generate_vim_performance_operating_range(@time_profile) - expect(@vm1.max_cpu_usage_rate_average_avg_over_time_period).to be_within(0.001).of(13.692) - expect(@vm1.max_mem_usage_absolute_average_avg_over_time_period).to be_within(0.001).of(33.085) + expect(@vm1.max_cpu_usage_rate_average_avg_over_time_period).to be_within(0.001).of(13.124) + expect(@vm1.max_mem_usage_absolute_average_avg_over_time_period).to be_within(0.001).of(33.056) end it "should calculate the correct right-size values" do