Skip to content

Adding Throughput Bucket Header #40340

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

Merged

Conversation

andrewmathew1
Copy link
Contributor

@andrewmathew1 andrewmathew1 commented Apr 2, 2025

Description

Adding the throughput bucket header, available at the request and client level for both async and sync operations.
The throughput bucket header is able to be passed for every request on container and database operations. It's also able to be set at the overall client level. However, the header passed into the request will take precedence over the client level header if both are passed in.

@Copilot Copilot AI review requested due to automatic review settings April 2, 2025 16:39
@andrewmathew1 andrewmathew1 requested review from annatisch and a team as code owners April 2, 2025 16:39
@github-actions github-actions bot added the Cosmos label Apr 2, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds support for a new throughput bucket header to the SDK at both the request and client levels.

  • Introduces the new "x-ms-cosmos-throughput-bucket" header in http_constants.py.
  • Adds a new parameter "throughput_bucket" to various container and database creation/update functions.
  • Updates internal request-building logic in _base.py to include the throughput bucket header.

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
sdk/cosmos/azure-cosmos/azure/cosmos/http_constants.py Adds the throughput bucket header constant.
sdk/cosmos/azure-cosmos/azure/cosmos/database.py Updates methods to accept and propagate a throughput_bucket parameter; includes an unexpected import.
sdk/cosmos/azure-cosmos/azure/cosmos/cosmos_client.py Adds throughput_bucket parameter support for client-level database creation.
sdk/cosmos/azure-cosmos/azure/cosmos/container.py Adds throughput_bucket support in item creation methods.
sdk/cosmos/azure-cosmos/azure/cosmos/_base.py Modifies header generation to include the throughput bucket if provided.
Comments suppressed due to low confidence (1)

sdk/cosmos/azure-cosmos/azure/cosmos/http_constants.py:192

  • [nitpick] Consider removing or clarifying the '#CHECK' comment to avoid leaving debugging markers in production code.
ThroughputBucket = "x-ms-cosmos-throughput-bucket" #CHECK

@andrewmathew1 andrewmathew1 force-pushed the users/andrewmathew1/throughputbucket branch from b424ad1 to 419e374 Compare April 8, 2025 01:32
@azure-sdk
Copy link
Collaborator

API change check

APIView has identified API level changes in this PR and created following API reviews.

azure-cosmos

@andrewmathew1
Copy link
Contributor Author

/azp run python - cosmos - ci

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Member

@kushagraThapar kushagraThapar left a comment

Choose a reason for hiding this comment

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

Great work @andrewmathew1
Everything looks good to me. Requesting some changes. Please do add samples as well and add a section in the readme.md that our sdk supports this feature and link to the sample on how to use it.

Copy link
Member

@kushagraThapar kushagraThapar left a comment

Choose a reason for hiding this comment

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

thanks @andrewmathew1 , great job!

Copy link
Member

@simorenoh simorenoh left a comment

Choose a reason for hiding this comment

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

just need pipelines to pass, LGTM otherwise!

@andrewmathew1 andrewmathew1 merged commit f32da5e into Azure:main Apr 22, 2025
18 checks passed
@@ -171,6 +171,7 @@ class CosmosClient: # pylint: disable=client-accepts-api-version-keyword
level (to log all requests) or at a single request level. Requests will be logged at INFO level.
:keyword bool no_response_on_write: Indicates whether service should be instructed to skip sending
response payloads for write operations on items by default unless specified differently per operation.
:keyword int throughput_bucket: The desired throughput bucket for the client
Copy link
Member

Choose a reason for hiding this comment

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

The readme mentioned that the feature is in public preview? If that's the case, then everywhere this parameter is documented, it needs to be marked as provisional.

@@ -265,6 +267,7 @@ async def create_database(
:paramtype offer_throughput: Union[int, ~azure.cosmos.ThroughputProperties]
:keyword dict[str, str] initial_headers: Initial headers to be sent as part of the request.
:keyword response_hook: A callable invoked with the response metadata.
:keyword int throughput_bucket: The desired throughput bucket for the client
Copy link
Member

Choose a reason for hiding this comment

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

It should be added to the per-method documentation that a value specified here will override any value already specified at the client-level.

Copy link
Member

Choose a reason for hiding this comment

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

Also - it looks like this was maybe copy+pasted from the client-level documentation? This should be rephrased as it's not the bucket "for the client", rather it's the bucket "for the request" (or maybe "operation", as some of these, like query, are multiple requests).

cRui861 pushed a commit that referenced this pull request May 14, 2025
* inital commit for throughput bucket

* added test for throughput bucket

* got rid of extra comment

* sync part of throughput headers

* added async part with new test file

* added async part with tests

* got rid of extra space

* added _async label to test_headers_async

* removed extra line

* removed unnecessary syntax

* made requested changes on pr, mostly for async tests

* added another finally block to test_headers

* edited replace container test

* added sample files and section to the readme

* got rid of trailing whitespace

* added negative test, added to changelog

* added header to changelog

* got rid of extra ,

* edited readme for new sample file names

* marked negative test as TODO

---------

Co-authored-by: Andrew Mathew <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

7 participants