Esempio n. 1
0
def _get_group_list(request, project, view=None):
    filters = []
    for cls in get_filters(Group, project):
        try:
            filters.append(cls(request, project))
        except Exception, e:
            logger = logging.getLogger('sentry.filters')
            logger.exception('Error initializing filter %r: %s', cls, e)
Esempio n. 2
0
def _get_group_list(request, project):
    filters = []
    for cls in get_filters(Group, project):
        try:
            filters.append(cls(request, project))
        except Exception, e:
            logger = logging.getLogger('sentry.filters')
            logger.exception('Error initializing filter %r: %s', cls, e)
Esempio n. 3
0
File: events.py Progetto: 755/sentry
def event_list(request, team, project):
    filters = []
    for cls in get_filters(Event, project):
        try:
            filters.append(cls(request, project))
        except Exception, e:
            logger = logging.getLogger('sentry.filters')
            logger.exception('Error initializing filter %r: %s', cls, e)
Esempio n. 4
0
def register_indexes(**kwargs):
    """
    Grabs all required indexes from filters and registers them.
    """
    from sentry.filters import get_filters
    logger = logging.getLogger('sentry.setup')
    for cls in (f for f in get_filters() if f.column.startswith('data__')):
        MessageIndex.objects.register_index(cls.column, index_to='group')
        logger.debug('Registered index for for %r', cls.column)
Esempio n. 5
0
def register_indexes(**kwargs):
    """
    Grabs all required indexes from filters and registers them.
    """
    from sentry.filters import get_filters
    logger = logging.getLogger('sentry.setup')
    for cls in (f for f in get_filters() if f.column.startswith('data__')):
        MessageIndex.objects.register_index(cls.column, index_to='group')
        logger.debug('Registered index for for %r', cls.column)
Esempio n. 6
0
def _get_group_list(request, project):
    filters = []
    for cls in get_filters(Group, project):
        try:
            filters.append(cls(request, project))
        except Exception as e:
            logger = logging.getLogger('sentry.filters')
            logger.exception('Error initializing filter %r: %s', cls, e)

    event_list = Group.objects
    if request.user.is_authenticated() and request.GET.get('bookmarks'):
        event_list = event_list.filter(
            bookmark_set__project=project,
            bookmark_set__user=request.user,
        )
    else:
        event_list = event_list.filter(project=project)

    for filter_ in filters:
        try:
            if not filter_.is_set():
                continue
            event_list = filter_.get_query_set(event_list)
        except Exception as e:
            logger = logging.getLogger('sentry.filters')
            logger.exception('Error processing filter %r: %s', cls, e)

    date_from = request.GET.get('df')
    time_from = request.GET.get('tf')
    date_to = request.GET.get('dt')
    time_to = request.GET.get('tt')
    date_type = request.GET.get('date_type')

    today = timezone.now()

    # date format is Y-m-d
    if any(x is not None for x in [date_from, time_from, date_to, time_to]):
        date_from, date_to = parse_date(date_from, time_from), parse_date(
            date_to, time_to)
    else:
        date_from = today - datetime.timedelta(days=5)
        date_to = None

    if date_type == 'first_seen':
        if date_from:
            event_list = event_list.filter(first_seen__gte=date_from)
        elif date_to:
            event_list = event_list.filter(first_seen__lte=date_to)
    else:
        if date_from and date_to:
            event_list = event_list.filter(
                groupcountbyminute__date__gte=date_from,
                groupcountbyminute__date__lte=date_to,
            )
        elif date_from:
            event_list = event_list.filter(last_seen__gte=date_from)
        elif date_to:
            event_list = event_list.filter(last_seen__lte=date_to)

    sort = request.GET.get('sort') or request.session.get('streamsort')
    if sort not in SORT_OPTIONS:
        sort = DEFAULT_SORT_OPTION

    # Save last sort in session
    if sort != request.session.get('streamsort'):
        request.session['streamsort'] = sort

    if sort.startswith('accel_') and not has_trending():
        sort = DEFAULT_SORT_OPTION

    engine = get_db_engine('default')
    if engine.startswith('sqlite'):
        score_clause = SQLITE_SORT_CLAUSES.get(sort)
        filter_clause = SQLITE_SCORE_CLAUSES.get(sort)
    elif engine.startswith('mysql'):
        score_clause = MYSQL_SORT_CLAUSES.get(sort)
        filter_clause = MYSQL_SCORE_CLAUSES.get(sort)
    elif engine.startswith('oracle'):
        score_clause = ORACLE_SORT_CLAUSES.get(sort)
        filter_clause = ORACLE_SCORE_CLAUSES.get(sort)
    elif engine in ('django_pytds', 'sqlserver_ado', 'sql_server.pyodbc'):
        score_clause = MSSQL_SORT_CLAUSES.get(sort)
        filter_clause = MSSQL_SCORE_CLAUSES.get(sort)
    else:
        score_clause = SORT_CLAUSES.get(sort)
        filter_clause = SCORE_CLAUSES.get(sort)

    # IMPORTANT: All filters must already be applied once we reach this point

    if sort == 'tottime':
        event_list = event_list.filter(time_spent_count__gt=0)
    elif sort == 'avgtime':
        event_list = event_list.filter(time_spent_count__gt=0)
    elif sort.startswith('accel_'):
        event_list = Group.objects.get_accelerated([project.id],
                                                   event_list,
                                                   minutes=int(
                                                       sort.split('_', 1)[1]))

    if score_clause:
        event_list = event_list.extra(select={'sort_value': score_clause}, )
        # HACK: don't sort by the same column twice
        if sort == 'date':
            event_list = event_list.order_by('-last_seen')
        else:
            event_list = event_list.order_by('-sort_value', '-last_seen')
        cursor = request.GET.get('cursor', request.GET.get('c'))
        if cursor:
            event_list = event_list.extra(
                where=['%s > %%s' % filter_clause],
                params=[float(cursor)],
            )

    return {
        'filters': filters,
        'event_list': event_list,
        'date_from': date_from,
        'date_to': date_to,
        'today': today,
        'sort': sort,
        'date_type': date_type
    }
