From 8cfc903f847cd7d448a3ea664340d19923696041 Mon Sep 17 00:00:00 2001 From: oharan2 Date: Mon, 20 May 2024 18:46:13 +0300 Subject: [PATCH 1/4] Sort matching_rules by the identical rules to failure.step --- src/report/report.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/report/report.py b/src/report/report.py index e6d197ea..8997cfce 100644 --- a/src/report/report.py +++ b/src/report/report.py @@ -350,6 +350,9 @@ def failure_matches_rule( if default_rule not in matching_rules: matching_rules.append(default_rule) + # Sort matching_rules by the identical rules to failure.step + if matching_rules: + matching_rules = sorted(matching_rules, key=lambda x: x.step.__eq__(failure.step), reverse=True) return matching_rules def add_passing_job_comment(self, job: Job, jira: Jira, issue_id: str) -> None: From f94f4d684e43f812b37a88932c211105c738b7c3 Mon Sep 17 00:00:00 2001 From: oharan2 Date: Mon, 20 May 2024 18:47:03 +0300 Subject: [PATCH 2/4] Add test_configuration_gets_failure_rules_with_two_matching_steps --- ...h_functions_report_failure_matches_rule.py | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tests/unittests/functions/report/test_firewatch_functions_report_failure_matches_rule.py b/tests/unittests/functions/report/test_firewatch_functions_report_failure_matches_rule.py index 096b612b..d3ea385e 100644 --- a/tests/unittests/functions/report/test_firewatch_functions_report_failure_matches_rule.py +++ b/tests/unittests/functions/report/test_firewatch_functions_report_failure_matches_rule.py @@ -68,3 +68,32 @@ def test_failure_matches_rule_with_matches(self): assert (matching_rules[0].step == match_rule.step) and ( matching_rules[0].failure_type == match_rule.failure_type ) + + def test_configuration_gets_failure_rules_with_two_matching_steps(self): + failure = Failure(failed_step="exact-failed-step", failure_type="test_failure") + + match_rule = FailureRule( + rule_dict={ + "step": "exact-failed-step", + "failure_type": "test_failure", + "classification": "NONE", + "jira_project": "NONE", + }, + ) + pattern_rule = FailureRule( + rule_dict={ + "step": "exact-*", + "failure_type": "test_failure", + "classification": "NONE", + "jira_project": "NONE", + }, + ) + rules = [pattern_rule, match_rule] + + matching_rules = self.report.failure_matches_rule( + failure=failure, + rules=rules, + default_jira_project=self.config.default_jira_project, + ) + # Check if match_rule is sorted higher than pattern_rule + assert matching_rules[0].step.__eq__(failure.step) From dc56944b5e13ce3c21b2d7dbaca3a491ea2388fa Mon Sep 17 00:00:00 2001 From: oharan2 Date: Mon, 20 May 2024 21:19:46 +0300 Subject: [PATCH 3/4] Update unittest with adding rule with different type --- ...firewatch_functions_report_failure_matches_rule.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tests/unittests/functions/report/test_firewatch_functions_report_failure_matches_rule.py b/tests/unittests/functions/report/test_firewatch_functions_report_failure_matches_rule.py index d3ea385e..d596a3e1 100644 --- a/tests/unittests/functions/report/test_firewatch_functions_report_failure_matches_rule.py +++ b/tests/unittests/functions/report/test_firewatch_functions_report_failure_matches_rule.py @@ -80,6 +80,14 @@ def test_configuration_gets_failure_rules_with_two_matching_steps(self): "jira_project": "NONE", }, ) + different_type_rule = FailureRule( + rule_dict={ + "step": "exact-failed-step", + "failure_type": "pod_failure", + "classification": "NONE", + "jira_project": "NONE", + }, + ) pattern_rule = FailureRule( rule_dict={ "step": "exact-*", @@ -88,12 +96,13 @@ def test_configuration_gets_failure_rules_with_two_matching_steps(self): "jira_project": "NONE", }, ) - rules = [pattern_rule, match_rule] + rules = [pattern_rule, different_type_rule, match_rule] matching_rules = self.report.failure_matches_rule( failure=failure, rules=rules, default_jira_project=self.config.default_jira_project, ) + # Check if match_rule is sorted higher than pattern_rule assert matching_rules[0].step.__eq__(failure.step) From c99a32621892002a4fb43f512533c20f71948d30 Mon Sep 17 00:00:00 2001 From: oharan2 Date: Tue, 21 May 2024 15:16:29 +0300 Subject: [PATCH 4/4] Revert "Update unittest with adding rule with different type" This reverts commit dc56944b5e13ce3c21b2d7dbaca3a491ea2388fa. --- ...firewatch_functions_report_failure_matches_rule.py | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/tests/unittests/functions/report/test_firewatch_functions_report_failure_matches_rule.py b/tests/unittests/functions/report/test_firewatch_functions_report_failure_matches_rule.py index d596a3e1..d3ea385e 100644 --- a/tests/unittests/functions/report/test_firewatch_functions_report_failure_matches_rule.py +++ b/tests/unittests/functions/report/test_firewatch_functions_report_failure_matches_rule.py @@ -80,14 +80,6 @@ def test_configuration_gets_failure_rules_with_two_matching_steps(self): "jira_project": "NONE", }, ) - different_type_rule = FailureRule( - rule_dict={ - "step": "exact-failed-step", - "failure_type": "pod_failure", - "classification": "NONE", - "jira_project": "NONE", - }, - ) pattern_rule = FailureRule( rule_dict={ "step": "exact-*", @@ -96,13 +88,12 @@ def test_configuration_gets_failure_rules_with_two_matching_steps(self): "jira_project": "NONE", }, ) - rules = [pattern_rule, different_type_rule, match_rule] + rules = [pattern_rule, match_rule] matching_rules = self.report.failure_matches_rule( failure=failure, rules=rules, default_jira_project=self.config.default_jira_project, ) - # Check if match_rule is sorted higher than pattern_rule assert matching_rules[0].step.__eq__(failure.step)