Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed problem that might raise ElasticsearchException depends on context by SearchChain processing #1339

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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