Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

various multi tenant improvements #2803

Merged
merged 4 commits into from
Oct 15, 2024
Merged

various multi tenant improvements #2803

merged 4 commits into from
Oct 15, 2024

Conversation

pablonyx
Copy link
Contributor

@pablonyx pablonyx commented Oct 15, 2024

Description

Improves various flows for multi-tenant usage while being a no-op for non multi tenant

  • Ensure File store always has tenant context
  • Ensure functions run in parallel have tenant context
  • Address ephemeral commit session issue
  • Improve JWT deletion client side for logging out

Copy link

vercel bot commented Oct 15, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
internal-search ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 15, 2024 5:07pm

@pablonyx pablonyx marked this pull request as ready for review October 15, 2024 17:05
Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Summary

This pull request introduces significant multi-tenant improvements across various components of the Danswer application. Key changes include:

  • Added tenant_id parameter to critical functions in connector deletion, periodic tasks, and indexing processes
  • Introduced tenant-specific database sessions using get_session_with_tenant instead of get_sqlalchemy_engine
  • Modified LocalFileConnector to support tenant-specific contexts
  • Updated token rate limiting system to include tenant-specific logic
  • Added DocumentSourceRequiringTenantContext constant to handle tenant-specific document sources
  • Improved logout process for cloud-enabled scenarios by deleting specific cookies
  • Introduced REGISTRATION_URL constant for potential user registration functionality

15 file(s) reviewed, 23 comment(s)
Edit PR Review Bot Settings | Greptile

@@ -23,7 +23,7 @@
bind=True,
base=AbortableTask,
)
def kombu_message_cleanup_task(self: Any) -> int:
def kombu_message_cleanup_task(self: Any, tenant_id: str | None) -> int:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Consider adding type hints for the return value of kombu_message_cleanup_task

@@ -118,6 +118,9 @@ class DocumentSource(str, Enum):
NOT_APPLICABLE = "not_applicable"


DocumentSourceRequiringTenantContext: list[DocumentSource] = [DocumentSource.FILE]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Consider adding a comment explaining the purpose and usage of this new constant

@@ -435,14 +435,13 @@ def cancel_indexing_attempts_for_ccpair(

db_session.execute(stmt)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: The db_session.commit() call has been removed. Verify that the transaction is committed elsewhere to ensure changes are persisted.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensured! Different ticket created to make sure we think about the proper level of abstraction to commit and create transactions

backend/danswer/db/index_attempt.py Show resolved Hide resolved
Comment on lines 115 to 116
for cc_pair in get_connector_credential_pairs(db_session):
resync_cc_pair(cc_pair, db_session=db_session)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: consider wrapping this loop in a try-except block to handle potential errors during resync



def _check_token_rate_limits(_: User | None) -> None:
_user_is_rate_limited_by_global()
def _check_token_rate_limits(_: User | None, tenant_id: str | None) -> None:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Update function signature to include type hint for tenant_id

Comment on lines +11 to +13
if (response && !response.ok) {
return new Response(response.body, { status: response?.status });
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Consider using response.status instead of response?.status to avoid potential undefined behavior

web/src/app/auth/logout/route.ts Show resolved Hide resolved
Comment on lines 62 to 63
export const REGISTRATION_URL =
process.env.INTERNAL_URL || "http://127.0.0.1:3001";
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: The REGISTRATION_URL uses INTERNAL_URL, which may not be appropriate for client-side usage

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is changed in a separate PR

@pablonyx pablonyx added this pull request to the merge queue Oct 15, 2024
Merged via the queue into main with commit bfe9639 Oct 15, 2024
7 checks passed
@pablonyx pablonyx deleted the multi_tenant_improvements branch October 17, 2024 23:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants