Monitorando um pipeline de dados

ETL e ELT em Python

Jake Roach

Data Engineer

Monitorando um pipeline de dados

Pipelines de dados devem ser monitorados por mudanças nos dados e falhas na execução

  • Dados ausentes
  • Mudança de tipos de dados
  • Descontinuação de pacote ou alteração de funcionalidade

$$

Fluxo de registro (logging) para um pipeline de dados.

ETL e ELT em Python

Registrando o desempenho do pipeline de dados

  • Documenta o desempenho na execução
  • Dá um ponto de partida quando uma solução falha
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 e ELT em Python

Registrando avisos e erros

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 e ELT em Python

Tratando exceções com try-except

try:
    # Execute some code here
    ...

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

  • Permite executar código se ocorrerem erros
ETL e ELT em Python

Tratando exceções específicas com try-except

Passe a exceção específica na cláusula 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)

ETL e ELT em Python

Vamos praticar!

ETL e ELT em Python

Preparing Video For Download...