Skip to content

Commit dfef9ee

Browse files
committed
ref(logging): enhance logging for dynamic ES sample filters and improve parameter conversion
Signed-off-by: Johnny Hujol <itudoben@users.noreply.github.com>
1 parent 110a11f commit dfef9ee

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ JMeter ElasticSearch Backend Listener is a JMeter plugin enabling you to send te
1616
* Filters
1717
* Only send the samples you want by using Filters! Simply type them as follows in the field ``es.sample.filter`` : ``filter1;filter2;filter3`` or ``sampleLabel_must_contain_this``.
1818
* You can also choose to exclude certain samplers; `!!exclude_this;filter1;filter2`
19+
* SYS_DYNAMIC_ES_PER_SAMPLE_FILTER is a System property that can be set before the ElasticsearchBackendClient#handleSampleResults(...) is called. It will override the es.sample.filter value set in the backendlistener configuration.
1920
* Specific fields ```field1;field2;field3`
2021
* Specify fields that you want to send to ElasticSearch (possible fields below)
2122
* AllThreads

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

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,18 @@ public void onFailure(Node node) {
173173
}
174174
}
175175

176+
/**
177+
* Method that converts a semicolon separated list contained in a System property {@link System#getProperty(String)} into a string set
178+
*
179+
* @param propertyName
180+
* @param set
181+
*/
182+
private void convertSystemPropertyToSet(String propertyName, Set<String> set) {
183+
String value = System.getProperty(propertyName);
184+
185+
convertValueToSet(propertyName, set, value);
186+
}
187+
176188
/**
177189
* Method that converts a semicolon separated list contained in a parameter into a string set
178190
*
@@ -181,8 +193,14 @@ public void onFailure(Node node) {
181193
* @param set
182194
*/
183195
private void convertParameterToSet(BackendListenerContext context, String parameter, Set<String> set) {
184-
String[] array = (context.getParameter(parameter).contains(";")) ? context.getParameter(parameter).split(";")
185-
: new String[]{context.getParameter(parameter)};
196+
String value = context.getParameter(parameter);
197+
198+
convertValueToSet(parameter, set, value);
199+
}
200+
201+
private static void convertValueToSet(String parameter, Set<String> set, String value) {
202+
String[] array = (value.contains(";")) ? value.split(";")
203+
: new String[]{value};
186204
if (array.length > 0 && !array[0].trim().equals("")) {
187205
for (String entry : array) {
188206
set.add(entry.toLowerCase().trim());
@@ -243,6 +261,15 @@ public void handleSampleResults(List<SampleResult> results, BackendListenerConte
243261
return;
244262
}
245263

264+
if (System.getProperty("SYS_DYNAMIC_ES_PER_SAMPLE_FILTER") != null) {
265+
// Override filters from ES_SAMPLE_FILTER if exists
266+
this.filters.clear();
267+
logger.info("============> Property SYS_DYNAMIC_ES_PER_SAMPLE_FILTER filters: {}", System.getProperty("SYS_DYNAMIC_ES_PER_SAMPLE_FILTER"));
268+
convertSystemPropertyToSet("SYS_DYNAMIC_ES_PER_SAMPLE_FILTER", this.filters);
269+
logger.info("============> Property SYS_DYNAMIC_ES_PER_SAMPLE_FILTER filters: {}", this.filters);
270+
}
271+
272+
final String filtersAsString = (this.filters.isEmpty()) ? "no filters" : String.join(", ", this.filters);
246273
for (SampleResult sr : results) {
247274
String respString = sr.getResponseDataAsString();
248275
int endIndex = Math.min(100, respString.length());
@@ -262,6 +289,10 @@ public void handleSampleResults(List<SampleResult> results, BackendListenerConte
262289
"The ElasticSearch Backend Listener was unable to add sampler to the list of samplers to send... More info in JMeter's console.");
263290
e.printStackTrace();
264291
}
292+
logger.info("Sampler result processed {} with filters {}", sr.getSampleLabel(), filtersAsString);
293+
}
294+
else {
295+
logger.info("Sampler result skipped {} with filters {}", sr.getSampleLabel(), filtersAsString);
265296
}
266297
}
267298

0 commit comments

Comments
 (0)