You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "andycai-sift (via GitHub)" <gi...@apache.org> on 2024/07/31 22:24:48 UTC
[I] The Celery Worker Pods terminated and lost task logs when scale down happened during HPA autoscaling [airflow]
andycai-sift opened a new issue, #41163:
URL: https://github.com/apache/airflow/issues/41163
### Official Helm Chart version
1.15.0 (latest released)
### Apache Airflow version
2.7.1
### Kubernetes Version
1.27.2
### Helm Chart configuration
After official helm charts supports HPA, then here is my HPA settings.
```
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: "airflow-worker"
namespace: airflow
labels:
app: airflow
component: worker
release: airflow
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: StatefulSet
name: "airflow-worker"
minReplicas: 2
maxReplicas:16
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 70
- type: Resource
resource:
name: memory
target:
type: Utilization
averageUtilization: 80
```
### Docker Image customizations
Not too much special packages, just added openjdk, mongo client and some other python related dependency.
### What happened
When I enabled HPA in the Airflow cluster, then during the scale down some long running tasks which might be over 15hrs got failed and lost the logs. More details.
- The long running task for example is calling python api to spin up a google dataproc cluster which will run the job over 15hrs. When the HPA started scale down the pods, then these tasks failed looks due to the pod terminated after the `terminationGracePeriodSeconds` was hitting. And then it caused the task failed, but actually the tasks still waiting the final response status from dataproc jobs.
- Also after the pod terminated, then the tasks' logs actually was not published to the GCS bucket. I set the remote log to GCS bucket already. But the logs actually are still in persistent disk side, I have to spin up the same pod then can upload the logs to GCS bucket. again.
- The `terminationGracePeriodSeconds` I set is 1hour right now, but due to the long running tasks so i am not sure how the HPA settings can support it.
### What you think should happen instead
It should be happened during HPA scaling down either the celery work pod need to graceful shutdown until all tasks are completed or Airflow should provide some config or something else to support kill the task process before final termination deadline and complete the cleanup and upload logs to remote settings like GCS bucket.
### How to reproduce
- Using official helm chart with HPA enabled with CPU/Memory metrics deploy airflow to Kubernetes.
- Setup remote logging
```
logging:
delete_local_logs: 'False'
remote_base_log_folder: "gs://xxx"
remote_logging: 'True'
```
- Run a long running task maybe just need 30mins or few hours, but you have to make sure setup `terminationGracePeriodSeconds` maybe to a small number.
- Try to trigger the HPA scale down the pods, then you should see the issue from the UI you should see the task failed without logs.
### Anything else
_No response_
### Are you willing to submit PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] The Celery Worker Pods terminated and lost task logs when scale down happened during HPA autoscaling [airflow]
Posted by "Miretpl (via GitHub)" <gi...@apache.org>.
Miretpl commented on issue #41163:
URL: https://github.com/apache/airflow/issues/41163#issuecomment-5591226711
My 2c:
This issue is not really connected to the Helm Chart itself, but rather to how remote logging works and the Celery provider in the Kubernetes setup (this is why HPA doesn't really matter here). In any case, when the Celery worker is killed, the default (and basically the only supported) behaviour is for the worker to wait for all tasks to finish and then shut down. In a Kubernetes setup, after the SIGTERM, we have `terminationGracePeriod`, after which we have `SIGKILL`. The reason why there are no logs is the fact that Celery waits for tasks to finish, and logs are uploaded only after a task is finished. One way of fixing it would be to manually propagate the `SIGTERM` signal from Celery to the Task Supervisers to let them know that they have to kill the task (change in the Celery provider). The other way would be to change how remote logging works from "logging after finish" to "logging in the stream to the remote location" (change in Google, Azure, etc. providers with logging ha
ndlers). Both of these have some pros and cons, like:
1. Celery - requires synchronisation between when we will send the `SIGTERM` signal from the main process to task supervisors with pod `terminationGracePeriod` time
2. Logging - moving from one upload to streaming can, e.g. increase cost, network traffic, etc., and we should be careful about it, as with scale, it might have a huge impact
Also, the logging change would require a bit of architectural changes in how the upload works, as currently (as far as I remember) it is invoked in the `close` methods of the task handlers. Next to it, with the streaming approach, is the fact that if we had streaming, we could skip creating and logging to the file and copying it to the remote location - we could just do it directly.
There is a chance that there are more ways of fixing this issue - none of them is on top of my mind now. I would leave the decision on how to solve it to the person who will propose a PR. Both log streaming and the Celery change can coexist.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] The Celery Worker Pods terminated and lost task logs when scale down happened during HPA autoscaling [airflow]
Posted by "boring-cyborg[bot] (via GitHub)" <gi...@apache.org>.
boring-cyborg[bot] commented on issue #41163:
URL: https://github.com/apache/airflow/issues/41163#issuecomment-2261560505
Thanks for opening your first issue here! Be sure to follow the issue template! If you are willing to raise PR to address this issue please do so, no need to wait for approval.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] The Celery Worker Pods terminated and lost task logs when scale down happened during HPA autoscaling [airflow]
Posted by "dimon222 (via GitHub)" <gi...@apache.org>.
dimon222 commented on issue #41163:
URL: https://github.com/apache/airflow/issues/41163#issuecomment-2282236848
Regarding first proposed solution - HPA waiting for completion of work:
I'm afraid this is not fixable by Airflow project, as it's the limitation of Kubernetes that during scale down operation request you can't choose the "wait for completion of work. The timing for graceful shutdown has to be configured on reason at start time, you can't update this when the container of celery worker is already running (the resource spec is immutable, you have to trigger "deploy" style operation to bounce container to do any changes).
I have been waiting for this for years, but K8s development community isn't working on it currently.
https://github.com/kubernetes/enhancements/issues/2255#issuecomment-2261281830
Not sure about second proposed solution though. I'm not certain is Kubernetes sends upfront signal to remind that shutdown signal will come in grace period amount of seconds.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] The Celery Worker Pods terminated and lost task logs when scale down happened during HPA autoscaling [airflow]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on issue #41163:
URL: https://github.com/apache/airflow/issues/41163#issuecomment-5378947620
This issue has been automatically marked as stale because it has been open for 365 days without any activity. There has been several Airflow releases since last activity on this issue. Kindly asking to recheck the report against latest Airflow version and let us know if the issue is reproducible. The issue will be closed in next 30 days if no further activity occurs from the issue author.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org