From 5b5c797d43deb23d7d0aef3c503dfd56e8b6302b Mon Sep 17 00:00:00 2001 From: Rohan Agarwal Date: Mon, 2 Sep 2024 17:02:30 -0700 Subject: [PATCH] Store issue summary in database --- .../versions/2e22d272d3b8_migration.py | 33 +++++++++++++++++++ src/seer/automation/summarize/issue.py | 10 +++++- src/seer/db.py | 10 ++++++ 3 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 src/migrations/versions/2e22d272d3b8_migration.py diff --git a/src/migrations/versions/2e22d272d3b8_migration.py b/src/migrations/versions/2e22d272d3b8_migration.py new file mode 100644 index 000000000..c85280805 --- /dev/null +++ b/src/migrations/versions/2e22d272d3b8_migration.py @@ -0,0 +1,33 @@ +"""Migration + +Revision ID: 2e22d272d3b8 +Revises: 96e56e375579 +Create Date: 2024-09-02 23:08:36.978554 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = '2e22d272d3b8' +down_revision = '96e56e375579' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.create_table('issue_summary', + sa.Column('group_id', sa.BigInteger(), nullable=False), + sa.Column('summary', sa.JSON(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.PrimaryKeyConstraint('group_id') + ) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_table('issue_summary') + # ### end Alembic commands ### diff --git a/src/seer/automation/summarize/issue.py b/src/seer/automation/summarize/issue.py index c801eb780..0db28ba9d 100644 --- a/src/seer/automation/summarize/issue.py +++ b/src/seer/automation/summarize/issue.py @@ -7,6 +7,7 @@ from seer.automation.agent.client import GptClient from seer.automation.models import EventDetails from seer.automation.summarize.models import SummarizeIssueRequest, SummarizeIssueResponse +from seer.db import DbIssueSummary, Session from seer.dependency_injection import inject, injected @@ -115,4 +116,11 @@ def run_summarize_issue(request: SummarizeIssueRequest): ), } - return summarize_issue(request, **extra_kwargs) + summary = summarize_issue(request, **extra_kwargs) + + with Session() as session: + db_state = DbIssueSummary(group_id=request.group_id, summary=summary.model_dump(mode="json")) + session.merge(db_state) + session.commit() + + return summary diff --git a/src/seer/db.py b/src/seer/db.py index e832e7622..7eabf8d3f 100644 --- a/src/seer/db.py +++ b/src/seer/db.py @@ -314,3 +314,13 @@ class DbSmokeTest(Base): request_id: Mapped[str] = mapped_column(String(128), index=True, unique=True, nullable=False) started_at: Mapped[datetime.datetime] = mapped_column(DateTime, nullable=False) completed_at: Mapped[Optional[datetime.datetime]] = mapped_column(DateTime, nullable=True) + + +class DbIssueSummary(Base): + __tablename__ = "issue_summary" + + group_id: Mapped[int] = mapped_column(BigInteger, primary_key=True) + summary: Mapped[dict] = mapped_column(JSON, nullable=False) + created_at: Mapped[datetime.datetime] = mapped_column( + DateTime, nullable=False, default=datetime.datetime.now(datetime.UTC) + )