Esempio n. 7
0
def _get_group_list(request, project):
    filters = []
    for cls in get_filters(Group, project):
        try:
            filters.append(cls(request, project))
        except Exception as e:
            logger = logging.getLogger('sentry.filters')
            logger.exception('Error initializing filter %r: %s', cls, e)

    event_list = Group.objects
    if request.user.is_authenticated() and request.GET.get('bookmarks'):
        event_list = event_list.filter(
            bookmark_set__project=project,
            bookmark_set__user=request.user,
        )
    else:
        event_list = event_list.filter(project=project)

    for filter_ in filters:
        try:
            if not filter_.is_set():
                continue
            event_list = filter_.get_query_set(event_list)
        except Exception as e:
            logger = logging.getLogger('sentry.filters')
            logger.exception('Error processing filter %r: %s', cls, e)

    date_from = request.GET.get('df')
    time_from = request.GET.get('tf')
    date_to = request.GET.get('dt')
    time_to = request.GET.get('tt')
    date_type = request.GET.get('date_type')

    today = timezone.now()

    # date format is Y-m-d
    if any(x is not None for x in [date_from, time_from, date_to, time_to]):
        date_from, date_to = parse_date(date_from, time_from), parse_date(date_to, time_to)
    else:
        date_from = today - datetime.timedelta(days=5)
        date_to = None

    if date_type == 'first_seen':
        if date_from:
            event_list = event_list.filter(first_seen__gte=date_from)
        elif date_to:
            event_list = event_list.filter(first_seen__lte=date_to)
    else:
        if date_from and date_to:
            event_list = event_list.filter(
                first_seen__gte=date_from,
                last_seen__lte=date_to,
            )
        elif date_from:
            event_list = event_list.filter(last_seen__gte=date_from)
        elif date_to:
            event_list = event_list.filter(last_seen__lte=date_to)

    sort = request.GET.get('sort') or request.session.get('streamsort')
    if sort not in SORT_OPTIONS:
        sort = DEFAULT_SORT_OPTION

    # Save last sort in session
    if sort != request.session.get('streamsort'):
        request.session['streamsort'] = sort

    engine = get_db_engine('default')
    if engine.startswith('sqlite'):
        score_clause = SQLITE_SORT_CLAUSES.get(sort)
        filter_clause = SQLITE_SCORE_CLAUSES.get(sort)
    elif engine.startswith('mysql'):
        score_clause = MYSQL_SORT_CLAUSES.get(sort)
        filter_clause = MYSQL_SCORE_CLAUSES.get(sort)
    elif engine.startswith('oracle'):
        score_clause = ORACLE_SORT_CLAUSES.get(sort)
        filter_clause = ORACLE_SCORE_CLAUSES.get(sort)
    elif engine in ('django_pytds', 'sqlserver_ado', 'sql_server.pyodbc'):
        score_clause = MSSQL_SORT_CLAUSES.get(sort)
        filter_clause = MSSQL_SCORE_CLAUSES.get(sort)
    else:
        score_clause = SORT_CLAUSES.get(sort)
        filter_clause = SCORE_CLAUSES.get(sort)

    # IMPORTANT: All filters must already be applied once we reach this point

    if sort == 'tottime':
        event_list = event_list.filter(time_spent_count__gt=0)
    elif sort == 'avgtime':
        event_list = event_list.filter(time_spent_count__gt=0)

    if score_clause:
        event_list = event_list.extra(
            select={'sort_value': score_clause},
        )
        # HACK: don't sort by the same column twice
        if sort == 'date':
            event_list = event_list.order_by('-last_seen')
        else:
            event_list = event_list.order_by('-sort_value', '-last_seen')
        cursor = request.GET.get('cursor', request.GET.get('c'))
        if cursor:
            event_list = event_list.extra(
                where=['%s > %%s' % filter_clause],
                params=[float(cursor)],
            )

    return {
        'filters': filters,
        'event_list': event_list,
        'date_from': date_from,
        'date_to': date_to,
        'today': today,
        'sort': sort,
        'date_type': date_type
    }