From 7f6f01ddbf0285c14fa68631758409b28d070169 Mon Sep 17 00:00:00 2001 From: Arik Gortsunian Date: Wed, 1 Jan 2025 15:57:40 +0200 Subject: [PATCH] added debug log and adjust terminology and logic to support --- .../entity_processor/jq_entity_processor.py | 37 +++++++------------ .../test_jq_entity_processor.py | 4 +- 2 files changed, 15 insertions(+), 26 deletions(-) diff --git a/port_ocean/core/handlers/entity_processor/jq_entity_processor.py b/port_ocean/core/handlers/entity_processor/jq_entity_processor.py index 7fac3cb81c..3ec80258c0 100644 --- a/port_ocean/core/handlers/entity_processor/jq_entity_processor.py +++ b/port_ocean/core/handlers/entity_processor/jq_entity_processor.py @@ -73,23 +73,11 @@ def inner() -> Any: return inner - @staticmethod - def _calculate_mapping_fault_counters( - entity_mapping_fault_counters: EntityMappingFaultCounters, result: MappedEntity - ) -> EntityMappingFaultCounters: - entity_mapping_fault_counters["empty_identifiers"] += ( - 1 if (result.entity.get("identifier") == "") else 0 - ) - entity_mapping_fault_counters["empty_blueprints"] += ( - 1 if (result.entity.get("blueprint") == "") else 0 - ) - return entity_mapping_fault_counters - @staticmethod def _log_mapping_issues_identified( entity_misconfigurations: dict[str, str], missing_required_fields: bool, - entity_mapping_fault_counters: EntityMappingFaultCounters, + entity_mapping_fault_counter: int, ) -> None: if len(entity_misconfigurations) > 0: @@ -98,9 +86,7 @@ def _log_mapping_issues_identified( ) if missing_required_fields: logger.info( - f"Unable to find valid data for identifier, blueprint due to empty values: \ -identifier: {entity_mapping_fault_counters['empty_identifiers']}, \ -blueprint: {entity_mapping_fault_counters['empty_blueprints']}" + f"{entity_mapping_fault_counter} transformations of batch failed due to empty values" ) async def _search(self, data: dict[str, Any], pattern: str) -> Any: @@ -289,10 +275,7 @@ async def _parse_items( examples_to_send: list[dict[str, Any]] = [] entity_misconfigurations: dict[str, str] = {} missing_required_fields: bool = False - entity_mapping_fault_counters: EntityMappingFaultCounters = { - "empty_identifiers": 0, - "empty_blueprints": 0, - } + entity_mapping_fault_counter: int = 0 for result in calculated_entities_results: if len(result.misconfigurations) > 0: @@ -311,14 +294,20 @@ async def _parse_items( failed_entities.append(parsed_entity) else: missing_required_fields = True - entity_mapping_fault_counters = self._calculate_mapping_fault_counters( - entity_mapping_fault_counters, result - ) + if (result.entity.get("identifier") == "") or ( + result.entity.get("blueprint") == "" + ): + entity_mapping_fault_counter += 1 + else: + logger.debug( + f"Transformation failed, values verification for identifier: {result.entity.get("identifier")}, \ + for blueprint: {result.entity.get("blueprint")}" + ) self._log_mapping_issues_identified( entity_misconfigurations, missing_required_fields, - entity_mapping_fault_counters, + entity_mapping_fault_counter, ) if ( diff --git a/port_ocean/tests/core/handlers/entity_processor/test_jq_entity_processor.py b/port_ocean/tests/core/handlers/entity_processor/test_jq_entity_processor.py index 7a530212eb..2a0010931b 100644 --- a/port_ocean/tests/core/handlers/entity_processor/test_jq_entity_processor.py +++ b/port_ocean/tests/core/handlers/entity_processor/test_jq_entity_processor.py @@ -340,9 +340,9 @@ async def test_parse_items_empty_required( logger.remove(sink_id) logs_captured = stream.getvalue() - assert "identifier: 1, blueprint: 1" in logs_captured + assert "2 transformations of batch failed due to empty values" in logs_captured assert ( "{'blueprint': '.bar', 'identifier': '.foo'} (null, missing, or misconfigured)" in logs_captured ) - assert "identifier: 0, blueprint: 1" in logs_captured + assert "1 transformations of batch failed due to empty values" in logs_captured