diff --git a/logstash-core/spec/logstash/api/commands/default_metadata_spec.rb b/logstash-core/spec/logstash/api/commands/default_metadata_spec.rb new file mode 100644 index 000000000..ee5157ffb --- /dev/null +++ b/logstash-core/spec/logstash/api/commands/default_metadata_spec.rb @@ -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 diff --git a/logstash-core/spec/logstash/api/commands/node_spec.rb b/logstash-core/spec/logstash/api/commands/node_spec.rb new file mode 100644 index 000000000..0077519bc --- /dev/null +++ b/logstash-core/spec/logstash/api/commands/node_spec.rb @@ -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 diff --git a/logstash-core/spec/logstash/api/commands/stats_spec.rb b/logstash-core/spec/logstash/api/commands/stats_spec.rb index c52b844ba..792a1d6df 100644 --- a/logstash-core/spec/logstash/api/commands/stats_spec.rb +++ b/logstash-core/spec/logstash/api/commands/stats_spec.rb @@ -5,25 +5,63 @@ describe LogStash::Api::Commands::Stats do include_context "api setup" let(:report_method) { :run } + let(:extended_pipeline) { nil } + let(:opts) { {} } subject(:report) do factory = ::LogStash::Api::CommandFactory.new(LogStash::Api::Service.new(@agent)) - - factory.build(:stats).send(report_method) + if extended_pipeline + factory.build(:stats).send(report_method, "main", extended_pipeline, opts) + else + factory.build(:stats).send(report_method) + end end 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 let(:report_method) { :events } 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 - + describe "#hot_threads" do let(:report_method) { :hot_threads } - + it "should return hot threads information as a string" do expect(report.to_s).to be_a(String) end @@ -35,19 +73,50 @@ describe LogStash::Api::Commands::Stats do describe "memory stats" do let(:report_method) { :memory } - + it "return hot threads information" do expect(report).not_to be_empty end - it "return heap information" do - expect(report.keys).to include(:heap_used_in_bytes) + it "return memory information" do + 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 - it "return non heap information" do - expect(report.keys).to include(:non_heap_used_in_bytes) + describe "jvm stats" do + 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 + describe "reloads stats" do + let(:report_method) { :reloads } + + it "return reloads information" do + expect(report.keys).to include( + :successes, + :failures, + ) + end end describe "pipeline stats" do @@ -74,6 +143,7 @@ describe LogStash::Api::Commands::Stats do ) end end + context "when using multiple pipelines" do before(:each) do expect(LogStash::Config::PipelinesInfo).to receive(:format_pipelines_info).and_return([ diff --git a/logstash-core/spec/logstash/api/modules/node_spec.rb b/logstash-core/spec/logstash/api/modules/node_spec.rb index 7fc7f1271..0f6a71113 100644 --- a/logstash-core/spec/logstash/api/modules/node_spec.rb +++ b/logstash-core/spec/logstash/api/modules/node_spec.rb @@ -123,6 +123,7 @@ describe LogStash::Api::Modules::Node do root_structure = { "pipelines" => { "main" => { + "ephemeral_id" => String, "workers" => Numeric, "batch_size" => Numeric, "batch_delay" => Numeric, diff --git a/logstash-core/spec/logstash/api/modules/node_stats_spec.rb b/logstash-core/spec/logstash/api/modules/node_stats_spec.rb index 729f9aee9..825604a4e 100644 --- a/logstash-core/spec/logstash/api/modules/node_stats_spec.rb +++ b/logstash-core/spec/logstash/api/modules/node_stats_spec.rb @@ -80,12 +80,22 @@ describe LogStash::Api::Modules::NodeStats do "filtered" => Numeric, "out" => Numeric, "queue_push_duration_in_millis" => Numeric - } + }, + "plugins" => { + "inputs" => Array, + "codecs" => Array, + "filters" => Array, + "outputs" => Array, + }, } }, "reloads" => { "successes" => Numeric, "failures" => Numeric + }, + "os" => Hash, + "queue" => { + "events_count" => Numeric } }