Beispiel #1
0
def get_data_per_version(version):
    """ Returns all data in the FuctionCall table, grouped by their version. """
    with session_scope() as db_session:
        result = db_session.query(FunctionCall.execution_time, FunctionCall.version). \
            filter(FunctionCall.version == version).all()
        db_session.expunge_all()
        return result
Beispiel #2
0
def get_monitor_rules():
    """ Return all monitor rules that are currently being monitored"""
    with session_scope() as db_session:
        result = db_session.query(MonitorRule).filter(
            MonitorRule.monitor).all()
        db_session.expunge_all()
        return result
def get_test_measurements(name, suite):
    """Return all measurements for some test of some Travis build. Used for creating a box plot. """
    with session_scope() as db_session:
        result = db_session.query(TestRun).filter(
            TestRun.name == name, TestRun.suite == suite).all()
        db_session.expunge_all()
        return result
Beispiel #4
0
def get_endpoints():
    with session_scope() as db_session:
        result = db_session.query(FunctionCall.endpoint,
                                  func.count(FunctionCall.endpoint).label('cnt')). \
            group_by(FunctionCall.endpoint).order_by(asc('cnt')).all()
        db_session.expunge_all()
        return result
def get_all_measurement(endpoint):
    """Return all entries with measurements from a given endpoint. Used for creating a histogram. """
    with session_scope() as db_session:
        result = db_session.query(FunctionCall).filter(
            FunctionCall.endpoint == endpoint).all()
        db_session.expunge_all()
        return result
def get_last_accessed_times():
    """ Returns a list of all endpoints and their last accessed time. """
    with session_scope() as db_session:
        result = db_session.query(MonitorRule.endpoint,
                                  MonitorRule.last_accessed).all()
        db_session.expunge_all()
        return result
Beispiel #7
0
def add_tests_grouped(json):
    """ Adds endpoint - unit tests combinations to the database. """
    with session_scope() as db_session:
        for combination in json:
            db_session.add(
                TestsGrouped(endpoint=combination['endpoint'],
                             test_name=combination['test_name']))
def get_outliers(endpoint):
    """ Returns a list of all outliers of a specific endpoint. """
    with session_scope() as db_session:
        result = db_session.query(Outlier).filter(
            Outlier.endpoint == endpoint).all()
        db_session.expunge_all()
        return result
Beispiel #9
0
def get_versions(end=None):
    with session_scope() as db_session:
        result = db_session.query(FunctionCall.version,
                                  func.min(FunctionCall.time).label('startedUsingOn')). \
            filter((FunctionCall.endpoint == end) | (end is None)).group_by(FunctionCall.version).order_by(
            asc('startedUsingOn')).all()
    db_session.expunge_all()
    return result
def get_all_measurement_per_column(endpoint, column, value):
    """Return all entries with measurements from a given endpoint for which the column has a specific value.
    Used for creating a box plot. """
    with session_scope() as db_session:
        result = db_session.query(FunctionCall).filter(
            FunctionCall.endpoint == endpoint, column == value).all()
        db_session.expunge_all()
        return result
def get_endpoint_column_user_sorted(endpoint, column):
    """ Returns a list of entries from column in which the endpoint is involved. """
    with session_scope() as db_session:
        result = db_session.query(column). \
            filter(FunctionCall.endpoint == endpoint). \
            group_by(column).order_by(asc(column)).all()
        db_session.expunge_all()
        return result
def add_or_update_test(name, last_run, succeeded):
    """ Updates values of a test. """
    with session_scope() as db_session:
        if db_session.query(Tests).filter(Tests.name == name).count():
            db_session.query(Tests).filter(Tests.name == name). \
                update({Tests.lastRun: last_run, Tests.succeeded: succeeded})
        else:
            db_session.add(
                Tests(name=name, lastRun=last_run, succeeded=succeeded))
