Skip to content

Commit

Permalink
Merge pull request #78 from bratwurzt/multiple_bugs
Browse files Browse the repository at this point in the history
Multiple bugs
  • Loading branch information
anthonygauthier committed Mar 3, 2020
2 parents 4a265bd + cf76b7d commit 0aa6b59
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 24 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -56,7 +56,7 @@ JMeter ElasticSearch Backend Listener is a JMeter plugin enabling you to send te
<dependency>
<groupId>io.github.delirius325</groupId>
<artifactId>jmeter.backendlistener.elasticsearch</artifactId>
<version>2.6.10</version>
<version>2.6.10-SNAPSHOT</version>
</dependency>
```

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>io.github.delirius325</groupId>
<artifactId>jmeter.backendlistener.elasticsearch</artifactId>
<version>2.6.10</version>
<version>2.6.10-SNAPSHOT</version>
<packaging>jar</packaging>

<name>jmeter.backendlistener.elasticsearch</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<String> fields) {
public ElasticSearchMetric(
SampleResult sr, String testMode, String timeStamp, int buildNumber,
boolean parseReqHeaders, boolean parseResHeaders, Set<String> fields) {
this.sampleResult = sr;
this.esTestMode = testMode.trim();
this.esTimestamp = timeStamp.trim();
Expand Down Expand Up @@ -155,18 +158,16 @@ private void addElapsedTime() {
*/
private void addCustomFields(BackendListenerContext context) {
Iterator<String> 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);
}
}
}
Expand Down Expand Up @@ -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());
}
}
Expand Down Expand Up @@ -280,4 +281,5 @@ public Date getElapsedTime(boolean forBuildComparison) {
return null;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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!");
}
}
Expand All @@ -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);
Expand Down Expand Up @@ -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()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void onFailure(Node node) {
}

@Test
public void createIndex() throws Exception {
public void createIndex() {
sender.createIndex();
}
}

0 comments on commit 0aa6b59

Please sign in to comment.