Skip to content

Commit

Permalink
Backport PR #12685 to 7.12: Fix Elasticsearch/DLQ integration test fl…
Browse files Browse the repository at this point in the history
…akiness (#12823)

Co-authored-by: Rob Bavey <[email protected]>
  • Loading branch information
kares and robbavey authored Apr 14, 2021
1 parent eb3e4af commit a0a95c8
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
3 changes: 1 addition & 2 deletions qa/integration/services/elasticsearch_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ def initialize(settings)
end

def get_client
Elasticsearch::Client.new(:hosts => "localhost:9200")
@client ||= Elasticsearch::Client.new(:hosts => "localhost:9200")
end

end
11 changes: 6 additions & 5 deletions qa/integration/specs/dlq_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,21 @@ def generate_message(number)

before(:all) {
@fixture = Fixture.new(__FILE__)
es_allow_wildcard_deletes(@fixture.get_service("elasticsearch").get_client)
}

after(:all) {
@fixture.teardown
clean_es(@fixture.get_service("elasticsearch").get_client)
@fixture.teardown
}

before(:each) {
IO.write(config_yaml_file, config_yaml)
clean_es(@fixture.get_service("elasticsearch").get_client)
}


after(:each) do
es_client = @fixture.get_service("elasticsearch").get_client
es_client.indices.delete(index: 'logstash-*') unless es_client.nil?
logstash_service.teardown
end

Expand All @@ -57,7 +59,6 @@ def generate_message(number)
{
"dead_letter_queue.enable" => true,
"path.dead_letter_queue" => dlq_dir,
"log.level" => "debug"
}
}
let!(:config_yaml) { dlq_config.to_yaml }
Expand Down Expand Up @@ -95,7 +96,7 @@ def generate_message(number)

before :each do
IO.write(pipelines_yaml_file, pipelines_yaml)
logstash_service.spawn_logstash("--path.settings", settings_dir, "--log.level=debug")
logstash_service.spawn_logstash("--path.settings", settings_dir)
end

context 'with multiple pipelines' do
Expand Down
4 changes: 2 additions & 2 deletions qa/integration/specs/es_output_how_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@

before(:all) {
@fixture = Fixture.new(__FILE__)
es_allow_wildcard_deletes(@fixture.get_service("elasticsearch").get_client)
}

after(:all) {
es_client = @fixture.get_service("elasticsearch").get_client
es_client.indices.delete(index: 'logstash-*')
clean_es(@fixture.get_service("elasticsearch").get_client)
@fixture.teardown
}

Expand Down
11 changes: 11 additions & 0 deletions qa/integration/specs/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@
# specific language governing permissions and limitations
# under the License.

def es_allow_wildcard_deletes(es_client)
es_client.cluster.put_settings body: { transient: { 'action.destructive_requires_name' => false } }
end

def clean_es(es_client)
es_client.indices.delete_template(:name => "*")
es_client.indices.delete(:index => "*")
es_client.indices.refresh
end

RSpec.configure do |config|
if RbConfig::CONFIG["host_os"] != "linux"
exclude_tags = { :linux => true }
Expand All @@ -25,6 +35,7 @@

RSpec::Matchers.define :have_hits do |expected|
match do |actual|
return false if actual.nil? || actual['hits'].nil?
# For Elasticsearch versions 7+, the result is in a value field, just in total for > 6
if actual['hits']['total'].is_a?(Hash)
expected == actual['hits']['total']['value']
Expand Down

0 comments on commit a0a95c8

Please sign in to comment.