Skip to content

Commit 3e77614

Browse files
Add support for table and index recommendations under a new command group
1 parent 2b87b6c commit 3e77614

File tree

7 files changed

+121
-90
lines changed

7 files changed

+121
-90
lines changed

src/azure-cli/azure/cli/command_modules/rdbms/_flexible_server_location_capabilities_util.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def _postgres_parse_list_capability(result):
5252
restricted = offer_restricted[0].status if offer_restricted else None
5353
zone_redundant = [feature for feature in supported_features if feature.name == "ZoneRedundantHa"]
5454
geo_backup = [feature for feature in supported_features if feature.name == "GeoBackup"]
55-
index_tuning = [feature for feature in supported_features if feature.name == "IndexTuning"]
55+
automated_tuning = [feature for feature in supported_features if feature.name == "IndexTuning"]
5656

5757
if restricted == "Enabled":
5858
raise InvalidArgumentValueError("The location is restricted for provisioning of flexible servers. Please try using another region.")
@@ -62,7 +62,7 @@ def _postgres_parse_list_capability(result):
6262

6363
single_az = zone_redundant[0].status != "Enabled" if zone_redundant else True
6464
geo_backup_supported = geo_backup[0].status == "Enabled" if geo_backup else False
65-
index_tuning_supported = index_tuning[0].status == "Enabled" if index_tuning else False
65+
automated_tuning_supported = automated_tuning[0].status == "Enabled" if automated_tuning else False
6666

6767
tiers = result[0].supported_server_editions
6868
tiers_dict = {}

src/azure-cli/azure/cli/command_modules/rdbms/_helptext_pg.py

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,55 +1164,63 @@
11641164
text: az postgres flexible-server fabric-mirroring update-databases -g testgroup -s testsvr --database-names testdb2 testdb3
11651165
"""
11661166

1167-
helps['postgres flexible-server index-tuning'] = """
1167+
helps['postgres flexible-server tuning'] = """
11681168
type: group
1169-
short-summary: Index tuning analyzes read queries captured in Query Store and recommends index changes to optimize these queries.
1169+
short-summary: Automated tuning analyzes read queries captured in Query Store and recommends table or index changes to optimize these queries.
11701170
"""
11711171

1172-
helps['postgres flexible-server index-tuning update'] = """
1172+
helps['postgres flexible-server tuning update'] = """
11731173
type: command
1174-
short-summary: Update index tuning to be enabled/disabled for a PostgreSQL flexible server.
1174+
short-summary: Update automated tuning to be enabled/disabled for a PostgreSQL flexible server.
11751175
examples:
1176-
- name: Update index tuning to be enabled/disabled for a PostgreSQL flexible server.
1177-
text: az postgres flexible-server index-tuning update -g testgroup -s testsvr --enabled True
1176+
- name: Update automated tuning to be enabled/disabled for a PostgreSQL flexible server.
1177+
text: az postgres flexible-server tuning update -g testgroup -s testsvr --enabled True
11781178
"""
11791179

1180-
helps['postgres flexible-server index-tuning show'] = """
1180+
helps['postgres flexible-server tuning show'] = """
11811181
type: command
1182-
short-summary: Show state of index tuning for a PostgreSQL flexible server.
1182+
short-summary: Show state of automated tuning for a PostgreSQL flexible server.
11831183
examples:
1184-
- name: Show state of index tuning for a PostgreSQL flexible server.
1185-
text: az postgres flexible-server index-tuning show -g testgroup -s testsvr
1184+
- name: Show state of automated tuning for a PostgreSQL flexible server.
1185+
text: az postgres flexible-server tuning show -g testgroup -s testsvr
11861186
"""
11871187

1188-
helps['postgres flexible-server index-tuning list-settings'] = """
1188+
helps['postgres flexible-server tuning list-settings'] = """
11891189
type: command
1190-
short-summary: Get tuning settings associated for a PostgreSQL flexible server.
1190+
short-summary: Get automated tuning settings associated to a PostgreSQL flexible server.
11911191
examples:
1192-
- name: Get tuning settings for a PostgreSQL flexible server.
1193-
text: az postgres flexible-server index-tuning list-settings -g testgroup -s testsvr
1192+
- name: Get automated tuning settings for a PostgreSQL flexible server.
1193+
text: az postgres flexible-server tuning list-settings -g testgroup -s testsvr
11941194
"""
11951195

1196-
helps['postgres flexible-server index-tuning show-settings'] = """
1196+
helps['postgres flexible-server tuning show-settings'] = """
11971197
type: command
1198-
short-summary: Get a tuning setting for a PostgreSQL flexible server.
1198+
short-summary: Get an automated tuning setting for a PostgreSQL flexible server.
11991199
examples:
1200-
- name: Get a tuning setting for a PostgreSQL flexible server.
1201-
text: az postgres flexible-server index-tuning show-settings -g testgroup -s testsvr --name setting-name
1200+
- name: Get an automated tuning setting for a PostgreSQL flexible server.
1201+
text: az postgres flexible-server tuning show-settings -g testgroup -s testsvr --name setting-name
12021202
"""
12031203

