-
Notifications
You must be signed in to change notification settings - Fork 7
Fix database and container creation on serverless accounts #222
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
Mike Krüger (mkrueger)
wants to merge
7
commits into
main
Choose a base branch
from
dev/mkrueger/serverless-create-throughput
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
72f8df0
Omit creation throughput on serverless accounts (#218)
mkrueger 5c7d3eb
Complete serverless creation coverage and documentation
mkrueger 93aa22a
Merge remote-tracking branch 'origin/main' into dev/mkrueger/serverle…
mkrueger 54b271c
Retry serverless creation only for throughput rejections
mkrueger 0d52882
Tighten creation retry match and neutralize create scale help
mkrueger 0311a6b
Reject any supplied scale value on serverless and tighten smoke asser…
mkrueger dfee198
Merge remote-tracking branch 'origin/main' into dev/mkrueger/serverle…
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
349 changes: 349 additions & 0 deletions
349
CosmosDBShell.Tests/CommandTests/ServerlessCreationThroughputTests.cs
Large diffs are not rendered by default.
Oops, something went wrong.
40 changes: 40 additions & 0 deletions
40
CosmosDBShell.Tests/Integration/ServerlessCreationSmokeTests.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| // ------------------------------------------------------------ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // ------------------------------------------------------------ | ||
|
|
||
| namespace CosmosShell.Tests.Integration; | ||
|
|
||
| using Azure.Data.Cosmos.Shell.Core; | ||
| using Azure.Data.Cosmos.Shell.Util; | ||
|
|
||
| // Opt-in: the emulator cannot establish serverless behavior, so this needs a real serverless account. | ||
| [Trait("Category", "LiveServerless")] | ||
| public class ServerlessCreationSmokeTests : IntegrationTestBase | ||
| { | ||
| internal const string ConnectionStringVariable = "COSMOSDB_SHELL_SERVERLESS_TEST_CONNECTION_STRING"; | ||
|
|
||
| [Fact] | ||
| public async Task MkdbAndMkcon_WithoutThroughputOptions_SucceedOnServerlessAccount() | ||
| { | ||
| var connectionString = Environment.GetEnvironmentVariable(ConnectionStringVariable); | ||
| Assert.SkipWhen(string.IsNullOrWhiteSpace(connectionString), $"Set {ConnectionStringVariable} to a serverless account connection string to run this test."); | ||
|
|
||
| await Shell.ConnectAsync(connectionString!, null, token: TestContext.Current.CancellationToken); | ||
| var databaseName = $"shell-serverless-{Guid.NewGuid():N}"; | ||
| try | ||
| { | ||
| var database = await RunScriptAsync($"mkdb {databaseName}"); | ||
| Assert.False(database is ErrorCommandState, FormatError(database)); | ||
|
|
||
| var container = await RunScriptAsync($"mkcon Items /pk --database {databaseName}"); | ||
| Assert.False(container is ErrorCommandState, FormatError(container)); | ||
|
|
||
| var rejected = await RunScriptAsync($"mkcon Rejected /pk --database {databaseName} --ru 400"); | ||
| Assert.Equal(MessageService.GetString("error-serverless_throughput_not_supported"), GetErrorMessage(rejected)); | ||
| } | ||
| finally | ||
| { | ||
| await RunScriptAsync($"rmdb {databaseName} true"); | ||
| } | ||
| } | ||
| } |
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
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
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
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
29 changes: 29 additions & 0 deletions
29
CosmosDBShell/Azure.Data.Cosmos.Shell.Core/CreationThroughput.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| // ------------------------------------------------------------ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // ------------------------------------------------------------ | ||
|
|
||
| namespace Azure.Data.Cosmos.Shell.Core; | ||
|
|
||
| using Microsoft.Azure.Cosmos; | ||
|
|
||
| /// <summary> | ||
| /// Resolves the provisioned throughput requested by <c>mkdb</c> and <c>mkcon</c>. | ||
| /// </summary> | ||
| internal static class CreationThroughput | ||
| { | ||
| internal const int DefaultMaxRu = 1000; | ||
|
|
||
| internal static bool IsSpecified(string? scale, int? maxRu) => scale is not null || maxRu.HasValue; | ||
|
|
||
| internal static bool IsManual(string? scale) => | ||
| string.Equals(scale, "manual", StringComparison.OrdinalIgnoreCase) || | ||
| string.Equals(scale, "m", StringComparison.OrdinalIgnoreCase); | ||
|
|
||
| internal static ThroughputProperties CreateProperties(string? scale, int? maxRu) | ||
| { | ||
| var ru = maxRu ?? DefaultMaxRu; | ||
| return IsManual(scale) | ||
| ? ThroughputProperties.CreateManualThroughput(ru) | ||
| : ThroughputProperties.CreateAutoscaleThroughput(ru); | ||
| } | ||
| } |
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
16 changes: 16 additions & 0 deletions
16
CosmosDBShell/Azure.Data.Cosmos.Shell.Core/ServerlessThroughputNotSupportedException.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| // ------------------------------------------------------------ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // ------------------------------------------------------------ | ||
| namespace Azure.Data.Cosmos.Shell.Core; | ||
|
|
||
| /// <summary> | ||
| /// Thrown when <c>--scale</c> or <c>--ru</c> is supplied while creating a database or | ||
| /// container on a serverless account, which cannot have provisioned throughput. | ||
| /// </summary> | ||
| internal sealed class ServerlessThroughputNotSupportedException : System.InvalidOperationException | ||
| { | ||
| public ServerlessThroughputNotSupportedException(System.Exception? innerException = null) | ||
| : base("Provisioned throughput is not supported on a serverless account.", innerException) | ||
| { | ||
| } | ||
| } |
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.