Skip to content

Commit

Permalink
k
Browse files Browse the repository at this point in the history
  • Loading branch information
yuhongsun96 committed Dec 15, 2024
1 parent 7fe46dd commit 1b9db0d
Show file tree
Hide file tree
Showing 12 changed files with 6 additions and 22 deletions.
1 change: 0 additions & 1 deletion backend/ee/onyx/server/tenants/provisioning.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ async def provision_tenant(tenant_id: str, email: str) -> None:
with get_session_with_tenant(tenant_id) as db_session:
create_milestone_and_report(
user=None,
tenant_id=tenant_id,
distinct_id=tenant_id,
event_type=MilestoneRecordType.TENANT_CREATED,
properties={
Expand Down
2 changes: 0 additions & 2 deletions backend/onyx/auth/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,6 @@ async def create(
if not user_count:
create_milestone_and_report(
user=user,
tenant_id=tenant_id,
distinct_id=user.email,
event_type=MilestoneRecordType.USER_SIGNED_UP,
properties=None,
Expand All @@ -295,7 +294,6 @@ async def create(
else:
create_milestone_and_report(
user=user,
tenant_id=tenant_id,
distinct_id=user.email,
event_type=MilestoneRecordType.MULTIPLE_USERS,
properties=None,
Expand Down
1 change: 0 additions & 1 deletion backend/onyx/background/indexing/run_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,6 @@ def _run_indexing(

create_milestone_and_report(
user=None,
tenant_id=tenant_id,
distinct_id=tenant_id or "N/A",
event_type=MilestoneRecordType.CONNECTOR_SUCCEEDED,
properties=None,
Expand Down
1 change: 0 additions & 1 deletion backend/onyx/chat/process_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,6 @@ def stream_chat_message_objects(

multi_assistant_milestone, _is_new = create_milestone_if_not_exists(
user=user,
tenant_id=tenant_id,
event_type=MilestoneRecordType.MULTIPLE_ASSISTANTS,
db_session=db_session,
)
Expand Down
10 changes: 2 additions & 8 deletions backend/onyx/db/milestone.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,12 @@

def create_milestone(
user: User | None,
tenant_id: str | None,
event_type: MilestoneRecordType,
db_session: Session,
) -> Milestone:
milestone = Milestone(
event_type=event_type,
user_id=user.id if user else None,
tenant_id=tenant_id,
)
db_session.add(milestone)
db_session.commit()
Expand All @@ -30,7 +28,6 @@ def create_milestone(

def create_milestone_if_not_exists(
user: User | None,
tenant_id: str | None,
event_type: MilestoneRecordType,
db_session: Session,
) -> tuple[Milestone, bool]:
Expand All @@ -41,18 +38,15 @@ def create_milestone_if_not_exists(
# Every milestone should only happen once per deployment/tenant
stmt = select(Milestone).where(
Milestone.event_type == event_type,
Milestone.tenant_id == tenant_id,
)
result = db_session.execute(stmt)
milestones = result.scalars().all()

if len(milestones) > 1:
raise ValueError(
f"Multiple {event_type} milestones found for tenant {tenant_id}"
)
raise ValueError(f"Multiple {event_type} milestones found")

if not milestones:
return create_milestone(user, tenant_id, event_type, db_session), True
return create_milestone(user, event_type, db_session), True

return milestones[0], False

Expand Down
1 change: 0 additions & 1 deletion backend/onyx/db/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1543,7 +1543,6 @@ class Milestone(Base):
id: Mapped[UUID] = mapped_column(
PGUUID(as_uuid=True), primary_key=True, default=uuid4
)
tenant_id: Mapped[str | None] = mapped_column(String, nullable=True)
user_id: Mapped[UUID | None] = mapped_column(
ForeignKey("user.id", ondelete="CASCADE"), nullable=True
)
Expand Down
3 changes: 0 additions & 3 deletions backend/onyx/server/documents/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,6 @@ def get_connector_indexing_status(
# Visiting admin page brings the user to the current connectors page which calls this endpoint
create_milestone_and_report(
user=user,
tenant_id=tenant_id,
distinct_id=user.email if user else tenant_id or "N/A",
event_type=MilestoneRecordType.VISITED_ADMIN_PAGE,
properties=None,
Expand Down Expand Up @@ -697,7 +696,6 @@ def create_connector_from_model(

create_milestone_and_report(
user=user,
tenant_id=tenant_id,
distinct_id=user.email if user else tenant_id or "N/A",
event_type=MilestoneRecordType.CREATED_CONNECTOR,
properties=None,
Expand Down Expand Up @@ -756,7 +754,6 @@ def create_connector_with_mock_credential(

create_milestone_and_report(
user=user,
tenant_id=tenant_id,
distinct_id=user.email if user else tenant_id or "N/A",
event_type=MilestoneRecordType.CREATED_CONNECTOR,
properties=None,
Expand Down
1 change: 0 additions & 1 deletion backend/onyx/server/features/persona/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ def create_persona(

create_milestone_and_report(
user=user,
tenant_id=tenant_id,
distinct_id=tenant_id or "N/A",
event_type=MilestoneRecordType.CREATED_ASSISTANT,
properties=None,
Expand Down
1 change: 0 additions & 1 deletion backend/onyx/server/manage/slack_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,6 @@ def create_bot(

create_milestone_and_report(
user=None,
tenant_id=tenant_id,
distinct_id=tenant_id or "N/A",
event_type=MilestoneRecordType.CREATED_ONYX_BOT,
properties=None,
Expand Down
1 change: 0 additions & 1 deletion backend/onyx/server/query_and_chat/chat_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,6 @@ def handle_new_chat_message(
with get_session_with_tenant(tenant_id) as db_session:
create_milestone_and_report(
user=user,
tenant_id=tenant_id,
distinct_id=user.email if user else tenant_id or "N/A",
event_type=MilestoneRecordType.RAN_QUERY,
properties=None,
Expand Down
3 changes: 1 addition & 2 deletions backend/onyx/utils/telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,12 @@ def mt_cloud_telemetry(

def create_milestone_and_report(
user: User | None,
tenant_id: str | None,
distinct_id: str,
event_type: MilestoneRecordType,
properties: dict | None,
db_session: Session,
) -> None:
_, is_new = create_milestone_if_not_exists(user, tenant_id, event_type, db_session)
_, is_new = create_milestone_if_not_exists(user, event_type, db_session)
if is_new:
mt_cloud_telemetry(
distinct_id=distinct_id,
Expand Down
3 changes: 3 additions & 0 deletions backend/scripts/restart_containers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,7 @@ sleep 1
echo "Running Alembic migration..."
alembic upgrade head

# Run the following instead of the above if using MT cloud
# alembic -n schema_private upgrade head

echo "Containers restarted and migration completed."

0 comments on commit 1b9db0d

Please sign in to comment.