Skip to content

Commit

Permalink
Merge pull request #1339 from userlocalhost/bugfix/workaround/overloa…
Browse files Browse the repository at this point in the history
…d_of_search_chain

Fixed problem that might raise ElasticsearchException depends on context by SearchChain processing
  • Loading branch information
hinashi authored Dec 10, 2024
2 parents 35b94cb + 92e8ca3 commit 11e7566
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
### Changed

### Fixed
* Fixed problem that might raise ElasticsearchException depends on context by
SearchChain processing.
Contributed by @hinashi, @userlocalhost

## v3.110.0

Expand Down
11 changes: 9 additions & 2 deletions api_v1/entry/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,15 +302,22 @@ def _do_forward_search(sub_query, sub_query_result):
]

# get Entry informations from result
# NOTE: small limit(=1000) is workaround to prevent overload
try:
search_result = AdvancedSearchService.search_entries(
user, entity_id_list, hint_attrs, limit=99999
user,
entity_id_list,
hint_attrs,
limit=CONFIG.SEARCH_CHAIN_ACCEPTABLE_RESULT_COUNT,
)
except Exception as e:
Logger.warning("Search Chain API error:%s" % e)
raise ElasticsearchException()

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

Expand Down
6 changes: 5 additions & 1 deletion api_v1/tests/entry/test_api_search_chain.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import copy
import json
from unittest import mock
from unittest import mock, skip

from airone.lib.test import AironeViewTest
from airone.lib.types import AttrType
Expand Down Expand Up @@ -1326,6 +1326,10 @@ def test_search_backward_chain_exceeding_search_limit(self):
),
)

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

0 comments on commit 11e7566

Please sign in to comment.