@@ -228,32 +228,43 @@ private void setSSLConfiguration(BackendListenerContext context) {
228228
229229 @ Override
230230 public void handleSampleResults (List <SampleResult > results , BackendListenerContext context ) {
231- for (SampleResult sr : results ) {
232- ElasticSearchMetric metric = new ElasticSearchMetric (sr , context .getParameter (ES_TEST_MODE ),
233- context .getParameter (ES_TIMESTAMP ), this .buildNumber ,
234- context .getBooleanParameter (ES_PARSE_REQ_HEADERS , false ),
235- context .getBooleanParameter (ES_PARSE_RES_HEADERS , false ), fields );
231+ if (results .isEmpty ()) {
232+ logger .warn ("There are no sampler results to handle!" );
233+ return ;
234+ }
236235
237- if (validateSample (context , sr )) {
238- try {
239- this .sender .addToList (new Gson ().toJson (metric .getMetric (context )));
240- } catch (Exception e ) {
241- logger .error (
242- "The ElasticSearch Backend Listener was unable to add sampler to the list of samplers to send... More info in JMeter's console." );
243- e .printStackTrace ();
244- }
245- }
236+ for (SampleResult sr : results ) {
237+ logger .info (String .format ("Handle sampler result %s: %s" , sr .getSampleLabel (), sr .getResponseDataAsString ()));
238+ ElasticSearchMetric metric = new ElasticSearchMetric (sr , context .getParameter (ES_TEST_MODE ),
239+ context .getParameter (ES_TIMESTAMP ), this .buildNumber ,
240+ context .getBooleanParameter (ES_PARSE_REQ_HEADERS , false ),
241+ context .getBooleanParameter (ES_PARSE_RES_HEADERS , false ), fields );
242+
243+ if (validateSample (context , sr )) {
244+ try {
245+ this .sender .addToList (new Gson ().toJson (metric .getMetric (context )));
246+ }
247+ catch (Exception e ) {
248+ logger .error (
249+ "The ElasticSearch Backend Listener was unable to add sampler to the list of samplers to send... More info in JMeter's console." );
250+ e .printStackTrace ();
251+ }
252+ } else {
253+ logger .warn (String .format ("Not valid sampler result %s: %s" , sr .getSampleLabel (), sr .getResponseDataAsString ()));
246254 }
255+ }
247256
248- if (this .sender .getListSize () >= this .bulkSize ) {
249- try {
250- this .sender .sendRequest (this .esVersion );
251- } catch (Exception e ) {
252- logger .error ("Error occured while sending bulk request." , e );
253- } finally {
254- this .sender .clearList ();
255- }
257+ if (this .sender .getListSize () >= this .bulkSize ) {
258+ try {
259+ this .sender .sendRequest (this .esVersion );
260+ }
261+ catch (Exception e ) {
262+ logger .error ("Error occurred while sending bulk request." , e );
263+ }
264+ finally {
265+ this .sender .clearList ();
256266 }
267+ }
257268 }
258269
259270 @ Override
@@ -305,6 +316,8 @@ private boolean validateSample(BackendListenerContext context, SampleResult sr)
305316 valid = true ;
306317 break ;
307318 } else {
319+ logger .warn (String .format ("Invalidate sample label %s, it may start with '!!' or it may not contain filter %s. " +
320+ "Check the %s property value in the JMX file. Leave it empty to increase validation" , sampleLabel , filter , ES_SAMPLE_FILTER ));
308321 valid = false ;
309322 }
310323 }
0 commit comments