vchiapaikeo opened a new pull request, #34209:
URL: https://github.com/apache/airflow/pull/34209
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<!--
Thank you for contributing! Please make sure that your code changes
are covered with tests. And in case of new features or big changes
remember to adjust the documentation.
Feel free to ping committers for the review!
In case of an existing issue, reference it using one of the following:
closes: #ISSUE
related: #ISSUE
How to write a good git commit message:
http://chris.beams.io/posts/git-commit/
-->
Currently, deferrable KPO will not allow users to see logs of the underlying
base container until completion (even with get_logs=True). This is because logs
are not streamed until [the trigger event successfully fires and
execute_complete is
called](https://github.com/apache/airflow/blob/5744b424f3ddb3efdf5c2607d13e084955907cc8/airflow/providers/cncf/kubernetes/operators/pod.py#L670-L672).
What's worse is that we do not know what the pod_name or the pod_namespace is
until execute_complete is called as well. With synchronous KPO, this happens
[immediately after get_or_create_pod is
called](https://github.com/apache/airflow/blob/5744b424f3ddb3efdf5c2607d13e084955907cc8/airflow/providers/cncf/kubernetes/operators/pod.py#L588-L590).
We should do the same with the deferrable flow. Therefore, users can add
extra_links to the KPO (retrieving pod_name and pod_namespace from xcom) and
stream in-flight logs from their monitoring tool of choice (for us, it is Cloud
Monitoring because we use
GKE).
This moves the xcom_push calls up to execute_async. To test, I used this dag
and observed xcom appear during deferral state.
```py
from airflow import DAG
from airflow.providers.google.cloud.operators.kubernetes_engine import (
GKEStartPodOperator,
)
DEFAULT_TASK_ARGS = {
"owner": "gcp-data-platform",
"start_date": "2021-04-20",
"retries": 0,
"retry_delay": 60,
}
with DAG(
dag_id="test_gke_op",
schedule_interval="@daily",
max_active_runs=1,
max_active_tasks=5,
catchup=False,
default_args=DEFAULT_TASK_ARGS,
) as dag:
whoami = GKEStartPodOperator(
task_id="whoami",
# This is the name of the pod and it cannot contain underscores
name="whoami",
cmds=["gcloud"],
arguments=["auth", "list"],
image="gcr.io/google.com/cloudsdktool/cloud-sdk:slim",
project_id="redacted-project-id",
namespace="airflow-default",
location="us-central1",
cluster_name="airflow-gke-cluster",
service_account_name="default",
is_delete_operator_pod=True,
)
sleep_3000 = GKEStartPodOperator(
task_id="sleep_3000",
# This is the name of the pod and it cannot contain underscores
name="sleep-3000",
cmds=["sleep"],
arguments=["3000"],
image="gcr.io/google.com/cloudsdktool/cloud-sdk:slim",
project_id="redacted-project-id",
namespace="airflow-default",
location="us-central1",
cluster_name="airflow-gke-cluster",
service_account_name="default",
is_delete_operator_pod=True,
deferrable=True,
)
sleep_3600 = GKEStartPodOperator(
task_id="sleep_3600",
# This is the name of the pod and it cannot contain underscores
name="sleep-3600",
cmds=["sleep"],
arguments=["3600"],
image="gcr.io/google.com/cloudsdktool/cloud-sdk:slim",
project_id="redacted-project-id",
namespace="airflow-default",
location="us-central1",
cluster_name="airflow-gke-cluster",
service_account_name="default",
is_delete_operator_pod=True,
deferrable=True,
)
sleep_4000 = GKEStartPodOperator(
task_id="sleep_4000",
# This is the name of the pod and it cannot contain underscores
name="sleep-4000",
cmds=["sleep"],
arguments=["4000"],
image="gcr.io/google.com/cloudsdktool/cloud-sdk:slim",
project_id="redacted-project-id",
namespace="airflow-default",
location="us-central1",
cluster_name="airflow-gke-cluster",
service_account_name="default",
is_delete_operator_pod=True,
)
sleep_4800 = GKEStartPodOperator(
task_id="sleep_4800",
# This is the name of the pod and it cannot contain underscores
name="sleep-4800",
cmds=["sleep"],
arguments=["4800"],
image="gcr.io/google.com/cloudsdktool/cloud-sdk:slim",
project_id="redacted-project-id",
namespace="airflow-default",
location="us-central1",
cluster_name="airflow-gke-cluster",
service_account_name="default",
is_delete_operator_pod=True,
)
```
<img width="1066" alt="image"
src="https://github.com/apache/airflow/assets/9200263/2b9964b6-3808-4843-97e8-a978f0e7889e">
<img width="1026" alt="image"
src="https://github.com/apache/airflow/assets/9200263/c50fd1ae-e600-435c-894f-e3cc20664af8">
<!-- Please keep an empty line above the dashes. -->
---
**^ Add meaningful description above**
Read the **[Pull Request
Guidelines](https://github.com/apache/airflow/blob/main/CONTRIBUTING.rst#pull-request-guidelines)**
for more information.
In case of fundamental code changes, an Airflow Improvement Proposal
([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvement+Proposals))
is needed.
In case of a new dependency, check compliance with the [ASF 3rd Party
License Policy](https://www.apache.org/legal/resolved.html#category-x).
In case of backwards incompatible changes please leave a note in a
newsfragment file, named `{pr_number}.significant.rst` or
`{issue_number}.significant.rst`, in
[newsfragments](https://github.com/apache/airflow/tree/main/newsfragments).
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]