def get_suite_nr():
    """ Retrieves the number of the next suite to run. """
    with session_scope() as db_session:
        result = db_session.query(func.max(TestRun.suite).label('nr')).one()
        if result.nr is None:
            next_nr = 1
        else:
            next_nr = result.nr + 1
        return next_nr
def get_endpoint_column(endpoint, column):
    """ Returns a list of entries from column in which the endpoint is involved. """
    with session_scope() as db_session:
        result = db_session.query(column,
                                  func.min(FunctionCall.time).label('startedUsingOn')). \
            filter(FunctionCall.endpoint == endpoint). \
            group_by(column).order_by(asc('startedUsingOn')).all()
        db_session.expunge_all()
        return result
def get_res_current(version):
    """ Return entries of measurements with their average from the current project version only. """
    with session_scope() as db_session:
        result = db_session.query(TestRun.name,
                                  func.count(TestRun.execution_time).label('count'),
                                  func.avg(TestRun.execution_time).label('average')) \
            .filter(TestRun.version == version) \
            .group_by(TestRun.name).order_by(desc('count')).all()
        db_session.expunge_all()
        return result
def add_test_result(name, exec_time, time, version, suite, iter):
    """ Add a test result to the database. """
    with session_scope() as db_session:
        db_session.add(
            TestRun(name=name,
                    execution_time=exec_time,
                    time=time,
                    version=version,
                    suite=suite,
                    run=iter))
def get_results():
    """ Return all entries of measurements with their average. The results are grouped by their name. """
    with session_scope() as db_session:
        result = db_session.query(
            TestRun.name,
            func.count(TestRun.execution_time).label('count'),
            func.avg(TestRun.execution_time).label('average')).group_by(
                TestRun.name).order_by(desc('count')).all()
        db_session.expunge_all()
        return result
Beispiel #18
0
def get_data():
    """ Returns all data in the FunctionCall table, for the export data option. """
    with session_scope() as db_session:
        result = db_session.query(FunctionCall.endpoint,
                                  FunctionCall.execution_time,
                                  FunctionCall.time, FunctionCall.version,
                                  FunctionCall.group_by,
                                  FunctionCall.ip).all()
        db_session.expunge_all()
        return result
def get_monitor_rule(endpoint):
    """ Get the MonitorRule from a given endpoint. If no value is found, a new value 
    is added to the database and the function is called again (recursively). """
    try:
        with session_scope() as db_session:
            result = db_session.query(MonitorRule). \
                filter(MonitorRule.endpoint == endpoint).one()
            # for using the result when the session is closed, use expunge
            db_session.expunge(result)
            return result
    except NoResultFound:
        with session_scope() as db_session:
            db_session.add(
                MonitorRule(endpoint=endpoint,
                            version_added=config.version,
                            time_added=datetime.datetime.now()))

        # return new added row
        return get_monitor_rule(endpoint)
Beispiel #20
0
def get_times():
    """ Return all entries of measurements with the average and total number of execution times. The results are 
    grouped by their endpoint. """
    with session_scope() as db_session:
        result = db_session.query(
            FunctionCall.endpoint,
            func.count(FunctionCall.execution_time).label('count'),
            func.avg(FunctionCall.execution_time).label('average')).group_by(
                FunctionCall.endpoint).order_by(desc('count')).all()
        db_session.expunge_all()
        return result
Beispiel #21
0
def get_reqs_endpoint_day():
    """ Retrieves the number of requests per endpoint per day. """
    with session_scope() as db_session:
        query = text("""select strftime('%Y-%m-%d', time) AS newTime,
                               count(endpoint) AS cnt,
                               endpoint
                        from functioncalls 
                        group by newTime, endpoint""")
        result = db_session.execute(query)
        data = result.fetchall()
        return data
def get_line_results():
    with session_scope() as db_session:
        result = db_session.query(
            TestRun.version,
            func.avg(TestRun.execution_time).label('avg'),
            func.min(TestRun.execution_time).label('min'),
            func.max(TestRun.execution_time).label('max'),
            func.count(TestRun.execution_time).label('count')).group_by(
                TestRun.version).order_by(desc('count')).all()
        db_session.expunge_all()
        return result
