Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add plugin data to scarf usage data collection #41318

Merged
merged 2 commits into from
Aug 8, 2024
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
13 changes: 13 additions & 0 deletions airflow/utils/usage_data_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

from airflow import __version__ as airflow_version, settings
from airflow.configuration import conf
from airflow.plugins_manager import get_plugin_info


def usage_data_collection():
Expand Down Expand Up @@ -95,3 +96,15 @@ def get_executor() -> str:

def get_python_version() -> str:
return platform.python_version()


def get_plugin_counts() -> dict[str, int]:
plugin_info = get_plugin_info()

return {
jedcunningham marked this conversation as resolved.
Show resolved Hide resolved
"plugins": len(plugin_info),
"flask_blueprints": sum(len(x["flask_blueprints"]) for x in plugin_info),
"appbuilder_views": sum(len(x["appbuilder_views"]) for x in plugin_info),
"appbuilder_menu_items": sum(len(x["appbuilder_menu_items"]) for x in plugin_info),
"timetables": sum(len(x["timetables"]) for x in plugin_info),
}
9 changes: 8 additions & 1 deletion airflow/www/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,15 +234,22 @@ def build_scarf_url(dags_count: int) -> str:
db_name = usage_data_collection.get_database_name()
executor = usage_data_collection.get_executor()
python_version = usage_data_collection.get_python_version()
plugin_counts = usage_data_collection.get_plugin_counts()
plugins_count = plugin_counts["plugins"]
flask_blueprints_count = plugin_counts["flask_blueprints"]
appbuilder_views_count = plugin_counts["appbuilder_views"]
appbuilder_menu_items_count = plugin_counts["appbuilder_menu_items"]
timetables_count = plugin_counts["timetables"]

# Path Format:
# /{version}/{python_version}/{platform}/{arch}/{database}/{db_version}/{executor}/{num_dags}
# /{version}/{python_version}/{platform}/{arch}/{database}/{db_version}/{executor}/{num_dags}/{plugin_count}/{flask_blueprint_count}/{appbuilder_view_count}/{appbuilder_menu_item_count}/{timetables}
#
# This path redirects to a Pixel tracking URL
scarf_url = (
f"{scarf_domain}/webserver"
f"/{version}/{python_version}"
f"/{platform_sys}/{platform_arch}/{db_name}/{db_version}/{executor}/{dags_count}"
f"/{plugins_count}/{flask_blueprints_count}/{appbuilder_views_count}/{appbuilder_menu_items_count}/{timetables_count}"
)

return scarf_url
Expand Down
2 changes: 2 additions & 0 deletions docs/apache-airflow/faq.rst
Original file line number Diff line number Diff line change
Expand Up @@ -546,3 +546,5 @@ The telemetry data collected is limited to the following:
- Executor
- Metadata DB type & its version
- Number of DAGs
- Number of Airflow plugins
- Number of timetables, Flask blueprints, Flask AppBuilder views, and Flask Appbuilder menu items from Airflow plugins
23 changes: 16 additions & 7 deletions tests/www/views/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -599,26 +599,35 @@ def test_invalid_dates(app, admin_client, url, content):
assert re.search(content, resp.get_data().decode())


@pytest.mark.parametrize("enabled, dags_count", [(False, 5), (True, 5)])
jedcunningham marked this conversation as resolved.
Show resolved Hide resolved
@pytest.mark.parametrize("enabled", [False, True])
@patch("airflow.utils.usage_data_collection.get_platform_info", return_value=("Linux", "x86_64"))
@patch("airflow.utils.usage_data_collection.get_database_version", return_value="12.3")
@patch("airflow.utils.usage_data_collection.get_database_name", return_value="postgres")
@patch("airflow.utils.usage_data_collection.get_executor", return_value="SequentialExecutor")
@patch("airflow.utils.usage_data_collection.get_python_version", return_value="3.8.5")
@patch("airflow.utils.usage_data_collection.get_plugin_counts")
def test_build_scarf_url(
get_platform_info,
jedcunningham marked this conversation as resolved.
Show resolved Hide resolved
get_database_version,
get_database_name,
get_executor,
get_plugin_counts,
get_python_version,
get_executor,
get_database_name,
get_database_version,
get_platform_info,
enabled,
dags_count,
):
get_plugin_counts.return_value = {
"plugins": 10,
"flask_blueprints": 15,
"appbuilder_views": 20,
"appbuilder_menu_items": 25,
"timetables": 30,
}
with patch("airflow.settings.is_usage_data_collection_enabled", return_value=enabled):
result = build_scarf_url(dags_count)
result = build_scarf_url(5)
expected_url = (
"https://apacheairflow.gateway.scarf.sh/webserver/"
f"{airflow_version}/3.8.5/Linux/x86_64/postgres/12.3/SequentialExecutor/5"
f"/10/15/20/25/30"
)
if enabled:
assert result == expected_url
Expand Down