Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions providers/openlineage/src/airflow/providers/openlineage/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,17 @@ def is_disabled() -> bool:
if _is_true(os.getenv("OPENLINEAGE_DISABLED", "")): # Check legacy variable
return True

# Check if both 'transport' and 'config_path' are not present and also
# if legacy 'OPENLINEAGE_URL' environment variables is not set
return transport() == {} and config_path(True) == "" and os.getenv("OPENLINEAGE_URL", "") == ""
if transport(): # Check if transport is present
return False
if config_path(True): # Check if config file is present
return False
if os.getenv("OPENLINEAGE_URL"): # Check if url simple env var is present
return False
# Check if any transport configuration env var is present
if any(k.startswith("OPENLINEAGE__TRANSPORT") and v for k, v in os.environ.items()):
return False

return True # No transport configuration is present, we can disable OpenLineage


@cache
Expand Down
33 changes: 33 additions & 0 deletions providers/openlineage/tests/unit/openlineage/test_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,39 @@ def test_is_disabled_empty_conf_option():
assert is_disabled() is True


@mock.patch.dict(os.environ, {_VAR_URL: "", "OPENLINEAGE__TRANSPORT": '{"type": "console"}'}, clear=True)
@conf_vars(
{
(_CONFIG_SECTION, _CONFIG_OPTION_CONFIG_PATH): "",
(_CONFIG_SECTION, _CONFIG_OPTION_TRANSPORT): "",
}
)
def test_is_disabled_env_variables_present():
assert is_disabled() is False


@mock.patch.dict(os.environ, {_VAR_URL: "", "OPENLINEAGE__TRANSPORT": ""}, clear=True)
@conf_vars(
{
(_CONFIG_SECTION, _CONFIG_OPTION_CONFIG_PATH): "",
(_CONFIG_SECTION, _CONFIG_OPTION_TRANSPORT): "",
}
)
def test_is_disabled_env_variables_not_present():
assert is_disabled() is True


@mock.patch.dict(os.environ, {_VAR_URL: "", "OPENLINEAGE__TRANSPOR": '{"type": "console"}'}, clear=True)
@conf_vars(
{
(_CONFIG_SECTION, _CONFIG_OPTION_CONFIG_PATH): "",
(_CONFIG_SECTION, _CONFIG_OPTION_TRANSPORT): "",
}
)
def test_is_disabled_env_variables_not_present_typo():
assert is_disabled() is True


@mock.patch.dict(os.environ, {_VAR_URL: ""}, clear=True)
@conf_vars(
{
Expand Down