Skip to content

Commit 11e7566

Browse files
authored
Merge pull request #1339 from userlocalhost/bugfix/workaround/overload_of_search_chain
Fixed problem that might raise ElasticsearchException depends on context by SearchChain processing
2 parents 35b94cb + 92e8ca3 commit 11e7566

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
### Changed
1111

1212
### Fixed
13+
* Fixed problem that might raise ElasticsearchException depends on context by
14+
SearchChain processing.
15+
Contributed by @hinashi, @userlocalhost
1316

1417
## v3.110.0
1518

api_v1/entry/serializer.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -302,15 +302,22 @@ def _do_forward_search(sub_query, sub_query_result):
302302
]
303303

304304
# get Entry informations from result
305+
# NOTE: small limit(=1000) is workaround to prevent overload
305306
try:
306307
search_result = AdvancedSearchService.search_entries(
307-
user, entity_id_list, hint_attrs, limit=99999
308+
user,
309+
entity_id_list,
310+
hint_attrs,
311+
limit=CONFIG.SEARCH_CHAIN_ACCEPTABLE_RESULT_COUNT,
308312
)
309313
except Exception as e:
310314
Logger.warning("Search Chain API error:%s" % e)
311315
raise ElasticsearchException()
312316

313-
if search_result.ret_count > CONFIG.SEARCH_CHAIN_ACCEPTABLE_RESULT_COUNT:
317+
# All results of this request would be joined and pass to next request. It might be
318+
# huge request and leads to glitch of Elasticsearch by just a single request.
319+
# This is our original curcit breaker to prevent overload because of them.
320+
if len(search_result.ret_values) > CONFIG.SEARCH_CHAIN_ACCEPTABLE_RESULT_COUNT:
314321
Logger.warning("Search Chain API error: SEARCH_CHAIN_ACCEPTABLE_RESULT_COUNT")
315322
raise ElasticsearchException()
316323

api_v1/tests/entry/test_api_search_chain.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import copy
22
import json
3-
from unittest import mock
3+
from unittest import mock, skip
44

55
from airone.lib.test import AironeViewTest
66
from airone.lib.types import AttrType
@@ -1326,6 +1326,10 @@ def test_search_backward_chain_exceeding_search_limit(self):
13261326
),
13271327
)
13281328

1329+
@skip("""
1330+
A situation that raises ElasticsearchException because of exceeding search count because of
1331+
installing workaround limitation cap won't be happened.
1332+
""")
13291333
def test_search_chain_when_result_exceeds_acceptable_count(self):
13301334
# Change configuration to test processing for acceptable result from elasticsearch
13311335
ENTRY_CONFIG.conf["SEARCH_CHAIN_ACCEPTABLE_RESULT_COUNT"] = 2

0 commit comments

Comments
 (0)