mobuchowski commented on code in PR #29940: URL: https://github.com/apache/airflow/pull/29940#discussion_r1135417063
########## airflow/providers/openlineage/plugins/facets.py: ########## @@ -0,0 +1,116 @@ +# 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. +from __future__ import annotations + +from attrs import define, field + +from airflow.providers.openlineage import version as OPENLINEAGE_AIRFLOW_VERSION +from airflow.version import version as AIRFLOW_VERSION +from openlineage.client.facet import BaseFacet +from openlineage.client.utils import RedactMixin + + +@define(slots=False) +class AirflowVersionRunFacet(BaseFacet): + """Run facet containing task and DAG info""" + + operator: str = field() + taskInfo: dict[str, object] = field() + airflowVersion: str = field() + openlineageAirflowVersion: str = field() + + _additional_skip_redact: list[str] = [ + "operator", + "airflowVersion", + "openlineageAirflowVersion", + ] + + @classmethod + def from_dagrun_and_task(cls, dagrun, task): + # task.__dict__ may contain values uncastable to str + from airflow.providers.openlineage.utils import get_operator_class, to_json_encodable + + task_info = to_json_encodable(task) + task_info["dag_run"] = to_json_encodable(dagrun) + + return cls( + operator=f"{get_operator_class(task).__module__}.{get_operator_class(task).__name__}", + taskInfo=task_info, + airflowVersion=AIRFLOW_VERSION, + openlineageAirflowVersion=OPENLINEAGE_AIRFLOW_VERSION, + ) + + +@define(slots=False) +class AirflowRunArgsRunFacet(BaseFacet): + """Run facet pointing if DAG was triggered manually""" + + externalTrigger: bool = field(default=False) + + _additional_skip_redact: list[str] = ["externalTrigger"] + + +@define(slots=False) +class AirflowMappedTaskRunFacet(BaseFacet): + """Run facet containing information about mapped tasks""" + + mapIndex: int = field() + operatorClass: str = field() + + _additional_skip_redact: list[str] = ["operatorClass"] + + @classmethod + def from_task_instance(cls, task_instance): + task = task_instance.task + from airflow.providers.openlineage.utils import get_operator_class + + return cls( + mapIndex=task_instance.map_index, + operatorClass=f"{get_operator_class(task).__module__}.{get_operator_class(task).__name__}", + ) + + +@define(slots=False) +class AirflowRunFacet(BaseFacet): + """Composite Airflow run facet.""" + + dag: dict = field() + dagRun: dict = field() + task: dict = field() + taskInstance: dict = field() + taskUuid: str = field() + + +@define(slots=False) +class UnknownOperatorInstance(RedactMixin): + """ + Describes an unknown operator - specifies the (class) name of the operator + and its properties + """ + + name: str = field() + properties: dict[str, object] = field() + type: str = field(default="operator") Review Comment: Done. ########## airflow/providers/openlineage/plugins/facets.py: ########## @@ -0,0 +1,116 @@ +# 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. +from __future__ import annotations + +from attrs import define, field + +from airflow.providers.openlineage import version as OPENLINEAGE_AIRFLOW_VERSION +from airflow.version import version as AIRFLOW_VERSION +from openlineage.client.facet import BaseFacet +from openlineage.client.utils import RedactMixin + + +@define(slots=False) +class AirflowVersionRunFacet(BaseFacet): + """Run facet containing task and DAG info""" + + operator: str = field() + taskInfo: dict[str, object] = field() + airflowVersion: str = field() + openlineageAirflowVersion: str = field() + + _additional_skip_redact: list[str] = [ + "operator", + "airflowVersion", + "openlineageAirflowVersion", + ] + + @classmethod + def from_dagrun_and_task(cls, dagrun, task): + # task.__dict__ may contain values uncastable to str + from airflow.providers.openlineage.utils import get_operator_class, to_json_encodable + + task_info = to_json_encodable(task) + task_info["dag_run"] = to_json_encodable(dagrun) + + return cls( + operator=f"{get_operator_class(task).__module__}.{get_operator_class(task).__name__}", + taskInfo=task_info, + airflowVersion=AIRFLOW_VERSION, + openlineageAirflowVersion=OPENLINEAGE_AIRFLOW_VERSION, + ) + + +@define(slots=False) +class AirflowRunArgsRunFacet(BaseFacet): + """Run facet pointing if DAG was triggered manually""" + + externalTrigger: bool = field(default=False) + + _additional_skip_redact: list[str] = ["externalTrigger"] + + +@define(slots=False) +class AirflowMappedTaskRunFacet(BaseFacet): + """Run facet containing information about mapped tasks""" + + mapIndex: int = field() + operatorClass: str = field() Review Comment: Done. -- 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]
