Monitoring einer Daten-Pipeline

ETL und ELT in Python

Jake Roach

Data Engineer

Monitoring einer Daten-Pipeline

Daten-Pipelines sollten auf Datenänderungen und Ausführungsfehler überwacht werden

  • Fehlende Daten
  • Wechselnde Datentypen
  • Paketveraltung oder Funktionsänderung

$$

Protokollierungs-Workflow für eine Daten-Pipeline.

ETL und ELT in Python

Performance der Daten-Pipeline protokollieren

  • Leistung bei der Ausführung dokumentieren
  • Liefert einen Startpunkt, wenn eine Lösung fehlschlägt
import logging
logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.DEBUG)

# Create different types of logs
logging.debug(f"Variable has value {path}")
logging.info("Data has been transformed and will now be loaded.")
DEBUG: Variable has value raw_file.csv
INFO: Data has been transformed and will now be loaded.
ETL und ELT in Python

Warnungen und Fehler protokollieren

import logging
logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.DEBUG)

# Create different types of logs
logging.warning("Unexpected number of rows detected.")
logging.error("{ke} arose in execution.")
WARNING: Unexpected number of rows detected.
ERROR: KeyError arose in execution.
ETL und ELT in Python

Ausnahmen mit try-except behandeln

try:
    # Execute some code here
    ...

except:
    # Logging about failures that occured
    # Logic to execute upon exception
    ...

  • Ermöglicht das Ausführen von Code, wenn Fehler auftreten
ETL und ELT in Python

Spezifische Ausnahmen mit try-except behandeln

Gib die spezifische Ausnahme in der except-Klausel an

try:
    # Try to filter by price_change
    clean_stock_data = transform(raw_stock_data)
    logging.info("Successfully filtered DataFrame by 'price_change'")

except KeyError as ke:
    # Handle the error, create new column, transform
    logging.warning(f"{ke}: Cannot filter DataFrame by 'price_change'")
    raw_stock_data["price_change"] = raw_stock_data["close"] - raw_stock_data["open"]
    clean_stock_data = transform(raw_stock_data)

ETL und ELT in Python

Lass uns üben!

ETL und ELT in Python

Preparing Video For Download...