Skip to content

Commit 808e80a

Browse files
spec: improve ls2ls spec (#17114) (#17117)
* spec: improve ls2ls spec - fixes upstream/downstream convention - upstream: the sending logstash (has an LS output) - downstream: the receiving logstash (has an LS input) - helper `run_logstash_instance` yields the `LogstashService` instance and handles the teardown. - pass the pipeline id and node name to the LS instances via command line flags to make logging easier to differentiate - use the generator input's sequence id to ensure that the _actual_ events generated are received by the downstream pipeline * start with port-offset 100 Co-authored-by: Mashhur <[email protected]> --------- Co-authored-by: Mashhur <[email protected]> (cherry picked from commit 9abad66) Co-authored-by: Ry Biesemeyer <[email protected]>
1 parent ee4e132 commit 808e80a

File tree

2 files changed

+26
-21
lines changed

2 files changed

+26
-21
lines changed

qa/integration/fixtures/logstash_to_logstash_spec.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ config:
1414
file {
1515
path => '<%=options[:output_file_path]%>'
1616
flush_interval => 0
17-
codec => line { format => "%{message}" }
17+
codec => line { format => "%{[event][sequence]}:%{message}" }
1818
}
1919
}
2020
basic_ls_output: |-

qa/integration/specs/logstash_to_logstash_spec.rb

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,26 @@ def get_temp_path_dir
4343
tmp_data_path
4444
end
4545

46-
def run_logstash_instance(config_name, options = {})
47-
@next_api_port_offset = (@next_api_port_offset||0).next.modulo(1000) # cycle through 1000 possibles
46+
def run_logstash_instance(config_name, options = {}, &block)
47+
@next_api_port_offset = (@next_api_port_offset||100).next.modulo(1000) # cycle through 1000 possibles
4848
api_port = 9600 + @next_api_port_offset
4949

5050
# to avoid LogstashService's clean-from-tarball default behaviour, we need
5151
# to tell it where our LOGSTASH_HOME is in the existing service
5252
existing_fixture_logstash_home = @fixture.get_service("logstash").logstash_home
5353
logstash_service = LogstashService.new(@fixture.settings.override("ls_home_abs_path" => existing_fixture_logstash_home), api_port)
5454

55-
logstash_service.spawn_logstash("--path.config", config_to_temp_file(@fixture.config(config_name, options)),
55+
logstash_service.spawn_logstash("--node.name", config_name,
56+
"--pipeline.id", config_name,
57+
"--path.config", config_to_temp_file(@fixture.config(config_name, options)),
5658
"--path.data", get_temp_path_dir,
5759
"--api.http.port", api_port.to_s)
5860
wait_for_logstash(logstash_service)
59-
logstash_service
61+
62+
yield logstash_service
63+
64+
ensure
65+
logstash_service&.teardown
6066
end
6167

6268
def wait_for_logstash(service)
@@ -86,26 +92,25 @@ def wait_for_logstash(service)
8692
}
8793

8894
it "successfully send events" do
89-
upstream_logstash_service = run_logstash_instance(input_config_name, all_config_options)
90-
downstream_logstash_service = run_logstash_instance(output_config_name, all_config_options)
95+
run_logstash_instance(input_config_name, all_config_options) do |downstream_logstash_service|
96+
run_logstash_instance(output_config_name, all_config_options) do |upstream_logstash_service|
9197

92-
try(num_retries) do
93-
event_stats = upstream_logstash_service.monitoring_api.event_stats
94-
if event_stats
95-
expect(event_stats["in"]).to eq(num_events)
96-
end
97-
end
98+
try(num_retries) do
99+
downstream_event_stats = downstream_logstash_service.monitoring_api.event_stats
98100

99-
upstream_logstash_service.teardown
100-
downstream_logstash_service.teardown
101+
expect(downstream_event_stats).to include({"in" => num_events}), lambda { "expected #{num_events} events to have been received by downstream"}
102+
end
101103

102-
# make sure received events are in the file
103-
file_output_path = File.join(upstream_logstash_service.logstash_home, output_file_path_with_datetime)
104-
expect(File).to exist(file_output_path), "Logstash to Logstash output file: #{file_output_path} does not exist"
105-
count = File.foreach(file_output_path).inject(0) { |c, _| c + 1 }
106-
expect(count).to eq(num_events)
104+
# make sure received events are in the file
105+
file_output_path = File.join(downstream_logstash_service.logstash_home, output_file_path_with_datetime)
106+
expect(File).to exist(file_output_path), "Logstash to Logstash output file: #{file_output_path} does not exist"
107+
actual_lines = File.read(file_output_path).lines.to_a
108+
expected_lines = (0...num_events).map { |sequence| "#{sequence}:Hello world!\n" }
109+
expect(actual_lines).to match_array(expected_lines)
107110

108-
File.delete(file_output_path)
111+
File.delete(file_output_path)
112+
end
113+
end
109114
end
110115
end
111116

0 commit comments

Comments
 (0)