From 9b66738941c4110577dbc21f79b9cba2ee90fec5 Mon Sep 17 00:00:00 2001 From: Sekar Saravanan Date: Tue, 2 Jul 2024 11:15:35 +0530 Subject: [PATCH] issue-5702 - Duplicate mapping route | ENVOY CONFIG MISMATCH issue fixed Signed-off-by: Sekar Saravanan --- CHANGELOG.md | 7 +++++++ python/ambassador/ir/ir.py | 11 ++++++++++- python/ambassador_diag/diagd.py | 2 +- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9be426e008..685c76b910 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -103,6 +103,13 @@ it will be removed; but as it won't be user-visible this isn't considered a brea - Change: Upgraded Emissary-ingress to the latest release of Golang as part of our general dependency upgrade process. +- Bugfix: Emissary creating duplicate mapping in ir.json and econf.json while adding weight for canary + release. This leads to getting IR MISMATCH & ENVOY CONFIG MISMATCH error frequently in the logs and + also consumes more cpu. We have introduced a condition that, it will add the mapping only if the mapping + is not already present in the group. + +[#5702]: https://github.com/emissary-ingress/emissary/issues/5702 + ## [3.9.0] November 13, 2023 [3.9.0]: https://github.com/emissary-ingress/emissary/compare/v3.8.0...v3.9.0 diff --git a/python/ambassador/ir/ir.py b/python/ambassador/ir/ir.py index 5676e56be9..30e941779d 100644 --- a/python/ambassador/ir/ir.py +++ b/python/ambassador/ir/ir.py @@ -1008,7 +1008,16 @@ def add_mapping(self, aconf: Config, mapping: IRBaseMapping) -> Optional[IRBaseM else: self.logger.debug(f"IR: already have group for {mapping.name}") group = self.groups[mapping.group_id] - group.add_mapping(aconf, mapping) + is_mapping_present = False + try: + existing_mapping_keys = [ group_mapping["rkey"] for group_mapping in group["mappings"] ] + is_mapping_present = True if mapping["rkey"] in existing_mapping_keys else False + except Exception as e: + self.logger.error(f"IR: Exception occurred {e} when checking {mapping.name} already presents in {mapping.group_id}") + + if not is_mapping_present: + self.logger.debug(f"IR: mapping {mapping.name} is not exists. adding it into the group.") + group.add_mapping(aconf, mapping) self.cache_add(mapping) self.cache_add(group) diff --git a/python/ambassador_diag/diagd.py b/python/ambassador_diag/diagd.py index 3d9f8611a4..ce0c6c393f 100644 --- a/python/ambassador_diag/diagd.py +++ b/python/ambassador_diag/diagd.py @@ -550,7 +550,7 @@ def check_cache(self) -> bool: result = False self.logger.error("CACHE: ENVOY CONFIG MISMATCH") errors += "econf diffs:\n" - errors += self.json_diff("econf", i1, i2) + errors += self.json_diff("econf", e1, e2) if not result: err_path = os.path.join(self.snapshot_path, "diff-tmp.txt")