mirror of
https://github.com/elastic/logstash.git
synced 2025-04-24 22:57:16 -04:00
Enhanced API testing (#10972)
* Starting to audit tests * Additional field checking in stats * Add epehemeral id * More tests * Test new structure of pipeline report * Add default_metadata testing * Add node command tests * add jvm * test no mutate * Add check for graph flag * Break apart test per review suggestion * Remove test that doesn't test much
This commit is contained in:
parent
3e99e1f203
commit
18ba98aa91
5 changed files with 255 additions and 11 deletions
|
@ -0,0 +1,37 @@
|
||||||
|
# encoding: utf-8
|
||||||
|
require "spec_helper"
|
||||||
|
|
||||||
|
describe LogStash::Api::Commands::DefaultMetadata do
|
||||||
|
include_context "api setup"
|
||||||
|
|
||||||
|
let(:report_method) { :all }
|
||||||
|
subject(:report) do
|
||||||
|
factory = ::LogStash::Api::CommandFactory.new(LogStash::Api::Service.new(@agent))
|
||||||
|
factory.build(:default_metadata).send(report_method)
|
||||||
|
end
|
||||||
|
|
||||||
|
let(:report_class) { described_class }
|
||||||
|
|
||||||
|
describe "#plugins_stats_report" do
|
||||||
|
let(:report_method) { :all }
|
||||||
|
# Enforce just the structure
|
||||||
|
it "check keys" do
|
||||||
|
expect(report.keys).to include(
|
||||||
|
:host,
|
||||||
|
:version,
|
||||||
|
:http_address,
|
||||||
|
:id,
|
||||||
|
:name,
|
||||||
|
:ephemeral_id,
|
||||||
|
:status,
|
||||||
|
:snapshot,
|
||||||
|
:pipeline
|
||||||
|
)
|
||||||
|
expect(report[:pipeline].keys).to include(
|
||||||
|
:workers,
|
||||||
|
:batch_size,
|
||||||
|
:batch_delay,
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
126
logstash-core/spec/logstash/api/commands/node_spec.rb
Normal file
126
logstash-core/spec/logstash/api/commands/node_spec.rb
Normal file
|
@ -0,0 +1,126 @@
|
||||||
|
# encoding: utf-8
|
||||||
|
require "spec_helper"
|
||||||
|
|
||||||
|
describe LogStash::Api::Commands::Node do
|
||||||
|
include_context "api setup"
|
||||||
|
|
||||||
|
let(:report_method) { :all }
|
||||||
|
let(:pipeline_id) { nil }
|
||||||
|
let(:opts) { {} }
|
||||||
|
let(:mocked_vertex) {{:config_name=>"elasticsearch",
|
||||||
|
:plugin_type=>"output",
|
||||||
|
:meta=>{
|
||||||
|
:source=>{
|
||||||
|
:protocol=>"str",
|
||||||
|
:id=>"pipeline",
|
||||||
|
:line=>1,
|
||||||
|
:column=>64
|
||||||
|
}
|
||||||
|
},
|
||||||
|
:id=>"2d2270426a2e8d7976b972b6a5318624331fa0d39fa3f903d2f3490e58a7d25a",
|
||||||
|
:explicit_id=>false,
|
||||||
|
:type=>"plugin"}
|
||||||
|
}
|
||||||
|
subject(:report) do
|
||||||
|
factory = ::LogStash::Api::CommandFactory.new(LogStash::Api::Service.new(@agent))
|
||||||
|
if report_method == :pipelines
|
||||||
|
factory.build(:node).send(report_method, opts)
|
||||||
|
elsif report_method == :pipeline
|
||||||
|
factory.build(:node).send(report_method, pipeline_id, opts)
|
||||||
|
elsif report_method == :decorate_with_cluster_uuids
|
||||||
|
factory.build(:node).send(report_method, mocked_vertex)
|
||||||
|
else
|
||||||
|
factory.build(:node).send(report_method)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
let(:report_class) { described_class }
|
||||||
|
|
||||||
|
describe "#all" do
|
||||||
|
let(:report_method) { :all }
|
||||||
|
# Enforce just the structure
|
||||||
|
it "check keys" do
|
||||||
|
expect(report.keys).to include(
|
||||||
|
:pipelines,
|
||||||
|
:os,
|
||||||
|
:jvm
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
describe "#pipeline" do
|
||||||
|
let(:report_method) { :pipeline }
|
||||||
|
let(:pipeline_id) { "main" }
|
||||||
|
# Enforce just the structure
|
||||||
|
it "check keys" do
|
||||||
|
expect(report.keys).to include(
|
||||||
|
:ephemeral_id,
|
||||||
|
:hash,
|
||||||
|
:workers,
|
||||||
|
:batch_size,
|
||||||
|
:batch_delay,
|
||||||
|
:config_reload_automatic,
|
||||||
|
:config_reload_interval,
|
||||||
|
:dead_letter_queue_enabled,
|
||||||
|
# :dead_letter_queue_path is nil in tests
|
||||||
|
# so it is ignored
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "#pipeline?opts" do
|
||||||
|
let(:report_method) { :pipeline }
|
||||||
|
let(:pipeline_id) { "main" }
|
||||||
|
let(:opts) { { :graph=>true } }
|
||||||
|
# Enforce just the structure
|
||||||
|
it "check keys" do
|
||||||
|
expect(report.keys).to include(
|
||||||
|
:ephemeral_id,
|
||||||
|
:hash,
|
||||||
|
:workers,
|
||||||
|
:batch_size,
|
||||||
|
:batch_delay,
|
||||||
|
:config_reload_automatic,
|
||||||
|
:config_reload_interval,
|
||||||
|
:dead_letter_queue_enabled,
|
||||||
|
# Be sure we display a graph when we set the option to
|
||||||
|
:graph
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "#os" do
|
||||||
|
let(:report_method) { :os }
|
||||||
|
it "check_keys" do
|
||||||
|
expect(report.keys).to include(
|
||||||
|
:name,
|
||||||
|
:arch,
|
||||||
|
:version,
|
||||||
|
:available_processors
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "#jvm" do
|
||||||
|
let(:report_method) { :jvm }
|
||||||
|
it "check_keys" do
|
||||||
|
expect(report.keys).to include(
|
||||||
|
:pid,
|
||||||
|
:version,
|
||||||
|
:vm_version,
|
||||||
|
:vm_vendor,
|
||||||
|
:vm_name,
|
||||||
|
:start_time_in_millis,
|
||||||
|
:mem,
|
||||||
|
:gc_collectors
|
||||||
|
)
|
||||||
|
expect(report[:mem].keys).to include(
|
||||||
|
:heap_init_in_bytes,
|
||||||
|
:heap_max_in_bytes,
|
||||||
|
:non_heap_init_in_bytes,
|
||||||
|
:non_heap_max_in_bytes
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -5,25 +5,63 @@ describe LogStash::Api::Commands::Stats do
|
||||||
include_context "api setup"
|
include_context "api setup"
|
||||||
|
|
||||||
let(:report_method) { :run }
|
let(:report_method) { :run }
|
||||||
|
let(:extended_pipeline) { nil }
|
||||||
|
let(:opts) { {} }
|
||||||
subject(:report) do
|
subject(:report) do
|
||||||
factory = ::LogStash::Api::CommandFactory.new(LogStash::Api::Service.new(@agent))
|
factory = ::LogStash::Api::CommandFactory.new(LogStash::Api::Service.new(@agent))
|
||||||
|
if extended_pipeline
|
||||||
factory.build(:stats).send(report_method)
|
factory.build(:stats).send(report_method, "main", extended_pipeline, opts)
|
||||||
|
else
|
||||||
|
factory.build(:stats).send(report_method)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
let(:report_class) { described_class }
|
let(:report_class) { described_class }
|
||||||
|
|
||||||
|
describe "#plugins_stats_report" do
|
||||||
|
let(:report_method) { :plugins_stats_report }
|
||||||
|
# Enforce just the structure
|
||||||
|
let(:extended_pipeline) {
|
||||||
|
{
|
||||||
|
:queue => "fake_queue",
|
||||||
|
:hash => "fake_hash",
|
||||||
|
:ephemeral_id => "fake_epehemeral_id",
|
||||||
|
:vertices => "fake_vertices"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
# TODO pass in a real sample vertex
|
||||||
|
# let(:opts) {
|
||||||
|
# {
|
||||||
|
# :vertices => "fake vertices"
|
||||||
|
# }
|
||||||
|
# }
|
||||||
|
it "check keys" do
|
||||||
|
expect(report.keys).to include(
|
||||||
|
:queue,
|
||||||
|
:hash,
|
||||||
|
:ephemeral_id,
|
||||||
|
# TODO re-add vertices -- see above
|
||||||
|
# :vertices
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe "#events" do
|
describe "#events" do
|
||||||
let(:report_method) { :events }
|
let(:report_method) { :events }
|
||||||
|
|
||||||
it "return events information" do
|
it "return events information" do
|
||||||
expect(report.keys).to include(:in, :filtered, :out)
|
expect(report.keys).to include(
|
||||||
|
:in,
|
||||||
|
:filtered,
|
||||||
|
:out,
|
||||||
|
:duration_in_millis,
|
||||||
|
:queue_push_duration_in_millis)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#hot_threads" do
|
describe "#hot_threads" do
|
||||||
let(:report_method) { :hot_threads }
|
let(:report_method) { :hot_threads }
|
||||||
|
|
||||||
it "should return hot threads information as a string" do
|
it "should return hot threads information as a string" do
|
||||||
expect(report.to_s).to be_a(String)
|
expect(report.to_s).to be_a(String)
|
||||||
end
|
end
|
||||||
|
@ -35,19 +73,50 @@ describe LogStash::Api::Commands::Stats do
|
||||||
|
|
||||||
describe "memory stats" do
|
describe "memory stats" do
|
||||||
let(:report_method) { :memory }
|
let(:report_method) { :memory }
|
||||||
|
|
||||||
it "return hot threads information" do
|
it "return hot threads information" do
|
||||||
expect(report).not_to be_empty
|
expect(report).not_to be_empty
|
||||||
end
|
end
|
||||||
|
|
||||||
it "return heap information" do
|
it "return memory information" do
|
||||||
expect(report.keys).to include(:heap_used_in_bytes)
|
expect(report.keys).to include(
|
||||||
|
:heap_used_percent,
|
||||||
|
:heap_committed_in_bytes,
|
||||||
|
:heap_max_in_bytes,
|
||||||
|
:heap_used_in_bytes,
|
||||||
|
:non_heap_used_in_bytes,
|
||||||
|
:non_heap_committed_in_bytes,
|
||||||
|
:pools
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
it "return non heap information" do
|
describe "jvm stats" do
|
||||||
expect(report.keys).to include(:non_heap_used_in_bytes)
|
let(:report_method) { :jvm }
|
||||||
|
|
||||||
|
it "return jvm information" do
|
||||||
|
expect(report.keys).to include(
|
||||||
|
:threads,
|
||||||
|
:mem,
|
||||||
|
:gc,
|
||||||
|
:uptime_in_millis
|
||||||
|
)
|
||||||
|
expect(report[:threads].keys).to include(
|
||||||
|
:count,
|
||||||
|
:peak_count
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "reloads stats" do
|
||||||
|
let(:report_method) { :reloads }
|
||||||
|
|
||||||
|
it "return reloads information" do
|
||||||
|
expect(report.keys).to include(
|
||||||
|
:successes,
|
||||||
|
:failures,
|
||||||
|
)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "pipeline stats" do
|
describe "pipeline stats" do
|
||||||
|
@ -74,6 +143,7 @@ describe LogStash::Api::Commands::Stats do
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when using multiple pipelines" do
|
context "when using multiple pipelines" do
|
||||||
before(:each) do
|
before(:each) do
|
||||||
expect(LogStash::Config::PipelinesInfo).to receive(:format_pipelines_info).and_return([
|
expect(LogStash::Config::PipelinesInfo).to receive(:format_pipelines_info).and_return([
|
||||||
|
|
|
@ -123,6 +123,7 @@ describe LogStash::Api::Modules::Node do
|
||||||
root_structure = {
|
root_structure = {
|
||||||
"pipelines" => {
|
"pipelines" => {
|
||||||
"main" => {
|
"main" => {
|
||||||
|
"ephemeral_id" => String,
|
||||||
"workers" => Numeric,
|
"workers" => Numeric,
|
||||||
"batch_size" => Numeric,
|
"batch_size" => Numeric,
|
||||||
"batch_delay" => Numeric,
|
"batch_delay" => Numeric,
|
||||||
|
|
|
@ -80,12 +80,22 @@ describe LogStash::Api::Modules::NodeStats do
|
||||||
"filtered" => Numeric,
|
"filtered" => Numeric,
|
||||||
"out" => Numeric,
|
"out" => Numeric,
|
||||||
"queue_push_duration_in_millis" => Numeric
|
"queue_push_duration_in_millis" => Numeric
|
||||||
}
|
},
|
||||||
|
"plugins" => {
|
||||||
|
"inputs" => Array,
|
||||||
|
"codecs" => Array,
|
||||||
|
"filters" => Array,
|
||||||
|
"outputs" => Array,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"reloads" => {
|
"reloads" => {
|
||||||
"successes" => Numeric,
|
"successes" => Numeric,
|
||||||
"failures" => Numeric
|
"failures" => Numeric
|
||||||
|
},
|
||||||
|
"os" => Hash,
|
||||||
|
"queue" => {
|
||||||
|
"events_count" => Numeric
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue