-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #493 from agrare/check_metrics_connection_validity…
…_before_queueing_perf_captures Check metrics authentication validity before perf_capture_queue
- Loading branch information
Showing
4 changed files
with
107 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
FactoryBot.define do | ||
factory :kubernetes_container_group, | ||
:parent => :container_group, | ||
:class => "ManageIQ::Providers::Kubernetes::ContainerManager::ContainerGroup" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 50 additions & 53 deletions
103
spec/models/manageiq/providers/kubernetes/container_manager/metrics_capture_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,78 +1,75 @@ | ||
describe ManageIQ::Providers::Kubernetes::ContainerManager::MetricsCapture do | ||
before do | ||
# @miq_server is required for worker_settings to work | ||
@miq_server = EvmSpecHelper.local_miq_server(:is_master => true) | ||
@ems_kubernetes = FactoryBot.create( | ||
:ems_kubernetes, | ||
:connection_configurations => [{:endpoint => {:role => :prometheus}, | ||
:authentication => {:role => :prometheus}}], | ||
).tap { |ems| ems.authentications.each { |auth| auth.update!(:status => "Valid") } } | ||
@container_project = FactoryBot.create(:container_project, :ext_management_system => @ems_kubernetes) | ||
|
||
@node = FactoryBot.create( | ||
:kubernetes_node, | ||
:name => 'node', | ||
:ext_management_system => @ems_kubernetes, | ||
:ems_ref => 'target' | ||
) | ||
|
||
@node.computer_system.hardware = FactoryBot.create( | ||
:hardware, | ||
:cpu_total_cores => 2, | ||
:memory_mb => 2048 | ||
) | ||
|
||
@group = FactoryBot.create( | ||
:container_group, | ||
:ext_management_system => @ems_kubernetes, | ||
:container_node => @node, | ||
:ems_ref => 'group' | ||
) | ||
|
||
@container = FactoryBot.create( | ||
:kubernetes_container, | ||
:name => 'container', | ||
:container_group => @group, | ||
:container_project => @container_project, | ||
:ext_management_system => @ems_kubernetes, | ||
:ems_ref => 'target' | ||
) | ||
let(:ems) { FactoryBot.create(:ems_kubernetes_with_zone, :with_metrics_endpoint) } | ||
let(:container_project) { FactoryBot.create(:container_project, :ext_management_system => ems) } | ||
let!(:group) { FactoryBot.create(:kubernetes_container_group, :ext_management_system => ems, :container_node => node) } | ||
let!(:container) { FactoryBot.create(:kubernetes_container, :ext_management_system => ems, :container_group => group, :container_project => container_project) } | ||
let(:node) do | ||
FactoryBot.create(:kubernetes_node, :name => 'node', :ext_management_system => ems, :ems_ref => 'target').tap do |node| | ||
node.computer_system.hardware = FactoryBot.create(:hardware, :cpu_total_cores => 2, :memory_mb => 2_048) | ||
end | ||
end | ||
|
||
context "#perf_capture_object" do | ||
it "returns the correct class" do | ||
expect(@ems_kubernetes.perf_capture_object.class).to eq(described_class) | ||
expect(ems.perf_capture_object.class).to eq(described_class) | ||
end | ||
end | ||
|
||
context "#capture_context" do | ||
context "#build_capture_context!" do | ||
it "detect prometheus metrics provider" do | ||
metric_capture = described_class.new(@node) | ||
context = metric_capture.capture_context( | ||
@ems_kubernetes, | ||
@node, | ||
5.minutes.ago, | ||
0.minutes.ago | ||
) | ||
metric_capture = described_class.new(node) | ||
context = metric_capture.build_capture_context!(ems, node, 5.minutes.ago, 0.minutes.ago) | ||
|
||
expect(context).to be_a(described_class::PrometheusCaptureContext) | ||
end | ||
|
||
context "on an invalid target" do | ||
let(:group) { FactoryBot.create(:kubernetes_container_group, :ext_management_system => ems) } | ||
|
||
it "raises an exception" do | ||
metric_capture = described_class.new(group) | ||
expect { metric_capture.build_capture_context!(ems, group, 5.minutes.ago, 0.minutes.ago) } | ||
.to raise_error(described_class::TargetValidationWarning, "no associated node") | ||
end | ||
end | ||
end | ||
|
||
context "#perf_capture_all_queue" do | ||
it "returns the objects" do | ||
expect(ems.perf_capture_object.perf_capture_all_queue).to include("Container" => [container], "ContainerGroup" => [group], "ContainerNode" => [node]) | ||
end | ||
|
||
context "with a missing metrics endpoint" do | ||
let(:ems) { FactoryBot.create(:ems_kubernetes) } | ||
|
||
it "returns no objects" do | ||
expect(ems.perf_capture_object.perf_capture_all_queue).to be_empty | ||
end | ||
end | ||
|
||
context "with invalid authentication on the metrics endpoint" do | ||
let(:ems) { FactoryBot.create(:ems_kubernetes_with_zone, :with_metrics_endpoint, :with_invalid_auth) } | ||
|
||
it "returns no objects" do | ||
expect(ems.perf_capture_object.perf_capture_all_queue).to be_empty | ||
end | ||
end | ||
end | ||
|
||
context "#perf_collect_metrics" do | ||
it "fails when no ems is defined" do | ||
@node.ext_management_system = nil | ||
expect { @node.perf_collect_metrics('interval_name') }.to raise_error(described_class::TargetValidationError) | ||
node.ext_management_system = nil | ||
expect { node.perf_collect_metrics('interval_name') }.to raise_error(described_class::TargetValidationError) | ||
end | ||
|
||
it "fails when no cpu cores are defined" do | ||
@node.hardware.cpu_total_cores = nil | ||
expect { @node.perf_collect_metrics('interval_name') }.to raise_error(described_class::TargetValidationError) | ||
node.hardware.cpu_total_cores = nil | ||
expect { node.perf_collect_metrics('interval_name') }.to raise_error(described_class::TargetValidationError) | ||
end | ||
|
||
it "fails when memory is not defined" do | ||
@node.hardware.memory_mb = nil | ||
expect { @node.perf_collect_metrics('interval_name') }.to raise_error(described_class::TargetValidationError) | ||
node.hardware.memory_mb = nil | ||
expect { node.perf_collect_metrics('interval_name') }.to raise_error(described_class::TargetValidationError) | ||
end | ||
end | ||
end |