[Cosmos] ThroughputControl API#4078
[Cosmos] ThroughputControl API#4078tvaron3 wants to merge 1 commit intoAzure:release/azure_data_cosmos-previewsfrom
Conversation
4bac98b to
1d414c3
Compare
|
/azp run rust - cosmos - weekly |
|
Azure Pipelines successfully started running 1 pipeline(s). |
There was a problem hiding this comment.
Pull request overview
This PR introduces an SDK-level Throughput Control API for Cosmos DB by allowing users to register named throughput control groups (priority-based execution or throughput buckets) at client creation time, then applying the appropriate service headers on supported operations.
Changes:
- Added
ThroughputControlGroup(SDK-facing) and re-exportedPriorityLevel,ThroughputControlGroupName, andContainerReferencefor public API usage. - Threaded a
ThroughputControlGroupRegistrythrough the client hierarchy and applied throughput control headers for write/query/batch requests. - Added a
ContainerReference::stub()helper in the driver for unit tests and documented the feature in the SDK changelog.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| sdk/cosmos/azure_data_cosmos/src/options/mod.rs | Adds SDK throughput control group type + client registration API and implements header application helpers + tests. |
| sdk/cosmos/azure_data_cosmos/src/clients/mod.rs | Introduces ClientContext to carry shared client infrastructure including throughput control registry. |
| sdk/cosmos/azure_data_cosmos/src/clients/cosmos_client.rs | Switches CosmosClient to store shared dependencies via ClientContext. |
| sdk/cosmos/azure_data_cosmos/src/clients/cosmos_client_builder.rs | Captures throughput control registry during build and populates it into ClientContext. |
| sdk/cosmos/azure_data_cosmos/src/clients/database_client.rs | Refactors to use ClientContext and passes it through to container construction. |
| sdk/cosmos/azure_data_cosmos/src/clients/container_client.rs | Applies throughput control headers for gateway-pipeline operations and uses ClientContext throughout. |
| sdk/cosmos/azure_data_cosmos/CHANGELOG.md | Adds an unreleased changelog entry for the new public Throughput Control API. |
| sdk/cosmos/azure_data_cosmos_driver/src/models/resource_reference.rs | Adds ContainerReference::stub() for unit testing without live service metadata resolution. |
sdk/cosmos/azure_data_cosmos_driver/src/models/resource_reference.rs
Outdated
Show resolved
Hide resolved
analogrelay
left a comment
There was a problem hiding this comment.
Rather than adding this to the SDK, should we adjust the driver's options to match this and then re-export it? I'd like to avoid adding new conversion layers if we can.
| /// ``` | ||
| #[derive(Clone, Debug)] | ||
| #[non_exhaustive] | ||
| pub enum ThroughputControlGroup { |
There was a problem hiding this comment.
Java's ThroughputControlGroupBuilder seems to allow setting both a throughput bucket AND a priority level. I kinda viewed TCGs as a struct holding optional Priority Level, and Throughput Bucket values (for server-side throughput control) as well as (in the future) Target Throughput (for client-side throughput control).
There was a problem hiding this comment.
Addressed — instead of merging into a single struct, we kept the enum (each variant represents a distinct server-side feature) and changed OperationOptions::throughput_control_group_name to throughput_control_group_names: Option<Vec<ThroughputControlGroupName>>. This lets a single request reference multiple groups (e.g., one priority group + one bucket group) and the driver merges their snapshots, applying both x-ms-cosmos-priority-level and x-ms-cosmos-throughput-bucket headers. The ClientSide variant was removed for GA (#[non_exhaustive] allows re-adding it later with target_throughput).
1d414c3 to
0c36db5
Compare
0c36db5 to
014d0df
Compare
6d00770 to
c3a04df
Compare
Add SDK-level throughput control API for server-side priority-based execution and throughput buckets (issue Azure#3904). New SDK types: - ThroughputControlGroup enum with PriorityBased and ThroughputBucket variants, hiding the driver's unimplemented ClientSide variant - Re-exports PriorityLevel, ThroughputControlGroupName, ContainerReference Registration and resolution: - CosmosClientOptions::with_throughput_control_group() for registration - ThroughputControlGroupRegistry threaded through CosmosClient, DatabaseClient, and ContainerClient - apply_throughput_control() on ItemWriteOptions, QueryOptions, and BatchOptions resolves group name to x-ms-cosmos-priority-level and x-ms-cosmos-throughput-bucket headers Driver: - ContainerReference::stub() doc-hidden helper for unit testing Tests cover registration errors, header application for priority and bucket groups, default group resolution, and empty registry behavior. Fixes Azure#3904 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
c3a04df to
b2cf22a
Compare
Add server-side throughput control API enabling priority-based execution and throughput buckets.
Flow
Registration (build time)
graph LR A[CosmosClientBuilder] -->|with_throughput_control_group| B[stores Vec of groups] B -->|build| C[CosmosDriverRuntimeBuilder] C -->|register_throughput_control_group| D[ThroughputControlGroupRegistry] D --> E[CosmosDriverRuntime] E --> F[CosmosDriver] F --> G[CosmosClient]Per-request resolution
graph TD A[OperationOptions::throughput_control_group_names] -->|resolve| B{Names provided?} B -->|Yes| C[Look up each name in registry] C --> D{Any found?} D -->|Yes| E[Merge into ThroughputControlGroupSnapshot] D -->|No| F[Return None - no headers set] B -->|No| G[Look up default group for container] G -->|Found| E G -->|Not found| F E --> H[build_transport_request] H -->|priority_level| I[x-ms-cosmos-priority-level header] H -->|throughput_bucket| J[x-ms-cosmos-throughput-bucket header]Combining groups
A single request can reference multiple groups to combine features:
The driver merges the first
priority_leveland firstthroughput_bucketfound across all named groups into a single snapshot.Driver changes (
azure_data_cosmos_driver)Throughput control types
ClientSidevariant fromThroughputControlGroupOptionsenum (deferred for GA; enum is#[non_exhaustive], can be re-added later — tracked in [Cosmos] Client-side throughput control #4089)ThroughputTargetenum (will return withClientSide)target_throughputandis_client_sidefromThroughputControlGroupSnapshotMulti-group per request
OperationOptions::throughput_control_group_name(singular) tothroughput_control_group_names(Option<Vec<...>>) so one request can reference both a priority group and a bucket groupNonewithtracing::warn!(no silent fallback to default)Pipeline header application
effective_throughput_control_group()passes resolvedThroughputControlGroupSnapshotthroughexecute_operation_pipeline()tobuild_transport_request()x-ms-cosmos-priority-levelandx-ms-cosmos-throughput-bucketheaders for all operationsOther
PRIORITY_LEVELandTHROUGHPUT_BUCKETconstants torequest_header_namesTransportRequestContextstruct to reducebuild_transport_requestparameter countServerSidePriorityBasedThrottlingdoc URL (was linking to throughput-buckets)tracing::debug!inset_*no-op paths (calling setter on wrong variant)SDK changes (
azure_data_cosmos)Re-exports
ThroughputControlGroupOptions,ThroughputControlGroupRegistry,ThroughputControlGroupKey,ThroughputControlGroupSnapshot,ThroughputControlGroupRegistrationErrorPriorityLevel,ThroughputControlGroupName,ContainerReferenceRegistration
CosmosClientBuilder::with_throughput_control_group()registers groups, passes toCosmosDriverRuntimeBuilderat build timeCosmosClient::throughput_control_groups()read-only access to the driver's registryClientContext refactor
ClientContextstruct bundling shared infrastructure (pipeline,driver,global_endpoint_manager,global_partition_endpoint_manager) threaded throughCosmosClienttoDatabaseClienttoContainerClientContainerClient::newfrom 8 arguments to 4Depends on #4059
Fixes #3904