anthonygauthier/jmeter-elasticsearch-backend-listener

Problem with ElasticSearch host URL

sg86-sourav opened this issue · 4 comments

Hi @delirius325 ,

I am facing a problem with respect to the ElasticSearch host URL. In a normal scenario, the URL for accessing the ElasticSearch is https://<ElasticSearch_Host_URL>, but the URL given to us for using is in this format - https://<ElasticSearch_Host_URL>/elasticsearch-loadtest/

So, my question is how can I fit this URL, (mainly the extra part /elasticsearch-loadtest/) in the backend listener form. Also, to use the URL https://<ElasticSearch_Host_URL>/elasticsearch-loadtest/ an user name and password is required. So in which field I have to add the user credential ?

Thanks,
Sourav

Hi @sg86-sourav ,

Technically, adding the extra /elasticsearch-loadtestin the es.host field should work. As far as username/password, it usually means XPack is installed on the instance. You would then need to add your username/password in the es.xpack.user and es.xpack.password.

Hopes this helps!

Hi @delirius325,

Regarding host, we have tried the option you have mentioned, but getting an error as mentioned below -

es.scheme = https
es.host = <ElasticSearch_Host_URL>/elasticsearch-loadtest/
es.port = 443
es.xpack.user = <user_name>
es.xpack.password = <user_passwd>

Error Message :
Error with node: [host=https://<host_url>/elasticsearch-loadtest/:443]

Thanks,
Sourav

Remove the extra / at the end of the es.host input @sg86-sourav

Hi @delirius325,

I have tried by removing extra '/', but getting the same error.

ElasticsearchBackendClient: Error with node: [host=https://commerce-dp.ah.nl/elasticsearch-loadtest:443]

However, I have tried with another approach, as mentioned below, and using that I am able to create index in ElasticSearch from Jmeter, but it is not able to post the data -

es.scheme = https
es.host = <ElasticSearch_Host_URL>
es.port = 443
es.index = elasticsearch-loadtest/<index_name>
es.xpack.user = <user_name>
es.xpack.password = <user_passwd>

After further analysis, I found that the following code snippet is failing due to which it is not able to detect the version of the ElasticSearch. Throwing the error message - ERROR i.g.d.j.b.e.ElasticSearchMetricSender: Exceptionorg.json.JSONException: A JSONObject text must begin with '{' at 1 [character 2 line 1]

public int getElasticSearchVersion() {
Request request = new Request("GET", "/" );
int elasticSearchVersion = -1;
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 for index {}. Response status: {}",
this.esIndex, response.getStatusLine().toString());
}else {
String responseBody = EntityUtils.toString(response.getEntity());
JSONObject elasticSearchConfig = new JSONObject(responseBody);
JSONObject version = (JSONObject) elasticSearchConfig.get("version");
String elasticVersion = version.get("number").toString();
elasticSearchVersion = Integer.parseInt(elasticVersion.split("\.")[0]);
logger.info("ElasticSearch Version : " + Integer.toString(elasticSearchVersion));
}
} catch (Exception e) {
if (logger.isErrorEnabled()) {
logger.error("Exception" + e);
logger.error("ElasticSearch Backend Listener was unable to perform request to the ElasticSearch engine. Check your JMeter console for more info.");
}
}
return elasticSearchVersion;
}

As it is not able to detect version, it is taking the default version i.e. -1 and due to this it is calling the following code snippet, which is for less than 7 version, but I am using 7.8.0 version.

_if(elasticSearchVersionPrefix < 7) {
request = new Request("POST", "/" + this.esIndex + "/SampleResult/bulk");
actionMetaData = String.format(SEND_BULK_REQUEST, this.esIndex, "SampleResult");
}

It supposed to call the following code snippet for posting the data as the version is more than 7-

_else {
request = new Request("POST", "/" + this.esIndex + "/bulk");
actionMetaData = String.format(SEND_BULK_REQUEST, this.esIndex);
}

Please look into it and let me know how I can resolve it.