Skip to content

Commit

Permalink
EPMRPP-88420: ALL analyzer mode now disregards current launch
Browse files Browse the repository at this point in the history
  • Loading branch information
HardNorth committed Dec 4, 2023
1 parent 9e76d78 commit 8079d06
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 68 deletions.
35 changes: 21 additions & 14 deletions app/service/analyzer_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@


class AnalyzerService:
launch_boost: float

def __init__(self, model_chooser, search_cfg=None):
self.search_cfg = search_cfg or {}
self.launch_boost = abs(self.search_cfg['BoostLaunch'])
self.log_preparation = LogPreparation()
self.log_merger = LogMerger()
self.model_chooser = model_chooser
Expand All @@ -53,19 +55,24 @@ def create_path(self, query: dict, path: tuple[str, ...], value: Any) -> Any:
current_node[last_element] = value
return current_node[last_element]

def _add_launch_name_and_id_boost(self, query: dict, launch_name: str, launch_id: int) -> None:
launch_boost = abs(self.search_cfg['BoostLaunch'])
def _add_launch_name_boost(self, query: dict, launch_name: str) -> None:
should = self.create_path(query, ('query', 'bool', 'should'), [])
should.append({'term': {'launch_name': {'value': launch_name, 'boost': self.launch_boost}}})

def _add_launch_id_boost(self, query: dict, launch_id: int) -> None:
should = self.create_path(query, ('query', 'bool', 'should'), [])
should.append({'term': {'launch_id': {'value': launch_id, 'boost': launch_boost}}})
should.append({'term': {'launch_name': {'value': launch_name, 'boost': launch_boost}}})
should.append({'term': {'launch_id': {'value': launch_id, 'boost': self.launch_boost}}})

def _add_launch_name_and_id_boost(self, query: dict, launch_name: str, launch_id: int):
self._add_launch_id_boost(query, launch_id)
self._add_launch_name_boost(query, launch_name)

def add_constraints_for_launches_into_query(self, query: dict, launch) -> dict:
previous_launch_id = getattr(launch, 'previousLaunchId', 0) or 0
previous_launch_id = int(previous_launch_id)
analyzer_mode = launch.analyzerConfig.analyzerMode
launch_name = launch.launchName
launch_id = launch.launchId
launch_boost = abs(self.search_cfg['BoostLaunch'])
if analyzer_mode == 'LAUNCH_NAME':
# Previous launches with the same name
must = self.create_path(query, ('query', 'bool', 'must'), [])
Expand All @@ -75,9 +82,8 @@ def add_constraints_for_launches_into_query(self, query: dict, launch) -> dict:
elif analyzer_mode == 'CURRENT_AND_THE_SAME_NAME':
# All launches with the same name
must = self.create_path(query, ('query', 'bool', 'must'), [])
should = self.create_path(query, ('query', 'bool', 'should'), [])
must.append({'term': {'launch_name': launch_name}})
should.append({'term': {'launch_id': {'value': launch_id, 'boost': launch_boost}}})
self._add_launch_id_boost(query, launch_id)
elif analyzer_mode == 'CURRENT_LAUNCH':
# Just current launch
must = self.create_path(query, ('query', 'bool', 'must'), [])
Expand All @@ -87,9 +93,12 @@ def add_constraints_for_launches_into_query(self, query: dict, launch) -> dict:
if previous_launch_id:
must = self.create_path(query, ('query', 'bool', 'must'), [])
must.append({'term': {'launch_id': previous_launch_id}})
elif analyzer_mode == 'ALL':
# All previous launches
must_not = self.create_path(query, ('query', 'bool', 'must_not'), [])
must_not.append({'term': {'launch_id': launch_id}})
else:
# Just all launches
# Boost launches with the same name, but do not ignore any
# Boost launches with the same name and ID, but do not ignore any
self._add_launch_name_and_id_boost(query, launch_name, launch_id)
return query

