Skip to content

Commit

Permalink
Drop machine_id from summary table
Browse files Browse the repository at this point in the history
  • Loading branch information
dianaclarke committed Jun 15, 2021
1 parent c7381ad commit e654d7f
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 38 deletions.
8 changes: 1 addition & 7 deletions conbench/api/_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ def _api_user_entity(user):
}


def _api_benchmark_entity(
summary_id, machine_id, context_id, case_id, batch_id, run_id, name
):
def _api_benchmark_entity(summary_id, context_id, case_id, batch_id, run_id, name):
return {
"id": summary_id,
"stats": {
Expand Down Expand Up @@ -83,7 +81,6 @@ def _api_benchmark_entity(
"list": "http://localhost/api/benchmarks/",
"self": "http://localhost/api/benchmarks/%s/" % summary_id,
"context": "http://localhost/api/contexts/%s/" % context_id,
"machine": "http://localhost/api/machines/%s/" % machine_id,
"run": "http://localhost/api/runs/%s/" % run_id,
},
}
Expand Down Expand Up @@ -262,7 +259,6 @@ def _api_run_entity(run_id, commit_id, machine_id, now, baseline_id):

BENCHMARK_ENTITY = _api_benchmark_entity(
"some-benchmark-uuid-1",
"some-machine-uuid-1",
"some-context-uuid-1",
"some-case-uuid-1",
"some-batch-uuid-1",
Expand All @@ -272,7 +268,6 @@ def _api_run_entity(run_id, commit_id, machine_id, now, baseline_id):
BENCHMARK_LIST = [
_api_benchmark_entity(
"some-benchmark-uuid-1",
"some-machine-uuid-1",
"some-context-uuid-1",
"some-case-uuid-1",
"some-batch-uuid-1",
Expand All @@ -281,7 +276,6 @@ def _api_run_entity(run_id, commit_id, machine_id, now, baseline_id):
),
_api_benchmark_entity(
"some-benchmark-uuid-2",
"some-machine-uuid-1",
"some-context-uuid-1",
"some-case-uuid-1",
"some-batch-uuid-1",
Expand Down
3 changes: 0 additions & 3 deletions conbench/app/benchmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,8 @@ def get_display_benchmark(self, benchmark_id):
return None

augment(benchmark)
machine = self._get_machine(benchmark)
context = self._get_context(benchmark)
machine.pop("links", None)
context.pop("links", None)
benchmark["machine"] = machine
benchmark["context"] = context

return benchmark
Expand Down
6 changes: 3 additions & 3 deletions conbench/entities/distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def get_distribution(repository, sha, case_id, context_id, machine_hash, limit):
Machine.memory_bytes,
)
.join(Run, Run.id == Summary.run_id)
.join(Machine, Machine.id == Summary.machine_id)
.join(Machine, Machine.id == Run.machine_id)
.join(commits_up, commits_up.c.id == Run.commit_id)
.filter(
Run.name.like("commit: %"),
Expand All @@ -127,7 +127,7 @@ def update_distribution(repository, sha, summary, limit):
sha,
summary.case_id,
summary.context_id,
summary.machine.hash,
summary.run.machine.hash,
limit,
).first()

Expand Down Expand Up @@ -158,7 +158,7 @@ def set_z_scores(summaries):
first = summaries[0]
repository = first.run.commit.repository
sha = first.run.commit.parent
machine_hash = first.machine.hash
machine_hash = first.run.machine.hash

where = [
Distribution.repository == repository,
Expand Down
7 changes: 0 additions & 7 deletions conbench/entities/summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,9 @@ class Summary(Base, EntityMixin):
id = NotNull(s.String(50), primary_key=True, default=generate_uuid)
case_id = NotNull(s.String(50), s.ForeignKey("case.id"))
context_id = NotNull(s.String(50), s.ForeignKey("context.id"))
# TODO: remove machine_id (it's on the run too)
machine_id = NotNull(s.String(50), s.ForeignKey("machine.id"))
run_id = NotNull(s.Text, s.ForeignKey("run.id"))
case = relationship("Case", lazy="joined")
context = relationship("Context", lazy="select")
machine = relationship("Machine", lazy="select")
run = relationship("Run", lazy="select")
data = relationship(
"Data",
Expand Down Expand Up @@ -135,7 +132,6 @@ def create(data):

stats["case_id"] = case.id
stats["context_id"] = context.id
stats["machine_id"] = machine.id
summary = Summary(**stats)
summary.save()

Expand Down Expand Up @@ -228,9 +224,6 @@ def _dump(self, summary):
"context": f.url_for(
"api.context", context_id=summary.context_id, _external=True
),
"machine": f.url_for(
"api.machine", machine_id=summary.machine_id, _external=True
),
"run": f.url_for("api.run", run_id=summary.run_id, _external=True),
},
}
Expand Down
2 changes: 1 addition & 1 deletion conbench/templates/benchmark-entity.html
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
</li>
{% endif %}
<li class="list-group-item active">Machine</li>
{% for k,v in benchmark.machine.items() %}
{% for k,v in run.machine.items() %}
<li class="list-group-item" style="overflow-y: auto;">
<b>{{ k }}</b>
<div align="right" style="display:inline-block; float: right;">{{ v }}</div>
Expand Down
4 changes: 2 additions & 2 deletions conbench/templates/compare-entity.html
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@
</li>
{% endfor %}
<li class="list-group-item active">Machine</li>
{% for k,v in baseline.machine.items() %}
{% for k,v in baseline_run.machine.items() %}
<li class="list-group-item" style="overflow-y: auto;">
<b>{{ k }}</b>
<div align="right" style="display:inline-block; float: right;">{{ v }}</div>
Expand Down Expand Up @@ -242,7 +242,7 @@
</li>
{% endfor %}
<li class="list-group-item active">Machine</li>
{% for k,v in contender.machine.items() %}
{% for k,v in contender_run.machine.items() %}
<li class="list-group-item" style="overflow-y: auto;">
<b>{{ k }}</b>
<div align="right" style="display:inline-block; float: right;">{{ v }}</div>
Expand Down
4 changes: 0 additions & 4 deletions conbench/tests/api/_expected_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
"links": {
"context": "http://localhost/api/contexts/some-context-uuid-1/",
"list": "http://localhost/api/benchmarks/",
"machine": "http://localhost/api/machines/some-machine-uuid-1/",
"run": "http://localhost/api/runs/some-run-uuid-1/",
"self": "http://localhost/api/benchmarks/some-benchmark-uuid-1/",
},
Expand Down Expand Up @@ -119,7 +118,6 @@
"links": {
"context": "http://localhost/api/contexts/some-context-uuid-1/",
"list": "http://localhost/api/benchmarks/",
"machine": "http://localhost/api/machines/some-machine-uuid-1/",
"run": "http://localhost/api/runs/some-run-uuid-1/",
"self": "http://localhost/api/benchmarks/some-benchmark-uuid-1/",
},
Expand Down Expand Up @@ -189,7 +187,6 @@
"links": {
"context": "http://localhost/api/contexts/some-context-uuid-1/",
"list": "http://localhost/api/benchmarks/",
"machine": "http://localhost/api/machines/some-machine-uuid-1/",
"run": "http://localhost/api/runs/some-run-uuid-1/",
"self": "http://localhost/api/benchmarks/some-benchmark-uuid-1/",
},
Expand Down Expand Up @@ -251,7 +248,6 @@
"links": {
"context": "http://localhost/api/contexts/some-context-uuid-1/",
"list": "http://localhost/api/benchmarks/",
"machine": "http://localhost/api/machines/some-machine-uuid-1/",
"run": "http://localhost/api/runs/some-run-uuid-1/",
"self": "http://localhost/api/benchmarks/some-benchmark-uuid-2/",
},
Expand Down
5 changes: 2 additions & 3 deletions conbench/tests/api/test_benchmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
def _expected_entity(summary):
return _api_benchmark_entity(
summary.id,
summary.machine_id,
summary.context_id,
summary.case.id,
summary.batch_id,
Expand Down Expand Up @@ -344,7 +343,7 @@ def test_create_benchmark_normalizes_data(self, client):
assert summary_1.id != summary_2.id
assert summary_1.case_id == summary_2.case_id
assert summary_1.context_id == summary_2.context_id
assert summary_1.machine_id == summary_2.machine_id
assert summary_1.run.machine_id == summary_2.run.machine_id
assert summary_1.run_id != summary_2.run_id
assert summary_1.run.commit_id == summary_2.run.commit_id

Expand Down Expand Up @@ -407,7 +406,7 @@ def test_create_benchmark_distribution(self, client):
self.assert_201_created(response, _expected_entity(summary_2), location)
assert summary_1.case_id == summary_2.case_id
assert summary_1.context_id == summary_2.context_id
assert summary_1.machine_id == summary_2.machine_id
assert summary_1.run.machine_id == summary_2.run.machine_id
assert summary_1.run.commit_id == summary_2.run.commit_id

# after two results
Expand Down
2 changes: 1 addition & 1 deletion conbench/tests/api/test_machines.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class TestMachineGet(_asserts.GetEnforcer):

def _create(self):
summary = create_benchmark_summary()
return summary.machine
return summary.run.machine

def test_get_machine(self, client):
self.authenticate(client)
Expand Down
14 changes: 7 additions & 7 deletions conbench/tests/entities/test_distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
FROM commit
WHERE commit.repository = :repository_1 ORDER BY commit.timestamp DESC)
SELECT text(:text_1) AS repository, text(:text_2) AS sha, summary.case_id, summary.context_id, concat(machine.name, :concat_1, machine.cpu_core_count, :concat_2, machine.cpu_thread_count, :concat_3, machine.memory_bytes) AS hash, max(summary.unit) AS unit, avg(summary.mean) AS mean_mean, stddev(summary.mean) AS mean_sd, avg(summary.min) AS min_mean, stddev(summary.min) AS min_sd, avg(summary.max) AS max_mean, stddev(summary.max) AS max_sd, avg(summary.median) AS median_mean, stddev(summary.median) AS median_sd, min(commits_up.timestamp) AS first_timestamp, max(commits_up.timestamp) AS last_timestamp, count(summary.mean) AS observations
FROM summary JOIN run ON run.id = summary.run_id JOIN machine ON machine.id = summary.machine_id JOIN (SELECT commit_index.id AS id, commit_index.sha AS sha, commit_index.timestamp AS timestamp, commit_index.row_number AS row_number
FROM summary JOIN run ON run.id = summary.run_id JOIN machine ON machine.id = run.machine_id JOIN (SELECT commit_index.id AS id, commit_index.sha AS sha, commit_index.timestamp AS timestamp, commit_index.row_number AS row_number
FROM (SELECT ordered_commits.id AS id, ordered_commits.sha AS sha, ordered_commits.timestamp AS timestamp, row_number() OVER () AS row_number
FROM ordered_commits) AS commit_index
WHERE commit_index.row_number >= (SELECT commit_index.row_number
Expand Down Expand Up @@ -241,14 +241,14 @@ def test_distibution():
assert summary_1.case_id == summary_4.case_id
assert summary_1.case_id == summary_5.case_id

assert summary_1.machine_id == summary_2.machine_id
assert summary_1.machine_id == summary_3.machine_id
assert summary_1.machine_id == summary_4.machine_id
assert summary_1.machine_id == summary_5.machine_id
assert summary_1.run.machine_id == summary_2.run.machine_id
assert summary_1.run.machine_id == summary_3.run.machine_id
assert summary_1.run.machine_id == summary_4.run.machine_id
assert summary_1.run.machine_id == summary_5.run.machine_id

case_id = summary_1.case_id
context_id = summary_1.context_id
machine_hash = summary_1.machine.hash
machine_hash = summary_1.run.machine.hash

assert Distribution.count() >= 7

Expand Down Expand Up @@ -501,7 +501,7 @@ def test_distibution_multiple_runs_same_commit():

case_id = summary_1.case_id
context_id = summary_1.context_id
machine_hash = summary_1.machine.hash
machine_hash = summary_1.run.machine.hash

assert get_distribution(
REPO, "xxxxx", case_id, context_id, machine_hash, 10
Expand Down
33 changes: 33 additions & 0 deletions migrations/versions/69493ddc938a_drop_machine_id.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"""drop machine id
Revision ID: 69493ddc938a
Revises: afc565181834
Create Date: 2021-06-15 15:12:07.013039
"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = "69493ddc938a"
down_revision = "afc565181834"
branch_labels = None
depends_on = None


def upgrade():
op.drop_constraint("summary_machine_id_fkey", "summary", type_="foreignkey")
op.drop_column("summary", "machine_id")


def downgrade():
op.add_column(
"summary",
sa.Column(
"machine_id", sa.VARCHAR(length=50), autoincrement=False, nullable=False
),
)
op.create_foreign_key(
"summary_machine_id_fkey", "summary", "machine", ["machine_id"], ["id"]
)

0 comments on commit e654d7f

Please sign in to comment.