Skip to content

Commit

Permalink
Merge c2413cd into 646b630
Browse files Browse the repository at this point in the history
  • Loading branch information
dianaclarke committed Apr 22, 2021
2 parents 646b630 + c2413cd commit 71736e1
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 9 deletions.
2 changes: 1 addition & 1 deletion conbench/api/benchmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def get(self):
filters=[Summary.run_id == run_id],
)
else:
summaries = Summary.all()
summaries = Summary.all(order_by=Summary.timestamp.desc(), limit=500)
return self.serializer.many.dump(summaries)

@flask_login.login_required
Expand Down
22 changes: 21 additions & 1 deletion conbench/api/runs.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import flask as f

from ..api import rule
from ..api._endpoint import ApiEndpoint
from ..entities._entity import NotFound
from ..entities.commit import Commit
from ..entities.run import Run, RunSerializer


Expand Down Expand Up @@ -44,10 +47,27 @@ def get(self):
responses:
"200": "RunList"
"401": "401"
parameters:
- in: query
name: sha
schema:
type: string
- in: query
name: machine_id
schema:
type: string
tags:
- Runs
"""
runs = Run.all(order_by=Run.timestamp.desc(), limit=500)
sha = f.request.args.get("sha")
machine_id = f.request.args.get("machine_id")
if sha and machine_id:
runs = Run.search(
filters=[Run.machine_id == machine_id, Commit.sha == sha],
joins=[Commit],
)
else:
runs = Run.all(order_by=Run.timestamp.desc(), limit=500)
return self.serializer.many.dump(runs)


Expand Down
14 changes: 14 additions & 0 deletions conbench/app/benchmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,20 @@ def get_display_run(self, run_id):
self._augment(run)
return run

def get_display_baseline_run(self, sha, machine_id):
response = self.api_get("api.runs", sha=sha, machine_id=machine_id)
if response.status_code != 200:
self.flash("Error getting run.")
return None

runs = response.json
if runs:
run = runs[0]
self._augment(run)
return run

return None

def get_display_runs(self):
runs, response = self._get_runs()
if response.status_code != 200:
Expand Down
22 changes: 19 additions & 3 deletions conbench/app/runs.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,35 @@
import flask as f

from ..app import rule
from ..app._endpoint import AppEndpoint
from ..app._util import augment
from ..app.benchmarks import RunMixin
from ..config import Config


class RunPlot(AppEndpoint):
def page(self, benchmarks):
class RunPlot(AppEndpoint, RunMixin):
def page(self, benchmarks, baseline_run, contender_run):
compare_runs_url = None
if baseline_run and contender_run:
compare = f'{baseline_run["id"]}...{contender_run["id"]}'
compare_runs_url = f.url_for("app.compare-runs", compare_ids=compare)

return self.render_template(
"run.html",
application=Config.APPLICATION_NAME,
title="Run",
benchmarks=benchmarks,
compare_runs_url=compare_runs_url,
)

def get(self, run_id):
contender_run, baseline_run = self.get_display_run(run_id), None
if contender_run:
parent = contender_run["commit"]["parent_sha"]
baseline_run = self.get_display_baseline_run(
parent, contender_run["machine"]["id"]
)

benchmarks, response = self._get_benchmarks(run_id)
if response.status_code != 200:
self.flash("Error getting benchmarks.")
Expand All @@ -22,7 +38,7 @@ def get(self, run_id):
for benchmark in benchmarks:
augment(benchmark)

return self.page(benchmarks)
return self.page(benchmarks, baseline_run, contender_run)

def _get_benchmarks(self, run_id):
response = self.api_get("api.benchmarks", run_id=run_id)
Expand Down
3 changes: 3 additions & 0 deletions conbench/entities/summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ def create(data):
session.headers = {"Authorization": f"Bearer {token}"}

response = session.get(url) if session else requests.get(url)
if response.status_code != 200:
print(response.json())

github = parse_commit(response.json())
commit = Commit.create(
{
Expand Down
5 changes: 5 additions & 0 deletions conbench/templates/run.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
{% if benchmarks %}
<li class="breadcrumb-item active" aria-current="page">{{ benchmarks[0].stats.run_id }}</li>
{% endif %}
{% if compare_runs_url %}
<span align="right" style="display:inline-block; float: right;">
<a href="{{ compare_runs_url }}">compare <span class="glyphicon glyphicon-arrow-right"></span></a>
</span>
{% endif %}
</ol>
</nav>

Expand Down
4 changes: 4 additions & 0 deletions conbench/tests/api/_expected_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1035,6 +1035,10 @@
"/api/runs/": {
"get": {
"description": "Get a list of runs.",
"parameters": [
{"in": "query", "name": "sha", "schema": {"type": "string"}},
{"in": "query", "name": "machine_id", "schema": {"type": "string"}},
],
"responses": {
"200": {"$ref": "#/components/responses/RunList"},
"401": {"$ref": "#/components/responses/401"},
Expand Down
6 changes: 3 additions & 3 deletions conbench/tests/api/test_benchmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,23 +163,23 @@ def test_benchmark_list_filter_by_name(self, client):
summary = create_benchmark_summary(name="bbb")
create_benchmark_summary(name="ccc")
response = client.get("/api/benchmarks/?name=bbb")
self.assert_200_ok(response, contains=_expected_entity(summary))
self.assert_200_ok(response, [_expected_entity(summary)])

def test_benchmark_list_filter_by_batch_id(self, client):
self.authenticate(client)
create_benchmark_summary(batch_id="10")
summary = create_benchmark_summary(batch_id="20")
create_benchmark_summary(batch_id="30")
response = client.get("/api/benchmarks/?batch_id=20")
self.assert_200_ok(response, contains=_expected_entity(summary))
self.assert_200_ok(response, [_expected_entity(summary)])

def test_benchmark_list_filter_by_run_id(self, client):
self.authenticate(client)
create_benchmark_summary(run_id="100")
summary = create_benchmark_summary(run_id="200")
create_benchmark_summary(run_id="300")
response = client.get("/api/benchmarks/?run_id=200")
self.assert_200_ok(response, contains=_expected_entity(summary))
self.assert_200_ok(response, [_expected_entity(summary)])


class TestBenchmarkPost(_asserts.PostEnforcer):
Expand Down
21 changes: 20 additions & 1 deletion conbench/tests/api/test_runs.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import copy
import urllib

from ...api._examples import _api_run_entity
from ...entities.summary import Summary
Expand Down Expand Up @@ -44,8 +45,26 @@ def _create(self):
summary = create_benchmark_summary()
return summary.run

def test_benchmark_list(self, client):
def test_run_list(self, client):
self.authenticate(client)
run = self._create()
response = client.get("/api/runs/")
self.assert_200_ok(response, contains=_expected_entity(run))

def test_run_list_filter_by_sha_and_machine(self, client):
sha = "02addad336ba19a654f9c857ede546331be7b631"
self.authenticate(client)
run = self._create()
args = {"sha": sha, "machine_id": run.machine_id}
args = urllib.parse.urlencode(args)
response = client.get(f"/api/runs/?{args}")
self.assert_200_ok(response, contains=_expected_entity(run))

def test_run_list_filter_by_sha_and_machine_no_match(self, client):
sha = "02addad336ba19a654f9c857ede546331be7b631"
self.authenticate(client)
self._create()
args = {"sha": sha, "machine_id": "some other machine id"}
args = urllib.parse.urlencode(args)
response = client.get(f"/api/runs/?{args}")
self.assert_200_ok(response, [])

0 comments on commit 71736e1

Please sign in to comment.