Skip to content

Commit de2958e

Browse files
{RDBMS} Add autonomous-tuning command group to support all recommendation types for automated tuning & deprecate index-tuning (#32546)
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent cee0d5e commit de2958e

10 files changed

+3317
-239
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@
33
# Licensed under the MIT License. See License.txt in the project root for license information.
44
# --------------------------------------------------------------------------------------------
55

6-
from azure.cli.core.breaking_change import register_argument_deprecate
6+
from azure.cli.core.breaking_change import register_argument_deprecate, register_command_group_deprecate
77

88
register_argument_deprecate('postgres flexible-server create', '--high-availability', redirect='--zonal-resiliency')
99
register_argument_deprecate('postgres flexible-server update', '--high-availability', redirect='--zonal-resiliency')
10+
register_command_group_deprecate(command_group='postgres flexible-server index-tuning',
11+
redirect='postgres flexible-server autonomous-tuning',
12+
message='Index tuning feature has now expanded its capabilities to support '
13+
'other automatically generated recommendations which are covered by the '
14+
'new command.')

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def _postgres_parse_list_capability(result, is_offer_restriction_check_required=
5353
restricted = offer_restricted[0].status if offer_restricted else None
5454
zone_redundant = [feature for feature in supported_features if feature.name == "ZoneRedundantHa"]
5555
geo_backup = [feature for feature in supported_features if feature.name == "GeoBackup"]
56-
index_tuning = [feature for feature in supported_features if feature.name == "IndexTuning"]
56+
autonomous_tuning = [feature for feature in supported_features if feature.name == "IndexTuning"]
5757

5858
if restricted == "Enabled" and not is_offer_restriction_check_required:
5959
raise InvalidArgumentValueError("The location is restricted for provisioning of flexible servers. Please try using another region.")
@@ -63,7 +63,7 @@ def _postgres_parse_list_capability(result, is_offer_restriction_check_required=
6363

6464
single_az = zone_redundant[0].status != "Enabled" if zone_redundant else True
6565
geo_backup_supported = geo_backup[0].status == "Enabled" if geo_backup else False
66-
index_tuning_supported = index_tuning[0].status == "Enabled" if index_tuning else False
66+
autonomous_tuning_supported = autonomous_tuning[0].status == "Enabled" if autonomous_tuning else False
6767

6868
tiers = result[0].supported_server_editions
6969
tiers_dict = {}
@@ -112,7 +112,7 @@ def _postgres_parse_list_capability(result, is_offer_restriction_check_required=
112112
'zones': zones,
113113
'server_versions': versions,
114114
'supported_server_versions': supported_server_versions,
115-
'index_tuning_supported': index_tuning_supported
115+
'autonomous_tuning_supported': autonomous_tuning_supported
116116
}
117117

118118

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

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,3 +1225,66 @@
12251225
- name: Get tuning index recommendations for a PostgreSQL flexible server. Filter by selected type.
12261226
text: az postgres flexible-server index-tuning list-recommendations -g testgroup -s testsvr --recommendation-type CreateIndex
12271227
"""
1228+
1229+
helps['postgres flexible-server autonomous-tuning'] = """
1230+
type: group
1231+
short-summary: Autonomous tuning analyzes read queries captured in query store and recommends operations on tables or index changes to optimize these queries.
1232+
"""
1233+
1234+
helps['postgres flexible-server autonomous-tuning update'] = """
1235+
type: command
1236+
short-summary: Update autonomous tuning to be enabled/disabled for a PostgreSQL flexible server.
1237+
examples:
1238+
- name: Update autonomous tuning to be enabled for a PostgreSQL flexible server.
1239+
text: az postgres flexible-server autonomous-tuning update -g testgroup -s testsvr --enabled True
1240+
- name: Update autonomous tuning to be disabled for a PostgreSQL flexible server.
1241+
text: az postgres flexible-server autonomous-tuning update -g testgroup -s testsvr --enabled False
1242+
"""
1243+
1244+
helps['postgres flexible-server autonomous-tuning show'] = """
1245+
type: command
1246+
short-summary: Show state of autonomous tuning for a PostgreSQL flexible server.
1247+
examples:
1248+
- name: Show state of autonomous tuning for a PostgreSQL flexible server.
1249+
text: az postgres flexible-server autonomous-tuning show -g testgroup -s testsvr
1250+
"""
1251+
1252+
helps['postgres flexible-server autonomous-tuning list-settings'] = """
1253+
type: command
1254+
short-summary: Get autonomous tuning settings associated to a PostgreSQL flexible server.
1255+
examples:
1256+
- name: Get autonomous tuning settings for a PostgreSQL flexible server.
1257+
text: az postgres flexible-server autonomous-tuning list-settings -g testgroup -s testsvr
1258+
"""
1259+
1260+
helps['postgres flexible-server autonomous-tuning show-settings'] = """
1261+
type: command
1262+
short-summary: Get an autonomous tuning setting for a PostgreSQL flexible server.
1263+
examples:
1264+
- name: Get an autonomous tuning setting for a PostgreSQL flexible server.
1265+
text: az postgres flexible-server autonomous-tuning show-settings -g testgroup -s testsvr --name setting-name
1266+
"""
1267+
1268+
helps['postgres flexible-server autonomous-tuning set-settings'] = """
1269+
type: command
1270+
short-summary: Update an autonomous tuning setting for a PostgreSQL flexible server.
1271+
examples:
1272+
- name: Update an autonomous tuning setting for a PostgreSQL flexible server.
1273+
text: az postgres flexible-server autonomous-tuning set-settings -g testgroup -s testsvr --name setting-name --value setting-value
1274+
"""
1275+
1276+
helps['postgres flexible-server autonomous-tuning list-index-recommendations'] = """
1277+
type: command
1278+
short-summary: Get available autonomous tuning index recommendations associated with a PostgreSQL flexible server.
1279+
examples:
1280+
- name: Get autonomous tuning index recommendations for a PostgreSQL flexible server. Filter by selected type.
1281+
text: az postgres flexible-server autonomous-tuning list-index-recommendations -g testgroup -s testsvr --recommendation-type CreateIndex
1282+
"""
1283+
1284+
helps['postgres flexible-server autonomous-tuning list-table-recommendations'] = """
1285+
type: command
1286+
short-summary: Get available autonomous tuning table recommendations associated with a PostgreSQL flexible server.
1287+
examples:
1288+
- name: Get autonomous tuning table recommendations for a PostgreSQL flexible server. Filter by selected type.
1289+
text: az postgres flexible-server autonomous-tuning list-table-recommendations -g testgroup -s testsvr --recommendation-type AnalyzeTable
1290+
"""

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

Lines changed: 40 additions & 3 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_autonomous_tuning_settings_map
2727

2828

2929
def load_arguments(self, _): # pylint: disable=too-many-statements, too-many-locals
@@ -1077,19 +1077,56 @@ def _flexible_server_params(command_group):
10771077
c.argument('recommendation_type',
10781078
options_list=['--recommendation-type', '-r'],
10791079
help='Retrieve recommendations based on type.',
1080-
arg_type=get_enum_type(['CreateIndex', 'DropIndex']))
1080+
arg_type=get_enum_type(['CreateIndex', 'DropIndex', 'ReIndex']))
10811081

10821082
for scope in ['show-settings', 'set-settings']:
10831083
argument_context_string = '{} flexible-server index-tuning {}'.format(command_group, scope)
10841084
with self.argument_context(argument_context_string) as c:
10851085
c.argument('setting_name', options_list=['--name', '-n'], required=True,
1086-
arg_type=get_enum_type(get_index_tuning_settings_map().keys()),
1086+
arg_type=get_enum_type(get_autonomous_tuning_settings_map().keys()),
10871087
help='The name of the tuning setting.')
10881088

10891089
with self.argument_context('{} flexible-server index-tuning set-settings'.format(command_group)) as c:
10901090
c.argument('value', options_list=['--value', '-v'],
10911091
help='Value of the tuning setting.')
10921092

1093+
# autonomous tuning
1094+
if command_group == 'postgres':
1095+
for scope in ['update', 'show', 'list-settings', 'show-settings', 'set-settings', 'list-table-recommendations', 'list-index-recommendations']:
1096+
argument_context_string = '{} flexible-server autonomous-tuning {}'.format(command_group, scope)
1097+
with self.argument_context(argument_context_string) as c:
1098+
c.argument('server_name', options_list=['--server-name', '-s'], arg_type=server_name_arg_type)
1099+
1100+
with self.argument_context('{} flexible-server autonomous-tuning update'.format(command_group)) as c:
1101+
c.argument('autonomous_tuning_enabled',
1102+
options_list=['--enabled'],
1103+
required=True,
1104+
help='Enable or disable autonomous tuning feature.',
1105+
arg_type=get_enum_type(['True', 'False']))
1106+
1107+
with self.argument_context('{} flexible-server autonomous-tuning list-index-recommendations'.format(command_group)) as c:
1108+
c.argument('recommendation_type',
1109+
options_list=['--recommendation-type', '-r'],
1110+
help='Retrieve recommendations based on type.',
1111+
arg_type=get_enum_type(['CreateIndex', 'DropIndex', 'ReIndex']))
1112+
1113+
with self.argument_context('{} flexible-server autonomous-tuning list-table-recommendations'.format(command_group)) as c:
1114+
c.argument('recommendation_type',
1115+
options_list=['--recommendation-type', '-r'],
1116+
help='Retrieve recommendations based on type.',
1117+
arg_type=get_enum_type(['AnalyzeTable', 'VacuumTable']))
1118+
1119+
for scope in ['show-settings', 'set-settings']:
1120+
argument_context_string = '{} flexible-server autonomous-tuning {}'.format(command_group, scope)
1121+
with self.argument_context(argument_context_string) as c:
1122+
c.argument('setting_name', options_list=['--name', '-n'], required=True,
1123+
arg_type=get_enum_type(get_autonomous_tuning_settings_map().keys()),
1124+
help='The name of the tuning setting.')
1125+
1126+
with self.argument_context('{} flexible-server autonomous-tuning set-settings'.format(command_group)) as c:
1127+
c.argument('value', options_list=['--value', '-v'],
1128+
help='Value of the tuning setting.')
1129+
10931130
# GTID
10941131
if command_group == 'mysql':
10951132
with self.argument_context('{} flexible-server gtid reset'.format(command_group)) as c:

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

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

105105

106-
def get_index_tuning_settings_map():
106+
def get_autonomous_tuning_settings_map():
107107
return {
108108
'analysis_interval': 'index_tuning.analysis_interval',
109109
'max_columns_per_index': 'index_tuning.max_columns_per_index',

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,4 +296,14 @@ def load_flexibleserver_command_table(self, _):
296296
g.custom_command('list-settings', 'index_tuning_settings_list', custom_command_type=flexible_servers_custom_postgres)
297297
g.custom_command('show-settings', 'index_tuning_settings_get', custom_command_type=flexible_servers_custom_postgres)
298298
g.custom_command('set-settings', 'index_tuning_settings_set', custom_command_type=flexible_servers_custom_postgres)
299-
g.custom_command('list-recommendations', 'recommendations_list', custom_command_type=flexible_servers_custom_postgres)
299+
g.custom_command('list-recommendations', 'index_tuning_recommendations_list', custom_command_type=flexible_servers_custom_postgres)
300+
301+
with self.command_group('postgres flexible-server autonomous-tuning', postgres_flexible_config_sdk,
302+
client_factory=cf_postgres_flexible_config) as g:
303+
g.custom_command('update', 'autonomous_tuning_update', custom_command_type=flexible_servers_custom_postgres)
304+
g.custom_show_command('show', 'autonomous_tuning_show', custom_command_type=flexible_servers_custom_postgres)
305+
g.custom_command('list-settings', 'autonomous_tuning_settings_list', custom_command_type=flexible_servers_custom_postgres)
306+
g.custom_command('show-settings', 'autonomous_tuning_settings_get', custom_command_type=flexible_servers_custom_postgres)
307+
g.custom_command('set-settings', 'autonomous_tuning_settings_set', custom_command_type=flexible_servers_custom_postgres)
308+
g.custom_command('list-table-recommendations', 'autonomous_tuning_table_recommendations_list', custom_command_type=flexible_servers_custom_postgres)
309+
g.custom_command('list-index-recommendations', 'autonomous_tuning_index_recommendations_list', custom_command_type=flexible_servers_custom_postgres)

0 commit comments

Comments
 (0)