Skip to content

Commit db49328

Browse files
committed
Correct ES stats URL
Choose correct stats API URL according to ES major and minor version up to ElasticSearch 2.0.
1 parent 37b6214 commit db49328

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

elasticsearch/python_modules/elasticsearch.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,9 @@ def get_indices_descriptors(index, skel, result, url):
178178

179179
return descriptors
180180

181+
def parse_elastic_version(version):
182+
match = re.match(r'(?P<major>\d+)\.(?P<minor>(\d+))(\.\d+)*', version)
183+
return int(match.group('major')), int(match.group('minor'))
181184

182185
def metric_init(params):
183186
descriptors = []
@@ -194,15 +197,14 @@ def metric_init(params):
194197

195198
host_version = result.get('version',{}).get('number') or "1.2"
196199
version = params.get('version', host_version)
200+
major, minor = parse_elastic_version(version)
197201

198-
m = re.match('(?P<major>\d+)\.(?P<minor>(\d+(\.\d+)*))', version)
199-
200-
if m and m.group('major') == '0':
202+
if major == 0:
201203
url_cluster = '{0}_cluster/nodes/_local/stats?all=true'.format(host)
202-
elif m and m.group('major') == '1' and m.group('minor') == '3.2':
203-
url_cluster = '{0}_nodes/_local/stats'.format(host)
204-
else:
204+
elif major == 1 and minor < 3:
205205
url_cluster = '{0}_cluster/state/nodes'.format(host)
206+
else:
207+
url_cluster = '{0}_nodes/_local/stats'.format(host)
206208

207209
# First iteration - Grab statistics
208210
logging.debug('[elasticsearch] Fetching ' + url_cluster)

0 commit comments

Comments
 (0)