mirror of
https://github.com/elastic/logstash.git
synced 2025-04-24 22:57:16 -04:00
parent
f6b623fe92
commit
4008a7ad7e
13 changed files with 86 additions and 87 deletions
|
@ -3,6 +3,8 @@ require_relative "../services/service_locator"
|
||||||
# A class that holds all fixtures for a given test file. This deals with
|
# A class that holds all fixtures for a given test file. This deals with
|
||||||
# bootstrapping services, dealing with config files, inputs etc
|
# bootstrapping services, dealing with config files, inputs etc
|
||||||
class Fixture
|
class Fixture
|
||||||
|
FIXTURES_DIR = File.expand_path(File.join("..", "..", "fixtures"), __FILE__)
|
||||||
|
|
||||||
attr_reader :input
|
attr_reader :input
|
||||||
attr_reader :actual_output
|
attr_reader :actual_output
|
||||||
attr_reader :test_dir
|
attr_reader :test_dir
|
||||||
|
@ -21,13 +23,10 @@ class Fixture
|
||||||
|
|
||||||
def initialize(test_file_location)
|
def initialize(test_file_location)
|
||||||
@test_file_location = test_file_location
|
@test_file_location = test_file_location
|
||||||
@fixtures_dir = File.expand_path(File.join("..", "..", "fixtures"), __FILE__)
|
|
||||||
@settings = TestSettings.new(@test_file_location)
|
@settings = TestSettings.new(@test_file_location)
|
||||||
@service_locator = ServiceLocator.new(@settings)
|
@service_locator = ServiceLocator.new(@settings)
|
||||||
setup_services
|
setup_services
|
||||||
@input = File.join(@fixtures_dir, @settings.get("input")) if @settings.is_set?("input")
|
@input = File.join(FIXTURES_DIR, @settings.get("input")) if @settings.is_set?("input")
|
||||||
# this assumes current PWD.
|
|
||||||
# TODO: Remove this when we have an erb template for LS config so you can inject such stuff
|
|
||||||
@actual_output = @settings.get("actual_output")
|
@actual_output = @settings.get("actual_output")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -74,7 +73,7 @@ class Fixture
|
||||||
end
|
end
|
||||||
if @settings.is_set?("setup_script")
|
if @settings.is_set?("setup_script")
|
||||||
puts "Setting up test specific fixtures"
|
puts "Setting up test specific fixtures"
|
||||||
script = File.join(@fixtures_dir, @settings.get("setup_script"))
|
script = File.join(FIXTURES_DIR, @settings.get("setup_script"))
|
||||||
`#{script}`
|
`#{script}`
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,17 +2,17 @@ require 'yaml'
|
||||||
|
|
||||||
# All settings for a test, global and per test
|
# All settings for a test, global and per test
|
||||||
class TestSettings
|
class TestSettings
|
||||||
|
# Setting for the entire test suite
|
||||||
|
INTEG_TESTS_DIR = File.expand_path(File.join("..", ".."), __FILE__)
|
||||||
|
# Test specific settings
|
||||||
|
SUITE_SETTINGS_FILE = File.join(INTEG_TESTS_DIR, "suite.yml")
|
||||||
|
FIXTURES_DIR = File.join(INTEG_TESTS_DIR, "fixtures")
|
||||||
|
|
||||||
def initialize(test_file_path)
|
def initialize(test_file_path)
|
||||||
# Setting for the entire test suite
|
|
||||||
integ_tests_dir = File.expand_path(File.join("..", ".."), __FILE__)
|
|
||||||
@suite_settings_file = File.join(integ_tests_dir, "suite.yml")
|
|
||||||
# Test specific settings
|
|
||||||
fixtures_dir = File.join(integ_tests_dir, "fixtures")
|
|
||||||
test_name = File.basename(test_file_path, ".*" )
|
test_name = File.basename(test_file_path, ".*" )
|
||||||
@tests_settings_file = File.join(fixtures_dir, "#{test_name}.yml")
|
@tests_settings_file = File.join(FIXTURES_DIR, "#{test_name}.yml")
|
||||||
# Global suite settings
|
# Global suite settings
|
||||||
@suite_settings = YAML.load_file(@suite_settings_file)
|
@suite_settings = YAML.load_file(SUITE_SETTINGS_FILE)
|
||||||
# Per test settings, where one can override stuff and define test specific config
|
# Per test settings, where one can override stuff and define test specific config
|
||||||
@test_settings = YAML.load_file(@tests_settings_file)
|
@test_settings = YAML.load_file(@tests_settings_file)
|
||||||
|
|
||||||
|
|
|
@ -18,4 +18,5 @@ Gem::Specification.new do |s|
|
||||||
s.add_development_dependency 'manticore'
|
s.add_development_dependency 'manticore'
|
||||||
s.add_development_dependency 'stud'
|
s.add_development_dependency 'stud'
|
||||||
s.add_development_dependency 'pry'
|
s.add_development_dependency 'pry'
|
||||||
|
s.add_development_dependency 'logstash-devutils'
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -ex
|
set -ex
|
||||||
current_dir="$(dirname "$0")"
|
current_dir="$(dirname "$0")"
|
||||||
source "${current_dir}/helpers.sh"
|
|
||||||
|
|
||||||
if [ -n "${ES_VERSION+1}" ]; then
|
if [ -n "${ES_VERSION+1}" ]; then
|
||||||
echo "Elasticsearch version is $ES_VERSION"
|
echo "Elasticsearch version is $ES_VERSION"
|
||||||
|
@ -10,5 +9,30 @@ else
|
||||||
version=5.0.0-alpha5
|
version=5.0.0-alpha5
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
setup_es() {
|
||||||
|
if [ ! -d $current_dir/elasticsearch ]; then
|
||||||
|
local version=$1
|
||||||
|
download_url=https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/tar/elasticsearch/$version/elasticsearch-$version.tar.gz
|
||||||
|
curl -sL $download_url > $current_dir/elasticsearch.tar.gz
|
||||||
|
mkdir $current_dir/elasticsearch
|
||||||
|
tar -xzf $current_dir/elasticsearch.tar.gz --strip-components=1 -C $current_dir/elasticsearch/.
|
||||||
|
rm $current_dir/elasticsearch.tar.gz
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
start_es() {
|
||||||
|
es_args=$@
|
||||||
|
$current_dir/elasticsearch/bin/elasticsearch $es_args -p $current_dir/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
|
||||||
|
count=$(( $count - 1 ))
|
||||||
|
[[ $count -eq 0 ]] && return 1
|
||||||
|
sleep 1
|
||||||
|
done
|
||||||
|
echo "Elasticsearch is Up !"
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
setup_es $version
|
setup_es $version
|
||||||
start_es
|
start_es
|
||||||
|
|
|
@ -1,6 +1,11 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
my_dir="$(dirname "$0")"
|
my_dir="$(dirname "$0")"
|
||||||
source "$my_dir/helpers.sh"
|
|
||||||
|
stop_es() {
|
||||||
|
pid=$(cat $current_dir/elasticsearch.pid)
|
||||||
|
[ "x$pid" != "x" ] && [ "$pid" -gt 0 ]
|
||||||
|
kill -SIGTERM $pid
|
||||||
|
}
|
||||||
|
|
||||||
stop_es
|
stop_es
|
|
@ -1,62 +0,0 @@
|
||||||
#! /bin/bash
|
|
||||||
|
|
||||||
current_dir="$(dirname "$0")"
|
|
||||||
|
|
||||||
setup_es() {
|
|
||||||
if [ ! -d $current_dir/elasticsearch ]; then
|
|
||||||
local version=$1
|
|
||||||
download_url=https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/tar/elasticsearch/$version/elasticsearch-$version.tar.gz
|
|
||||||
curl -sL $download_url > $current_dir/elasticsearch.tar.gz
|
|
||||||
mkdir $current_dir/elasticsearch
|
|
||||||
tar -xzf $current_dir/elasticsearch.tar.gz --strip-components=1 -C $current_dir/elasticsearch/.
|
|
||||||
rm $current_dir/elasticsearch.tar.gz
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
start_es() {
|
|
||||||
es_args=$@
|
|
||||||
$current_dir/elasticsearch/bin/elasticsearch $es_args -p $current_dir/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
|
|
||||||
count=$(( $count - 1 ))
|
|
||||||
[[ $count -eq 0 ]] && return 1
|
|
||||||
sleep 1
|
|
||||||
done
|
|
||||||
echo "Elasticsearch is Up !"
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
stop_es() {
|
|
||||||
pid=$(cat $current_dir/elasticsearch.pid)
|
|
||||||
[ "x$pid" != "x" ] && [ "$pid" -gt 0 ]
|
|
||||||
kill -SIGTERM $pid
|
|
||||||
}
|
|
||||||
|
|
||||||
setup_kafka() {
|
|
||||||
local version=$1
|
|
||||||
if [ ! -d $current_dir/kafka ]; then
|
|
||||||
echo "Downloading Kafka version $version"
|
|
||||||
curl -s -o $current_dir/kafka.tgz "http://ftp.wayne.edu/apache/kafka/$version/kafka_2.11-$version.tgz"
|
|
||||||
mkdir $current_dir/kafka && tar xzf $current_dir/kafka.tgz -C $current_dir/kafka --strip-components 1
|
|
||||||
rm $current_dir/kafka.tgz
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
start_kafka() {
|
|
||||||
echo "Starting ZooKeeper"
|
|
||||||
$current_dir/kafka/bin/zookeeper-server-start.sh -daemon $current_dir/kafka/config/zookeeper.properties
|
|
||||||
sleep 3
|
|
||||||
echo "Starting Kafka broker"
|
|
||||||
$current_dir/kafka/bin/kafka-server-start.sh -daemon $current_dir/kafka/config/server.properties --override delete.topic.enable=true
|
|
||||||
sleep 3
|
|
||||||
}
|
|
||||||
|
|
||||||
stop_kafka() {
|
|
||||||
echo "Stopping Kafka broker"
|
|
||||||
$current_dir/kafka/bin/kafka-server-stop.sh
|
|
||||||
sleep 2
|
|
||||||
echo "Stopping zookeeper"
|
|
||||||
$current_dir/kafka/bin/zookeeper-server-stop.sh
|
|
||||||
sleep 2
|
|
||||||
}
|
|
|
@ -1,7 +1,6 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -ex
|
set -ex
|
||||||
current_dir="$(dirname "$0")"
|
current_dir="$(dirname "$0")"
|
||||||
source "${current_dir}/helpers.sh"
|
|
||||||
|
|
||||||
if [ -n "${KAFKA_VERSION+1}" ]; then
|
if [ -n "${KAFKA_VERSION+1}" ]; then
|
||||||
echo "KAFKA_VERSION is $KAFKA_VERSION"
|
echo "KAFKA_VERSION is $KAFKA_VERSION"
|
||||||
|
@ -10,6 +9,25 @@ else
|
||||||
version=0.10.0.0
|
version=0.10.0.0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
setup_kafka() {
|
||||||
|
local version=$1
|
||||||
|
if [ ! -d $current_dir/kafka ]; then
|
||||||
|
echo "Downloading Kafka version $version"
|
||||||
|
curl -s -o $current_dir/kafka.tgz "http://ftp.wayne.edu/apache/kafka/$version/kafka_2.11-$version.tgz"
|
||||||
|
mkdir $current_dir/kafka && tar xzf $current_dir/kafka.tgz -C $current_dir/kafka --strip-components 1
|
||||||
|
rm $current_dir/kafka.tgz
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
start_kafka() {
|
||||||
|
echo "Starting ZooKeeper"
|
||||||
|
$current_dir/kafka/bin/zookeeper-server-start.sh -daemon $current_dir/kafka/config/zookeeper.properties
|
||||||
|
sleep 3
|
||||||
|
echo "Starting Kafka broker"
|
||||||
|
$current_dir/kafka/bin/kafka-server-start.sh -daemon $current_dir/kafka/config/server.properties --override delete.topic.enable=true
|
||||||
|
sleep 3
|
||||||
|
}
|
||||||
|
|
||||||
setup_kafka $version
|
setup_kafka $version
|
||||||
start_kafka
|
start_kafka
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,15 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -ex
|
set -ex
|
||||||
current_dir="$(dirname "$0")"
|
current_dir="$(dirname "$0")"
|
||||||
source "${current_dir}/helpers.sh"
|
|
||||||
|
stop_kafka() {
|
||||||
|
echo "Stopping Kafka broker"
|
||||||
|
$current_dir/kafka/bin/kafka-server-stop.sh
|
||||||
|
sleep 2
|
||||||
|
echo "Stopping zookeeper"
|
||||||
|
$current_dir/kafka/bin/zookeeper-server-stop.sh
|
||||||
|
sleep 2
|
||||||
|
}
|
||||||
|
|
||||||
# delete test topic
|
# delete test topic
|
||||||
echo "Deleting test topic in Kafka"
|
echo "Deleting test topic in Kafka"
|
||||||
|
|
|
@ -3,10 +3,14 @@ require_relative "monitoring_api"
|
||||||
require "childprocess"
|
require "childprocess"
|
||||||
require "bundler"
|
require "bundler"
|
||||||
require "tempfile"
|
require "tempfile"
|
||||||
|
require 'yaml'
|
||||||
|
|
||||||
# A locally started Logstash service
|
# A locally started Logstash service
|
||||||
class LogstashService < Service
|
class LogstashService < Service
|
||||||
|
|
||||||
|
LS_VERSION_FILE = File.expand_path(File.join("../../../",versions.yml), __FILE__)
|
||||||
|
LS_BIN = "bin/logstash"
|
||||||
|
|
||||||
STDIN_CONFIG = "input {stdin {}} output { }"
|
STDIN_CONFIG = "input {stdin {}} output { }"
|
||||||
RETRY_ATTEMPTS = 10
|
RETRY_ATTEMPTS = 10
|
||||||
|
|
||||||
|
@ -20,12 +24,14 @@ class LogstashService < Service
|
||||||
@logstash_home = @settings.get("ls_home_abs_path")
|
@logstash_home = @settings.get("ls_home_abs_path")
|
||||||
else
|
else
|
||||||
# use the LS which was just built in source repo
|
# use the LS which was just built in source repo
|
||||||
ls_file = "logstash-" + @settings.get("ls_version")
|
ls_version_file = YAML.load_file(LS_VERSION_FILE)
|
||||||
ls_file += "-SNAPSHOT" if @settings.get("snapshot")
|
ls_file = "logstash-" + ls_version_file["logstash"]
|
||||||
@logstash_home = File.expand_path(File.join("../../../../build",ls_file), __FILE__)
|
# First try without the snapshot if it's there
|
||||||
|
@logstash_home = File.expand_path(File.join("../../../../build", ls_file), __FILE__)
|
||||||
|
@logstash_home += "-SNAPSHOT" unless Dir.exists?(@logstash_home)
|
||||||
|
|
||||||
puts "Using #{@logstash_home} as LS_HOME"
|
puts "Using #{@logstash_home} as LS_HOME"
|
||||||
@logstash_bin = File.join("#{@logstash_home}", "bin/logstash")
|
@logstash_bin = File.join("#{@logstash_home}", LS_BIN)
|
||||||
raise "Logstash binary not found in path #{@logstash_home}" unless File.file? @logstash_bin
|
raise "Logstash binary not found in path #{@logstash_home}" unless File.file? @logstash_bin
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
require_relative '../framework/fixture'
|
require_relative '../framework/fixture'
|
||||||
require_relative '../framework/settings'
|
require_relative '../framework/settings'
|
||||||
require_relative '../services/logstash'
|
require_relative '../services/logstash_service'
|
||||||
|
|
||||||
describe "a config which indexes data into Elasticsearch", :integration => true do
|
describe "a config which indexes data into Elasticsearch", :integration => true do
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
require_relative '../framework/fixture'
|
require_relative '../framework/fixture'
|
||||||
require_relative '../framework/settings'
|
require_relative '../framework/settings'
|
||||||
require_relative '../services/logstash'
|
require_relative '../services/logstash_service'
|
||||||
require "rspec/wait"
|
require "rspec/wait"
|
||||||
|
|
||||||
describe "Kafka Input", :integration => true do
|
describe "Kafka Input", :integration => true do
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
require_relative '../framework/fixture'
|
require_relative '../framework/fixture'
|
||||||
require_relative '../framework/settings'
|
require_relative '../framework/settings'
|
||||||
require_relative '../services/logstash'
|
require_relative '../services/logstash_service'
|
||||||
|
require "logstash/devutils/rspec/spec_helper"
|
||||||
|
|
||||||
describe "Monitoring API", :integration => true do
|
describe "Monitoring API", :integration => true do
|
||||||
before(:all) {
|
before(:all) {
|
||||||
|
@ -15,10 +16,9 @@ describe "Monitoring API", :integration => true do
|
||||||
logstash_service = @fixture.get_service("logstash")
|
logstash_service = @fixture.get_service("logstash")
|
||||||
logstash_service.start_with_stdin
|
logstash_service.start_with_stdin
|
||||||
5.times { logstash_service.write_to_stdin("Hello world") }
|
5.times { logstash_service.write_to_stdin("Hello world") }
|
||||||
# TODO: get rid of this sleep, or loop
|
|
||||||
sleep 3
|
|
||||||
# check metrics
|
# check metrics
|
||||||
result = logstash_service.monitoring_api.event_stats
|
result = logstash_service.monitoring_api.event_stats
|
||||||
|
try { expect(result["in"]).to eq(5) }
|
||||||
expect(result["in"]).to eq(5)
|
expect(result["in"]).to eq(5)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue