From dfd6164edde3afe414539c19fda022a221c6687a Mon Sep 17 00:00:00 2001 From: Suyog Rao Date: Tue, 20 Sep 2016 15:37:59 -0700 Subject: [PATCH] changes after review Fixes #5917 --- ci/ci_integration.sh | 8 +++++-- qa/integration/.rspec | 1 + qa/integration/fixtures/kafka_input_spec.yml | 12 +++++----- qa/integration/framework/fixture.rb | 2 +- qa/integration/framework/settings.rb | 9 ++++++++ .../services/elasticsearch_setup.sh | 2 +- .../services/elasticsearch_teardown.sh | 6 ++--- qa/integration/services/kafka_setup.sh | 2 +- qa/integration/services/logstash_service.rb | 2 +- qa/integration/specs/beats_input_spec.rb | 2 +- qa/integration/specs/es_output_how_spec.rb | 2 +- qa/integration/specs/kafka_input_spec.rb | 9 ++++---- qa/integration/specs/monitoring_api_spec.rb | 22 ++++++++++++++----- qa/integration/suite.yml | 6 +++-- 14 files changed, 55 insertions(+), 30 deletions(-) create mode 100644 qa/integration/.rspec diff --git a/ci/ci_integration.sh b/ci/ci_integration.sh index 5aaeca000..088a1884b 100755 --- a/ci/ci_integration.sh +++ b/ci/ci_integration.sh @@ -6,5 +6,9 @@ set -e # installing gems. See https://github.com/elastic/logstash/issues/5179 export JRUBY_OPTS="-J-Xmx1g" -rake test:install-default -rake test:integration +rm -rf build/* +rake artifact:tar +cd build +tar xvf *.tar.gz +cd ../qa/integration +rspec diff --git a/qa/integration/.rspec b/qa/integration/.rspec new file mode 100644 index 000000000..12f9968c3 --- /dev/null +++ b/qa/integration/.rspec @@ -0,0 +1 @@ +--default-path specs/ \ No newline at end of file diff --git a/qa/integration/fixtures/kafka_input_spec.yml b/qa/integration/fixtures/kafka_input_spec.yml index 533014e97..a7df6098e 100644 --- a/qa/integration/fixtures/kafka_input_spec.yml +++ b/qa/integration/fixtures/kafka_input_spec.yml @@ -12,13 +12,13 @@ config: |- } } output { - #file { - # path => "kafka_input.output" - # flush_interval => 0 - # codec => line { format => "%{message}" } - #} + file { + path => "kafka_input.output" + flush_interval => 0 + codec => line { format => "%{message}" } + } } input: how_sample.input -setup_script: download_input.sh +actual_output: kafka_input.output teardown_script: diff --git a/qa/integration/framework/fixture.rb b/qa/integration/framework/fixture.rb index 7fdbe837c..7c3d7d21b 100644 --- a/qa/integration/framework/fixture.rb +++ b/qa/integration/framework/fixture.rb @@ -57,7 +57,7 @@ class Fixture end def teardown - File.delete(@actual_output) if @settings.is_set?(@actual_output) && output_exists? + File.delete(@actual_output) if @settings.is_set?("actual_output") && output_exists? puts "Tearing down services" services = @settings.get("services") services.each do |name| diff --git a/qa/integration/framework/settings.rb b/qa/integration/framework/settings.rb index cef3bd6d7..d0a25ad3a 100644 --- a/qa/integration/framework/settings.rb +++ b/qa/integration/framework/settings.rb @@ -15,6 +15,11 @@ class TestSettings @suite_settings = YAML.load_file(SUITE_SETTINGS_FILE) # Per test settings, where one can override stuff and define test specific config @test_settings = YAML.load_file(@tests_settings_file) + + if verbose_mode? + puts "Test settings file: #{@tests_settings_file}" + puts "Suite settings file: #{SUITE_SETTINGS_FILE}" + end if is_set?("config") if get("config").is_a?(Hash) @@ -37,6 +42,10 @@ class TestSettings @suite_settings[key] end end + + def verbose_mode? + @suite_settings["verbose_mode"] + end def is_set?(key) @suite_settings.key?(key) || @test_settings.key?(key) diff --git a/qa/integration/services/elasticsearch_setup.sh b/qa/integration/services/elasticsearch_setup.sh index 4934e9608..65078ab0d 100755 --- a/qa/integration/services/elasticsearch_setup.sh +++ b/qa/integration/services/elasticsearch_setup.sh @@ -22,7 +22,7 @@ setup_es() { start_es() { es_args=$@ - $current_dir/elasticsearch/bin/elasticsearch $es_args -p $current_dir/elasticsearch.pid > /tmp/elasticsearch.log 2>/dev/null & + $current_dir/elasticsearch/bin/elasticsearch $es_args -p $current_dir/elasticsearch/elasticsearch.pid > /tmp/elasticsearch.log 2>/dev/null & count=120 echo "Waiting for elasticsearch to respond..." while ! curl --silent localhost:9200 && [[ $count -ne 0 ]]; do diff --git a/qa/integration/services/elasticsearch_teardown.sh b/qa/integration/services/elasticsearch_teardown.sh index a70df5e52..5d59f30fa 100755 --- a/qa/integration/services/elasticsearch_teardown.sh +++ b/qa/integration/services/elasticsearch_teardown.sh @@ -1,9 +1,9 @@ #!/bin/bash - -my_dir="$(dirname "$0")" +set -ex +current_dir="$(dirname "$0")" stop_es() { - pid=$(cat $current_dir/elasticsearch.pid) + pid=$(cat $current_dir/elasticsearch/elasticsearch.pid) [ "x$pid" != "x" ] && [ "$pid" -gt 0 ] kill -SIGTERM $pid } diff --git a/qa/integration/services/kafka_setup.sh b/qa/integration/services/kafka_setup.sh index 3591ead89..26740d693 100755 --- a/qa/integration/services/kafka_setup.sh +++ b/qa/integration/services/kafka_setup.sh @@ -33,5 +33,5 @@ start_kafka # Set up topics $current_dir/kafka/bin/kafka-topics.sh --create --partitions 1 --replication-factor 1 --topic logstash_topic_plain --zookeeper localhost:2181 -cat $current_dir/kafka_input.input | $current_dir/kafka/bin/kafka-console-producer.sh --topic logstash_topic_plain --broker-list localhost:9092 +cat $current_dir/../fixtures/how_sample.input | $current_dir/kafka/bin/kafka-console-producer.sh --topic logstash_topic_plain --broker-list localhost:9092 echo "Kafka Setup complete" diff --git a/qa/integration/services/logstash_service.rb b/qa/integration/services/logstash_service.rb index ecae635ec..09e3ea806 100644 --- a/qa/integration/services/logstash_service.rb +++ b/qa/integration/services/logstash_service.rb @@ -8,7 +8,7 @@ require 'yaml' # A locally started Logstash service class LogstashService < Service - LS_VERSION_FILE = File.expand_path(File.join("../../../",versions.yml), __FILE__) + LS_VERSION_FILE = File.expand_path(File.join("../../../../", "versions.yml"), __FILE__) LS_BIN = "bin/logstash" STDIN_CONFIG = "input {stdin {}} output { }" diff --git a/qa/integration/specs/beats_input_spec.rb b/qa/integration/specs/beats_input_spec.rb index 7f2c78e62..1dc31b5e1 100644 --- a/qa/integration/specs/beats_input_spec.rb +++ b/qa/integration/specs/beats_input_spec.rb @@ -6,7 +6,7 @@ require "rspec/wait" require "yaml" require "fileutils" -describe "Beat Input", :integration => true do +describe "Beat Input" do before(:all) do @fixture = Fixture.new(__FILE__) end diff --git a/qa/integration/specs/es_output_how_spec.rb b/qa/integration/specs/es_output_how_spec.rb index e464363bc..27f2ef2d4 100644 --- a/qa/integration/specs/es_output_how_spec.rb +++ b/qa/integration/specs/es_output_how_spec.rb @@ -2,7 +2,7 @@ require_relative '../framework/fixture' require_relative '../framework/settings' require_relative '../services/logstash_service' -describe "a config which indexes data into Elasticsearch", :integration => true do +describe "a config which indexes data into Elasticsearch" do before(:all) { @fixture = Fixture.new(__FILE__) diff --git a/qa/integration/specs/kafka_input_spec.rb b/qa/integration/specs/kafka_input_spec.rb index e78b9f389..2cd52e9e4 100644 --- a/qa/integration/specs/kafka_input_spec.rb +++ b/qa/integration/specs/kafka_input_spec.rb @@ -3,7 +3,7 @@ require_relative '../framework/settings' require_relative '../services/logstash_service' require "rspec/wait" -describe "Kafka Input", :integration => true do +describe "Kafka Input" do let(:timeout_seconds) { 5 } before(:all) { @fixture = Fixture.new(__FILE__) @@ -17,10 +17,9 @@ describe "Kafka Input", :integration => true do logstash_service = @fixture.get_service("logstash") logstash_service.start_background(@fixture.config) - # TODO: File Output is busted so this test fails - #wait(timeout_seconds).for { @fixture.output_exists? }.to be true - #expect(@fixture.output_equals_expected?).to be true, - # lambda { "Expected File output to match what was ingested into Kafka." } + wait(timeout_seconds).for { @fixture.output_exists? }.to be true + expect(@fixture.output_equals_expected?).to be true + lambda { "Expected File output to match what was ingested into Kafka." } end end diff --git a/qa/integration/specs/monitoring_api_spec.rb b/qa/integration/specs/monitoring_api_spec.rb index 9a9be51e2..66028bb98 100644 --- a/qa/integration/specs/monitoring_api_spec.rb +++ b/qa/integration/specs/monitoring_api_spec.rb @@ -3,7 +3,7 @@ require_relative '../framework/settings' require_relative '../services/logstash_service' require "logstash/devutils/rspec/spec_helper" -describe "Monitoring API", :integration => true do +describe "Monitoring API" do before(:all) { @fixture = Fixture.new(__FILE__) } @@ -11,15 +11,25 @@ describe "Monitoring API", :integration => true do after(:all) { @fixture.teardown } + + let(:number_of_events) { 5 } + let(:max_retry) { 120 } it "can retrieve event stats" do logstash_service = @fixture.get_service("logstash") logstash_service.start_with_stdin - 5.times { logstash_service.write_to_stdin("Hello world") } - # check metrics - result = logstash_service.monitoring_api.event_stats - try { expect(result["in"]).to eq(5) } - expect(result["in"]).to eq(5) + number_of_events.times { logstash_service.write_to_stdin("Hello world") } + + begin + sleep(1) while (result = logstash_service.monitoring_api.event_stats).nil? + rescue + retry + end + + Stud.try(max_retry.times, RSpec::Expectations::ExpectationNotMetError) do + result = logstash_service.monitoring_api.event_stats + expect(result["in"]).to eq(number_of_events) + end end end diff --git a/qa/integration/suite.yml b/qa/integration/suite.yml index d9e457376..8ccdff47b 100644 --- a/qa/integration/suite.yml +++ b/qa/integration/suite.yml @@ -1,4 +1,6 @@ --- -ls_version: 5.0.0-alpha6 -snapshot: true +# Use this to output more debug-level information +verbose_mode: false +# Typically we use the binaries in LS_HOME/build. If you want to QA a LS in different location, +# use the absolute path below #ls_home_abs_path: /tmp/logstash-5.0.0-alpha6 \ No newline at end of file