Sample pull_repo events

This commit is contained in:
Silas Sewell 2015-09-15 15:23:06 -04:00
parent 68deff0e24
commit a8183ed87b
2 changed files with 8 additions and 4 deletions

View file

@ -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)

View file

@ -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)