-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[ENH] Add RPC for setting tenant resource_name and getting collection by CRN #4735
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
base: drew/_enh_add_static_name_to_sysdb_tenants_table
Are you sure you want to change the base?
Conversation
Reviewer ChecklistPlease leverage this checklist to ensure your code review is thorough before approving Testing, Bugs, Errors, Logs, Documentation
System Compatibility
Quality
|
Warning This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
This stack of pull requests is managed by Graphite. Learn more about stacking. |
Add Support for Tenant Resource Name and Get Collection by CRN RPCs This major PR introduces new SysDB APIs allowing tenants to have a unique, immutable Key Changes: Affected Areas: Potential Impact: Functionality: Introduces a new pattern for uniquely identifying tenants and collections by externally meaningful resource_name, enabling clients to resolve resources through CRN patterns as well as legacy IDs. Changes GetTenant and collection flows with new properties and lookup semantics. Tenant resource_name immutability is strictly enforced. Performance: No significant runtime performance impact; new lookups are single-row lookups or add predictable DB joins. Security: If resource_name is leaked or misused, could permit unintended resource access; implementation enforces immutability and uniqueness to minimize risk. Scalability: Allows for large cross-tenant queries and managed directory structures at scale, but no new hot paths or scaling bottlenecks introduced. Review Focus: Testing Needed• Exercise all new Code Quality Assessmentgo/pkg/sysdb/metastore/db/dao/tenant.go: Correctly enforces immutability via SQL 'IS NULL' checks; handles all error scenarios; robust logging. go/pkg/sysdb/metastore/db/dao/collection.go: Adds CRN query path safely; joins tenant table by resource_name and reuses shared listing methods. idl/chromadb/proto/coordinator.proto: Clearly documents new RPCs/fields; keeps backwards compatibility; all affected messages updated. go/pkg/sysdb/grpc/tenant_database_service.go: Wires through new RPC cleanly; consistent error mapping. tests: Thorough coverage; valid error case assertions; covers all branches of new logic. go/pkg/sysdb/coordinator/table_catalog.go: Implements new methods with clear error handling and correct propagation; follows established catalog patterns. Best PracticesAPI Versioning: Immutability: Test Coverage: Potential Issues• If an operator mistakenly assigns resource_name incorrectly, it is immutable and cannot be recovered (by design). This summary was automatically generated by @propel-code-bot |
b17758d
to
b8f2529
Compare
48caba8
to
67d8771
Compare
f6661cf
to
628ecae
Compare
var tenants []dbmodel.Tenant | ||
result := s.db.Model(&tenants). | ||
Clauses(clause.Returning{Columns: []clause.Column{{Name: "id"}}}). | ||
Where("id = ? AND resource_name IS NULL", tenantID). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The IS NULL
check enforces that you can only set the resource_name
once
return common.ErrTenantNotFound | ||
} | ||
return common.ErrTenantResourceNameAlreadySet | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check to see if the tenant exists or not in order to return the correct error
67d8771
to
1fff500
Compare
d28bc91
to
8332e31
Compare
1fff500
to
e6f6417
Compare
dd5547e
to
2c288bf
Compare
1bc4b1b
to
8b83952
Compare
fb2d83b
to
7a5ad5a
Compare
6d6dd56
to
1fc07be
Compare
7a5ad5a
to
ad222e3
Compare
@@ -111,6 +111,10 @@ func (s *Coordinator) GetCollections(ctx context.Context, collectionIDs []types. | |||
return s.catalog.GetCollections(ctx, collectionIDs, collectionName, tenantID, databaseName, limit, offset, includeSoftDeleted) | |||
} | |||
|
|||
func (s *Coordinator) GetCollectionByResourceName(ctx context.Context, tenantResourceName string, databaseName string, collectionName string) (*model.Collection, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to make the sysdb the source of truth for this parsing? I think thats a better design / encapsulation of the parsing rather than pushing it to calling services
@@ -229,6 +233,10 @@ func (s *Coordinator) GetTenantsLastCompactionTime(ctx context.Context, tenantID | |||
return s.catalog.GetTenantsLastCompactionTime(ctx, tenantIDs) | |||
} | |||
|
|||
func (s *Coordinator) SetTenantResourceName(ctx context.Context, tenantID string, resourceName string) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we instead prefer having a UpdateTenant
call ? cc @sanketkedia
@@ -3,7 +3,8 @@ package model | |||
import "github.com/chroma-core/chroma/go/pkg/types" | |||
|
|||
type Tenant struct { | |||
Name string | |||
Name string | |||
ResourceName *string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would be good to leave a comment on what this is
@@ -192,6 +192,13 @@ message GetCollectionsResponse { | |||
reserved "status"; | |||
} | |||
|
|||
message GetCollectionByResourceNameRequest { | |||
string id = 1; | |||
optional string tenant_resource_name = 2; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why are these marked as optional?
} | ||
|
||
message SetTenantResourceNameResponse { | ||
reserved 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why reserve these?
Description of changes
Summarize the changes made by this PR.
resource_name
on atenant
Tenant
model to includeresource_name
, expressed onGetTenant
tenant_resource_name
,database
,name
)Test plan
How are these changes tested?
pytest
for python,yarn test
for js,cargo test
for rustDocumentation Changes
Are all docstrings for user-facing APIs updated if required? Do we need to make documentation changes in the docs section?