diff --git a/README.md b/README.md
index 2ba3c42..282ec0f 100644
--- a/README.md
+++ b/README.md
@@ -15,7 +15,7 @@ JMeter ElasticSearch Backend Listener is a JMeter plugin enabling you to send te
* Bulk requests
* By making bulk requests, there are practically no impacts on the performance of the tests themselves.
* Filters
- * Only send the samples you want by using Filters! Simply type them as follows in the appropriate field : ``filter1;filter2;filter3`` or ``sampleLabel_must_contain_this``.
+ * 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``.
* Specific fields ```field1;field2;field3`
* Specify fields that you want to send to ElasticSearch (possible fields below)
* AllThreads
@@ -56,7 +56,7 @@ JMeter ElasticSearch Backend Listener is a JMeter plugin enabling you to send te
io.github.delirius325
jmeter.backendlistener.elasticsearch
- 2.6.10
+ 2.6.10-SNAPSHOT
```
diff --git a/pom.xml b/pom.xml
index 2251ff8..0b3f334 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,7 +5,7 @@
4.0.0
io.github.delirius325
jmeter.backendlistener.elasticsearch
- 2.6.10
+ 2.6.10-SNAPSHOT
jar
jmeter.backendlistener.elasticsearch
diff --git a/src/main/java/io/github/delirius325/jmeter/backendlistener/elasticsearch/ElasticSearchMetric.java b/src/main/java/io/github/delirius325/jmeter/backendlistener/elasticsearch/ElasticSearchMetric.java
index f959770..71b9817 100644
--- a/src/main/java/io/github/delirius325/jmeter/backendlistener/elasticsearch/ElasticSearchMetric.java
+++ b/src/main/java/io/github/delirius325/jmeter/backendlistener/elasticsearch/ElasticSearchMetric.java
@@ -20,6 +20,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import static org.apache.commons.lang.math.NumberUtils.isNumber;
+
public class ElasticSearchMetric {
private static final Logger logger = LoggerFactory.getLogger(ElasticSearchMetric.class);
private SampleResult sampleResult;
@@ -31,8 +33,9 @@ public class ElasticSearchMetric {
private boolean allReqHeaders;
private boolean allResHeaders;
- public ElasticSearchMetric(SampleResult sr, String testMode, String timeStamp, int buildNumber,
- boolean parseReqHeaders, boolean parseResHeaders, Set fields) {
+ public ElasticSearchMetric(
+ SampleResult sr, String testMode, String timeStamp, int buildNumber,
+ boolean parseReqHeaders, boolean parseResHeaders, Set fields) {
this.sampleResult = sr;
this.esTestMode = testMode.trim();
this.esTimestamp = timeStamp.trim();
@@ -155,18 +158,16 @@ private void addElapsedTime() {
*/
private void addCustomFields(BackendListenerContext context) {
Iterator pluginParameters = context.getParameterNamesIterator();
+ String parameter;
while (pluginParameters.hasNext()) {
String parameterName = pluginParameters.next();
- if (!parameterName.startsWith("es.") && !context.getParameter(parameterName).trim().equals("")) {
- String parameter = context.getParameter(parameterName).trim();
-
- try {
+ if (!parameterName.startsWith("es.") && context.containsParameter(parameterName)
+ && !"".equals(parameter = context.getParameter(parameterName).trim())) {
+ if (isNumber(parameter)) {
addFilteredJSON(parameterName, Long.parseLong(parameter));
- } catch (Exception e) {
- if (logger.isDebugEnabled())
- logger.debug("Cannot convert custom field to number");
- addFilteredJSON(parameterName, context.getParameter(parameterName).trim());
+ } else {
+ addFilteredJSON(parameterName, parameter);
}
}
}
@@ -217,7 +218,7 @@ private void parseHeadersAsJsonProps(boolean allReqHeaders, boolean allResHeader
// if not all res/req headers and header contains special X-tag
if (!allReqHeaders && !allResHeaders && header.length > 1) {
- if (header[0].startsWith("X-es-backend")) {
+ if (header[0].startsWith("X-es-backend-")) {
this.json.put(header[0].replaceAll("X-es-backend-", "").trim(), header[1].trim());
}
}
@@ -280,4 +281,5 @@ public Date getElapsedTime(boolean forBuildComparison) {
return null;
}
}
+
}
diff --git a/src/main/java/io/github/delirius325/jmeter/backendlistener/elasticsearch/ElasticSearchMetricSender.java b/src/main/java/io/github/delirius325/jmeter/backendlistener/elasticsearch/ElasticSearchMetricSender.java
index 95cd949..bbeecaa 100644
--- a/src/main/java/io/github/delirius325/jmeter/backendlistener/elasticsearch/ElasticSearchMetricSender.java
+++ b/src/main/java/io/github/delirius325/jmeter/backendlistener/elasticsearch/ElasticSearchMetricSender.java
@@ -87,13 +87,11 @@ private Request setAuthorizationHeader(Request request) {
/**
* This method creates the ElasticSearch index.
- *
- * @throws IOException
*/
- public void createIndex() throws IOException {
+ public void createIndex() {
try {
this.client.performRequest(setAuthorizationHeader(new Request("PUT", "/" + this.esIndex)));
- } catch (Exception e) {
+ } catch (IOException e) {
logger.info("Index already exists!");
}
}
@@ -104,7 +102,8 @@ public int getElasticSearchVersion() {
try {
Response response = this.client.performRequest(setAuthorizationHeader(request));
if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK && logger.isErrorEnabled()) {
- logger.error("Unable to perform request to ElasticSearch engine", this.esIndex);
+ logger.error("Unable to perform request to ElasticSearch engine for index {}. Response status: {}",
+ this.esIndex, response.getStatusLine().toString());
}else {
String responseBody = EntityUtils.toString(response.getEntity());
JSONObject elasticSearchConfig = new JSONObject(responseBody);
@@ -152,8 +151,14 @@ public void sendRequest(int elasticSearchVersionPrefix) {
Response response = this.client.performRequest(setAuthorizationHeader(request));
- if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK && logger.isErrorEnabled()) {
- logger.error("ElasticSearch Backend Listener failed to write results for index {}", this.esIndex);
+ if (logger.isErrorEnabled()) {
+ if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
+ logger.error("ElasticSearch Backend Listener failed to write results for index {}. Response status: {}",
+ this.esIndex, response.getStatusLine().toString());
+ } else {
+ logger.debug("ElasticSearch Backend Listener has successfully written to ES instance [{}] _bulk request {}",
+ client.getNodes().iterator().next().getHost().toHostString(), request.toString());
+ }
}
} catch (Exception e) {
if (logger.isErrorEnabled()) {
diff --git a/src/main/java/io/github/delirius325/jmeter/backendlistener/elasticsearch/ElasticsearchBackendClient.java b/src/main/java/io/github/delirius325/jmeter/backendlistener/elasticsearch/ElasticsearchBackendClient.java
index a545d04..923efe4 100644
--- a/src/main/java/io/github/delirius325/jmeter/backendlistener/elasticsearch/ElasticsearchBackendClient.java
+++ b/src/main/java/io/github/delirius325/jmeter/backendlistener/elasticsearch/ElasticsearchBackendClient.java
@@ -1,4 +1,4 @@
-package io.github.delirius325.jmeter.backendlistener.elasticsearch;
+ package io.github.delirius325.jmeter.backendlistener.elasticsearch;
import java.util.*;
import java.util.regex.Matcher;
@@ -11,7 +11,6 @@
import org.apache.jmeter.samplers.SampleResult;
import org.apache.jmeter.util.JMeterUtils;
import org.apache.jmeter.visualizers.backend.AbstractBackendListenerClient;
-import org.apache.jmeter.visualizers.backend.BackendListener;
import org.apache.jmeter.visualizers.backend.BackendListenerContext;
import org.elasticsearch.client.Node;
import org.elasticsearch.client.RestClient;
diff --git a/src/test/java/io/github/delirius325/jmeter/backendlistener/elasticsearch/TestElasticSearchBackendHTTPsConnection.java b/src/test/java/io/github/delirius325/jmeter/backendlistener/elasticsearch/TestElasticSearchBackendHTTPsConnection.java
index 797e844..11eadeb 100644
--- a/src/test/java/io/github/delirius325/jmeter/backendlistener/elasticsearch/TestElasticSearchBackendHTTPsConnection.java
+++ b/src/test/java/io/github/delirius325/jmeter/backendlistener/elasticsearch/TestElasticSearchBackendHTTPsConnection.java
@@ -52,7 +52,7 @@ public void onFailure(Node node) {
}
@Test
- public void createIndex() throws Exception {
+ public void createIndex() {
sender.createIndex();
}
}