Skip to content

Commit bc2b1ce

Browse files
pjohari-msvipulvishal-msShorya Kumar
authored
[CosmosDB] az cosmosdb create/update: Add --enable-prpp-autoscale to enable/disable burst capacity feature (#30415)
* adding vector policy * CLI changes - prpp autoscale * Testing prpp autoscale * adding tests * Bump up the dependency * Recordings * Merge recordings with master * Merge recordings with Vipul's changes * Recordings * Updated recordings * Test recording * Re-recording tests, again * Changed vector embeddings flag due to linter max param length * The test * External modules - recordings --------- Co-authored-by: Vipul Vishal <[email protected]> Co-authored-by: Shorya Kumar <[email protected]>
1 parent 73addea commit bc2b1ce

File tree

90 files changed

+49221
-58684
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+49221
-58684
lines changed

src/azure-cli/azure/cli/command_modules/cosmosdb/_help.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,12 @@
193193
Usage: --enable-burst-capacity true
194194
Default: false
195195
The accepted values for the enable-burst-capacity are true and false.
196+
- name: --enable-prpp-autoscale
197+
short-summary: Flag to Enable/Disable burst capacity feature
198+
long-summary: |
199+
Usage: --enable-prpp-autoscale true
200+
Default: false
201+
The accepted values for the --enable-prpp-autoscale are true and false.
196202
examples:
197203
- name: Creates a new Azure Cosmos DB database account. (autogenerated)
198204
text: az cosmosdb create --name MyCosmosDBDatabaseAccount --resource-group MyResourceGroup --subscription MySubscription
@@ -957,6 +963,12 @@
957963
Usage: --enable-burst-capacity true
958964
Default: false
959965
The accepted values for the enable-burst-capacity are true and false.
966+
- name: --enable-prpp-autoscale
967+
short-summary: Flag to Enable/Disable burst capacity feature
968+
long-summary: |
969+
Usage: --enable-prpp-autoscale true
970+
Default: false
971+
The accepted values for the --enable-prpp-autoscale are true and false.
960972
examples:
961973
- name: Update an Azure Cosmos DB database account. (autogenerated)
962974
text: az cosmosdb update --capabilities EnableGremlin --name MyCosmosDBDatabaseAccount --resource-group MyResourceGroup

src/azure-cli/azure/cli/command_modules/cosmosdb/_params.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,12 @@
3737
from azure.mgmt.cosmosdb.models import (
3838
ContinuousTier, MinimalTlsVersion)
3939

40-
SQL_GREMLIN_INDEXING_POLICY_EXAMPLE = """--idx "{\\"indexingMode\\": \\"consistent\\", \\"automatic\\": true, \\"includedPaths\\": [{\\"path\\": \\"/*\\"}], \\"excludedPaths\\": [{ \\"path\\": \\"/headquarters/employees/?\\"}, { \\"path\\": \\"/\\\\"_etag\\\\"/?\\"}]}"
40+
GREMLIN_INDEXING_POLICY_EXAMPLE = """--idx "{\\"indexingMode\\": \\"consistent\\", \\"automatic\\": true, \\"includedPaths\\": [{\\"path\\": \\"/*\\"}], \\"excludedPaths\\": [{ \\"path\\": \\"/headquarters/employees/?\\"}, { \\"path\\": \\"/\\\\"_etag\\\\"/?\\"}]}"
41+
"""
42+
SQL_INDEXING_POLICY_EXAMPLE = """--idx "{\\"indexingMode\\": \\"consistent\\", \\"automatic\\": true, \\"includedPaths\\": [{\\"path\\": \\"/*\\"}], \\"excludedPaths\\": [{ \\"path\\": \\"/headquarters/employees/?\\"}, { \\"path\\": \\"/\\\\"_etag\\\\"/?\\"}],\\"vectorIndexes\\": [{\\"path\\": \\"/vector1\\",\\"type\\": \\"flat\\"}]}"
43+
"""
44+
45+
SQL_VECTOR_EMBEDDING_POLICY_EXAMPLE = """--vector-embeddings "{\\"vectorEmbeddings\\": [{\\"path\\": \\"/vector1\\", \\"dataType\\": \\"float32\\", \\"dimensions\\": 2, \\"distanceFunction\\": \\"dotproduct\\" }]}"
4146
"""
4247

4348
SQL_UNIQUE_KEY_POLICY_EXAMPLE = """--unique-key-policy "{\\"uniqueKeys\\": [{\\"paths\\": [\\"/path/to/key1\\"]}, {\\"paths\\": [\\"/path/to/key2\\"]}]}"
@@ -90,6 +95,7 @@ def load_arguments(self, _):
9095
c.argument('tables_to_restore', nargs='+', action=CreateTableRestoreResource, arg_group='Restore')
9196
c.argument('enable_partition_merge', arg_type=get_three_state_flag(), help="Flag to enable partition merge on the account.")
9297
c.argument('enable_burst_capacity', arg_type=get_three_state_flag(), help="Flag to enable burst capacity on the account.")
98+
c.argument('enable_prpp_autoscale', arg_type=get_three_state_flag(), help="Enable or disable PerRegionPerPartitionAutoscale.")
9399
c.argument('key_uri', help="The URI of the key vault")
94100

95101
for scope in ['cosmosdb create', 'cosmosdb update']:
@@ -121,6 +127,7 @@ def load_arguments(self, _):
121127
c.argument('backup_policy_type', arg_type=get_enum_type(BackupPolicyType), help="The type of backup policy of the account to create", arg_group='Backup Policy')
122128
c.argument('enable_partition_merge', arg_type=get_three_state_flag(), help="Flag to enable partition merge on the account.")
123129
c.argument('enable_burst_capacity', arg_type=get_three_state_flag(), help="Flag to enable burst capacity on the account.")
130+
c.argument('enable_prpp_autoscale', arg_type=get_three_state_flag(), help="Enable or disable PerRegionPerPartitionAutoscale.")
124131
c.argument('continuous_tier', arg_type=get_enum_type(ContinuousTier), help="The tier of Continuous backup", arg_group='Backup Policy')
125132
c.argument('minimal_tls_version', arg_type=get_enum_type(MinimalTlsVersion), help="Indicates the minimum allowed TLS version")
126133

@@ -156,6 +163,7 @@ def load_arguments(self, _):
156163
c.argument('throughput', type=int, help='Offer Throughput (RU/s)')
157164
c.argument('partition_key_path', help='Partition Key Path, e.g., \'/properties/name\'')
158165
c.argument('client_encryption_policy', options_list=['--cep'], type=shell_safe_json_parse, completer=FilesCompleter(), validator=validate_client_encryption_policy, help='Client Encryption Policy, you can enter it as a string or as a file, e.g., --cep @policy-file.json or ' + SQL_CLIENT_ENCRYPTION_POLICY_EXAMPLE)
166+
c.argument('vector_embedding_policy', options_list=['--vector-embeddings'], type=shell_safe_json_parse, completer=FilesCompleter(), help='Vector Encryption Policy, you can enter it as a string or as a file, e.g., --vector-embeddings @policy-file.json or ' + SQL_VECTOR_EMBEDDING_POLICY_EXAMPLE)
159167
c.argument('indexing_policy', type=shell_safe_json_parse, completer=FilesCompleter(), help='Indexing Policy, you can enter it as a string or as a file, e.g., --indexing-policy @policy-file.json)')
160168
c.argument('default_ttl', type=int, help='Default TTL. Provide 0 to disable.')
161169

@@ -208,8 +216,9 @@ def load_arguments(self, _):
208216
c.argument('partition_key_path', options_list=['--partition-key-path', '-p'], help='Partition Key Path, e.g., \'/address/zipcode\'')
209217
c.argument('partition_key_version', type=int, options_list=['--partition-key-version'], help='The version of partition key.')
210218
c.argument('default_ttl', options_list=['--ttl'], type=int, help='Default TTL. If the value is missing or set to "-1", items don’t expire. If the value is set to "n", items will expire "n" seconds after last modified time.')
211-
c.argument('indexing_policy', options_list=['--idx'], type=shell_safe_json_parse, completer=FilesCompleter(), help='Indexing Policy, you can enter it as a string or as a file, e.g., --idx @policy-file.json or ' + SQL_GREMLIN_INDEXING_POLICY_EXAMPLE)
219+
c.argument('indexing_policy', options_list=['--idx'], type=shell_safe_json_parse, completer=FilesCompleter(), help='Indexing Policy, you can enter it as a string or as a file, e.g., --idx @policy-file.json or ' + SQL_INDEXING_POLICY_EXAMPLE)
212220
c.argument('client_encryption_policy', options_list=['--cep'], type=shell_safe_json_parse, completer=FilesCompleter(), validator=validate_client_encryption_policy, help='Client Encryption Policy, you can enter it as a string or as a file, e.g., --cep @policy-file.json or ' + SQL_CLIENT_ENCRYPTION_POLICY_EXAMPLE)
221+
c.argument('vector_embedding_policy', options_list=['--vector-embeddings'], type=shell_safe_json_parse, completer=FilesCompleter(), help='Vector Encryption Policy, you can enter it as a string or as a file, e.g., --vector-embeddings @policy-file.json or ' + SQL_VECTOR_EMBEDDING_POLICY_EXAMPLE)
213222
c.argument('unique_key_policy', options_list=['--unique-key-policy', '-u'], type=shell_safe_json_parse, completer=FilesCompleter(), help='Unique Key Policy, you can enter it as a string or as a file, e.g., --unique-key-policy @policy-file.json or ' + SQL_UNIQUE_KEY_POLICY_EXAMPLE)
214223
c.argument('conflict_resolution_policy', options_list=['--conflict-resolution-policy', '-c'], type=shell_safe_json_parse, completer=FilesCompleter(), help='Conflict Resolution Policy, you can enter it as a string or as a file, e.g., --conflict-resolution-policy @policy-file.json or ' + SQL_GREMLIN_CONFLICT_RESOLUTION_POLICY_EXAMPLE)
215224
c.argument('max_throughput', max_throughput_type)
@@ -289,7 +298,7 @@ def load_arguments(self, _):
289298
c.argument('graph_name', options_list=['--name', '-n'], help="Graph name")
290299
c.argument('partition_key_path', options_list=['--partition-key-path', '-p'], help='Partition Key Path, e.g., \'/address/zipcode\'')
291300
c.argument('default_ttl', options_list=['--ttl'], type=int, help='Default TTL. If the value is missing or set to "-1", items don’t expire. If the value is set to "n", items will expire "n" seconds after last modified time.')
292-
c.argument('indexing_policy', options_list=['--idx'], type=shell_safe_json_parse, completer=FilesCompleter(), help='Indexing Policy, you can enter it as a string or as a file, e.g., --idx @policy-file.json or ' + SQL_GREMLIN_INDEXING_POLICY_EXAMPLE)
301+
c.argument('indexing_policy', options_list=['--idx'], type=shell_safe_json_parse, completer=FilesCompleter(), help='Indexing Policy, you can enter it as a string or as a file, e.g., --idx @policy-file.json or ' + GREMLIN_INDEXING_POLICY_EXAMPLE)
293302
c.argument('conflict_resolution_policy', options_list=['--conflict-resolution-policy', '-c'], type=shell_safe_json_parse, completer=FilesCompleter(), help='Conflict Resolution Policy, you can enter it as a string or as a file, e.g., --conflict-resolution-policy @policy-file.json or ' + SQL_GREMLIN_CONFLICT_RESOLUTION_POLICY_EXAMPLE)
294303
c.argument('max_throughput', max_throughput_type)
295304
c.argument('throughput', help='The throughput of Gremlin graph (RU/s). Default value is 400. Omit this parameter if the database has shared throughput unless the graph should have dedicated throughput.')

src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ def cli_cosmosdb_create(cmd,
141141
restore_timestamp=None,
142142
enable_partition_merge=None,
143143
enable_burst_capacity=None,
144+
enable_prpp_autoscale=None,
144145
minimal_tls_version=None):
145146
"""Create a new Azure Cosmos DB database account."""
146147

@@ -196,6 +197,7 @@ def cli_cosmosdb_create(cmd,
196197
arm_location=resource_group_location,
197198
enable_partition_merge=enable_partition_merge,
198199
enable_burst_capacity=enable_burst_capacity,
200+
enable_prpp_autoscale=enable_prpp_autoscale,
199201
minimal_tls_version=minimal_tls_version)
200202

201203

@@ -241,6 +243,7 @@ def _create_database_account(client,
241243
arm_location=None,
242244
enable_partition_merge=None,
243245
enable_burst_capacity=None,
246+
enable_prpp_autoscale=None,
244247
minimal_tls_version=None,
245248
disable_ttl=None):
246249

@@ -379,6 +382,7 @@ def _create_database_account(client,
379382
restore_parameters=restore_parameters,
380383
enable_partition_merge=enable_partition_merge,
381384
enable_burst_capacity=enable_burst_capacity,
385+
enable_per_region_per_partition_autoscale=enable_prpp_autoscale,
382386
minimal_tls_version=minimal_tls_version
383387
)
384388

@@ -419,6 +423,7 @@ def cli_cosmosdb_update(client,
419423
continuous_tier=None,
420424
enable_partition_merge=None,
421425
enable_burst_capacity=None,
426+
enable_prpp_autoscale=None,
422427
minimal_tls_version=None):
423428
"""Update an existing Azure Cosmos DB database account. """
424429
existing = client.get(resource_group_name, account_name)
@@ -516,6 +521,7 @@ def cli_cosmosdb_update(client,
516521
analytical_storage_configuration=analytical_storage_configuration,
517522
enable_partition_merge=enable_partition_merge,
518523
enable_burst_capacity=enable_burst_capacity,
524+
enable_per_region_per_partition_autoscale=enable_prpp_autoscale,
519525
minimal_tls_version=minimal_tls_version)
520526

521527
async_docdb_update = client.begin_update(resource_group_name, account_name, params)
@@ -599,9 +605,10 @@ def _populate_sql_container_definition(sql_container_resource,
599605
client_encryption_policy,
600606
partition_key_version,
601607
conflict_resolution_policy,
602-
analytical_storage_ttl):
608+
analytical_storage_ttl,
609+
vector_embedding_policy):
603610
if all(arg is None for arg in
604-
[partition_key_path, partition_key_version, default_ttl, indexing_policy, unique_key_policy, client_encryption_policy, conflict_resolution_policy, analytical_storage_ttl]):
611+
[partition_key_path, partition_key_version, default_ttl, indexing_policy, unique_key_policy, client_encryption_policy, conflict_resolution_policy, analytical_storage_ttl, vector_embedding_policy]):
605612
return False
606613

607614
if partition_key_path is not None:
@@ -630,6 +637,9 @@ def _populate_sql_container_definition(sql_container_resource,
630637
if analytical_storage_ttl is not None:
631638
sql_container_resource.analytical_storage_ttl = analytical_storage_ttl
632639

640+
if vector_embedding_policy is not None:
641+
sql_container_resource.vector_embedding_policy = vector_embedding_policy
642+
633643
return True
634644

635645

@@ -647,7 +657,8 @@ def cli_cosmosdb_sql_container_create(client,
647657
max_throughput=None,
648658
unique_key_policy=None,
649659
conflict_resolution_policy=None,
650-
analytical_storage_ttl=None):
660+
analytical_storage_ttl=None,
661+
vector_embedding_policy=None):
651662
"""Creates an Azure Cosmos DB SQL container """
652663
sql_container_resource = SqlContainerResource(id=container_name)
653664

@@ -659,7 +670,8 @@ def cli_cosmosdb_sql_container_create(client,
659670
client_encryption_policy,
660671
partition_key_version,
661672
conflict_resolution_policy,
662-
analytical_storage_ttl)
673+
analytical_storage_ttl,
674+
vector_embedding_policy)
663675

664676
options = _get_options(throughput, max_throughput)
665677

@@ -681,7 +693,8 @@ def cli_cosmosdb_sql_container_update(client,
681693
container_name,
682694
default_ttl=None,
683695
indexing_policy=None,
684-
analytical_storage_ttl=None):
696+
analytical_storage_ttl=None,
697+
vector_embedding_policy=None):
685698
"""Updates an Azure Cosmos DB SQL container """
686699
logger.debug('reading SQL container')
687700
sql_container = client.get_sql_container(resource_group_name, account_name, database_name, container_name)
@@ -692,6 +705,7 @@ def cli_cosmosdb_sql_container_update(client,
692705
sql_container_resource.default_ttl = sql_container.resource.default_ttl
693706
sql_container_resource.unique_key_policy = sql_container.resource.unique_key_policy
694707
sql_container_resource.conflict_resolution_policy = sql_container.resource.conflict_resolution_policy
708+
sql_container_resource.vector_embedding_policy = sql_container.resource.vector_embedding_policy
695709

696710
# client encryption policy is immutable
697711
sql_container_resource.client_encryption_policy = sql_container.resource.client_encryption_policy
@@ -704,7 +718,8 @@ def cli_cosmosdb_sql_container_update(client,
704718
None,
705719
None,
706720
None,
707-
analytical_storage_ttl):
721+
analytical_storage_ttl,
722+
vector_embedding_policy):
708723
logger.debug('replacing SQL container')
709724

710725
sql_container_create_update_resource = SqlContainerCreateUpdateParameters(
@@ -2145,7 +2160,8 @@ def _populate_collection_definition(collection,
21452160
partition_key_path=None,
21462161
default_ttl=None,
21472162
indexing_policy=None,
2148-
client_encryption_policy=None):
2163+
client_encryption_policy=None,
2164+
vector_embedding_policy=None):
21492165
if all(arg is None for arg in [partition_key_path, default_ttl, indexing_policy]):
21502166
return False
21512167

@@ -2166,6 +2182,9 @@ def _populate_collection_definition(collection,
21662182
if client_encryption_policy is not None:
21672183
collection['clientEncryptionPolicy'] = client_encryption_policy
21682184

2185+
if vector_embedding_policy is not None:
2186+
collection['vectorIndexingPolicy'] = vector_embedding_policy
2187+
21692188
return True
21702189

21712190

@@ -2176,7 +2195,8 @@ def cli_cosmosdb_collection_create(client,
21762195
partition_key_path=None,
21772196
default_ttl=None,
21782197
indexing_policy=DEFAULT_INDEXING_POLICY,
2179-
client_encryption_policy=None):
2198+
client_encryption_policy=None,
2199+
vector_embedding_policy=None):
21802200
"""Creates an Azure Cosmos DB collection """
21812201
collection = {'id': collection_id}
21822202

@@ -2188,7 +2208,8 @@ def cli_cosmosdb_collection_create(client,
21882208
partition_key_path,
21892209
default_ttl,
21902210
indexing_policy,
2191-
client_encryption_policy)
2211+
client_encryption_policy,
2212+
vector_embedding_policy)
21922213

21932214
created_collection = client.CreateContainer(_get_database_link(database_id), collection,
21942215
options)

0 commit comments

Comments
 (0)