From 3428238aac9edadd99f12d312343dcf5ea92025e Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Fri, 10 Nov 2023 13:11:57 +0300 Subject: [PATCH] Bypass launchNumber to suggest_info index --- app/commons/launch_objects.py | 3 +++ app/service/auto_analyzer_service.py | 38 ++++++++++++++++------------ 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/app/commons/launch_objects.py b/app/commons/launch_objects.py index a7e0bed1..57c5003b 100644 --- a/app/commons/launch_objects.py +++ b/app/commons/launch_objects.py @@ -122,6 +122,7 @@ class SuggestAnalysisResult(BaseModel): testItemLogId: int launchId: int launchName: str + launchNumber: int issueType: str relevantItem: int relevantLogId: int @@ -209,6 +210,7 @@ class BatchLogInfo(BaseModel): project: int launchId: int launchName: str + launchNumber: int = 0 class AnalysisCandidate(BaseModel): @@ -220,3 +222,4 @@ class AnalysisCandidate(BaseModel): project: int launchId: int launchName: str + launchNumber: int = 0 diff --git a/app/service/auto_analyzer_service.py b/app/service/auto_analyzer_service.py index 90b6d6cb..3a71f95b 100644 --- a/app/service/auto_analyzer_service.py +++ b/app/service/auto_analyzer_service.py @@ -263,25 +263,28 @@ def _send_result_to_queue(self, test_item_dict, batches, batch_logs): candidates = [] candidates_with_no_defect = [] time_processed = 0.0 - for ind in test_item_dict[test_item_id]: - batch_log_info = batch_logs[ind] + batch_log_info = None + for idx in test_item_dict[test_item_id]: + batch_log_info = batch_logs[idx] if batch_log_info.query_type == "without no defect": candidates.append( - (batch_log_info.log_info, partial_res[ind])) + (batch_log_info.log_info, partial_res[idx])) if batch_log_info.query_type == "with no defect": candidates_with_no_defect.append( - (batch_log_info.log_info, partial_res[ind])) + (batch_log_info.log_info, partial_res[idx])) time_processed += avg_time_processed - self.queue.put(AnalysisCandidate( - analyzerConfig=batch_log_info.analyzerConfig, - testItemId=batch_log_info.testItemId, - project=batch_log_info.project, - launchId=batch_log_info.launchId, - launchName=batch_log_info.launchName, - timeProcessed=time_processed, - candidates=candidates, - candidatesWithNoDefect=candidates_with_no_defect - )) + if batch_log_info: + self.queue.put(AnalysisCandidate( + analyzerConfig=batch_log_info.analyzerConfig, + testItemId=batch_log_info.testItemId, + project=batch_log_info.project, + launchId=batch_log_info.launchId, + launchName=batch_log_info.launchName, + launchNumber=batch_log_info.launchNumber, + timeProcessed=time_processed, + candidates=candidates, + candidatesWithNoDefect=candidates_with_no_defect + )) def _query_elasticsearch(self, launches, max_batch_size=30): t_start = time() @@ -337,7 +340,8 @@ def _query_elasticsearch(self, launches, max_batch_size=30): query_type=query_type, project=launch.project, launchId=launch.launchId, - launchName=launch.launchName + launchName=launch.launchName, + launchNumber=launch.launchNumber )) if test_item.testItemId not in test_item_dict: test_item_dict[test_item.testItemId] = [] @@ -493,6 +497,7 @@ def analyze_logs(self, launches): testItemLogId=test_item_log_id, launchId=analyzer_candidates.launchId, launchName=analyzer_candidates.launchName, + launchNumber=analyzer_candidates.launchNumber, issueType=predicted_issue_type, relevantItem=relevant_item, relevantLogId=relevant_log_id, @@ -534,7 +539,8 @@ def analyze_logs(self, launches): results_to_share[launch_id]["errors"].append( utils.extract_exception(err)) results_to_share[launch_id]["errors_count"] += 1 - if "amqpUrl" in self.app_config and self.app_config["amqpUrl"].strip(): + if "amqpUrl" in self.app_config and self.app_config["amqpUrl"].strip() and len( + analyzed_results_for_index) > 0: AmqpClient(self.app_config["amqpUrl"]).send_to_inner_queue( self.app_config["exchangeName"], "index_suggest_info", json.dumps([_info.dict() for _info in analyzed_results_for_index]))