question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't view running tasks logs using KubernetesExecutor.

See original GitHub issue

Description

I want to be able to see logs for running tasks in airflow web UI when I’m using “KubernetesExecutor”. Airflow tries to read logs of worker pod which does not contain my task logs because “airflow tasks run” command redirects all stdout/stderr to log file.

Here is what I see when I try to read logs of running tasks:

*** Falling back to local log
*** Trying to get logs (last 100 lines) from worker pod datainfraexporterhourlydagwaitforpublishedpostdump.a825336790e24b40ad43b2411ef617c5 ***

BACKEND=postgres
DB_HOST=divar-infra-db-cluster-master-service.skubel-76f219d5-eb73-4f23-96b3-a8cf4ab4f00a
DB_PORT=5432

[2021-05-22 19:00:30,157] {dagbag.py:451} INFO - Filling up the DagBag from /git/airflow/dags/data_infra/exporter/hourly.py

Use case / motivation

It’s not convenient to wait for tasks to finish in order to read their logs.

Are you willing to submit a PR?

I can help.

Related Issues

I don’t think so.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:4
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
hsnprsdcommented, May 23, 2021

I came up with a solution today. I changed the default logging config class like this:

import sys
from copy import deepcopy

from airflow.config_templates.airflow_local_settings import DEFAULT_LOGGING_CONFIG

LOGGING_CONFIG = deepcopy(DEFAULT_LOGGING_CONFIG)

LOGGING_CONFIG["handlers"]["custom_console"] = {
    "class": "logging.StreamHandler",
    "formatter": "airflow",
    "stream": sys.__stdout__,
}
LOGGING_CONFIG["loggers"]["airflow.task"]["handlers"].append("custom_console")

I moved this file to $AIRFLOW_HOME/config/logging_config.py and changed AIRFLOW__LOGGING__LOGGING_CONFIG_CLASS to logging_config.LOGGING_CONFIG

0reactions
whitleykeithcommented, Aug 24, 2021

I’ve had this issue for a while now, but I was able to resolve it by adding this to the top of my dag.py file.

# Set Task Logger to INFO for better task logs
log = logging.getLogger("airflow.task")
handler = logging.StreamHandler(sys.stdout)
handler.setLevel(logging.INFO)
log.addHandler(handler)

It does pretty much what @hsnprsd had in his class, but doesn’t require overriding the default logging config.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cant get Kubernetes task's log when using ... - GitHub
Once you have got that fixed, log will be empty in the running state, because it is trying to read container logs and...
Read more >
Unable to see Task logs in Airflow Deployed via Kubernetes
Was currently using Airflow 2.0.2 release and installing it via its latest Helm chart using the Kubernetes executor. I also had to set...
Read more >
Kubernetes Executor — Airflow Documentation - Apache Airflow
When a DAG submits a task, the KubernetesExecutor requests a worker pod from the Kubernetes API. The worker pod then runs the task,...
Read more >
"Log file does not exist" - Astronomer Nebula
Is it a problem with my task, or astronomer cloud, or airflow? *** Log file does not exist: /usr/local/airflow/logs/[TASKNAME]s/run/2019-07- ...
Read more >
Running Apache Airflow Workflows on a Kubernetes Cluster
In this series, our goal is to show how to deploy Apache Airflow on ... to use Kubernetes Executor when running task instances...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found