From f83a345bfe6e7add0894beba6533421d173849f3 Mon Sep 17 00:00:00 2001 From: "Joshua M. Boniface" Date: Sat, 2 Oct 2021 00:53:27 -0400 Subject: [PATCH] Add test format versioning to storage benchmarks Adds a test_format database column and a value in the API return for the test format version, starting at 0 for the existing format as of 0.9.37. References #143 --- .../5c2109dbbeae_pvc_version_0_9_37.py | 28 +++++++++++++++++++ api-daemon/pvcapid/benchmark.py | 8 ++++-- api-daemon/pvcapid/flaskapi.py | 4 +++ api-daemon/pvcapid/models.py | 4 ++- docs/manuals/swagger.json | 5 ++++ 5 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 api-daemon/migrations/versions/5c2109dbbeae_pvc_version_0_9_37.py diff --git a/api-daemon/migrations/versions/5c2109dbbeae_pvc_version_0_9_37.py b/api-daemon/migrations/versions/5c2109dbbeae_pvc_version_0_9_37.py new file mode 100644 index 00000000..c236670e --- /dev/null +++ b/api-daemon/migrations/versions/5c2109dbbeae_pvc_version_0_9_37.py @@ -0,0 +1,28 @@ +"""PVC version 0.9.37 + +Revision ID: 5c2109dbbeae +Revises: bae4d5a77c74 +Create Date: 2021-10-02 00:47:29.693579 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = '5c2109dbbeae' +down_revision = 'bae4d5a77c74' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.add_column('storage_benchmarks', sa.Column('test_format', sa.Integer(), server_default='0', nullable=False)) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_column('storage_benchmarks', 'test_format') + # ### end Alembic commands ### diff --git a/api-daemon/pvcapid/benchmark.py b/api-daemon/pvcapid/benchmark.py index 4c896aa6..68846c88 100755 --- a/api-daemon/pvcapid/benchmark.py +++ b/api-daemon/pvcapid/benchmark.py @@ -95,6 +95,7 @@ def list_benchmarks(job=None): benchmark_data = dict() benchmark_data['id'] = benchmark['id'] benchmark_data['job'] = benchmark['job'] + benchmark_data['test_format'] = benchmark['test_format'] benchmark_data['benchmark_result'] = loads(benchmark['result']) # Append the new data to our actual output structure data.append(benchmark_data) @@ -111,6 +112,9 @@ def run_benchmark(self, pool): import json from datetime import datetime + # Define the current test format + TEST_FORMAT = 0 + time.sleep(2) # Phase 0 - connect to databases @@ -135,8 +139,8 @@ def run_benchmark(self, pool): print("Storing running status for job '{}' in database".format(job_name)) try: - query = "INSERT INTO storage_benchmarks (job, result) VALUES (%s, %s);" - args = (job_name, "Running",) + query = "INSERT INTO storage_benchmarks (job, test_format, result) VALUES (%s, %s);" + args = (job_name, TEST_FORMAT, "Running",) db_cur.execute(query, args) db_conn.commit() except Exception as e: diff --git a/api-daemon/pvcapid/flaskapi.py b/api-daemon/pvcapid/flaskapi.py index e7ec69e9..987d3900 100755 --- a/api-daemon/pvcapid/flaskapi.py +++ b/api-daemon/pvcapid/flaskapi.py @@ -3420,8 +3420,12 @@ class API_Storage_Ceph_Benchmark(Resource): job: type: string description: The job name (an ISO date) of the test result + test_format: + type: integer + description: The PVC benchmark format of the results benchmark_result: type: object + description: A format 0 test result properties: test_name: type: object diff --git a/api-daemon/pvcapid/models.py b/api-daemon/pvcapid/models.py index ccf31792..8082afe1 100755 --- a/api-daemon/pvcapid/models.py +++ b/api-daemon/pvcapid/models.py @@ -231,11 +231,13 @@ class DBStorageBenchmarks(db.Model): id = db.Column(db.Integer, primary_key=True) job = db.Column(db.Text, nullable=False) + test_format = db.Column(db.Integer, nullable=False, default=0, server_default='0') result = db.Column(db.Text, nullable=False) - def __init__(self, job, result): + def __init__(self, job, result, test_format): self.job = job self.result = result + self.test_format = test_format def __repr__(self): return ''.format(self.id) diff --git a/docs/manuals/swagger.json b/docs/manuals/swagger.json index 1275b129..88b1a4c3 100644 --- a/docs/manuals/swagger.json +++ b/docs/manuals/swagger.json @@ -961,6 +961,7 @@ "storagebenchmark": { "properties": { "benchmark_result": { + "description": "A format 0 test result", "properties": { "test_name": { "properties": { @@ -1094,6 +1095,10 @@ "job": { "description": "The job name (an ISO date) of the test result", "type": "string" + }, + "test_format": { + "description": "The PVC benchmark format of the results", + "type": "integer" } }, "type": "object"