Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sniffing function not working properly #629

Closed
ProFire opened this issue Aug 23, 2017 · 4 comments
Closed

Sniffing function not working properly #629

ProFire opened this issue Aug 23, 2017 · 4 comments

Comments

@ProFire
Copy link

ProFire commented Aug 23, 2017

Summary of problem

The sniff function isn't picking the other nodes in the cluster when the connectionpool is set to \Elasticsearch\ConnectionPool\SniffingConnectionPool

The server is returning the host as 172.25.120.23:9200 format whenever a sniff function is done on Elasticsearch\Connections\Connection::sniff()

When Elasticsearch\ConnectionPool\SniffingConnectionPool::parseClusterState() is executed, the host and port is not properly captured due to wrong $pattern.

Code snippet of problem

The wrong pattern on line 131 of Elasticsearch\ConnectionPool\SniffingConnectionPool

$pattern       = '/\/([^:]*):([0-9]+)\]/';

Results in preg_match not matching the hosts 172.25.120.23:9200 on line 137 of Elasticsearch\ConnectionPool\SniffingConnectionPool

if (preg_match($pattern, $node[$schemaAddress], $match) === 1) {

Regex Example: http://regexr.com/3gjoo

Proposed Change

I propose a change of regex on line 131 of Elasticsearch\ConnectionPool\SniffingConnectionPool

$pattern       = '/([^:]*):([0-9]+)/';

Regex Example: http://regexr.com/3gjor

Environment

ElasticSearch: 2.0.2
PHP: 7.1

@polyfractal
Copy link
Contributor

What version of Elasticsearch-PHP are you using?

It does look like the format has changed slightly. Would you mind posting the output of your Node Info API (feel free to sanitize addresses/sensitive details)? I'd like to see if the output is different from 5.x, and how far changes need to be backported.

@ProFire
Copy link
Author

ProFire commented Aug 24, 2017

Here's the sample of the sanitized output

{
"cluster_name": "es2_digital",
"nodes": {
"bIeDcsdfv7JRo": {
"name": "g123",
"transport_address": "172.25.120.23:9300",
"host": "172.25.120.23",
"ip": "172.25.120.23",
"version": "2.0.2",
"build": "6abf5d8",
"http_address": "172.25.120.23:9200",
"attributes": {
"master": "false"
}
},
}
}

I'm using the 5.3 version of elasticsearch-php

@ProFire
Copy link
Author

ProFire commented Aug 24, 2017

I downgraded elasticsearch-php to 2.3.0 and noticed that the code is the same. I still can't sniff.
https://github.com/elastic/elasticsearch-php/blob/v2.3.0/src/Elasticsearch/ConnectionPool/SniffingConnectionPool.php#L131

@polyfractal
Copy link
Contributor

This should be fixed. I'll tag a release in a bit... need to look after something else first.

ankushgup2a added a commit to ankushgup2a/elasticsearch-php that referenced this issue Feb 26, 2018
Please add these changes, they are imported from :
Fix parsing of NodesInfo for Sniffing
Closes elastic#629 and elastic#648

elastic@c0ed43c
ankushgup2a added a commit to ankushgup2a/elasticsearch-php that referenced this issue Feb 26, 2018
This change is imported from :
Fix parsing of NodesInfo for Sniffing
Closes elastic#629 and elastic#648
elastic@c0ed43c
ankushgup2a added a commit to ankushgup2a/elasticsearch-php that referenced this issue Feb 26, 2018
These changes are imported from :
Fix parsing of NodesInfo for Sniffing
Closes elastic#629 and elastic#648
for sniffing to work properly.

elastic@c0ed43c
ankushgup2a added a commit to ankushgup2a/elasticsearch-php that referenced this issue Feb 26, 2018
These changes are imported from :
Fix parsing of NodesInfo for Sniffing
Closes elastic#629 and elastic#648
for sniffing to work properly.

elastic@c0ed43c
ankushgup2a added a commit to ankushgup2a/elasticsearch-php that referenced this issue Feb 26, 2018
These changes are imported from :
Fix parsing of NodesInfo for Sniffing
Closes elastic#629 and elastic#648
for sniffing to work properly.

elastic@c0ed43c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants