Skip to content

Commit

Permalink
Add context_id to run table
Browse files Browse the repository at this point in the history
  • Loading branch information
dianaclarke committed Apr 26, 2021
1 parent 78f392c commit 47cb42d
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 7 deletions.
20 changes: 14 additions & 6 deletions conbench/api/_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ def _api_compare_list(
]


def _api_context_entity(context_id):
return {
def _api_context_entity(context_id, links=True):
result = {
"id": context_id,
"arrow_compiler_flags": "-fPIC -arch x86_64 -arch x86_64 -std=c++11 -Qunused-arguments -fcolor-diagnostics -O3 -DNDEBUG",
"arrow_compiler_id": "AppleClang",
Expand All @@ -188,6 +188,9 @@ def _api_context_entity(context_id):
"self": "http://localhost/api/contexts/%s/" % context_id,
},
}
if not links:
result.pop("links", None)
return result


def _api_machine_entity(machine_id, links=True):
Expand Down Expand Up @@ -216,15 +219,17 @@ def _api_machine_entity(machine_id, links=True):
return result


def _api_run_entity(run_id, machine_id, commit_id, now):
def _api_run_entity(run_id, commit_id, context_id, machine_id, now):
return {
"id": run_id,
"name": "pull request: 9564",
"timestamp": now,
"commit": _api_commit_entity(commit_id),
"context": _api_context_entity(context_id, links=False),
"machine": _api_machine_entity(machine_id, links=False),
"links": {
"self": "http://localhost/api/runs/%s/" % run_id,
"context": "http://localhost/api/contexts/%s/" % context_id,
"machine": "http://localhost/api/machines/%s/" % machine_id,
},
}
Expand Down Expand Up @@ -281,21 +286,24 @@ def _api_run_entity(run_id, machine_id, commit_id, now):
MACHINE_ENTITY = _api_machine_entity("some-machine-uuid-1")
RUN_ENTITY = _api_run_entity(
"some-run-uuid-1",
"some-machine-uuid-1",
"some-commit-uuid-1",
"some-context-uuid-1",
"some-machine-uuid-1",
"2021-02-04T17:22:05.225583",
)
RUN_LIST = [
_api_run_entity(
"some-run-uuid-1",
"some-machine-uuid-1",
"some-commit-uuid-1",
"some-context-uuid-1",
"some-machine-uuid-1",
"2021-02-04T17:22:05.225583",
),
_api_run_entity(
"some-run-uuid-2",
"some-machine-uuid-1",
"some-commit-uuid-1",
"some-context-uuid-1",
"some-machine-uuid-1",
"2021-03-04T17:18:05.715583",
),
]
Expand Down
13 changes: 13 additions & 0 deletions conbench/entities/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from ..entities._entity import Base, EntityMixin, EntitySerializer, NotNull, Nullable
from ..entities.commit import CommitSerializer
from ..entities.context import ContextSerializer
from ..entities.machine import MachineSerializer


Expand All @@ -14,27 +15,39 @@ class Run(Base, EntityMixin):
timestamp = NotNull(s.DateTime(timezone=False), server_default=s.sql.func.now())
commit_id = NotNull(s.String(50), s.ForeignKey("commit.id"))
commit = relationship("Commit", lazy="joined")
context_id = Nullable(s.String(50), s.ForeignKey("context.id"))
context = relationship("Context", lazy="joined")
machine_id = NotNull(s.String(50), s.ForeignKey("machine.id"))
machine = relationship("Machine", lazy="joined")


class _Serializer(EntitySerializer):
def _dump(self, run):
commit = CommitSerializer().one.dump(run.commit)
context = ContextSerializer().one.dump(run.context)
machine = MachineSerializer().one.dump(run.machine)
commit.pop("links", None)
foo = context.pop("links", None)
print("\n\n HELLO!")
print(foo)
print(context)
print("---------------")
machine.pop("links", None)
result = {
"id": run.id,
"name": run.name,
"timestamp": run.timestamp.isoformat(),
"commit": commit,
"context": context,
"machine": machine,
"links": {
"self": f.url_for("api.run", run_id=run.id, _external=True),
"machine": f.url_for(
"api.machine", machine_id=run.machine_id, _external=True
),
"context": f.url_for(
"api.context", context_id=run.context_id, _external=True
),
},
}
return result
Expand Down
1 change: 1 addition & 0 deletions conbench/entities/summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ def create(data):
"id": run_id,
"name": run_name,
"commit_id": commit.id,
"context_id": context.id,
"machine_id": machine.id,
}
)
Expand Down
33 changes: 33 additions & 0 deletions conbench/tests/api/_expected_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,8 +460,19 @@
"timestamp": "2021-02-25T01:02:51",
"url": "https://github.com/apache/arrow/commit/02addad336ba19a654f9c857ede546331be7b631",
},
"context": {
"arrow_compiler_flags": "-fPIC -arch x86_64 -arch x86_64 -std=c++11 -Qunused-arguments -fcolor-diagnostics -O3 -DNDEBUG",
"arrow_compiler_id": "AppleClang",
"arrow_compiler_version": "11.0.0.11000033",
"arrow_git_revision": "02addad336ba19a654f9c857ede546331be7b631",
"arrow_version": "2.0.0",
"benchmark_language": "Python",
"benchmark_language_version": "Python 3.8.5",
"id": "some-context-uuid-1",
},
"id": "some-run-uuid-1",
"links": {
"context": "http://localhost/api/contexts/some-context-uuid-1/",
"machine": "http://localhost/api/machines/some-machine-uuid-1/",
"self": "http://localhost/api/runs/some-run-uuid-1/",
},
Expand Down Expand Up @@ -507,8 +518,19 @@
"timestamp": "2021-02-25T01:02:51",
"url": "https://github.com/apache/arrow/commit/02addad336ba19a654f9c857ede546331be7b631",
},
"context": {
"arrow_compiler_flags": "-fPIC -arch x86_64 -arch x86_64 -std=c++11 -Qunused-arguments -fcolor-diagnostics -O3 -DNDEBUG",
"arrow_compiler_id": "AppleClang",
"arrow_compiler_version": "11.0.0.11000033",
"arrow_git_revision": "02addad336ba19a654f9c857ede546331be7b631",
"arrow_version": "2.0.0",
"benchmark_language": "Python",
"benchmark_language_version": "Python 3.8.5",
"id": "some-context-uuid-1",
},
"id": "some-run-uuid-1",
"links": {
"context": "http://localhost/api/contexts/some-context-uuid-1/",
"machine": "http://localhost/api/machines/some-machine-uuid-1/",
"self": "http://localhost/api/runs/some-run-uuid-1/",
},
Expand Down Expand Up @@ -546,8 +568,19 @@
"timestamp": "2021-02-25T01:02:51",
"url": "https://github.com/apache/arrow/commit/02addad336ba19a654f9c857ede546331be7b631",
},
"context": {
"arrow_compiler_flags": "-fPIC -arch x86_64 -arch x86_64 -std=c++11 -Qunused-arguments -fcolor-diagnostics -O3 -DNDEBUG",
"arrow_compiler_id": "AppleClang",
"arrow_compiler_version": "11.0.0.11000033",
"arrow_git_revision": "02addad336ba19a654f9c857ede546331be7b631",
"arrow_version": "2.0.0",
"benchmark_language": "Python",
"benchmark_language_version": "Python 3.8.5",
"id": "some-context-uuid-1",
},
"id": "some-run-uuid-2",
"links": {
"context": "http://localhost/api/contexts/some-context-uuid-1/",
"machine": "http://localhost/api/machines/some-machine-uuid-1/",
"self": "http://localhost/api/runs/some-run-uuid-2/",
},
Expand Down
3 changes: 2 additions & 1 deletion conbench/tests/api/test_runs.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
def _expected_entity(run):
return _api_run_entity(
run.id,
run.machine_id,
run.commit_id,
run.context_id,
run.machine_id,
run.timestamp.isoformat(),
)

Expand Down
30 changes: 30 additions & 0 deletions migrations/versions/52b6915e289a_run_context.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""run context
Revision ID: 52b6915e289a
Revises: b86538f84533
Create Date: 2021-04-26 10:39:14.479883
"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = "52b6915e289a"
down_revision = "b86538f84533"
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column("run", sa.Column("context_id", sa.String(length=50), nullable=True))
op.create_foreign_key(None, "run", "context", ["context_id"], ["id"])
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_constraint(None, "run", type_="foreignkey")
op.drop_column("run", "context_id")
# ### end Alembic commands ###

0 comments on commit 47cb42d

Please sign in to comment.