summaryrefslogtreecommitdiff
path: root/zuul/driver/sql
diff options
context:
space:
mode:
Diffstat (limited to 'zuul/driver/sql')
-rw-r--r--zuul/driver/sql/alembic/versions/eca077de5e1b_add_event_timestamp_column.py39
-rw-r--r--zuul/driver/sql/sqlconnection.py5
-rw-r--r--zuul/driver/sql/sqlreporter.py4
3 files changed, 47 insertions, 1 deletions
diff --git a/zuul/driver/sql/alembic/versions/eca077de5e1b_add_event_timestamp_column.py b/zuul/driver/sql/alembic/versions/eca077de5e1b_add_event_timestamp_column.py
new file mode 100644
index 000000000..cf216c21f
--- /dev/null
+++ b/zuul/driver/sql/alembic/versions/eca077de5e1b_add_event_timestamp_column.py
@@ -0,0 +1,39 @@
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+"""add event timestamp column
+
+Revision ID: eca077de5e1b
+Revises: 40c49b6fc2e3
+Create Date: 2022-01-03 13:52:37.262934
+
+"""
+
+# revision identifiers, used by Alembic.
+revision = 'eca077de5e1b'
+down_revision = '40c49b6fc2e3'
+branch_labels = None
+depends_on = None
+
+from alembic import op
+import sqlalchemy as sa
+
+
+def upgrade(table_prefix=''):
+ op.add_column(
+ table_prefix + "zuul_buildset",
+ sa.Column("event_timestamp", sa.DateTime, nullable=True)
+ )
+
+
+def downgrade():
+ raise Exception("Downgrades not supported")
diff --git a/zuul/driver/sql/sqlconnection.py b/zuul/driver/sql/sqlconnection.py
index 36259eaa8..0b077f213 100644
--- a/zuul/driver/sql/sqlconnection.py
+++ b/zuul/driver/sql/sqlconnection.py
@@ -61,7 +61,7 @@ class DatabaseSession(object):
def getBuilds(self, tenant=None, project=None, pipeline=None,
change=None, branch=None, patchset=None, ref=None,
- newrev=None, event_id=None, uuid=None,
+ newrev=None, event_id=None, event_timestamp=None, uuid=None,
job_name=None, voting=None, nodeset=None,
result=None, provides=None, final=None, held=None,
complete=None, sort_by_buildset=False, limit=50,
@@ -102,6 +102,8 @@ class DatabaseSession(object):
q = self.listFilter(q, buildset_table.c.ref, ref)
q = self.listFilter(q, buildset_table.c.newrev, newrev)
q = self.listFilter(q, buildset_table.c.event_id, event_id)
+ q = self.listFilter(
+ q, buildset_table.c.event_timestamp, event_timestamp)
q = self.listFilter(q, build_table.c.uuid, uuid)
q = self.listFilter(q, build_table.c.job_name, job_name)
q = self.listFilter(q, build_table.c.voting, voting)
@@ -339,6 +341,7 @@ class SQLConnection(BaseConnection):
branch = sa.Column(sa.String(255))
uuid = sa.Column(sa.String(36))
event_id = sa.Column(sa.String(255), nullable=True)
+ event_timestamp = sa.Column(sa.DateTime, nullable=True)
sa.Index(self.table_prefix + 'project_pipeline_idx',
project, pipeline)
diff --git a/zuul/driver/sql/sqlreporter.py b/zuul/driver/sql/sqlreporter.py
index a971f379c..52baa29c6 100644
--- a/zuul/driver/sql/sqlreporter.py
+++ b/zuul/driver/sql/sqlreporter.py
@@ -46,9 +46,12 @@ class SQLReporter(BaseReporter):
if not buildset.uuid:
return
event_id = None
+ event_timestamp = None
item = buildset.item
if item.event is not None:
event_id = getattr(item.event, "zuul_event_id", None)
+ event_timestamp = datetime.datetime.fromtimestamp(
+ item.event.timestamp, tz=datetime.timezone.utc)
with self.connection.getSession() as db:
db_buildset = db.createBuildSet(
@@ -65,6 +68,7 @@ class SQLReporter(BaseReporter):
zuul_ref=buildset.ref,
ref_url=item.change.url,
event_id=event_id,
+ event_timestamp=event_timestamp,
)
return db_buildset