Skip to content

Commit

Permalink
don't return records that were captured (but are not valid for this r…
Browse files Browse the repository at this point in the history
…ange)
  • Loading branch information
kbrock committed Jun 26, 2023
1 parent e705b2a commit c0d7ee2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/models/vim_performance_state.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def container_groups

def containers
ids = get_assoc(:containers)
ids.empty? ? [] : Container.where(:id => ids).order(:id).to_a
ids.empty? ? [] : Container.where(:id => ids).active_for(timestamp_range).order(:id).to_a
end

def all_container_groups
Expand Down
27 changes: 27 additions & 0 deletions spec/models/vim_performance_state_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,33 @@
end
end

describe "#containers" do
it "doesnt return records that are archived before the range" do
container_image = FactoryBot.create(:container_image)
# not deleted is captured
containers = FactoryBot.create_list(:container, 1, :container_image => container_image)
# deleted before is not captured
other_containers = FactoryBot.create_list(:container, 1, :container_image => container_image, :deleted_on => (capture_time - 2.hours))
# deleted later is captured
containers << FactoryBot.create(:container, :container_image => container_image, :deleted_on => (capture_time + 2.hours))

state_data = {:assoc_ids => {:containers => {:on => (containers + other_containers).map(&:id)}}}
actual = described_class.new(:timestamp => capture_time, :state_data => state_data)
expect(actual.containers).to match_array(containers)
end

it "handles pruned ids" do
container_image = FactoryBot.create(:container_image)
# not deleted is captured
containers = FactoryBot.create_list(:container, 1, :container_image => container_image)

# add a few ids in here - these represent container ids that are no longer valid (were deleted)
state_data = {:assoc_ids => {:containers => {:on => (containers.map(&:id) + [22, 23, 24, 25, 26, 27])}}}
actual = described_class.new(:timestamp => capture_time, :state_data => state_data)
expect(actual.containers).to match_array(containers)
end
end

describe "#timestamp_range" do
let(:timestamp) { Time.now.utc }
let(:vim_performance_state) { described_class.new(:timestamp => timestamp) }
Expand Down

0 comments on commit c0d7ee2

Please sign in to comment.