Skip to content

Commit c9f729e

Browse files
authored
Merge pull request #4 from ramondepieri/sample_child
* added new parameter "es.log.child.sample" that enable the feature t…
2 parents 4b130b7 + 135299e commit c9f729e

File tree

1 file changed

+28
-5
lines changed

1 file changed

+28
-5
lines changed

src/main/java/io/github/delirius325/jmeter/backendlistener/elasticsearch/ElasticsearchBackendClient.java

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package io.github.delirius325.jmeter.backendlistener.elasticsearch;
1+
package io.github.delirius325.jmeter.backendlistener.elasticsearch;
22

33
import java.util.*;
44
import java.util.regex.Matcher;
@@ -50,6 +50,7 @@ public class ElasticsearchBackendClient extends AbstractBackendListenerClient {
5050
private static final String ES_SSL_KEYSTORE_PATH = "es.ssl.keystore.path";
5151
private static final String ES_SSL_KEYSTORE_PW = "es.ssl.keystore.pw";
5252
private static final String ES_SSL_VERIFICATION_MODE = "es.ssl.verificationMode";
53+
private static final String ES_LOG_CHILD_SAMPLE = "es.log.child.sample";
5354
private static final long DEFAULT_TIMEOUT_MS = 200L;
5455
private static final String SERVICE_NAME = "es";
5556
private static RestClient client;
@@ -78,6 +79,7 @@ public class ElasticsearchBackendClient extends AbstractBackendListenerClient {
7879
DEFAULT_ARGS.put(ES_SSL_KEYSTORE_PATH, "");
7980
DEFAULT_ARGS.put(ES_SSL_KEYSTORE_PW, "");
8081
DEFAULT_ARGS.put(ES_SSL_VERIFICATION_MODE, "full");
82+
DEFAULT_ARGS.put(ES_LOG_CHILD_SAMPLE, "false");
8183
}
8284
private ElasticSearchMetricSender sender;
8385
private Set<String> modes;
@@ -107,7 +109,7 @@ public void setupTest(BackendListenerContext context) throws Exception {
107109
this.timeoutMs = Integer.parseInt((context.getParameter(ES_TIMEOUT_MS)));
108110
this.buildNumber = (JMeterUtils.getProperty(ElasticsearchBackendClient.BUILD_NUMBER) != null
109111
&& !JMeterUtils.getProperty(ElasticsearchBackendClient.BUILD_NUMBER).trim().equals(""))
110-
? Integer.parseInt(JMeterUtils.getProperty(ElasticsearchBackendClient.BUILD_NUMBER)) : 0;
112+
? Integer.parseInt(JMeterUtils.getProperty(ElasticsearchBackendClient.BUILD_NUMBER)) : 0;
111113

112114
setSSLConfiguration(context);
113115

@@ -228,6 +230,27 @@ private void setSSLConfiguration(BackendListenerContext context) {
228230

229231
@Override
230232
public void handleSampleResults(List<SampleResult> results, BackendListenerContext context) {
233+
234+
// Gather all the listeners
235+
List<SampleResult> allSampleResults = new ArrayList<SampleResult>();
236+
for (SampleResult sampleResult : results) {
237+
allSampleResults.add(sampleResult);
238+
239+
if(context.getBooleanParameter(ES_LOG_CHILD_SAMPLE, false)) {
240+
for (SampleResult subResult : sampleResult.getSubResults()) {
241+
allSampleResults.add(subResult);
242+
/*
243+
Check if sub samplers have their own sub samplers and add them to the list
244+
*/
245+
if (subResult.getSubResults().length > 0) {
246+
Collections.addAll(allSampleResults, subResult.getSubResults());
247+
}
248+
}
249+
}
250+
}
251+
252+
results = allSampleResults;
253+
231254
for (SampleResult sr : results) {
232255
ElasticSearchMetric metric = new ElasticSearchMetric(sr, context.getParameter(ES_TEST_MODE),
233256
context.getParameter(ES_TIMESTAMP), this.buildNumber,
@@ -267,7 +290,7 @@ public void teardownTest(BackendListenerContext context) throws Exception {
267290

268291
/**
269292
* This method checks if the test mode is valid
270-
*
293+
*
271294
* @param mode
272295
* The test mode as String
273296
*/
@@ -285,7 +308,7 @@ private void checkTestMode(String mode) {
285308

286309
/**
287310
* This method will validate the current sample to see if it is part of the filters or not.
288-
*
311+
*
289312
* @param context
290313
* The Backend Listener's context
291314
* @param sr
@@ -317,4 +340,4 @@ private boolean validateSample(BackendListenerContext context, SampleResult sr)
317340

318341
return valid;
319342
}
320-
}
343+
}

0 commit comments

Comments
 (0)