From 8079d06032bf31f5637b1d1be9fcbf2dcb762d4a Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Mon, 4 Dec 2023 17:32:33 +0300 Subject: [PATCH] EPMRPP-88420: ALL analyzer mode now disregards current launch --- app/service/analyzer_service.py | 35 +++++++++++-------- .../query_all_logs_empty_stacktrace.json | 13 +------ .../query_all_logs_nonempty_stacktrace.json | 15 ++------ .../query_merged_small_logs_search.json | 13 +------ test_res/fixtures/query_two_log_lines.json | 15 ++------ ...ggest_query_all_logs_empty_stacktrace.json | 2 +- ...st_query_all_logs_nonempty_stacktrace.json | 2 +- ...uggest_query_merged_small_logs_search.json | 2 +- .../fixtures/suggest_query_two_log_lines.json | 2 +- 9 files changed, 31 insertions(+), 68 deletions(-) diff --git a/app/service/analyzer_service.py b/app/service/analyzer_service.py index f0649fe8..1193d7e2 100644 --- a/app/service/analyzer_service.py +++ b/app/service/analyzer_service.py @@ -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 @@ -53,11 +55,17 @@ 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 @@ -65,7 +73,6 @@ def add_constraints_for_launches_into_query(self, query: dict, launch) -> dict: 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'), []) @@ -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'), []) @@ -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 @@ -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 diff --git a/test_res/fixtures/query_all_logs_empty_stacktrace.json b/test_res/fixtures/query_all_logs_empty_stacktrace.json index 9bb8fb52..71af3cbe 100644 --- a/test_res/fixtures/query_all_logs_empty_stacktrace.json +++ b/test_res/fixtures/query_all_logs_empty_stacktrace.json @@ -15,6 +15,7 @@ {"wildcard": {"issue_type": "ti*"}}, {"wildcard": {"issue_type": "nd*"}}, {"term": {"test_item": "123"}}, + {"term": {"launch_id": 12}}, {"wildcard": {"stacktrace": "*"}} ], "must": [ @@ -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": "", diff --git a/test_res/fixtures/query_all_logs_nonempty_stacktrace.json b/test_res/fixtures/query_all_logs_nonempty_stacktrace.json index 71e86dfe..bb8795c7 100644 --- a/test_res/fixtures/query_all_logs_nonempty_stacktrace.json +++ b/test_res/fixtures/query_all_logs_nonempty_stacktrace.json @@ -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": { @@ -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": "", diff --git a/test_res/fixtures/query_merged_small_logs_search.json b/test_res/fixtures/query_merged_small_logs_search.json index a2f883a6..7dbb4a2b 100644 --- a/test_res/fixtures/query_merged_small_logs_search.json +++ b/test_res/fixtures/query_merged_small_logs_search.json @@ -15,6 +15,7 @@ {"wildcard": {"issue_type": "ti*"}}, {"wildcard": {"issue_type": "nd*"}}, {"term": {"test_item": "123"}}, + {"term": {"launch_id": 12}}, {"wildcard": {"message": "*"}} ], "must": [ @@ -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", diff --git a/test_res/fixtures/query_two_log_lines.json b/test_res/fixtures/query_two_log_lines.json index 4730d84e..b6cab8cd 100644 --- a/test_res/fixtures/query_two_log_lines.json +++ b/test_res/fixtures/query_two_log_lines.json @@ -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": { @@ -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", diff --git a/test_res/fixtures/suggest_query_all_logs_empty_stacktrace.json b/test_res/fixtures/suggest_query_all_logs_empty_stacktrace.json index b7e6ed6f..ea43a2ae 100644 --- a/test_res/fixtures/suggest_query_all_logs_empty_stacktrace.json +++ b/test_res/fixtures/suggest_query_all_logs_empty_stacktrace.json @@ -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": "", diff --git a/test_res/fixtures/suggest_query_all_logs_nonempty_stacktrace.json b/test_res/fixtures/suggest_query_all_logs_nonempty_stacktrace.json index a70afe9b..505619e7 100644 --- a/test_res/fixtures/suggest_query_all_logs_nonempty_stacktrace.json +++ b/test_res/fixtures/suggest_query_all_logs_nonempty_stacktrace.json @@ -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": "", diff --git a/test_res/fixtures/suggest_query_merged_small_logs_search.json b/test_res/fixtures/suggest_query_merged_small_logs_search.json index ff2e7fce..20fedc47 100644 --- a/test_res/fixtures/suggest_query_merged_small_logs_search.json +++ b/test_res/fixtures/suggest_query_merged_small_logs_search.json @@ -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", diff --git a/test_res/fixtures/suggest_query_two_log_lines.json b/test_res/fixtures/suggest_query_two_log_lines.json index 40d155f2..3f47b4be 100644 --- a/test_res/fixtures/suggest_query_two_log_lines.json +++ b/test_res/fixtures/suggest_query_two_log_lines.json @@ -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": "",