|
1121 | 1121 | end if LOGSTASH_VERSION > '6.0'
|
1122 | 1122 |
|
1123 | 1123 | context 'handling elasticsearch document-level status meant for the DLQ' do
|
| 1124 | + let(:es_api_action) { "CUSTOM_ACTION" } |
| 1125 | + let(:es_api_params) { Hash['_index' => 'MY_INDEX'] } |
| 1126 | + |
1124 | 1127 | let(:options) { { "manage_template" => false, "data_stream" => 'false' } }
|
1125 |
| - let(:action) { LogStash::Outputs::ElasticSearch::EventActionTuple.new(:action, :params, LogStash::Event.new("foo" => "bar")) } |
| 1128 | + let(:action) { LogStash::Outputs::ElasticSearch::EventActionTuple.new(es_api_action, es_api_params, LogStash::Event.new("foo" => "bar")) } |
| 1129 | + |
| 1130 | + let(:logger) { double('logger').as_null_object } |
| 1131 | + before(:each) { subject.instance_variable_set(:@logger, logger) } |
1126 | 1132 |
|
1127 | 1133 | context 'when @dlq_writer is nil' do
|
1128 | 1134 | before { subject.instance_variable_set '@dlq_writer', nil }
|
1129 |
| - let(:action) { LogStash::Outputs::ElasticSearch::EventActionTuple.new(:action, :params, LogStash::Event.new("foo" => "bar")) } |
1130 | 1135 |
|
1131 | 1136 | context 'resorting to previous behaviour of logging the error' do
|
1132 | 1137 | context 'getting an invalid_index_name_exception' do
|
1133 | 1138 | it 'should log at ERROR level' do
|
1134 |
| - subject.instance_variable_set(:@logger, double("logger").as_null_object) |
| 1139 | + # logger = double("logger").as_null_object |
| 1140 | + # subject.instance_variable_set(:@logger, logger) |
| 1141 | + |
1135 | 1142 | mock_response = { 'index' => { 'error' => { 'type' => 'invalid_index_name_exception' } } }
|
1136 | 1143 | subject.handle_dlq_response("Could not index event to Elasticsearch.", action, :some_status, mock_response)
|
| 1144 | + |
| 1145 | + expect(logger).to have_received(:error).with(a_string_including("Could not index event to Elasticsearch"), |
| 1146 | + a_hash_including(:status => :some_status, |
| 1147 | + :action => [es_api_action, es_api_params, action.event.to_hash], |
| 1148 | + :response => mock_response)) |
1137 | 1149 | end
|
1138 | 1150 | end
|
1139 | 1151 |
|
1140 | 1152 | context 'when getting any other exception' do
|
1141 | 1153 | it 'should log at WARN level' do
|
1142 |
| - logger = double("logger").as_null_object |
1143 |
| - subject.instance_variable_set(:@logger, logger) |
1144 |
| - expect(logger).to receive(:warn).with(a_string_including "Could not index event to Elasticsearch. status: some_status, action: [:action, :params, {") |
| 1154 | + # logger = double("logger").as_null_object |
| 1155 | + # subject.instance_variable_set(:@logger, logger) |
| 1156 | + |
1145 | 1157 | mock_response = { 'index' => { 'error' => { 'type' => 'illegal_argument_exception' } } }
|
1146 | 1158 | subject.handle_dlq_response("Could not index event to Elasticsearch.", action, :some_status, mock_response)
|
| 1159 | + |
| 1160 | + expect(logger).to have_received(:warn).with(a_string_including("Could not index event to Elasticsearch"), |
| 1161 | + a_hash_including(:status => :some_status, |
| 1162 | + :action => [es_api_action, es_api_params, action.event.to_hash], |
| 1163 | + :response => mock_response)) |
1147 | 1164 | end
|
1148 | 1165 | end
|
1149 | 1166 |
|
1150 | 1167 | context 'when the response does not include [error]' do
|
1151 | 1168 | it 'should not fail, but just log a warning' do
|
1152 |
| - logger = double("logger").as_null_object |
1153 |
| - subject.instance_variable_set(:@logger, logger) |
1154 |
| - expect(logger).to receive(:warn).with(a_string_including "Could not index event to Elasticsearch. status: some_status, action: [:action, :params, {") |
| 1169 | + # logger = double("logger").as_null_object |
| 1170 | + # subject.instance_variable_set(:@logger, logger) |
| 1171 | + |
1155 | 1172 | mock_response = { 'index' => {} }
|
1156 | 1173 | expect do
|
1157 | 1174 | subject.handle_dlq_response("Could not index event to Elasticsearch.", action, :some_status, mock_response)
|
1158 | 1175 | end.to_not raise_error
|
| 1176 | + |
| 1177 | + expect(logger).to have_received(:warn).with(a_string_including("Could not index event to Elasticsearch"), |
| 1178 | + a_hash_including(:status => :some_status, |
| 1179 | + :action => [es_api_action, es_api_params, action.event.to_hash], |
| 1180 | + :response => mock_response)) |
1159 | 1181 | end
|
1160 | 1182 | end
|
1161 | 1183 | end
|
|
1175 | 1197 | mock_response = { 'index' => { 'error' => { 'type' => 'illegal_argument_exception' } } }
|
1176 | 1198 | action = LogStash::Outputs::ElasticSearch::EventActionTuple.new(:action, :params, event)
|
1177 | 1199 | subject.handle_dlq_response("Could not index event to Elasticsearch.", action, 404, mock_response)
|
| 1200 | + |
| 1201 | + expect(logger).to_not have_received(:warn).with(a_string_including("Could not index event to Elasticsearch")) |
1178 | 1202 | end
|
1179 | 1203 | end
|
1180 | 1204 |
|
|
0 commit comments