Enhance logging in ingestion_processor.py for improved change detection diagnostics
Add detailed debug and warning logs to the change detection process, providing insights into hash comparisons and artifact checks. This update aims to facilitate better traceability and debugging during ingestion, particularly when handling hash changes and missing hashes. The changes ensure that the ingestion workflow is more transparent and easier to troubleshoot.
This commit is contained in:
parent
6047e94964
commit
7cb8fd6602
|
|
@ -269,6 +269,9 @@ class IngestionService:
|
||||||
# Prüft Hash VOR der Verarbeitung, um redundante Ingestion zu vermeiden
|
# Prüft Hash VOR der Verarbeitung, um redundante Ingestion zu vermeiden
|
||||||
old_payload = None if force_replace else fetch_note_payload(self.client, self.prefix, note_id)
|
old_payload = None if force_replace else fetch_note_payload(self.client, self.prefix, note_id)
|
||||||
|
|
||||||
|
# WP-24c v4.5.9-DEBUG: Erweiterte Diagnose-Logs für Change-Detection
|
||||||
|
logger.debug(f"🔍 [CHANGE-DETECTION] Start für '{note_id}': force_replace={force_replace}, old_payload={old_payload is not None}")
|
||||||
|
|
||||||
content_changed = True
|
content_changed = True
|
||||||
hash_match = False
|
hash_match = False
|
||||||
if old_payload and not force_replace:
|
if old_payload and not force_replace:
|
||||||
|
|
@ -278,16 +281,36 @@ class IngestionService:
|
||||||
new_h = note_pl.get("hashes", {}).get(h_key)
|
new_h = note_pl.get("hashes", {}).get(h_key)
|
||||||
old_h = old_payload.get("hashes", {}).get(h_key)
|
old_h = old_payload.get("hashes", {}).get(h_key)
|
||||||
|
|
||||||
|
# WP-24c v4.5.9-DEBUG: Detaillierte Hash-Diagnose
|
||||||
|
logger.debug(f"🔍 [CHANGE-DETECTION] Hash-Vergleich für '{note_id}':")
|
||||||
|
logger.debug(f" -> Hash-Key: '{h_key}'")
|
||||||
|
logger.debug(f" -> Active Hash-Mode: '{self.active_hash_mode or 'full'}'")
|
||||||
|
logger.debug(f" -> New Hash vorhanden: {bool(new_h)}")
|
||||||
|
logger.debug(f" -> Old Hash vorhanden: {bool(old_h)}")
|
||||||
|
if new_h:
|
||||||
|
logger.debug(f" -> New Hash (erste 32 Zeichen): {new_h[:32]}...")
|
||||||
|
if old_h:
|
||||||
|
logger.debug(f" -> Old Hash (erste 32 Zeichen): {old_h[:32]}...")
|
||||||
|
logger.debug(f" -> Verfügbare Hash-Keys in new: {list(note_pl.get('hashes', {}).keys())}")
|
||||||
|
logger.debug(f" -> Verfügbare Hash-Keys in old: {list(old_payload.get('hashes', {}).keys())}")
|
||||||
|
|
||||||
if new_h and old_h:
|
if new_h and old_h:
|
||||||
hash_match = (new_h == old_h)
|
hash_match = (new_h == old_h)
|
||||||
if hash_match:
|
if hash_match:
|
||||||
content_changed = False
|
content_changed = False
|
||||||
logger.debug(f"🔍 [CHANGE-DETECTION] Hash identisch für '{note_id}': {h_key} = {new_h[:16]}...")
|
logger.debug(f"🔍 [CHANGE-DETECTION] ✅ Hash identisch für '{note_id}': {h_key} = {new_h[:16]}...")
|
||||||
else:
|
else:
|
||||||
logger.debug(f"🔍 [CHANGE-DETECTION] Hash geändert für '{note_id}': alt={old_h[:16]}..., neu={new_h[:16]}...")
|
logger.debug(f"🔍 [CHANGE-DETECTION] ❌ Hash geändert für '{note_id}': alt={old_h[:16]}..., neu={new_h[:16]}...")
|
||||||
|
logger.debug(f" -> Hash-Unterschied: Erste unterschiedliche Position: {next((i for i, (a, b) in enumerate(zip(new_h, old_h)) if a != b), 'keine')}")
|
||||||
else:
|
else:
|
||||||
# WP-24c v4.5.9: Wenn Hash fehlt, als geändert behandeln (Sicherheit)
|
# WP-24c v4.5.9: Wenn Hash fehlt, als geändert behandeln (Sicherheit)
|
||||||
logger.debug(f"🔍 [CHANGE-DETECTION] Hash fehlt für '{note_id}': new_h={bool(new_h)}, old_h={bool(old_h)}")
|
logger.warning(f"⚠️ [CHANGE-DETECTION] Hash fehlt für '{note_id}': new_h={bool(new_h)}, old_h={bool(old_h)}")
|
||||||
|
logger.debug(f" -> Grund: Hash wird als 'geändert' behandelt, da Hash-Werte fehlen")
|
||||||
|
else:
|
||||||
|
if force_replace:
|
||||||
|
logger.debug(f"🔍 [CHANGE-DETECTION] '{note_id}': force_replace=True -> überspringe Hash-Check")
|
||||||
|
elif not old_payload:
|
||||||
|
logger.debug(f"🔍 [CHANGE-DETECTION] '{note_id}': Keine alte Payload gefunden -> erste Verarbeitung oder gelöscht")
|
||||||
|
|
||||||
# WP-24c v4.5.9: Strikte Logik - überspringe komplett wenn Hash identisch
|
# WP-24c v4.5.9: Strikte Logik - überspringe komplett wenn Hash identisch
|
||||||
# WICHTIG: Artifact-Check NACH Hash-Check, da purge_before die Artefakte löschen kann
|
# WICHTIG: Artifact-Check NACH Hash-Check, da purge_before die Artefakte löschen kann
|
||||||
|
|
@ -298,9 +321,13 @@ class IngestionService:
|
||||||
# Artefakte werden beim nächsten normalen Import wieder erstellt, wenn nötig
|
# Artefakte werden beim nächsten normalen Import wieder erstellt, wenn nötig
|
||||||
logger.info(f"⏭️ [SKIP] '{note_id}' unverändert (Hash identisch - überspringe komplett, auch wenn Artefakte fehlen)")
|
logger.info(f"⏭️ [SKIP] '{note_id}' unverändert (Hash identisch - überspringe komplett, auch wenn Artefakte fehlen)")
|
||||||
return {**result, "status": "unchanged", "note_id": note_id, "reason": "hash_identical"}
|
return {**result, "status": "unchanged", "note_id": note_id, "reason": "hash_identical"}
|
||||||
|
elif not force_replace and old_payload and not hash_match:
|
||||||
|
# WP-24c v4.5.9-DEBUG: Hash geändert - erlaube Verarbeitung
|
||||||
|
logger.debug(f"🔍 [CHANGE-DETECTION] '{note_id}': Hash geändert -> erlaube Verarbeitung")
|
||||||
|
|
||||||
# WP-24c v4.5.9: Hash geändert oder keine alte Payload - prüfe Artefakte für normale Verarbeitung
|
# WP-24c v4.5.9: Hash geändert oder keine alte Payload - prüfe Artefakte für normale Verarbeitung
|
||||||
c_miss, e_miss = artifacts_missing(self.client, self.prefix, note_id)
|
c_miss, e_miss = artifacts_missing(self.client, self.prefix, note_id)
|
||||||
|
logger.debug(f"🔍 [CHANGE-DETECTION] '{note_id}': Artifact-Check: c_miss={c_miss}, e_miss={e_miss}")
|
||||||
|
|
||||||
if not apply:
|
if not apply:
|
||||||
return {**result, "status": "dry-run", "changed": True, "note_id": note_id}
|
return {**result, "status": "dry-run", "changed": True, "note_id": note_id}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user