def get_data_from(time_from):
    """
        Returns all data in the FunctionCall table, for the export data option.
        This function returns all data after the time_from date.
    """
    with session_scope() as db_session:
        result = db_session.query(
            FunctionCall.endpoint, FunctionCall.execution_time,
            FunctionCall.time, FunctionCall.version, FunctionCall.group_by,
            FunctionCall.ip).filter(FunctionCall.time >= time_from)
        db_session.expunge_all()
        return result
def get_endpoint_results(endpoint, column):
    """ Returns a list of entries with measurements in which the endpoint is involved.
    The entries are grouped by their version and the given column. """
    with session_scope() as db_session:
        result = db_session.query(FunctionCall.version,
                                  column,
                                  func.count(FunctionCall.execution_time).label('count'),
                                  func.avg(FunctionCall.execution_time).label('average')
                                  ).filter(FunctionCall.endpoint == endpoint). \
            group_by(FunctionCall.version, column).all()
        db_session.expunge_all()
        return result
def get_line_results(endpoint):
    with session_scope() as db_session:
        query = text("""select
                datetime(CAST(strftime('%s', time)/3600 AS INT)*3600, 'unixepoch') AS newTime, 
                avg(execution_time) AS avg,
                min(execution_time) as min,
                max(execution_time) as max,
                count(execution_time) as count
            from functioncalls 
            where endpoint=:val group by newTime""")
        result = db_session.execute(query, {'val': endpoint})
        data = result.fetchall()
        return data
Beispiel #26
0
def get_monitor_data():
    """
    Returns all data in the rules-table. This table contains which endpoints are being
    monitored and which are not.
    :return: all data from the database in the rules-table.
    """
    with session_scope() as db_session:
        result = db_session.query(MonitorRule.endpoint,
                                  MonitorRule.last_accessed,
                                  MonitorRule.monitor, MonitorRule.time_added,
                                  MonitorRule.version_added).all()
        db_session.expunge_all()
        return result
def get_num_requests(endpoint):
    """ Returns a list with all dates on which an endpoint is accessed.
        :param endpoint: if None, the result is the sum of all endpoints
    """
    with session_scope() as db_session:
        query = text("""select
                datetime(CAST(strftime('%s', time)/3600 AS INT)*3600, 'unixepoch') AS newTime,
                count(execution_time) as count
                from functioncalls
                where (endpoint=:val OR :val='None') group by newTime""")
        result = db_session.execute(query, {'val': str(endpoint)})
        data = result.fetchall()
        return data
def add_outlier(endpoint, execution_time, stack_info):
    """ Collects information (request-parameters, memory, stacktrace) about the request and adds it in the database. """
    with session_scope() as db_session:
        outlier = Outlier(endpoint=endpoint,
                          request_values=json.dumps(request.values),
                          request_headers=str(request.headers),
                          request_environment=str(request.environ),
                          request_url=str(request.url),
                          cpu_percent=stack_info.cpu_percent,
                          memory=stack_info.memory,
                          stacktrace=stack_info.stacktrace,
                          execution_time=execution_time,
                          time=datetime.datetime.now())
        db_session.add(outlier)
Beispiel #29
0
def add_function_call(time, endpoint):
    """ Add a measurement to the database. """
    with session_scope() as db_session:
        group_by = None
        if config.get_group_by:
            group_by = config.get_group_by()

        ip = request.environ['REMOTE_ADDR']
        call = FunctionCall(endpoint=endpoint,
                            execution_time=time,
                            version=config.version,
                            time=datetime.datetime.now(),
                            group_by=str(group_by),
                            ip=ip)
        db_session.add(call)
Beispiel #30
0
def reset_monitor_endpoints():
    """ Update all monitor rules in the database and set them to false. """
    with session_scope() as db_session:
        db_session.query(MonitorRule).update({MonitorRule.monitor: False})