Skip to content

Commit a5aa160

Browse files
committed
Factored out the ES communication when sniffing
This should help with elastic#312
1 parent fb8eb4e commit a5aa160

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

elasticsearch/transport.py

+21-9
Original file line numberDiff line numberDiff line change
@@ -181,17 +181,14 @@ def get_connection(self):
181181
self.sniff_hosts()
182182
return self.connection_pool.get_connection()
183183

184-
def sniff_hosts(self, initial=False):
184+
def _get_sniff_data(self, initial=False):
185185
"""
186-
Obtain a list of nodes from the cluster and create a new connection
187-
pool using the information retrieved.
188-
189-
To extract the node connection parameters use the ``nodes_to_host_callback``.
190-
191-
:arg initial: flag indicating if this is during startup
192-
(``sniff_on_start``), ignore the ``sniff_timeout`` if ``True``
186+
Perform the request to get sniffins information. Returns a list of
187+
dictionaries (one per node) containing all the information from the
188+
cluster.
193189
"""
194190
previous_sniff = self.last_sniff
191+
195192
try:
196193
# reset last_sniff timestamp
197194
self.last_sniff = time.time()
@@ -213,9 +210,24 @@ def sniff_hosts(self, initial=False):
213210
self.last_sniff = previous_sniff
214211
raise
215212

213+
return list(node_info['nodes'].values())
214+
215+
216+
def sniff_hosts(self, initial=False):
217+
"""
218+
Obtain a list of nodes from the cluster and create a new connection
219+
pool using the information retrieved.
220+
221+
To extract the node connection parameters use the ``nodes_to_host_callback``.
222+
223+
:arg initial: flag indicating if this is during startup
224+
(``sniff_on_start``), ignore the ``sniff_timeout`` if ``True``
225+
"""
226+
node_info = self._get_sniff_data(initial)
227+
216228
hosts = []
217229
address_key = self.connection_class.transport_schema + '_address'
218-
for n in node_info['nodes'].values():
230+
for n in node_info:
219231
host = {}
220232
address = n.get(address_key, '')
221233
if '/' in address:

0 commit comments

Comments
 (0)