Skip to content

Commit 43228ff

Browse files
Fixed some stuff
1 parent 60e38ea commit 43228ff

File tree

4 files changed

+31
-73
lines changed

4 files changed

+31
-73
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<modelVersion>4.0.0</modelVersion>
66
<groupId>main.java.io.github.delirius325</groupId>
77
<artifactId>jmeter.backendlistener.elasticsearch</artifactId>
8-
<version>2.6.4-SNAPSHOT</version>
8+
<version>2.6.5</version>
99
<packaging>jar</packaging>
1010

1111
<name>jmeter.backendlistener.elasticsearch</name>

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,13 @@
2222

2323
public class ElasticSearchMetric {
2424
private static final Logger logger = LoggerFactory.getLogger(ElasticSearchMetric.class);
25-
2625
private SampleResult sampleResult;
27-
2826
private String esTestMode;
29-
3027
private String esTimestamp;
31-
3228
private int ciBuildNumber;
33-
3429
private HashMap<String, Object> json;
35-
3630
private Set<String> fields;
37-
3831
private boolean allReqHeaders;
39-
4032
private boolean allResHeaders;
4133

4234
public ElasticSearchMetric(SampleResult sr, String testMode, String timeStamp, int buildNumber,

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

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,20 @@
1919

2020
public class ElasticSearchMetricSender {
2121
private static final Logger logger = LoggerFactory.getLogger(ElasticSearchMetricSender.class);
22-
2322
private RestClient client;
24-
2523
private String esIndex;
26-
2724
private List<String> metricList;
28-
2925
private String authUser;
30-
3126
private String authPwd;
32-
33-
private String awsendpoint;
27+
private String awsEndpoint;
3428

3529
public ElasticSearchMetricSender(RestClient cli, String index, String user, String pwd, String endpoint) {
3630
this.client = cli;
3731
this.esIndex = index;
3832
this.metricList = new LinkedList<String>();
3933
this.authUser = user.trim();
4034
this.authPwd = pwd.trim();
41-
this.awsendpoint = endpoint;
35+
this.awsEndpoint = endpoint;
4236
}
4337

4438
/**
@@ -77,8 +71,8 @@ public void addToList(String metric) {
7771
/**
7872
* This method sets the Basic Authorization header to requests
7973
*/
80-
private Request setAuthoizationHeader(Request request) {
81-
if (this.awsendpoint.equals("") && !this.authPwd.equals("")) {
74+
private Request setAuthorizationHeader(Request request) {
75+
if (this.awsEndpoint.equals("") && !this.authPwd.equals("")) {
8276
String encodedCredentials = Base64.getEncoder()
8377
.encodeToString((this.authUser + ":" + this.authPwd).getBytes());
8478
RequestOptions.Builder options = request.getOptions().toBuilder();
@@ -97,7 +91,7 @@ private Request setAuthoizationHeader(Request request) {
9791
public void createIndex() throws IOException {
9892
Response response = null;
9993
try {
100-
response = this.client.performRequest(setAuthoizationHeader(new Request("PUT", "/" + this.esIndex)));
94+
response = this.client.performRequest(setAuthorizationHeader(new Request("PUT", "/" + this.esIndex)));
10195
if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK && logger.isErrorEnabled()) {
10296
logger.error("ElasticSearch Backend Listener failed to create index {}", this.esIndex);
10397
}
@@ -128,16 +122,15 @@ public void sendRequest() {
128122

129123
try {
130124

131-
Response response = this.client.performRequest(setAuthoizationHeader(request));
125+
Response response = this.client.performRequest(setAuthorizationHeader(request));
132126

133127
if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK && logger.isErrorEnabled()) {
134128
logger.error("ElasticSearch Backend Listener failed to write results for index {}", this.esIndex);
135129
}
136130
} catch (Exception e) {
137131
if (logger.isErrorEnabled()) {
138132
logger.error("Exception" + e);
139-
logger.error(
140-
"ElasticSearch Backend Listener was unable to perform request to the ElasticSearch engine. Request reached timeout.");
133+
logger.error("ElasticSearch Backend Listener was unable to perform request to the ElasticSearch engine. Check your JMeter console for more info.");
141134
}
142135
}
143136
}

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

Lines changed: 23 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package io.github.delirius325.jmeter.backendlistener.elasticsearch;
22

3-
import java.util.Arrays;
4-
import java.util.HashSet;
5-
import java.util.List;
6-
import java.util.Set;
3+
import java.util.*;
74
import java.util.regex.Matcher;
85
import java.util.regex.Pattern;
96

@@ -29,55 +26,30 @@
2926

3027
public class ElasticsearchBackendClient extends AbstractBackendListenerClient {
3128
private static final String BUILD_NUMBER = "BuildNumber";
32-
3329
private static final String ES_SCHEME = "es.scheme";
34-
3530
private static final String ES_HOST = "es.host";
36-
3731
private static final String ES_PORT = "es.port";
38-
3932
private static final String ES_INDEX = "es.index";
40-
4133
private static final String ES_FIELDS = "es.fields";
42-
4334
private static final String ES_TIMESTAMP = "es.timestamp";
44-
4535
private static final String ES_BULK_SIZE = "es.bulk.size";
46-
4736
private static final String ES_TIMEOUT_MS = "es.timout.ms";
48-
4937
private static final String ES_SAMPLE_FILTER = "es.sample.filter";
50-
5138
private static final String ES_TEST_MODE = "es.test.mode";
52-
5339
private static final String ES_AUTH_USER = "es.xpack.user";
54-
5540
private static final String ES_AUTH_PWD = "es.xpack.password";
56-
5741
private static final String ES_PARSE_REQ_HEADERS = "es.parse.all.req.headers";
58-
5942
private static final String ES_PARSE_RES_HEADERS = "es.parse.all.res.headers";
60-
6143
private static final String ES_AWS_ENDPOINT = "es.aws.endpoint";
62-
6344
private static final String ES_AWS_REGION = "es.aws.region";
64-
65-
private static final String SSL_TRUSTSTORE_PATH = "es.ssl.truststore.path";
66-
67-
private static final String SSL_TRUSTSTORE_PW = "es.ssl.truststore.pw";
68-
69-
private static final String SSL_KEYSTORE_PATH = "es.ssl.keystore.path";
70-
71-
private static final String SSL_KEYSTORE_PW = "es.ssl.keystore.pw";
72-
45+
private static final String ES_SSL_TRUSTSTORE_PATH = "es.ssl.truststore.path";
46+
private static final String ES_SSL_TRUSTSTORE_PW = "es.ssl.truststore.pw";
47+
private static final String ES_SSL_KEYSTORE_PATH = "es.ssl.keystore.path";
48+
private static final String ES_SSL_KEYSTORE_PW = "es.ssl.keystore.pw";
7349
private static final long DEFAULT_TIMEOUT_MS = 200L;
74-
7550
private static final String SERVICE_NAME = "es";
76-
7751
private static RestClient client;
78-
7952
private static final Logger logger = LoggerFactory.getLogger(ElasticsearchBackendClient.class);
80-
8153
private static final AWSCredentialsProvider credentialsProvider = new DefaultAWSCredentialsProviderChain();
8254
private static final Map<String, String> DEFAULT_ARGS = new LinkedHashMap<>();
8355
static {
@@ -96,20 +68,17 @@ public class ElasticsearchBackendClient extends AbstractBackendListenerClient {
9668
DEFAULT_ARGS.put(ES_PARSE_RES_HEADERS, "false");
9769
DEFAULT_ARGS.put(ES_AWS_ENDPOINT, "");
9870
DEFAULT_ARGS.put(ES_AWS_REGION, "");
71+
DEFAULT_ARGS.put(ES_SSL_TRUSTSTORE_PATH, "");
72+
DEFAULT_ARGS.put(ES_SSL_TRUSTSTORE_PW, "");
73+
DEFAULT_ARGS.put(ES_SSL_KEYSTORE_PATH, "");
74+
DEFAULT_ARGS.put(ES_SSL_KEYSTORE_PW, "");
9975
}
100-
10176
private ElasticSearchMetricSender sender;
102-
10377
private Set<String> modes;
104-
10578
private Set<String> filters;
106-
10779
private Set<String> fields;
108-
10980
private int buildNumber;
110-
11181
private int bulkSize;
112-
11382
private long timeoutMs;
11483

11584
public ElasticsearchBackendClient() {
@@ -175,34 +144,38 @@ public void onFailure(Node node) {
175144
}
176145

177146
/**
178-
* This method converts a semicolon sepearted list contained in a parameter into s string set
179-
*
147+
* Method that converts a semicolon separated list contained in a parameter into a string set
148+
* @param context
149+
* @param parameter
150+
* @param set
180151
*/
181152
private void convertParameterToSet(BackendListenerContext context, String parameter, Set<String> set) {
182153
String[] array = (context.getParameter(parameter).contains(";")) ? context.getParameter(parameter).split(";")
183154
: new String[] { context.getParameter(parameter) };
184155
if (array.length > 0 && !array[0].trim().equals("")) {
185156
for (String entry : array) {
186157
set.add(entry.toLowerCase().trim());
187-
logger.info("Parsed from " + parameter + ": " + entry.toLowerCase().trim());
158+
if(logger.isDebugEnabled())
159+
logger.debug("Parsed from " + parameter + ": " + entry.toLowerCase().trim());
188160
}
189161
}
190162
}
191163

192164
/**
193-
* This methods sets the system properties for SSL to the provided parameters
165+
* Method that sets the SSL configuration to be able to send requests to a secured endpoint
166+
* @param context
194167
*/
195168
private void setSSLConfiguration(BackendListenerContext context) {
196-
System.setProperty("javax.net.ssl.keyStore", context.getParameter(SSL_KEYSTORE_PATH));
197-
System.setProperty("javax.net.ssl.keyStorePassword", context.getParameter(SSL_KEYSTORE_PW));
169+
System.setProperty("javax.net.ssl.keyStore", context.getParameter(ES_SSL_KEYSTORE_PATH));
170+
System.setProperty("javax.net.ssl.keyStorePassword", context.getParameter(ES_SSL_KEYSTORE_PW));
198171
System.setProperty("javax.net.ssl.keyStoreType",
199-
FilenameUtils.getExtension(context.getParameter(SSL_KEYSTORE_PATH)).equals("jks") ? "jks" : "pkcs12");
172+
FilenameUtils.getExtension(context.getParameter(ES_SSL_KEYSTORE_PATH)).equals("jks") ? "jks" : "pkcs12");
200173
//jks (.jks) or pkcs12 (.p12)
201174

202-
System.setProperty("javax.net.ssl.trustStore", context.getParameter(SSL_TRUSTSTORE_PATH));
203-
System.setProperty("javax.net.ssl.trustStorePassword", context.getParameter(SSL_TRUSTSTORE_PW));
175+
System.setProperty("javax.net.ssl.trustStore", context.getParameter(ES_SSL_TRUSTSTORE_PATH));
176+
System.setProperty("javax.net.ssl.trustStorePassword", context.getParameter(ES_SSL_TRUSTSTORE_PW));
204177
System.setProperty("javax.net.ssl.trustStoreType",
205-
FilenameUtils.getExtension(context.getParameter(SSL_TRUSTSTORE_PATH)).equals("jks") ? "jks"
178+
FilenameUtils.getExtension(context.getParameter(ES_SSL_TRUSTSTORE_PATH)).equals("jks") ? "jks"
206179
: "pkcs12");
207180

208181
}

0 commit comments

Comments
 (0)