|
103 | 103 | "status" => 400}
|
104 | 104 | }
|
105 | 105 |
|
106 |
| - let(:elasticsearch_8_err_response) { |
107 |
| - {"error" => |
108 |
| - {"root_cause" => |
109 |
| - [{"type" => "index_not_found_exception", |
110 |
| - "reason" => "no such index [.logstash]", |
111 |
| - "resource.type" => "index_expression", |
112 |
| - "resource.id" => ".logstash", |
113 |
| - "index_uuid" => "_na_", |
114 |
| - "index" => ".logstash"}], |
115 |
| - "type" => "index_not_found_exception", |
116 |
| - "reason" => "no such index [.logstash]", |
117 |
| - "resource.type" => "index_expression", |
118 |
| - "resource.id" => ".logstash", |
119 |
| - "index_uuid" => "_na_", |
120 |
| - "index" => ".logstash"}, |
121 |
| - "status" => 404} |
122 |
| - } |
| 106 | + let(:elasticsearch_8_err_response) { {"error" => "Incorrect HTTP method for uri", "status" => 405} } |
123 | 107 |
|
124 | 108 | before do
|
125 | 109 | extension.additionals_settings(system_settings)
|
|
466 | 450 | }]
|
467 | 451 | }.to_json
|
468 | 452 | end
|
469 |
| - let(:es_path) { ".logstash/_mget" } |
| 453 | + let(:legacy_api) { ".logstash/_mget" } |
470 | 454 | let(:request_body_string) { LogStash::Json.dump({ "docs" => [{ "_id" => pipeline_id }] }) }
|
471 | 455 |
|
472 | 456 | before do
|
473 | 457 | allow(mock_client).to receive(:get).with(system_indices_url_regex).and_return(LogStash::Json.load(elasticsearch_response))
|
474 | 458 | allow(mock_client).to receive(:get).with("/").and_return(es_version_response)
|
475 |
| - allow(mock_client).to receive(:post).with(es_path, {}, request_body_string).and_return(LogStash::Json.load(elasticsearch_7_9_response)) |
| 459 | + allow(mock_client).to receive(:post).with(legacy_api, {}, request_body_string).and_return(LogStash::Json.load(elasticsearch_7_9_response)) |
476 | 460 | allow(mock_license_client).to receive(:get).with('_xpack').and_return(valid_xpack_response)
|
477 | 461 | allow(mock_license_client).to receive(:get).with('/').and_return(cluster_info(LOGSTASH_VERSION))
|
478 | 462 |
|
|
493 | 477 | before :each do
|
494 | 478 | expect_any_instance_of(described_class).to receive(:build_client).and_return(mock_client)
|
495 | 479 | allow_any_instance_of(described_class).to receive(:logger).and_return(logger_stub)
|
496 |
| - allow(mock_client).to receive(:post).with(es_path, {}, request_body_string).and_return(LogStash::Json.load(elasticsearch_7_9_response)) |
| 480 | + allow(mock_client).to receive(:post).with(legacy_api, {}, request_body_string).and_return(LogStash::Json.load(elasticsearch_7_9_response)) |
497 | 481 | end
|
498 | 482 |
|
499 | 483 | let(:config) { "input { generator {} } filter { mutate {} } output { }" }
|
|
734 | 718 |
|
735 | 719 | describe "when exception occur" do
|
736 | 720 | let(:elasticsearch_response) { "" }
|
| 721 | + let(:bad_response_404) { LogStash::Outputs::ElasticSearch::HttpClient::Pool::BadResponseCodeError.new(404, "url", "request_body", "response_body") } |
737 | 722 |
|
738 | 723 | before do
|
739 | 724 | expect_any_instance_of(described_class).to receive(:build_client).and_return(mock_client)
|
|
747 | 732 |
|
748 | 733 | it "raises the exception upstream in [7.9]" do
|
749 | 734 | allow(mock_client).to receive(:get).with("/").and_return(es_version_7_9_response)
|
750 |
| - expect(mock_client).to receive(:post).with(es_path, {}, request_body_string).and_raise("Something bad") |
| 735 | + expect(mock_client).to receive(:post).with(legacy_api, {}, request_body_string).and_raise("Something bad") |
751 | 736 | expect { subject.pipeline_configs }.to raise_error /Something bad/
|
752 | 737 | end
|
| 738 | + |
| 739 | + it "returns empty pipeline when ES client raise BadResponseCodeError in [8]" do |
| 740 | + allow(mock_client).to receive(:get).with("/").and_return(es_version_response) |
| 741 | + expect(mock_client).to receive(:get).with(system_indices_url_regex).and_raise(bad_response_404) |
| 742 | + expect(subject.pipeline_configs).to be_empty |
| 743 | + end |
| 744 | + |
| 745 | + it "returns empty pipeline when ES client raise BadResponseCodeError in [7.9]" do |
| 746 | + allow(mock_client).to receive(:get).with("/").and_return(es_version_7_9_response) |
| 747 | + expect(mock_client).to receive(:post).with(legacy_api, {}, request_body_string).and_raise(bad_response_404) |
| 748 | + expect(subject.pipeline_configs).to be_empty |
| 749 | + end |
753 | 750 | end
|
754 | 751 | end
|
755 | 752 |
|
|
0 commit comments