Skip to content

Commit

Permalink
Pass timeout with generic params for optimize API
Browse files Browse the repository at this point in the history
With this commit we pass the request timeout via the generic `params`
dictionary to the optimize API (which we call via the client's raw
transport API) instead of as a dedicated kw parameter (which is plain
wrong).

Relates #669
  • Loading branch information
danielmitterdorfer committed Mar 19, 2019
1 parent 98bfa0b commit 57d3bfe
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions esrally/driver/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,11 +508,12 @@ def __call__(self, es, params):
except elasticsearch.TransportError as e:
# this is caused by older versions of Elasticsearch (< 2.1), fall back to optimize
if e.status_code == 400:
params = {"request_timeout": request_timeout}
if max_num_segments:
es.transport.perform_request("POST", "/_optimize?max_num_segments={}".format(max_num_segments),
timeout=request_timeout)
params=params)
else:
es.transport.perform_request("POST", "/_optimize", timeout=request_timeout)
es.transport.perform_request("POST", "/_optimize", params=params)
else:
raise e

Expand Down
5 changes: 3 additions & 2 deletions tests/driver/runner_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -695,15 +695,16 @@ def test_optimize_with_defaults(self, es):
force_merge = runner.ForceMerge()
force_merge(es, params={})

es.transport.perform_request.assert_called_once_with("POST", "/_optimize", timeout=None)
es.transport.perform_request.assert_called_once_with("POST", "/_optimize", params={"request_timeout": None})

@mock.patch("elasticsearch.Elasticsearch")
def test_optimize_with_params(self, es):
es.indices.forcemerge.side_effect = elasticsearch.TransportError(400, "Bad Request")
force_merge = runner.ForceMerge()
force_merge(es, params={"max-num-segments": 3, "request-timeout": 17000})

es.transport.perform_request.assert_called_once_with("POST", "/_optimize?max_num_segments=3", timeout=17000)
es.transport.perform_request.assert_called_once_with("POST", "/_optimize?max_num_segments=3",
params={"request_timeout": 17000})


class QueryRunnerTests(TestCase):
Expand Down

0 comments on commit 57d3bfe

Please sign in to comment.