@@ -32,7 +32,7 @@ public class ElasticsearchBackendClient extends AbstractBackendListenerClient {
3232
3333 private ElasticSearchMetricSender sender ;
3434 private Set <String > modes ;
35- private List <String > filters ;
35+ private Set <String > filters ;
3636 private RestClient client ;
3737 private int buildNumber ;
3838 private int bulkSize ;
@@ -58,7 +58,7 @@ public Arguments getDefaultParameters() {
5858 @ Override
5959 public void setupTest (BackendListenerContext context ) throws Exception {
6060 try {
61- this .filters = new LinkedList < String >();
61+ this .filters = new HashSet < >();
6262 this .modes = new HashSet <>(Arrays .asList ("info" ,"debug" ,"error" ,"quiet" ));
6363 this .bulkSize = Integer .parseInt (context .getParameter (ES_BULK_SIZE ));
6464 this .timeoutMs = JMeterUtils .getPropDefault (ES_TIMEOUT_MS , DEFAULT_TIMEOUT_MS );
@@ -83,7 +83,7 @@ public void onFailure(Node node) {
8383 String [] filterArray = (context .getParameter (ES_SAMPLE_FILTER ).contains (";" )) ? context .getParameter (ES_SAMPLE_FILTER ).split (";" ) : new String [] {context .getParameter (ES_SAMPLE_FILTER )};
8484 if (filterArray .length >= 1 && filterArray [0 ].trim () != "" ) {
8585 for (String filter : filterArray ) {
86- this .filters .add (filter );
86+ this .filters .add (filter . toLowerCase (). trim () );
8787 }
8888 }
8989
@@ -97,21 +97,8 @@ public void onFailure(Node node) {
9797 public void handleSampleResults (List <SampleResult > results , BackendListenerContext context ) {
9898 for (SampleResult sr : results ) {
9999 ElasticSearchMetric metric = new ElasticSearchMetric (sr , context .getParameter (ES_TEST_MODE ), context .getParameter (ES_TIMESTAMP ), this .buildNumber );
100- boolean validSample = false ;
101- String sampleLabel = sr .getSampleLabel ().toLowerCase ().trim ();
102-
103- if (this .filters .size () == 0 ) {
104- validSample = (context .getParameter (ES_TEST_MODE ).trim ().equals ("error" ) && sr .isSuccessful ()) ? false : true ;
105- } else {
106- for (String filter : this .filters ) {
107- if (filter .toLowerCase ().trim ().equals (sampleLabel ) || sampleLabel .contains (filter .toLowerCase ().trim ())) {
108- validSample = (context .getParameter (ES_TEST_MODE ).trim ().equals ("error" ) && sr .isSuccessful ()) ? false : true ;
109- break ;
110- }
111- }
112- }
113100
114- if (validSample ) {
101+ if (validateSample ( context , sr ) ) {
115102 try {
116103 this .sender .addToList (new Gson ().toJson (metric .getMetric (context )));
117104 } catch (Exception e ) {
@@ -151,7 +138,25 @@ private void checkTestMode(String mode) {
151138 logger .warn ("The parameter \" es.test.mode\" isn't set properly. Three modes are allowed: debug ,info, and quiet." );
152139 logger .warn (" -- \" debug\" : sends request and response details to ElasticSearch. Info only sends the details if the response has an error." );
153140 logger .warn (" -- \" info\" : should be used in production" );
141+ logger .warn (" -- \" error\" : should be used if you." );
154142 logger .warn (" -- \" quiet\" : should be used if you don't care to have the details." );
155143 }
156144 }
145+
146+ /**
147+ * This method will validate the current sample to see if it is part of the filters or not.
148+ * @param context The Backend Listener's context
149+ * @param sr The current SampleResult
150+ * @return true or false depending on whether or not the sample is valid
151+ */
152+ private boolean validateSample (BackendListenerContext context , SampleResult sr ) {
153+ boolean validSample = false ;
154+ String sampleLabel = sr .getSampleLabel ().toLowerCase ().trim ();
155+
156+ if (this .filters .size () == 0 || this .filters .contains (sampleLabel )) {
157+ validSample = (context .getParameter (ES_TEST_MODE ).trim ().equals ("error" ) && sr .isSuccessful ()) ? false : true ;
158+ }
159+
160+ return validSample ;
161+ }
157162}
0 commit comments