-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Kubevirt metrics capture specs #270
Open
nasark
wants to merge
6
commits into
ManageIQ:master
Choose a base branch
from
nasark:metrics_capture_specs
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d5482fc
specify kubevirt class in error handling
nasark 870b79c
add kubevirt host factory
nasark 0525f36
add metrics_capture spec
nasark 1603ac2
add prometheus_capture_context spec
nasark 42d0613
add prometheus_capture_context vcrs
nasark 3101683
add kubevirt secrets defaults
nasark File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,3 @@ | ||
FactoryBot.define do | ||
factory(:host_kubevirt, :class => "ManageIQ::Providers::Kubevirt::InfraManager::Host", :traits => [:with_ref], :parent => :host) { vmm_vendor { "kubevirt" } } | ||
end |
122 changes: 122 additions & 0 deletions
122
...ageiq/providers/kubevirt/infra_manager/metrics_capture/prometheus_capture_context_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 |
---|---|---|
@@ -0,0 +1,122 @@ | ||
describe ManageIQ::Providers::Kubevirt::InfraManager::MetricsCapture::PrometheusCaptureContext do | ||
let(:ems) do | ||
hostname = Rails.application.secrets.kubevirt[:hostname] | ||
metrics_hostname = Rails.application.secrets.kubevirt[:metrics_hostname] | ||
token = Rails.application.secrets.kubevirt[:token] | ||
|
||
FactoryBot.create( | ||
:ems_kubernetes_with_zone, | ||
:name => 'KubernetesProvider', | ||
:connection_configurations => [{:endpoint => {:role => :default, | ||
:hostname => hostname, | ||
:port => "6443", | ||
:verify_ssl => false}, | ||
:authentication => {:role => :bearer, | ||
:auth_key => token, | ||
:userid => "_"}}, | ||
{:endpoint => {:role => :prometheus, | ||
:hostname => metrics_hostname, | ||
:port => "443", | ||
:verify_ssl => false}, | ||
:authentication => {:role => :prometheus, | ||
:auth_key => token, | ||
:userid => "_"}}] | ||
) | ||
end | ||
let(:ems_kubevirt) { FactoryBot.create(:ems_kubevirt, :parent_manager => ems) } | ||
|
||
before(:each) do | ||
VCR.use_cassette("#{described_class.name.underscore}_refresh") do | ||
EmsRefresh.refresh(ems_kubevirt) | ||
ems_kubevirt.reload | ||
|
||
@vm = ems_kubevirt.vms.last | ||
@targets = [['VmOrTemplate', @vm]] | ||
end | ||
end | ||
|
||
it "will read prometheus metrics" do | ||
start_time = Time.parse("2024-12-18 21:28:00 UTC").utc | ||
end_time = Time.parse("2024-12-18 21:38:00 UTC").utc | ||
interval = 60 | ||
|
||
@targets.each do |target_name, target| | ||
VCR.use_cassette("#{described_class.name.underscore}_#{target_name}_metrics") do | ||
context = ManageIQ::Providers::Kubevirt::InfraManager::MetricsCapture::PrometheusCaptureContext.new( | ||
target, start_time, end_time, interval | ||
) | ||
|
||
data = context.collect_metrics | ||
|
||
expect(data).to be_a_kind_of(Hash) | ||
expect(data.keys).to include(start_time, end_time) | ||
expect(data[start_time].keys).to include( | ||
"cpu_usage_rate_average", | ||
"mem_usage_absolute_average" | ||
) | ||
end | ||
end | ||
end | ||
|
||
it "will read only specific timespan prometheus metrics" do | ||
start_time = Time.parse("2024-12-18 21:28:00 UTC").utc | ||
end_time = Time.parse("2024-12-18 21:38:00 UTC").utc | ||
interval = 60 | ||
|
||
@targets.each do |target_name, target| | ||
VCR.use_cassette("#{described_class.name.underscore}_#{target_name}_timespan") do | ||
context = ManageIQ::Providers::Kubevirt::InfraManager::MetricsCapture::PrometheusCaptureContext.new( | ||
target, start_time, end_time, interval | ||
) | ||
|
||
data = context.collect_metrics | ||
|
||
expect(data.count).to be > 8 | ||
expect(data.count).to be < 13 | ||
end | ||
end | ||
end | ||
|
||
describe "#ts_values" do | ||
let(:start_time) { Time.parse("2024-12-18 21:28:00 UTC").utc } | ||
let(:end_time) { Time.parse("2024-12-18 21:38:00 UTC").utc } | ||
let(:interval) { 60 } | ||
let!(:context) { ManageIQ::Providers::Kubevirt::InfraManager::MetricsCapture::PrometheusCaptureContext.new(@vm, start_time, end_time, interval) } | ||
|
||
context "with no missing metrics" do | ||
before do | ||
ts_values = context.instance_variable_get(:@ts_values) | ||
ts_values[start_time] = {"cpu_usage_rate_average" => [1], "container_memory_usage_bytes" => [1], "net_usage_rate_average" => [1]} | ||
ts_values[end_time] = {"cpu_usage_rate_average" => [1], "container_memory_usage_bytes" => [1], "net_usage_rate_average" => [1]} | ||
end | ||
|
||
it "returns all timestamps" do | ||
expect(context.ts_values.keys).to include(start_time, end_time) | ||
end | ||
end | ||
|
||
context "with some timestamps missing metrics" do | ||
before do | ||
ts_values = context.instance_variable_get(:@ts_values) | ||
ts_values[start_time] = {"cpu_usage_rate_average" => [1], "container_memory_usage_bytes" => [1], "net_usage_rate_average" => [1]} | ||
ts_values[end_time] = {"cpu_usage_rate_average" => [1], "net_usage_rate_average" => [1]} | ||
end | ||
|
||
it "only returns timestamps with all metrics" do | ||
expect(context.ts_values.keys).not_to include(end_time) | ||
end | ||
end | ||
|
||
context "with some missing metrics from all timestamps" do | ||
before do | ||
ts_values = context.instance_variable_get(:@ts_values) | ||
ts_values[start_time] = {"cpu_usage_rate_average" => [1], "net_usage_rate_average" => [1]} | ||
ts_values[end_time] = {"cpu_usage_rate_average" => [1], "net_usage_rate_average" => [1]} | ||
end | ||
|
||
it "returns all timestamps" do | ||
expect(context.ts_values.keys).to include(start_time, end_time) | ||
end | ||
end | ||
end | ||
end |
61 changes: 61 additions & 0 deletions
61
spec/models/manageiq/providers/kubevirt/infra_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 |
---|---|---|
@@ -0,0 +1,61 @@ | ||
describe ManageIQ::Providers::Kubevirt::InfraManager::MetricsCapture do | ||
let(:ems) { FactoryBot.create(:ems_kubevirt, :with_metrics_endpoint) } | ||
let(:hardware) { FactoryBot.create(:hardware, :cpu1x1, :ram1GB) } | ||
let(:host) { FactoryBot.create(:host_kubevirt, :ext_management_system => ems, :name => "test-host") } | ||
let(:vm) { FactoryBot.create(:vm_kubevirt, :ext_management_system => ems, :hardware => hardware, :host => host) } | ||
let(:template) { FactoryBot.create(:template_kubevirt, :ext_management_system => ems) } | ||
|
||
context "#perf_capture_object" do | ||
it "returns the correct class" do | ||
expect(ems.perf_capture_object.class).to eq(described_class) | ||
end | ||
end | ||
|
||
context "#build_capture_context!" do | ||
it "detect prometheus metrics provider" do | ||
metric_capture = described_class.new(vm) | ||
context = metric_capture.build_capture_context!(ems, vm, 5.minutes.ago, 0.minutes.ago) | ||
|
||
expect(context).to be_a(described_class::PrometheusCaptureContext) | ||
end | ||
|
||
context "on an invalid target" do | ||
it "raises an exception" do | ||
metric_capture = described_class.new(template) | ||
|
||
expect { metric_capture.build_capture_context!(ems, template, 5.minutes.ago, 0.minutes.ago) } | ||
.to raise_error(described_class::TargetValidationWarning, "no associated hardware") | ||
end | ||
end | ||
end | ||
|
||
context "#perf_capture_all_queue" do | ||
context "with a missing metrics endpoint" do | ||
let(:ems) { FactoryBot.create(:ems_kubevirt) } | ||
|
||
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_kubevirt, :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 cpu cores are defined" do | ||
vm.hardware.cpu_total_cores = nil | ||
expect { vm.perf_collect_metrics('interval_name') }.to raise_error(described_class::TargetValidationError) | ||
end | ||
|
||
it "fails when memory is not defined" do | ||
vm.hardware.memory_mb = nil | ||
expect { vm.perf_collect_metrics('interval_name') }.to raise_error(described_class::TargetValidationError) | ||
end | ||
end | ||
end |
73 changes: 73 additions & 0 deletions
73
...ubevirt/infra_manager/metrics_capture/prometheus_capture_context_VmOrTemplate_metrics.yml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
73 changes: 73 additions & 0 deletions
73
...bevirt/infra_manager/metrics_capture/prometheus_capture_context_VmOrTemplate_timespan.yml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was needed since the capture context is subclassed from k8s which has its own error handling classes
This should not be needed if ManageIQ/manageiq-providers-kubernetes#543 is resolved but that may necessitate other changes to the specs