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

Open
wants to merge 16 commits into
base: main
Choose a base branch
from

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.

@@ -160,6 +160,10 @@ def __init__( # pylint: disable=too-many-statements
http_constants.HttpHeaders.IsContinuationExpected: False,
}

throughput_bucket = kwargs.pop('throughput_bucket', None)
if throughput_bucket:
Copy link
Member

Choose a reason for hiding this comment

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

what if the value is 0? how does python handle it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If the bucket id is between 1-5, it will either go to the corresponding bucket or be ignored based on if the user has set up their buckets. If its any other value like 0 or a number greater than 5 a bad request is thrown.

@@ -232,6 +237,7 @@ async def create_item(
:keyword bool no_response: Indicates whether service should be instructed to skip
sending response payloads. When not specified explicitly here, the default value will be determined from
client-level options.
: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.

is there any default value for this?
We should put some guidance here on the usage, etc. Please discuss with a PM to understand more on this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Discussed with Achint and he mentioned that there is no default value, it should just be null.

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!

@@ -874,6 +874,20 @@ may have additional latencies associated with searching in the service.

You can find our sync samples [here][cosmos_index_sample] and our async samples [here][cosmos_index_sample_async] as well for additional guidance.

### Public Preview - Throughput Buckets
Copy link
Member

Choose a reason for hiding this comment

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

This should have a changelog entry for this new feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

5 participants