データパイプラインのモニタリング

Python で学ぶ ETL と ELT

Jake Roach

Data Engineer

データパイプラインのモニタリング

データや実行失敗の変化に備えてパイプラインを監視します

  • 欠損データ
  • データ型の変化
  • パッケージの非推奨・仕様変更

$$

データパイプラインのログ処理フロー。

Python で学ぶ ETL と ELT

パイプライン性能のログ出力

  • 実行時の性能を記録
  • 障害時の初動に役立つ
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.
Python で学ぶ ETL と ELT

警告とエラーのログ出力

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.
Python で学ぶ ETL と ELT

try-except で例外処理

try:
    # Execute some code here
    ...

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

  • エラー発生時に処理を実行できる
Python で学ぶ ETL と ELT

try-except で特定の例外を処理

except 節に特定の例外を渡します

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)

Python で学ぶ ETL と ELT

演習に進みましょう!

Python で学ぶ ETL と ELT

Preparing Video For Download...