Skip to content

Commit 06c3f8d

Browse files
committed
[IMP] connector_elasticsearch: timeout and retries
Add configuration options on the elasticsearch backend model to support passing the timeout / max_retries / retry_on_timeout argument to the Elasticsearch constructor.
1 parent d702195 commit 06c3f8d

3 files changed

Lines changed: 24 additions & 0 deletions

File tree

connector_elasticsearch/models/se_backend.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,22 @@ class SeBackend(models.Model):
3737
default=True,
3838
help="Verify SSL certificates. Only set to False in development environments.",
3939
)
40+
es_timeout = fields.Integer(
41+
string="Elasticsearch timeout",
42+
default=10,
43+
help="Elastic Search request timeout",
44+
)
45+
es_max_retries = fields.Integer(
46+
string="Elasticsearch max retries",
47+
default=0,
48+
help="Number of retries, when an occurs. "
49+
"0 or negative means no retries and the exception is raised.",
50+
)
51+
es_retry_on_timeout = fields.Boolean(
52+
string="Elasticsearch retry on timeout",
53+
help="If set, retry when a connection timeout occurs. "
54+
"Otherwise, the retries are only on other errors",
55+
)
4056

4157
@property
4258
def _server_env_fields(self):

connector_elasticsearch/tools/adapter.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ def _get_es_client(self):
6161
[backend.es_server_host],
6262
connection_class=self._es_connection_class,
6363
api_key=api_key,
64+
timeout=max(backend.es_timout or 1),
65+
retry_on_timeout=backend.es_retry_on_timeout,
66+
max_retries=max(0, backend.es_max_retries),
6467
)
6568
if backend.auth_type == "http":
6669
auth = (backend.es_user, backend.es_password)

connector_elasticsearch/views/se_backend.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@
4343
attrs="{'invisible': [('auth_type', '!=', 'api_key')]}"
4444
/>
4545
</group>
46+
<group name="se-params">
47+
<field string="Max retries" name="es_max_retries" />
48+
<field string="Retry on timeout" name="es_retry_on_timeout" />
49+
<field string="Timeout" name="es_timeout" />
50+
</group>
4651
</group>
4752
</field>
4853
</record>

0 commit comments

Comments
 (0)