1204-
helps['postgres flexible-server index-tuning set-settings'] = """
1204+
helps['postgres flexible-server tuning set-settings'] = """
12051205
type: command
1206-
short-summary: Update a tuning setting for a PostgreSQL flexible server.
1206+
short-summary: Update an automated tuning setting for a PostgreSQL flexible server.
12071207
examples:
1208-
- name: Update a tuning setting for a PostgreSQL flexible server.
1209-
text: az postgres flexible-server index-tuning set-settings -g testgroup -s testsvr --name setting-name --value setting-value
1208+
- name: Update an automated tuning setting for a PostgreSQL flexible server.
1209+
text: az postgres flexible-server tuning set-settings -g testgroup -s testsvr --name setting-name --value setting-value
12101210
"""
12111211

1212-
helps['postgres flexible-server index-tuning list-recommendations'] = """
1212+
helps['postgres flexible-server tuning list-index-recommendations'] = """
12131213
type: command
1214-
short-summary: Get available tuning index recommendations associated with a PostgreSQL flexible server.
1214+
short-summary: Get available automated tuning index recommendations associated with a PostgreSQL flexible server.
12151215
examples:
1216-
- name: Get tuning index recommendations for a PostgreSQL flexible server. Filter by selected type.
1217-
text: az postgres flexible-server index-tuning list-recommendations -g testgroup -s testsvr --recommendation-type CreateIndex
1216+
- name: Get automated tuning index recommendations for a PostgreSQL flexible server. Filter by selected type.
1217+
text: az postgres flexible-server tuning list-index-recommendations -g testgroup -s testsvr --recommendation-type CreateIndex
1218+
"""
1219+
1220+
helps['postgres flexible-server tuning list-table-recommendations'] = """
1221+
type: command
1222+
short-summary: Get available automated tuning table recommendations associated with a PostgreSQL flexible server.
1223+
examples:
1224+
- name: Get automated tuning table recommendations for a PostgreSQL flexible server. Filter by selected type.
1225+
text: az postgres flexible-server tuning list-table-recommendations -g testgroup -s testsvr --recommendation-type AnalyzeTable
12181226
"""

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

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from .randomname.generate import generate_username
2424
from ._flexible_server_util import get_current_time
2525
from argcomplete.completers import FilesCompleter
26-
from ._util import get_index_tuning_settings_map
26+
from ._util import get_automated_tuning_settings_map
2727

2828

2929
def load_arguments(self, _): # pylint: disable=too-many-statements, too-many-locals
@@ -1057,34 +1057,40 @@ def _flexible_server_params(command_group):
10571057
c.argument('resource_group_name', arg_type=resource_group_name_type)
10581058
c.argument('server_name', options_list=['--server-name', '-s'], id_part='name', arg_type=server_name_arg_type, required=False)
10591059

1060-
# index tuning
1060+
# automated tuning
10611061
if command_group == 'postgres':
1062-
for scope in ['update', 'show', 'list-settings', 'show-settings', 'set-settings', 'list-recommendations']:
1063-
argument_context_string = '{} flexible-server index-tuning {}'.format(command_group, scope)
1062+
for scope in ['update', 'show', 'list-settings', 'show-settings', 'set-settings', 'list-table-recommendations', 'list-index-recommendations']:
1063+
argument_context_string = '{} flexible-server tuning {}'.format(command_group, scope)
10641064
with self.argument_context(argument_context_string) as c:
10651065
c.argument('server_name', options_list=['--server-name', '-s'], arg_type=server_name_arg_type)
10661066

