Skip to content

Commit

Permalink
Ensure that request error meta-data is string (#1075)
Browse files Browse the repository at this point in the history
With this commit we ensure that the `error-description` property that is
added to request metadata on errors always contains a string. This
avoids serialization issues later on when these objects are written to
the metrics store.
  • Loading branch information
danielmitterdorfer authored Oct 7, 2020
1 parent d457448 commit bcf9bb8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
6 changes: 5 additions & 1 deletion esrally/driver/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -1432,7 +1432,11 @@ async def execute_single(runner, es, params, on_error):
elif e.info:
request_meta_data["error-description"] = "%s (%s)" % (e.error, e.info)
else:
request_meta_data["error-description"] = e.error
if isinstance(e.error, bytes):
error_description = e.error.decode("utf-8")
else:
error_description = str(e.error)
request_meta_data["error-description"] = error_description
except KeyError as e:
logging.getLogger(__name__).exception("Cannot execute runner [%s]; most likely due to missing parameters.", str(runner))
msg = "Cannot execute [%s]. Provided parameters are: %s. Error: [%s]." % (str(runner), list(params.keys()), str(e))
Expand Down
20 changes: 20 additions & 0 deletions tests/driver/driver_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1459,6 +1459,26 @@ async def test_execute_single_with_http_400(self):
"success": False
}, request_meta_data)

@run_async
async def test_execute_single_with_http_413(self):
import elasticsearch
es = None
params = None
runner = mock.Mock(side_effect=
as_future(exception=elasticsearch.NotFoundError(413, b"", b"")))

ops, unit, request_meta_data = await driver.execute_single(
self.context_managed(runner), es, params, on_error="continue-on-non-fatal")

self.assertEqual(0, ops)
self.assertEqual("ops", unit)
self.assertEqual({
"http-status": 413,
"error-type": "transport",
"error-description": "",
"success": False
}, request_meta_data)

@run_async
async def test_execute_single_with_key_error(self):
class FailingRunner:
Expand Down

0 comments on commit bcf9bb8

Please sign in to comment.