|
1 | 1 | #!/usr/bin/env python3 |
2 | 2 |
|
3 | | -from elasticsearch import Elasticsearch |
| 3 | +from elasticsearch import Elasticsearch, VERSION as ES_VERSION |
4 | 4 | from cortexutils.analyzer import Analyzer |
5 | 5 | import dateutil.parser |
6 | 6 | from datetime import datetime |
7 | 7 | import pytz |
| 8 | +from packaging.version import Version |
8 | 9 |
|
9 | 10 | # utils |
10 | 11 | import operator |
@@ -142,21 +143,29 @@ def run(self): |
142 | 143 | client_timeout = 30 # seconds |
143 | 144 |
|
144 | 145 | for endpoint,key,user,password in zip(self.endpoints,self.keys,self.users,self.passwords): |
| 146 | + hosts = [endpoint] if isinstance(endpoint, str) else endpoint |
145 | 147 | es_dict = dict( |
146 | | - hosts=endpoint, |
| 148 | + hosts=hosts, |
147 | 149 | ca_certs=self.cert, |
148 | 150 | verify_certs=self.verify, |
149 | 151 | request_timeout=client_timeout, |
150 | | - connections_per_node=20, # prevent FullPoolError |
151 | 152 | max_retries=3, |
152 | 153 | retry_on_timeout=True, |
153 | 154 | http_compress=True, |
154 | 155 | ) |
155 | | - |
| 156 | + |
| 157 | + if Version(".".join(map(str, ES_VERSION))) < Version("8.0.0"): |
| 158 | + es_dict["maxsize"] = 20 |
| 159 | + else: |
| 160 | + es_dict["connections_per_node"] = 20 |
| 161 | + |
156 | 162 | if key: |
157 | 163 | es_dict["api_key"] = key |
158 | 164 | elif user: |
159 | | - es_dict["basic_auth"] = (user, password) |
| 165 | + if Version(".".join(map(str, ES_VERSION))) < Version("8.0.0"): |
| 166 | + es_dict["http_auth"] = (user, password) |
| 167 | + else: |
| 168 | + es_dict["basic_auth"] = (user, password) |
160 | 169 |
|
161 | 170 | # ES client (ensure connections get closed) |
162 | 171 | with Elasticsearch(**es_dict) as es: |
|
0 commit comments