-
Notifications
You must be signed in to change notification settings - Fork 14.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ability to add custom facet in OpenLineage events (#38982)
* Ability to add custom facet in OpenLineage events * Update airflow/providers/openlineage/provider.yaml Co-authored-by: Elad Kalif <[email protected]> * Update airflow/providers/openlineage/provider.yaml Co-authored-by: Kacper Muda <[email protected]> * Adding None type hint for the custom facet function * Fix a test after rebase * Removed the legacy OPENLINEAGE_ configs format for OPENLINEAGE_CUSTOM_FACET_FUNCTIONS * Duplicate facet key check * Update airflow/providers/openlineage/utils/utils.py Co-authored-by: Kacper Muda <[email protected]> * Update airflow/providers/openlineage/utils/utils.py Co-authored-by: Kacper Muda <[email protected]> * Fixes after rebase * Adding user docs for custom_facet_functions * Rename custom_facet_functions as custom_run_facets * Increment version for custom_run_facets feature * Enrich example with access to operator and return value as None. * Add try-except for custom facet function execution * Fix the typing for the custom facet fucntion return type * Documentation: funcs are executed only for START events * Fix the typing for the custom facet function return type * Fixes after pre-commit hook checks * Adding start_date to test DAGs for 2.7 compatibility tests * Removing a out of scope __init__ file added by pre-commit check --------- Co-authored-by: Anandhi <[email protected]> Co-authored-by: Elad Kalif <[email protected]> Co-authored-by: Kacper Muda <[email protected]>
- Loading branch information
1 parent
05c39b4
commit e30f810
Showing
8 changed files
with
443 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
# 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 typing import TYPE_CHECKING | ||
|
||
import attrs | ||
from openlineage.client.facet import BaseFacet | ||
|
||
if TYPE_CHECKING: | ||
from airflow.models import TaskInstance | ||
|
||
|
||
@attrs.define(slots=False) | ||
class MyCustomRunFacet(BaseFacet): | ||
"""Define a custom run facet.""" | ||
|
||
name: str | ||
jobState: str | ||
uniqueName: str | ||
displayName: str | ||
dagId: str | ||
taskId: str | ||
cluster: str | ||
|
||
|
||
def get_additional_test_facet(task_instance: TaskInstance) -> dict[str, dict] | None: | ||
operator_name = task_instance.task.operator_name if task_instance.task else None | ||
if operator_name == "BashOperator": | ||
return None | ||
job_unique_name = f"TEST.{task_instance.dag_id}.{task_instance.task_id}" | ||
return { | ||
"additional_run_facet": attrs.asdict( | ||
MyCustomRunFacet( | ||
name="test-lineage-namespace", | ||
jobState=task_instance.state, | ||
uniqueName=job_unique_name, | ||
displayName=f"{task_instance.dag_id}.{task_instance.task_id}", | ||
dagId=task_instance.dag_id, | ||
taskId=task_instance.task_id, | ||
cluster="TEST", | ||
) | ||
) | ||
} | ||
|
||
|
||
def get_duplicate_test_facet_key(task_instance: TaskInstance): | ||
job_unique_name = f"TEST.{task_instance.dag_id}.{task_instance.task_id}" | ||
return { | ||
"additional_run_facet": attrs.asdict( | ||
MyCustomRunFacet( | ||
name="test-lineage-namespace", | ||
jobState=task_instance.state, | ||
uniqueName=job_unique_name, | ||
displayName=f"{task_instance.dag_id}.{task_instance.task_id}", | ||
dagId=task_instance.dag_id, | ||
taskId=task_instance.task_id, | ||
cluster="TEST", | ||
) | ||
) | ||
} | ||
|
||
|
||
def get_another_test_facet(task_instance: TaskInstance): | ||
return {"another_run_facet": {"name": "another-lineage-namespace"}} | ||
|
||
|
||
def return_type_is_not_dict(task_instance: TaskInstance): | ||
return "return type is not dict" | ||
|
||
|
||
def get_custom_facet_throws_exception(task_instance: TaskInstance): | ||
raise Exception("fake exception from custom fcet function") |
Oops, something went wrong.