Repository: pulp/pulpcore

Issue:
Adds anonymous telemetry posting along with TELEMETRY setting to disable it
By default Pulp systems will post anonymous data to https://analytics.pulpproject.org/ to help in project decision making and growth. Background and discussion on this feature's aspect has been discussed here:  https://discourse.pulpproject.org/t/proposal-telemetry/259

This change should do a few things:

* Introduce a new setting named `TELEMETRY` which when `True` would submit telemetry and not otherwise.
* Clearly identify via a release note that this has been added.
* Clearly identify to users how they can disable it.


Discussion:

Resolving patch:
diff --git a/pulpcore/app/settings.py b/pulpcore/app/settings.py
--- a/pulpcore/app/settings.py
+++ b/pulpcore/app/settings.py
@@ -289,6 +289,8 @@
 
 TASK_DIAGNOSTICS = False
 
+TELEMETRY = True
+
 # HERE STARTS DYNACONF EXTENSION LOAD (Keep at the very bottom of settings.py)
 # Read more at https://dynaconf.readthedocs.io/en/latest/guides/django.html
 from dynaconf import DjangoDynaconf, Validator  # noqa
diff --git a/pulpcore/app/tasks/telemetry.py b/pulpcore/app/tasks/telemetry.py
--- a/pulpcore/app/tasks/telemetry.py
+++ b/pulpcore/app/tasks/telemetry.py
@@ -9,7 +9,6 @@
 from google.protobuf.json_format import MessageToJson
 
 from pulpcore.app.apps import pulp_plugin_configs
-from pulpcore.app.util import get_telemetry_posting_url
 from pulpcore.app.models import SystemID
 from pulpcore.app.models.status import ContentAppStatus
 from pulpcore.app.models.task import Worker
@@ -19,6 +18,18 @@
 logger = logging.getLogger(__name__)
 
 
+PRODUCTION_URL = "https://analytics.pulpproject.org/"
+DEV_URL = "https://dev.analytics.pulpproject.org/"
+
+
+def get_telemetry_posting_url():
+    for app in pulp_plugin_configs():
+        if ".dev" in app.version:
+            return DEV_URL
+
+    return PRODUCTION_URL
+
+
 async def _num_hosts(qs):
     hosts = set()
     items = await sync_to_async(list)(qs.all())
diff --git a/pulpcore/app/util.py b/pulpcore/app/util.py
--- a/pulpcore/app/util.py
+++ b/pulpcore/app/util.py
@@ -17,12 +17,9 @@
 from pulpcore.app import models
 from pulpcore.exceptions.validation import InvalidSignatureError
 
-# a little cache so viewset_for_model doesn't have iterate over every app every time
+# a little cache so viewset_for_model doesn't have to iterate over every app every time
 _model_viewset_cache = {}
 
-PRODUCTION_URL = "https://analytics.pulpproject.org/"
-DEV_URL = "https://dev.analytics.pulpproject.org/"
-
 
 def get_url(model):
     """
@@ -249,23 +246,13 @@ def gpg_verify(public_keys, signature, detached_data=None):
     return verified
 
 
-def get_telemetry_posting_url():
-    for app in pulp_plugin_configs():
-        if ".dev" in app.version:
-            return DEV_URL
-
-    return PRODUCTION_URL
-
-
 def configure_telemetry():
-    url = get_telemetry_posting_url()
     task_name = "pulpcore.app.tasks.telemetry.post_telemetry"
     dispatch_interval = timedelta(days=1)
     name = "Post Anonymous Telemetry Periodically"
-    # Initially only dev systems send data.
-    if url == PRODUCTION_URL:
-        models.TaskSchedule.objects.filter(task_name=task_name).delete()
-    else:
+    if settings.TELEMETRY:
         models.TaskSchedule.objects.update_or_create(
             name=name, defaults={"task_name": task_name, "dispatch_interval": dispatch_interval}
         )
+    else:
+        models.TaskSchedule.objects.filter(task_name=task_name).delete()


Test patch: