示例#1
0
def loadtest(request):
    # The multimech results api is kinda all over the place.
    # the docs are here: http://testutils.org/multi-mechanize/datastore.html

    scripts = ["submit_form.py", "ota_restore.py"]

    tests = []
    # datetime info seems to be buried in GlobalConfig.results[0].run_id,
    # which makes ORM-level sorting problematic
    for gc in Session.query(GlobalConfig).all()[::-1]:
        gc.scripts = dict((uc.script, uc) for uc in gc.user_group_configs)
        if gc.results:
            for script, uc in gc.scripts.items():
                uc.results = filter(lambda res: res.user_group_name == uc.user_group, gc.results)
            test = {"datetime": gc.results[0].run_id, "run_time": gc.run_time, "results": gc.results}
            for script in scripts:
                test[script.split(".")[0]] = gc.scripts.get(script)
            tests.append(test)

    context = get_hqadmin_base_context(request)
    context.update({"tests": tests, "hide_filters": True})

    date_axis = Axis(label="Date", dateFormat="%m/%d/%Y")
    tests_axis = Axis(label="Number of Tests in 30s")
    chart = LineChart("HQ Load Test Performance", date_axis, tests_axis)
    submit_data = []
    ota_data = []
    total_data = []
    max_val = 0
    max_date = None
    min_date = None
    for test in tests:
        date = test["datetime"]
        total = len(test["results"])
        max_val = total if total > max_val else max_val
        max_date = date if not max_date or date > max_date else max_date
        min_date = date if not min_date or date < min_date else min_date
        submit_data.append({"x": date, "y": len(test["submit_form"].results)})
        ota_data.append({"x": date, "y": len(test["ota_restore"].results)})
        total_data.append({"x": date, "y": total})

    deployments = [row["key"][1] for row in HqDeploy.get_list(settings.SERVER_ENVIRONMENT, min_date, max_date)]
    deploy_data = [{"x": min_date, "y": 0}]
    for date in deployments:
        deploy_data.extend([{"x": date, "y": 0}, {"x": date, "y": max_val}, {"x": date, "y": 0}])
    deploy_data.append({"x": max_date, "y": 0})

    chart.add_dataset("Deployments", deploy_data)
    chart.add_dataset("Form Submission Count", submit_data)
    chart.add_dataset("OTA Restore Count", ota_data)
    chart.add_dataset("Total Count", total_data)

    context["charts"] = [chart]

    template = "hqadmin/loadtest.html"
    return render(request, template, context)
    def handle(self, *args, **options):
        start = parser.parse(options['startdate'])
        enddate = options['enddate']
        end = parser.parse(enddate) if enddate else datetime.now()

        ds = HqDeploy.get_list('production', start, end)
        ids = [d['id'] for d in ds]
        sha_prev = None
        print_row('Deploy Date', "Commit Date", "Diff")
        for id in ids:
            d = HqDeploy.get(id)
            s = d.code_snapshot['commits'][0]
            sha = s['sha']
            url = "https://github.com/dimagi/commcare-hq/compare/{sha_prev}...{sha}".format(
                sha=sha, sha_prev=sha_prev)
            print_row(d.date, s['date'], url)
            sha_prev = sha
示例#3
0
    def handle(self, *args, **options):
        start = parser.parse(options['startdate'])
        enddate = options['enddate']
        end = parser.parse(enddate) if enddate else datetime.utcnow()

        ds = HqDeploy.get_list('production', start, end)
        ids = [d['id'] for d in ds]
        sha_prev = None
        print_row('Deploy Date', "Commit Date", "Diff")
        for id in ids:
            d = HqDeploy.get(id)
            s = d.code_snapshot['commits'][0]
            sha = s['sha']
            url = "https://github.com/dimagi/commcare-hq/compare/{sha_prev}...{sha}".format(
                sha=sha,
                sha_prev=sha_prev
            )
            print_row(d.date, s['date'], url)
            sha_prev = sha
示例#4
0
def loadtest(request):
    # The multimech results api is kinda all over the place.
    # the docs are here: http://testutils.org/multi-mechanize/datastore.html

    db_settings = settings.DATABASES["default"]
    db_settings['PORT'] = db_settings.get('PORT', '') or '5432'
    db_url = "postgresql://{USER}:{PASSWORD}@{HOST}:{PORT}/{NAME}".format(
        **db_settings)
    engine = create_engine(db_url)
    session = sessionmaker(bind=engine)
    current = session()

    scripts = ['submit_form.py', 'ota_restore.py']

    tests = []
    # datetime info seems to be buried in GlobalConfig.results[0].run_id,
    # which makes ORM-level sorting problematic
    for gc in current.query(GlobalConfig).all()[::-1]:
        gc.scripts = dict((uc.script, uc) for uc in gc.user_group_configs)
        if gc.results:
            for script, uc in gc.scripts.items():
                uc.results = filter(
                    lambda res: res.user_group_name == uc.user_group,
                    gc.results)
            test = {
                'datetime': gc.results[0].run_id,
                'run_time': gc.run_time,
                'results': gc.results,
            }
            for script in scripts:
                test[script.split('.')[0]] = gc.scripts.get(script)
            tests.append(test)

    context = get_hqadmin_base_context(request)
    context.update({
        "tests": tests,
        "hide_filters": True,
    })

    date_axis = Axis(label="Date", dateFormat="%m/%d/%Y")
    tests_axis = Axis(label="Number of Tests in 30s")
    chart = LineChart("HQ Load Test Performance", date_axis, tests_axis)
    submit_data = []
    ota_data = []
    total_data = []
    max_val = 0
    max_date = None
    min_date = None
    for test in tests:
        date = test['datetime']
        total = len(test['results'])
        max_val = total if total > max_val else max_val
        max_date = date if not max_date or date > max_date else max_date
        min_date = date if not min_date or date < min_date else min_date
        submit_data.append({'x': date, 'y': len(test['submit_form'].results)})
        ota_data.append({'x': date, 'y': len(test['ota_restore'].results)})
        total_data.append({'x': date, 'y': total})

    deployments = [
        row['key'][1] for row in HqDeploy.get_list(settings.SERVER_ENVIRONMENT,
                                                   min_date, max_date)
    ]
    deploy_data = [{'x': min_date, 'y': 0}]
    for date in deployments:
        deploy_data.extend([{
            'x': date,
            'y': 0
        }, {
            'x': date,
            'y': max_val
        }, {
            'x': date,
            'y': 0
        }])
    deploy_data.append({'x': max_date, 'y': 0})

    chart.add_dataset("Deployments", deploy_data)
    chart.add_dataset("Form Submission Count", submit_data)
    chart.add_dataset("OTA Restore Count", ota_data)
    chart.add_dataset("Total Count", total_data)

    context['charts'] = [chart]

    template = "hqadmin/loadtest.html"
    return render(request, template, context)
示例#5
0
def loadtest(request):
    # The multimech results api is kinda all over the place.
    # the docs are here: http://testutils.org/multi-mechanize/datastore.html

    db_settings = settings.DATABASES["default"]
    db_settings['PORT'] = db_settings.get('PORT', '') or '5432'
    db_url = "postgresql://{USER}:{PASSWORD}@{HOST}:{PORT}/{NAME}".format(
        **db_settings
    )
    engine = create_engine(db_url)
    session = sessionmaker(bind=engine)
    current = session()

    scripts = ['submit_form.py', 'ota_restore.py']

    tests = []
    # datetime info seems to be buried in GlobalConfig.results[0].run_id,
    # which makes ORM-level sorting problematic
    for gc in current.query(GlobalConfig).all()[::-1]:
        gc.scripts = dict((uc.script, uc) for uc in gc.user_group_configs)
        if gc.results:
            for script, uc in gc.scripts.items():
                uc.results = filter(
                    lambda res: res.user_group_name == uc.user_group,
                    gc.results
                )
            test = {
                'datetime': gc.results[0].run_id,
                'run_time': gc.run_time,
                'results': gc.results,
            }
            for script in scripts:
                test[script.split('.')[0]] = gc.scripts.get(script)
            tests.append(test)

    context = get_hqadmin_base_context(request)
    context.update({
        "tests": tests,
        "hide_filters": True,
    })

    date_axis = Axis(label="Date", dateFormat="%m/%d/%Y")
    tests_axis = Axis(label="Number of Tests in 30s")
    chart = LineChart("HQ Load Test Performance", date_axis, tests_axis)
    submit_data = []
    ota_data = []
    total_data = []
    max_val = 0
    max_date = None
    min_date = None
    for test in tests:
        date = test['datetime']
        total = len(test['results'])
        max_val = total if total > max_val else max_val
        max_date = date if not max_date or date > max_date else max_date
        min_date = date if not min_date or date < min_date else min_date
        submit_data.append({'x': date, 'y': len(test['submit_form'].results)})
        ota_data.append({'x': date, 'y': len(test['ota_restore'].results)})
        total_data.append({'x': date, 'y': total})

    deployments = [row['key'][1] for row in HqDeploy.get_list(settings.SERVER_ENVIRONMENT, min_date, max_date)]
    deploy_data = [{'x': min_date, 'y': 0}]
    for date in deployments:
        deploy_data.extend([{'x': date, 'y': 0}, {'x': date, 'y': max_val}, {'x': date, 'y': 0}])
    deploy_data.append({'x': max_date, 'y': 0})

    chart.add_dataset("Deployments", deploy_data)
    chart.add_dataset("Form Submission Count", submit_data)
    chart.add_dataset("OTA Restore Count", ota_data)
    chart.add_dataset("Total Count", total_data)

    context['charts'] = [chart]

    template = "hqadmin/loadtest.html"
    return render(request, template, context)