1067-
with self.argument_context('{} flexible-server index-tuning update'.format(command_group)) as c:
1068-
c.argument('index_tuning_enabled',
1067+
with self.argument_context('{} flexible-server tuning update'.format(command_group)) as c:
1068+
c.argument('tuning_enabled',
10691069
options_list=['--enabled'],
10701070
required=True,
1071-
help='Enable or disable index tuning feature.',
1071+
help='Enable or disable index and table tuning feature.',
10721072
arg_type=get_enum_type(['True', 'False']))
10731073

1074-
with self.argument_context('{} flexible-server index-tuning list-recommendations'.format(command_group)) as c:
1074+
with self.argument_context('{} flexible-server tuning list-index-recommendations'.format(command_group)) as c:
10751075
c.argument('recommendation_type',
10761076
options_list=['--recommendation-type', '-r'],
10771077
help='Retrieve recommendations based on type.',
1078-
arg_type=get_enum_type(['CreateIndex', 'DropIndex']))
1078+
arg_type=get_enum_type(['CreateIndex', 'DropIndex', 'ReIndex']))
1079+
1080+
with self.argument_context('{} flexible-server tuning list-table-recommendations'.format(command_group)) as c:
1081+
c.argument('recommendation_type',
1082+
options_list=['--recommendation-type', '-r'],
1083+
help='Retrieve recommendations based on type.',
1084+
arg_type=get_enum_type(['AnalyzeTable']))
10791085

10801086
for scope in ['show-settings', 'set-settings']:
1081-
argument_context_string = '{} flexible-server index-tuning {}'.format(command_group, scope)
1087+
argument_context_string = '{} flexible-server tuning {}'.format(command_group, scope)
10821088
with self.argument_context(argument_context_string) as c:
10831089
c.argument('setting_name', options_list=['--name', '-n'], required=True,
1084-
arg_type=get_enum_type(get_index_tuning_settings_map().keys()),
1090+
arg_type=get_enum_type(get_automated_tuning_settings_map().keys()),
10851091
help='The name of the tuning setting.')
10861092

1087-
with self.argument_context('{} flexible-server index-tuning set-settings'.format(command_group)) as c:
1093+
with self.argument_context('{} flexible-server tuning set-settings'.format(command_group)) as c:
10881094
c.argument('value', options_list=['--value', '-v'],
10891095
help='Value of the tuning setting.')
10901096

src/azure-cli/azure/cli/command_modules/rdbms/_util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def call(*args, **kwargs):
105105
return decorate
106106

107107

108-
def get_index_tuning_settings_map():
108+
def get_automated_tuning_settings_map():
109109
return {
110110
'analysis_interval': 'index_tuning.analysis_interval',
111111
'max_columns_per_index': 'index_tuning.max_columns_per_index',

src/azure-cli/azure/cli/command_modules/rdbms/flexible_server_commands.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -296,11 +296,12 @@ def load_flexibleserver_command_table(self, _):
296296
g.custom_command('stop', 'flexible_server_fabric_mirroring_stop')
297297
g.custom_command('update-databases', 'flexible_server_fabric_mirroring_update_databases')
298298

299-
with self.command_group('postgres flexible-server index-tuning', postgres_flexible_config_sdk,
299+
with self.command_group('postgres flexible-server automated-tuning', postgres_flexible_config_sdk,
300300
client_factory=cf_postgres_flexible_config) as g:
301-
g.custom_command('update', 'index_tuning_update', custom_command_type=flexible_servers_custom_postgres)
302-
g.custom_show_command('show', 'index_tuning_show', custom_command_type=flexible_servers_custom_postgres)
303-
g.custom_command('list-settings', 'index_tuning_settings_list', custom_command_type=flexible_servers_custom_postgres)
304-
g.custom_command('show-settings', 'index_tuning_settings_get', custom_command_type=flexible_servers_custom_postgres)
305-
g.custom_command('set-settings', 'index_tuning_settings_set', custom_command_type=flexible_servers_custom_postgres)
306-
g.custom_command('list-recommendations', 'recommendations_list', custom_command_type=flexible_servers_custom_postgres)
301+
g.custom_command('update', 'automated_tuning_update', custom_command_type=flexible_servers_custom_postgres)
302+
g.custom_show_command('show', 'automated_tuning_show', custom_command_type=flexible_servers_custom_postgres)
303+
g.custom_command('list-settings', 'automated_tuning_settings_list', custom_command_type=flexible_servers_custom_postgres)
304+
g.custom_command('show-settings', 'automated_tuning_settings_get', custom_command_type=flexible_servers_custom_postgres)
305+
g.custom_command('set-settings', 'automated_tuning_settings_set', custom_command_type=flexible_servers_custom_postgres)
306+
g.custom_command('list-index-recommendations', 'index_recommendations_list', custom_command_type=flexible_servers_custom_postgres)
307+
g.custom_command('list-table-recommendations', 'table_recommendations_list', custom_command_type=flexible_servers_custom_postgres)

0 commit comments

Comments
 (0)