pankajkoti commented on code in PR #39510:
URL: https://github.com/apache/airflow/pull/39510#discussion_r1603666980
##########
airflow/www/views.py:
##########
@@ -217,6 +217,32 @@ def get_safe_url(url):
return redirect_url.geturl()
+def build_scarf_url(dags_count: int) -> str:
+ """Build the URL for the Scarf telemetry collection."""
+ if not settings.is_telemetry_collection_enabled():
+ return ""
+
+ scarf_domain = "https://apacheairflow.gateway.scarf.sh"
+
+ platform_sys, platform_arch = scarf.get_platform_info()
+ db_version = scarf.get_database_version()
+ db_name = scarf.get_database_name()
Review Comment:
```suggestion
db_engine_name = scarf.get_database_engine_name()
```
if the above comment is considered
##########
airflow/utils/scarf.py:
##########
@@ -0,0 +1,89 @@
+#
+# 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
+
+import platform
+
+import httpx
+from packaging.version import parse
+
+from airflow import __version__ as airflow_version, settings
+from airflow.configuration import conf
+
+
+def scarf_analytics():
+ if not settings.is_telemetry_collection_enabled():
+ return
+
+ # Exclude pre-releases and dev versions
+ if _version_is_prerelease(airflow_version):
+ return
+
+ scarf_domain = "https://apacheairflow.gateway.scarf.sh/scheduler"
+
+ try:
+ platform_sys, arch = get_platform_info()
+ db_version = get_database_version()
+ db_name = get_database_name()
+ executor = get_executor()
+ python_version = get_python_version()
+
+ scarf_url = (
+ f"{scarf_domain}?version={airflow_version}"
+ f"&python_version={python_version}"
+ f"&platform={platform_sys}"
+ f"&arch={arch}"
+ f"&database={db_name}"
+ f"&db_version={db_version}"
+ f"&executor={executor}"
+ )
+
+ httpx.get(scarf_url, timeout=5.0)
+ except Exception:
+ pass
+
+
+def _version_is_prerelease(version: str) -> bool:
+ return parse(version).is_prerelease
+
+
+def get_platform_info() -> tuple[str, str]:
+ return platform.system(), platform.machine()
+
+
+def get_database_version() -> str:
+ if settings.engine is None:
+ return "None"
+
+ version_info = settings.engine.dialect.server_version_info
+ # Example: (1, 2, 3) -> "1.2.3"
+ return ".".join(map(str, version_info)) if version_info else "None"
+
+
+def get_database_name() -> str:
Review Comment:
```suggestion
def get_database_engine_name() -> str:
```
IMO, could be better to call `db_name`/`database_name` occurrences in the PR
to `database_engine` / `database_engine_name` / `db_engine` / `db_engine_name`
instead so as to not confuse with the name of the database.
##########
airflow/settings.py:
##########
@@ -576,6 +576,13 @@ def initialize():
atexit.register(dispose_orm)
+def is_telemetry_collection_enabled() -> bool:
+ """Check if scarf analytics is enabled."""
+ return conf.getboolean("telemetry_collection", "enabled", fallback=True)
and (
+ os.getenv("SCARF_ANALYTICS") != "false"
Review Comment:
```suggestion
os.getenv("SCARF_ANALYTICS").strip().lower() != "false"
```
could be helpful in case someone sets it to `False` or `FALSE` etc; and/or
adds some leading/trailing whitespaces.
--
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]