Skip to content

Add throughput command for viewing and scaling RU/s (#109)#130

Open
mkrueger wants to merge 7 commits into
mainfrom
dev/mkrueger/throughput-command
Open

Add throughput command for viewing and scaling RU/s (#109)#130
mkrueger wants to merge 7 commits into
mainfrom
dev/mkrueger/throughput-command

Conversation

@mkrueger

Copy link
Copy Markdown
Contributor

Summary

Adds a throughput command 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

Subcommand Behavior
show Reads current throughput as JSON (mode, provisioned RU/s, autoscale max, min).
set <RUs> Sets manual throughput. Alias of manual.
manual <RUs> Switches to manual provisioning at the given RU/s.
autoscale <maxRUs> Switches to autoscale with the given maximum RU/s.

Commits

  1. Add throughput command for viewing and scaling RU/s — base command, state-visitor wiring, ARM + data-plane operations, facade, view/update models, localization, docs, tests.
  2. Support autoscale/manual mode switching — mode migration handled automatically over a token connection; rejected with actionable guidance over a key-based connection (ThroughputModeSwitchNotSupportedException).
  3. Add confirmation prompt for throughput writesset/manual/autoscale prompt before applying because changes can affect billing. A --yes/-y/--force flag and non-interactive contexts (MCP, script execution, piped input) skip the prompt.
  4. Validate throughput RU/s increments — manual RU/s must be ≥400 and a multiple of 100; autoscale max must be ≥1000 and a multiple of 1000. Validated client-side for clear messages instead of raw server errors.
  5. Fix VSTHRD103 warning in FilterCommandTests — small unrelated test-only cleanup (Cancel()await CancelAsync()) to keep the test build warning-free.

Notes

  • Containers in a shared-throughput database and serverless accounts have no dedicated throughput to change; show reports this.
  • MCP tool is auto-derived from the command attributes (ReadOnly = false).

Validation

  • dotnet build of both CosmosDBShell and CosmosDBShell.Tests: 0 warnings, 0 errors.
  • Throughput command tests pass (9 focused tests); FilterCommand tests pass (27).

mkrueger added 5 commits June 15, 2026 11:14
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.
@mkrueger

Copy link
Copy Markdown
Contributor Author

Some screenshots
Image

Image Image

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 throughput command with show, set/manual, and autoscale subcommands, 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.

Comment thread CosmosDBShell/Azure.Data.Cosmos.Shell.Commands/ThroughputCommand.cs
mkrueger added 2 commits June 15, 2026 14:37
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.
Copilot AI review requested due to automatic review settings June 15, 2026 13:35

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 14 out of 14 changed files in this pull request and generated 7 comments.

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;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[P2] Add Throughput Scaling commands

2 participants