Expand All @@ -100,21 +109,19 @@ def add_constraints_for_launches_into_query_suggest(self, query: dict, test_item
launch_name = test_item_info.launchName
launch_id = test_item_info.launchId
launch_boost = abs(self.search_cfg['BoostLaunch'])
if analyzer_mode == 'LAUNCH_NAME':
if analyzer_mode in {'LAUNCH_NAME', 'ALL'}:
# Previous launches with the same name
self._add_launch_name_boost(query, launch_name)
should = self.create_path(query, ('query', 'bool', 'should'), [])
should.append({'term': {'launch_name': {'value': launch_name, 'boost': launch_boost}}})
should.append({'term': {'launch_id': {'value': launch_id, 'boost': 1 / launch_boost}}})
elif analyzer_mode == 'PREVIOUS_LAUNCH':
# Just previous launch
if previous_launch_id:
should = self.create_path(query, ('query', 'bool', 'should'), [])
should.append({'term': {'launch_id': {'value': previous_launch_id, 'boost': launch_boost}}})
self._add_launch_id_boost(query, previous_launch_id)
else:
# For:
# * CURRENT_LAUNCH
# * CURRENT_AND_THE_SAME_NAME
# * All launches
# Boost launches with the same name, but do not ignore any
self._add_launch_name_and_id_boost(query, launch_name, launch_id)
return query
Expand Down
13 changes: 1 addition & 12 deletions test_res/fixtures/query_all_logs_empty_stacktrace.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
{"wildcard": {"issue_type": "ti*"}},
{"wildcard": {"issue_type": "nd*"}},
{"term": {"test_item": "123"}},
{"term": {"launch_id": 12}},
{"wildcard": {"stacktrace": "*"}}
],
"must": [
Expand Down Expand Up @@ -50,18 +51,6 @@
"boost": 10
}
}},
{"term": {
"launch_id": {
"value": 12,
"boost": 5
}
}},
{"term": {
"launch_name": {
"value": "Launch name",
"boost": 5
}
}},
{"more_like_this": {
"fields": ["merged_small_logs"],
"like": "",
Expand Down
15 changes: 2 additions & 13 deletions test_res/fixtures/query_all_logs_nonempty_stacktrace.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"must_not": [
{"wildcard": {"issue_type": "ti*"}},
{"wildcard": {"issue_type": "nd*"}},
{"term": {"test_item": "123"}}
{"term": {"test_item": "123"}},
{"term": {"launch_id": 12}}
],
"must": [
{"more_like_this": {
Expand Down Expand Up @@ -58,18 +59,6 @@
"boost": 10
}
}},
{"term": {
"launch_id": {
"value": 12,
"boost": 5
}
}},
{"term": {
"launch_name": {
"value": "Launch name",
"boost": 5
}
}},
{"more_like_this": {
"fields": ["merged_small_logs"],
"like": "",
Expand Down
13 changes: 1 addition & 12 deletions test_res/fixtures/query_merged_small_logs_search.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
{"wildcard": {"issue_type": "ti*"}},
{"wildcard": {"issue_type": "nd*"}},
{"term": {"test_item": "123"}},
{"term": {"launch_id": 12}},
{"wildcard": {"message": "*"}}
],
"must": [
Expand Down Expand Up @@ -50,18 +51,6 @@
"boost": 10
}
}},
{"term": {
"launch_id": {
"value": 12,
"boost": 5
}
}},
{"term": {
"launch_name": {
"value": "Launch name",
"boost": 5
}
}},
{"more_like_this": {
"fields": ["detected_message_without_params_extended"],
"like": "hello world",
Expand Down
15 changes: 2 additions & 13 deletions test_res/fixtures/query_two_log_lines.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"must_not": [
{"wildcard": {"issue_type": "ti*"}},
{"wildcard": {"issue_type": "nd*"}},
{"term": {"test_item": "123"}}
{"term": {"test_item": "123"}},
{"term": {"launch_id": 12}}
],
"must": [
{"more_like_this": {
Expand Down Expand Up @@ -49,18 +50,6 @@
"boost": 10
}
}},
{"term": {
"launch_id": {
"value": 12,
"boost": 5
}
}},
{"term": {
"launch_name": {
"value": "Launch name",
"boost": 5
}
}},
{"more_like_this": {
"fields": ["detected_message"],
"like": "hello world",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@
"boost": 10
}
}},
{"term": {"launch_id": {"boost": 5, "value": 12}}},
{"term": {
"launch_name": {
"value": "Launch name",
"boost": 5
}
}},
{"term": {"launch_id": {"boost": 0.2, "value": 12}}},
{"more_like_this": {
"fields": ["merged_small_logs"],
"like": "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@
"boost": 10
}
}},
{"term": {"launch_id": {"boost": 5, "value": 12}}},
{"term": {
"launch_name": {
"value": "Launch name",
"boost": 5
}
}},
{"term": {"launch_id": {"boost": 0.2, "value": 12}}},
{"more_like_this": {
"fields": ["merged_small_logs"],
"like": "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@
"boost": 10
}
}},
{"term": {"launch_id": {"boost": 5, "value": 12}}},
{"term": {
"launch_name": {
"value": "Launch name",
"boost": 5
}
}},
{"term": {"launch_id": {"boost": 0.2, "value": 12}}},
{"more_like_this": {
"fields": ["detected_message_without_params_extended"],
"like": "hello world",
Expand Down
2 changes: 1 addition & 1 deletion test_res/fixtures/suggest_query_two_log_lines.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@
"boost": 10
}
}},
{"term": {"launch_id": {"boost": 5, "value": 12}}},
{"term": {
"launch_name": {
"value": "Launch name",
"boost": 5
}
}},
{"term": {"launch_id": {"boost": 0.2, "value": 12}}},
{"more_like_this": {
"fields": ["stacktrace_extended"],
"like": "",
Expand Down

0 comments on commit 8079d06

Please sign in to comment.