From cef1b1327c7dbce754904d79f3acb2a0490d9f8e Mon Sep 17 00:00:00 2001 From: Joe Rafaniello Date: Thu, 15 Aug 2024 17:26:02 -0400 Subject: [PATCH] Query metric rollups using start_date derived from the first rollup This resolves a time based sporadic failure. This means it works for many hours of the day but fails with specific ones. Previously, Time.zone is UTC, so Time.zone.today when run at August 15th at 12:05 AM UTC would return Thu, 15 Aug 2024. If we created the rollups using 1.hour.ago, the first one would be August 14th 11:05 PM. If we our rollups were on August 14th and we're looking for August 15th hourly rollups, we find nothing. This change ensures both the timestamp on the rollups and the start_date we query the rollups with come from the same time. --- spec/requests/providers_spec.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/requests/providers_spec.rb b/spec/requests/providers_spec.rb index 9b5bc0d828..94c00263d9 100644 --- a/spec/requests/providers_spec.rb +++ b/spec/requests/providers_spec.rb @@ -1457,9 +1457,10 @@ def gen_import_request let(:provider) { FactoryBot.create(:ems_redhat) } let(:provider1) { FactoryBot.create(:ems_redhat) } let(:url) { api_provider_metric_rollups_url(nil, provider) } + let(:first_ts) { 1.hour.ago } before do - FactoryBot.create_list(:metric_rollup_cm_hr, 3, :resource => provider, :timestamp => 1.hour.ago) + FactoryBot.create_list(:metric_rollup_cm_hr, 3, :resource => provider, :timestamp => first_ts) FactoryBot.create_list(:metric_rollup_cm_daily, 1, :resource => provider) FactoryBot.create_list(:metric_rollup_cm_hr, 1, :resource => provider1) end @@ -1467,8 +1468,7 @@ def gen_import_request it 'returns the metric rollups for the provider' do api_basic_authorize subcollection_action_identifier(:providers, :metric_rollups, :read, :get) - provider.metric_rollups.where(:capture_interval_name => 'hourly').name - get(url, :params => { :capture_interval => 'hourly', :start_date => Time.zone.today.to_s }) + get(url, :params => { :capture_interval => 'hourly', :start_date => first_ts.to_date.to_s }) expected = { 'count' => 5, @@ -1483,7 +1483,7 @@ def gen_import_request it 'will not return metric rollups without an appropriate role' do api_basic_authorize - get(url, :params => { :capture_interval => 'hourly', :start_date => Time.zone.today.to_s }) + get(url, :params => { :capture_interval => 'hourly', :start_date => first_ts.to_date.to_s }) expect(response).to have_http_status(:forbidden) end