Skip to content

Commit

Permalink
Do not create telemetry TaskSchedule for production systems.
Browse files Browse the repository at this point in the history
closes pulp#3015
  • Loading branch information
ipanova authored and bmbouter committed Aug 18, 2022
1 parent a492fb7 commit 9014220
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 39 deletions.
2 changes: 1 addition & 1 deletion .github/template_gitref
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2021.08.26-160-g672272f
2021.08.26-161-g7cd6cdb
10 changes: 5 additions & 5 deletions .github/workflows/scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@ source .github/workflows/scripts/utils.sh

export PULP_API_ROOT="/pulp/"

if [[ "$TEST" = "docs" || "$TEST" = "publish" ]]; then
pip install psycopg2-binary
pip install -r doc_requirements.txt
fi

cd .ci/ansible/

TAG=ci_build
Expand Down Expand Up @@ -131,6 +126,11 @@ fi

ansible-playbook build_container.yaml
ansible-playbook start_container.yaml

if [[ "$TEST" = "docs" || "$TEST" = "publish" ]]; then
pip install psycopg2-binary
cmd_prefix bash -c "cd pulpcore; pip install -r doc_requirements.txt"
fi
echo ::group::SSL
# Copy pulp CA
sudo docker cp pulp:/etc/pulp/certs/pulp_webserver.crt /usr/local/share/ca-certificates/pulp_webserver.crt
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/scripts/script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@ if [[ "$TEST" = "docs" ]]; then
pip install towncrier==19.9.0
towncrier --yes --version 4.0.0.ci
fi
cd docs
make PULP_URL="$PULP_URL" diagrams html
tar -cvf docs.tar ./_build
cmd_prefix bash -c "cd pulpcore/docs; make diagrams html; tar -cvf docs.tar ./_build"
docker cp pulp:/pulpcore//docs/docs.tar docs.tar
cd ..

if [ -f $POST_DOCS_TEST ]; then
Expand Down
1 change: 1 addition & 0 deletions CHANGES/3015.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Do not create telemetry TaskSchedule for production systems.
33 changes: 20 additions & 13 deletions pulpcore/app/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,14 +212,11 @@ def ready(self):
super().ready()
from . import checks # noqa

_configure_telemetry(self.apps)

post_migrate.connect(
_populate_system_id, sender=self, dispatch_uid="populate_system_id_identifier"
)
post_migrate.connect(
_populate_telemetry_periodic_task,
sender=self,
dispatch_uid="populate_telemetry_periodic_task_identifier",
)


def _populate_access_policies(sender, apps, verbosity, **kwargs):
Expand Down Expand Up @@ -265,14 +262,24 @@ def _populate_system_id(sender, apps, verbosity, **kwargs):
SystemID().save()


def _populate_telemetry_periodic_task(sender, apps, **kwargs):
TaskSchedule = apps.get_model("core", "TaskSchedule")
task_name = "pulpcore.app.tasks.telemetry.post_telemetry"
dispatch_interval = timedelta(days=1)
name = "Post Anonymous Telemetry Periodically"
TaskSchedule.objects.update_or_create(
name=name, defaults={"task_name": task_name, "dispatch_interval": dispatch_interval}
)
def _configure_telemetry(apps):
from django.db import connection
from pulpcore.app.util import get_telemetry_posting_url, PRODUCTION_URL

if "core_taskschedule" in connection.introspection.table_names():
url = get_telemetry_posting_url()
TaskSchedule = apps.get_model("core", "TaskSchedule")
task_name = "pulpcore.app.tasks.telemetry.post_telemetry"
dispatch_interval = timedelta(days=1)
name = "Post Anonymous Telemetry Periodically"
# Initially only dev systems receive posted data.
if url == PRODUCTION_URL:
TaskSchedule.objects.filter(task_name=task_name).delete()
else:
TaskSchedule.objects.update_or_create(
name=name, defaults={"task_name": task_name, "dispatch_interval": dispatch_interval}
)
connection.close()


def _populate_roles(sender, apps, verbosity, **kwargs):
Expand Down
19 changes: 2 additions & 17 deletions pulpcore/app/tasks/telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from asgiref.sync import sync_to_async

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
Expand All @@ -15,10 +16,6 @@
logger = logging.getLogger(__name__)


PRODUCTION_URL = "https://analytics-pulpproject-org.pulpproject.workers.dev/"
DEV_URL = "https://dev-analytics-pulpproject-org.pulpproject.workers.dev/"


async def _num_hosts(qs):
hosts = set()
items = await sync_to_async(list)(qs.all())
Expand Down Expand Up @@ -67,20 +64,8 @@ async def _system_id():
return {"system_id": str(system_id_entry.pk)}


def _get_posting_url():
for app in pulp_plugin_configs():
if ".dev" in app.version:
return DEV_URL

return PRODUCTION_URL


async def post_telemetry():
url = _get_posting_url()

if url == PRODUCTION_URL:
return # Initially only dev systems receive posted data. If we got here, bail.

url = get_telemetry_posting_url()
data = {}

awaitables = (
Expand Down
11 changes: 11 additions & 0 deletions pulpcore/app/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
# a little cache so viewset_for_model doesn't have iterate over every app every time
_model_viewset_cache = {}

PRODUCTION_URL = "https://analytics-pulpproject-org.pulpproject.workers.dev/"
DEV_URL = "https://dev-analytics-pulpproject-org.pulpproject.workers.dev/"


def get_url(model):
"""
Expand Down Expand Up @@ -243,3 +246,11 @@ def gpg_verify(public_keys, signature, detached_data=None):
if not verified.valid:
raise InvalidSignatureError(_("The signature is not valid."), verified=verified)
return verified


def get_telemetry_posting_url():
for app in pulp_plugin_configs():
if ".dev" in app.version:
return DEV_URL

return PRODUCTION_URL

0 comments on commit 9014220

Please sign in to comment.