Skip to content

Commit

Permalink
added debug log and adjust terminology and logic to support
Browse files Browse the repository at this point in the history
  • Loading branch information
Arik Gortsunian authored and Arik Gortsunian committed Jan 1, 2025
1 parent 5224100 commit 7f6f01d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 26 deletions.
37 changes: 13 additions & 24 deletions port_ocean/core/handlers/entity_processor/jq_entity_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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 (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 7f6f01d

Please sign in to comment.