Skip to content

Commit

Permalink
Query metric rollups using start_date derived from the first rollup
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jrafanie committed Aug 15, 2024
1 parent e318288 commit cef1b13
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions spec/requests/providers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1457,18 +1457,18 @@ 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

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,
Expand All @@ -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
Expand Down

0 comments on commit cef1b13

Please sign in to comment.