@@ -156,21 +156,21 @@ public void onFailure(Exception e) {
156156 listener .onFailure (e );
157157 }
158158
159- public void testMaybeWrapListenerForStackTraceLogs () {
159+ public void testMaybeWrapListenerForStackTraceDebugLog () {
160160 final String nodeId = "node" ;
161161 final String index = "index" ;
162162 ShardId shardId = new ShardId (index , index , 0 );
163163
164164 try (var mockLog = MockLog .capture (SearchService .class )) {
165- Configurator .setLevel ("org.elasticsearch.search. SearchService" , Level .DEBUG );
165+ Configurator .setLevel (SearchService . class , Level .DEBUG );
166166 final String exceptionMessage = "test exception message" ;
167167 mockLog .addExpectation (
168- new MockLog .PatternAndExceptionSeenEventExpectation (
169- format ("Tracking information ( [%s]%s) and exception logged before stack trace cleared " , nodeId , shardId ),
168+ new MockLog .ExceptionSeenEventExpectation (
169+ format ("\" [%s]%s: failed to execute search request \" and an exception logged " , nodeId , shardId ),
170170 SearchService .class .getCanonicalName (),
171171 Level .DEBUG ,
172- format ("\\ [%s\\ ]%s: failed to execute search request" , nodeId , shardId ),
173- Exception .class ,
172+ format ("[%s]%s: failed to execute search request" , nodeId , shardId ),
173+ IllegalArgumentException .class ,
174174 exceptionMessage
175175 )
176176 );
@@ -187,7 +187,45 @@ public void onFailure(Exception e) {
187187 mockLog .assertAllExpectationsMatched ();
188188 }
189189 };
190- Exception e = new Exception (exceptionMessage );
190+ // This is a 400-level exception, so it should only be debug logged
191+ IllegalArgumentException e = new IllegalArgumentException (exceptionMessage );
192+ listener = maybeWrapListenerForStackTrace (listener , TransportVersion .current (), nodeId , shardId , threadPool );
193+ listener .onFailure (e );
194+ }
195+ }
196+
197+ public void testMaybeWrapListenerForStackTraceWarnLog () {
198+ final String nodeId = "node" ;
199+ final String index = "index" ;
200+ ShardId shardId = new ShardId (index , index , 0 );
201+
202+ try (var mockLog = MockLog .capture (SearchService .class )) {
203+ final String exceptionMessage = "test exception message" ;
204+ mockLog .addExpectation (
205+ new MockLog .ExceptionSeenEventExpectation (
206+ format ("\" [%s]%s: failed to execute search request\" and an exception logged" , nodeId , shardId ),
207+ SearchService .class .getCanonicalName (),
208+ Level .WARN ,
209+ format ("[%s]%s: failed to execute search request" , nodeId , shardId ),
210+ IllegalStateException .class ,
211+ exceptionMessage
212+ )
213+ );
214+
215+ // Tests the listener has logged if it is wrapped
216+ ActionListener <SearchPhaseResult > listener = new ActionListener <>() {
217+ @ Override
218+ public void onResponse (SearchPhaseResult searchPhaseResult ) {
219+ // noop - we only care about failure scenarios
220+ }
221+
222+ @ Override
223+ public void onFailure (Exception e ) {
224+ mockLog .assertAllExpectationsMatched ();
225+ }
226+ };
227+ // This is a 400-level exception, so it should only be debug logged
228+ IllegalStateException e = new IllegalStateException (exceptionMessage );
191229 listener = maybeWrapListenerForStackTrace (listener , TransportVersion .current (), nodeId , shardId , threadPool );
192230 listener .onFailure (e );
193231 }
0 commit comments