diff --git a/endpoints/trackhelper.py b/endpoints/trackhelper.py index b3e2d86eb..7635d2a19 100644 --- a/endpoints/trackhelper.py +++ b/endpoints/trackhelper.py @@ -1,4 +1,5 @@ import logging +import random from app import analytics, app, userevents from data import model @@ -7,7 +8,7 @@ from auth.auth_context import get_authenticated_user, get_validated_token, get_v logger = logging.getLogger(__name__) -def track_and_log(event_name, repo, **kwargs): +def track_and_log(event_name, repo, analytics_name=None, analytics_sample=1, **kwargs): repository = repo.name namespace = repo.namespace_user.username metadata = { @@ -62,8 +63,11 @@ def track_and_log(event_name, repo, **kwargs): event.publish_event_data('docker-cli', user_event_data) # Save the action to mixpanel. - logger.debug('Logging the %s to Mixpanel', event_name) - analytics.track(analytics_id, event_name, extra_params) + if random.random() < analytics_sample: + if analytics_name is None: + analytics_name = event_name + logger.debug('Logging the %s to Mixpanel', analytics_name) + analytics.track(analytics_id, analytics_name, extra_params) # Log the action to the database. logger.debug('Logging the %s to logs system', event_name) diff --git a/endpoints/v1/index.py b/endpoints/v1/index.py index 457ffd43d..4d701b918 100644 --- a/endpoints/v1/index.py +++ b/endpoints/v1/index.py @@ -270,7 +270,7 @@ def get_repository_images(namespace, repository): resp = make_response(json.dumps([]), 200) resp.mimetype = 'application/json' - track_and_log('pull_repo', repo) + track_and_log('pull_repo', repo, analytics_name='pull_repo_100x', analytics_sample=0.01) return resp abort(403)