Add throughput command for viewing and scaling RU/s (#109)#130
Open
mkrueger wants to merge 7 commits into
Open
Add throughput command for viewing and scaling RU/s (#109)#130mkrueger wants to merge 7 commits into
mkrueger wants to merge 7 commits into
Conversation
Adds a top-level 'throughput' command with show/set/manual/autoscale subcommands for database and container scope. Implements GetThroughputAsync/ReplaceThroughputAsync across the data-plane and ARM operations and the resource facade. Includes localization, docs, and offline command tests.
ARM backend migrates between manual and autoscale before setting the requested RU/s. Data-plane backend detects an unsupported mode switch and throws a friendly localized error directing users to a token connection, portal, CLI, or PowerShell.
Write subcommands (set/manual/autoscale) now prompt before applying because throughput changes can affect billing. A --yes/-y/--force flag skips the prompt, and it is automatically bypassed in non-interactive contexts (MCP, script execution, piped input).
Manual RU/s must be at least 400 and a multiple of 100; autoscale maximum RU/s must be at least 1000 and a multiple of 1000. Values are validated before the request is sent so users get clear guidance instead of raw server errors.
Replace synchronous CancellationTokenSource.Cancel() with await CancelAsync() to clear the analyzer warning.
Contributor
Author
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a new throughput CLI command to view and update Cosmos DB database/container provisioned throughput (RU/s), supporting both ARM (AAD/token) and data-plane (key) connections via CosmosResourceFacade.
Changes:
- Introduces
throughputcommand withshow,set/manual, andautoscalesubcommands, plus confirmation prompting and RU increment validation. - Extends the core resource-operations abstraction (
ICosmosResourceOperations) with throughput read/replace APIs and implements them for ARM + data-plane backends. - Updates localization/docs and adds focused command tests; includes a small test-only cancellation API cleanup.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| docs/commands.md | Documents the new throughput command usage, subcommands, validation rules, and confirmation behavior. |
| CosmosDBShell/lang/en.ftl | Adds localized help/error/prompt strings for the new command. |
| CosmosDBShell/Azure.Data.Cosmos.Shell.Core/ThroughputView.cs | Introduces a view model for throughput reads. |
| CosmosDBShell/Azure.Data.Cosmos.Shell.Core/ThroughputUpdate.cs | Introduces a model for throughput updates (manual vs autoscale). |
| CosmosDBShell/Azure.Data.Cosmos.Shell.Core/ThroughputNotConfiguredException.cs | Adds a typed exception for “no dedicated throughput” targets. |
| CosmosDBShell/Azure.Data.Cosmos.Shell.Core/ThroughputModeSwitchNotSupportedException.cs | Adds a typed exception for unsupported manual↔autoscale switching on key/data-plane connections. |
| CosmosDBShell/Azure.Data.Cosmos.Shell.Core/ICosmosResourceOperations.cs | Extends the resource operations interface with throughput get/replace methods. |
| CosmosDBShell/Azure.Data.Cosmos.Shell.Core/DataPlaneCosmosResourceOperations.cs | Implements throughput get/replace via Cosmos data-plane SDK (including mode-switch rejection). |
| CosmosDBShell/Azure.Data.Cosmos.Shell.Core/CosmosResourceFacade.cs | Wires throughput APIs through the facade for backend selection (ARM vs data-plane). |
| CosmosDBShell/Azure.Data.Cosmos.Shell.Core/ArmCosmosResourceOperations.cs | Implements throughput get/replace via ARM, including mode migrations. |
| CosmosDBShell/Azure.Data.Cosmos.Shell.Commands/ThroughputCommand.cs | Adds the new CLI command implementation, validation, confirmation prompt, and error translation. |
| CosmosDBShell.Tests/CommandTests/ThroughputCommandTests.cs | Adds offline unit tests for scope/argument validation branches. |
| CosmosDBShell.Tests/CommandTests/FilterCommandTests.cs | Replaces Cancel() with await CancelAsync() to address VSTHRD103 in tests. |
ShellInterpreter.Confirm (shared by rmdb, rmcon, and throughput) looped on a blocking Console.ReadKey() while the global cancel-key handler swallowed Ctrl+C, so the prompt could never be aborted. Take over Ctrl+C for the duration of the prompt (TreatControlCAsInput) and read with intercept, treating Ctrl+C and Escape as decline, and handle non-interactive consoles gracefully.
When output is redirected (e.g. 'throughput show > out.json'), return the ShellJson result with IsPrinted=false so the interpreter writes JSON to the file, honoring the documented JSON contract. Interactive sessions still render the friendly table, and MCP/piping consume the structured Result as before. Addresses Copilot review feedback on PR #130.
| throw new NotInDatabaseException("throughput"); | ||
| } | ||
|
|
||
| return await this.ExecuteOnScopeAsync(state, shell, this.Database, this.Container, token); |
Comment on lines
+81
to
+82
| string databaseName = this.Database ?? state.DatabaseName; | ||
| return await this.ExecuteOnScopeAsync(state, shell, databaseName, this.Container, token); |
Comment on lines
+87
to
+89
| string databaseName = this.Database ?? state.DatabaseName; | ||
| string containerName = this.Container ?? state.ContainerName; | ||
| return await this.ExecuteOnScopeAsync(state, shell, databaseName, containerName, token); |
Comment on lines
+212
to
+213
| string scope = containerName is null ? "database" : "container"; | ||
| string resourceName = containerName ?? databaseName; |
Comment on lines
+229
to
+230
| string scope = containerName is null ? "database" : "container"; | ||
| string resourceName = containerName ?? databaseName; |
Comment on lines
+175
to
+176
| string scope = containerName is null ? "database" : "container"; | ||
| string resourceName = containerName ?? databaseName; |
Comment on lines
+203
to
+204
| string scope = containerName is null ? "database" : "container"; | ||
| string resourceName = containerName ?? databaseName; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Summary
Adds a
throughputcommand to view and change the provisioned throughput (RU/s) of a Cosmos DB database or container. Closes #109.The command works over both Azure AD (ARM control-plane) and key-based (data-plane) connections via
CosmosResourceFacade, which selects the appropriate operations implementation.Subcommands
showset <RUs>manual.manual <RUs>autoscale <maxRUs>Commits
ThroughputModeSwitchNotSupportedException).set/manual/autoscaleprompt before applying because changes can affect billing. A--yes/-y/--forceflag and non-interactive contexts (MCP, script execution, piped input) skip the prompt.Cancel()→await CancelAsync()) to keep the test build warning-free.Notes
showreports this.ReadOnly = false).Validation
dotnet buildof bothCosmosDBShellandCosmosDBShell.Tests: 0 warnings, 0 errors.