Exemple #1
0
def record(fact_type, request_or_user, info):
    # Disabled to save money on running fewer servers.
    return

    extra_info = {'type': fact_type, 'ts': time.time()}

    if hasattr(request_or_user, 'user'):
        request = request_or_user
        user = request.user
    else:
        request = None
        user = request_or_user

    if request:
        extra_info['session_key'] = request.session.session_key
        extra_info['ip'] = request.META.get('REMOTE_ADDR')
        extra_info['utma'] = request.COOKIES.get('__utma')

        if not hasattr(request, "experiments"):
            request.experiments = create_experiments_for_request(request)
            logging.debug(
                "Request did not have experiments ... recreating ...")

        experiments = request.experiments
    elif user:
        experiments = user.redis.experiments
    else:
        raise Exception("request_or_user is required.")

    if user.is_authenticated():
        extra_info['user'] = user.id

    if experiments:
        experiments_mapping = dict(
            (experiment.name, branch.name)
            for experiment, branch in experiments.get_all_current_branches())
        if experiments_mapping:
            extra_info["experiments"] = experiments_mapping

    info = dict(info, **extra_info)

    if settings.DEBUG:
        debug_fact_channel().publish(info)

    @bgwork.defer
    def make_request():
        try:
            req = urllib2.Request(
                "http://%s/" % settings.FACT_HOST,
                headers={'X-Fact-Log': util.backend_dumps(info)})
            urllib2.urlopen(req, timeout=3)
        except IOError:
            from canvas.models import Metrics
            Metrics.fact_record_fail.record(request, record_fact=False)
def record(fact_type, request_or_user, info):
    # Disabled to save money on running fewer servers.
    return

    extra_info = { 'type': fact_type, 'ts': time.time()}

    if hasattr(request_or_user, 'user'):
        request = request_or_user
        user = request.user
    else:
        request = None
        user = request_or_user

    if request:
        extra_info['session_key'] = request.session.session_key
        extra_info['ip'] = request.META.get('REMOTE_ADDR')
        extra_info['utma'] = request.COOKIES.get('__utma')

        if not hasattr(request, "experiments"):
            request.experiments = create_experiments_for_request(request)
            logging.debug("Request did not have experiments ... recreating ...")

        experiments = request.experiments
    elif user:
        experiments = user.redis.experiments
    else:
        raise Exception("request_or_user is required.")

    if user.is_authenticated():
        extra_info['user'] = user.id

    if experiments:
        experiments_mapping = dict((experiment.name, branch.name) for experiment, branch in experiments.get_all_current_branches())
        if experiments_mapping:
            extra_info["experiments"] = experiments_mapping

    info = dict(info, **extra_info)

    if settings.DEBUG:
        debug_fact_channel().publish(info)

    @bgwork.defer
    def make_request():
        try:
            req = urllib2.Request("http://%s/" % settings.FACT_HOST, headers={'X-Fact-Log': util.backend_dumps(info)})
            urllib2.urlopen(req, timeout=3)
        except IOError:
            from canvas.models import Metrics
            Metrics.fact_record_fail.record(request, record_fact=False)
Exemple #3
0
    def process_request(self, request):
        request._start_times = times()
        CachedCall.inprocess_cache.flush()

        # Associate the correct experiments backend for this request
        request.experiments = create_experiments_for_request(request)

        request.user_kv = {} #TODO: probably use a FrozenDict when we can write to the authenticated user_kv.
        if request.user.is_authenticated():
            request.user_kv = request.user.redis.user_kv.hgetall()

        request.config = Config

        # As a side effect, sets the CSRF cookie
        django.middleware.csrf.get_token(request)
    def __init__(self, user=None, path=None, GET={}, extra_META={}):
        HttpRequest.__init__(self)
        self.user = user or AnonymousUser()
        self.user_kv = {}
        if hasattr(self.user, "redis"):
            self.user_kv = self.user.redis.user_kv.hgetall()
        self.session = SessionStore(session_key="skey")
        self.experiments = create_experiments_for_request(self)
        self.META = {"REMOTE_ADDR": "127.0.0.1", "PATH_INFO": path}
        self.META.update(extra_META)
        if path is not None:
            self.path = path

        if GET is not None:
            self.GET = QueryDict(GET)
Exemple #5
0
    def __init__(self, user=None, path=None, GET={}, extra_META={}):
        HttpRequest.__init__(self)
        self.user = user or AnonymousUser()
        self.user_kv = {}
        if hasattr(self.user, 'redis'):
            self.user_kv = self.user.redis.user_kv.hgetall()
        self.session = SessionStore(session_key='skey')
        self.experiments = create_experiments_for_request(self)
        self.META = {"REMOTE_ADDR": "127.0.0.1", "PATH_INFO": path}
        self.META.update(extra_META)
        if path is not None:
            self.path = path

        if GET is not None:
            self.GET = QueryDict(GET)
Exemple #6
0
    def process_request(self, request):
        request._start_times = times()
        CachedCall.inprocess_cache.flush()

        # Associate the correct experiments backend for this request
        request.experiments = create_experiments_for_request(request)

        request.user_kv = {
        }  #TODO: probably use a FrozenDict when we can write to the authenticated user_kv.
        if request.user.is_authenticated():
            request.user_kv = request.user.redis.user_kv.hgetall()

        request.config = Config

        # As a side effect, sets the CSRF cookie
        django.middleware.csrf.get_token(request)