Skip to content

Adding ability to scale for Redis Cache, adding tests#2821

Merged
tjprescott merged 7 commits intoAzure:masterfrom
alfantp:master
Apr 17, 2017
Merged

Adding ability to scale for Redis Cache, adding tests#2821
tjprescott merged 7 commits intoAzure:masterfrom
alfantp:master

Conversation

@alfantp
Copy link
Copy Markdown
Contributor

@alfantp alfantp commented Apr 10, 2017


This checklist is used to make sure that common guidelines for a pull request are followed.

General Guidelines

  • The PR has modified HISTORY.rst with an appropriate description of the change (see Modifying change log).

Command Guidelines

  • Each command and parameter has a meaningful description.
  • Each new command has a test.

(see Authoring Command Modules)

@msftclas
Copy link
Copy Markdown

@alfantp,
Thanks for your contribution.
To ensure that the project team has proper rights to use your work, please complete the Contribution License Agreement at https://cla.microsoft.com.

It will cover your contributions to all Microsoft-managed open source projects.
Thanks,
Microsoft Pull Request Bot

@codecov-io
Copy link
Copy Markdown

codecov-io commented Apr 11, 2017

Codecov Report

Merging #2821 into master will increase coverage by 0.27%.
The diff coverage is 56.66%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2821      +/-   ##
==========================================
+ Coverage   62.89%   63.17%   +0.27%     
==========================================
  Files         480      466      -14     
  Lines       26012    26139     +127     
  Branches     3946     3997      +51     
==========================================
+ Hits        16361    16514     +153     
+ Misses       8627     8544      -83     
- Partials     1024     1081      +57
Impacted Files Coverage Δ
...-redis/azure/cli/command_modules/redis/commands.py 100% <100%> (ø) ⬆️
...i-redis/azure/cli/command_modules/redis/_params.py 77.77% <100%> (-0.61%) ⬇️
...cli-redis/azure/cli/command_modules/redis/_help.py 100% <100%> (ø) ⬆️
...li-redis/azure/cli/command_modules/redis/custom.py 40% <40.9%> (+6.66%) ⬆️
src/azure-cli-core/azure/cli/core/_debug.py 66.66% <0%> (-20.84%) ⬇️
...ure-cli-sql/azure/cli/command_modules/sql/_util.py 84.21% <0%> (-8.65%) ⬇️
...-cli-find/azure/cli/command_modules/find/custom.py 88% <0%> (-5.45%) ⬇️
...h/azure/cli/command_modules/batch/_command_type.py 90.04% <0%> (-4.36%) ⬇️
...-cli-iot/azure/cli/command_modules/iot/commands.py 96.07% <0%> (-3.93%) ⬇️
...torage/azure/cli/command_modules/storage/custom.py 83.47% <0%> (-3.54%) ⬇️
... and 69 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update de6fe79...73dec9d. Read the comment docs.

Copy link
Copy Markdown
Member

@tjprescott tjprescott left a comment

Choose a reason for hiding this comment

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

The addition of the SKU parameters is fine, but then "redis_configuration" should be removed and this should be a "generic update" command (with --set, --add, --remove). Also, it seems the command should be named "redis update" instead of "update-settings".

def cli_redis_update_settings(client, resource_group_name, name, redis_configuration):
def cli_redis_update_settings(client, resource_group_name, name, redis_configuration=None, # pylint:disable=too-many-arguments
sku_name=None, sku_family=None, sku_capacity=None):
if sku_name != None or sku_family != None or sku_capacity != None:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Recommendation:

sku_group = [sku_name, sku_family, sku_capacity]
if any(sku_group) and not all(sku_group):
  raise CLIError('incorrect usage: --sku-name NAME --sku-family FAMILY --sku-capactity CAPACITY')

The "usage string" style error is favored.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the recommendation. Will update it. About renaming the command name, wouldnt changing the name break existing customers who use this for automations? Or since the product is in its early stages it's okay to do that? I'll be very willing to change the command if you can confirm its okay

Copy link
Copy Markdown
Member

@tjprescott tjprescott Apr 11, 2017

Choose a reason for hiding this comment

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

It would. Also, looking into it, apparently the "redis-configuration" parameter only lets you change a very specific subset of things that aren't clearly enumerated.

In that case, my recommendation is:

  • create a new command called "redis update" that uses the "cli_generic_update" pattern that other resource types use.
  • Move the SKU related parameters as the convenience layer on that command, and leave "redis update-settings" as is.
  • In the future, we can deprecate "update-settings" (as the generic update would accomplish everything it does and more).

existing.redis_configuration.update(redis_configuration)

if sku_name != None and sku_family != None and sku_capacity != None:
existing.sku = Sku(sku_name, sku_family, sku_capacity)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why are we exposing a "configuration" object AND convenience parameters? This looks like it should be a generic update command and "redis_configuration" should be removed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

There are two ways to update a cache. One, you can update the Sku/VMSize to scale. Second, you can update the settings/properties within cache like say max memory threshold or backup interval etc. So IMO, it's fine to have both. Also, this is how the command is in powershell.

alfantp added 2 commits April 13, 2017 10:41
…Adding 'getting deprecated' message for update-settings command
Copy link
Copy Markdown
Member

@tjprescott tjprescott left a comment

Choose a reason for hiding this comment

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

Looks much better. A few suggestions. Main ask is to replace the hard-coded enum with more flexible parsing and let the service handle that validation. Feel free to reach out to me with questions.

===============

* Adding update command which also adds the ability to scale for redis cache
* Adding 'getting deprecated' message for update-settings command
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Rec: Deprecates the 'update-settings' command.

type: command
short-summary: Update the settings of a redis cache.
long-summary: |
WARNING: This command is being deprecated. Please use 'update' command
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Recommend you add (DEPRECATED) to the short summary so it shows up in az redis -h. I like that the long summary directs the user to the right command.

dictval = shell_safe_json_parse(value)
self.update(dictval)

class VmSize(Enum): # pylint: disable=too-few-public-methods
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is definitely one way of doing this but then it has the problem that you have to manually add things to this enum if the service supports something new.

I would recommend something like this:

family = size[0]
capacity = int(size[1:])

And then in the help for the param, you give examples of the format. "C1, P2, etc." In this way, if the service starts to support additional combinations, then the CLI will automatically support them instead of artificially restricting them.

register_cli_argument('redis', 'vm_size', **enum_choice_list(VmSize))
register_cli_argument('redis', 'enable_non_ssl_port', action='store_true')
register_cli_argument('redis', 'shard_count', type=int)
register_cli_argument('redis', 'subnet_id') # TODO: Create generic id completer similar to name
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please create an issue for this follow-up work.

:param sku_name: What type of redis cache to deploy. Valid values: (Basic, Standard, Premium).
:param sku_family: Which family to use. Valid values: (C, P).
:param sku_capacity: What size of redis cache to deploy. Valid values for C family (0, 1, 2, 3, 4, 5, 6), for P family (1, 2, 3, 4)
:param sku: What type of redis cache to deploy. Valid values: (Basic, Standard, Premium).
Copy link
Copy Markdown
Member

@tjprescott tjprescott Apr 14, 2017

Choose a reason for hiding this comment

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

If you are using the **enum_choice_list, it will automatically list (and validate) the options, so you don't need this. If you run this command with -h you'll see the list essentially repeated twice.

:param sku_family: Which family to use. Valid values: (C, P).
:param sku_capacity: What size of redis cache to deploy. Valid values for C family (0, 1, 2, 3, 4, 5, 6), for P family (1, 2, 3, 4)
:param sku: What type of redis cache to deploy. Valid values: (Basic, Standard, Premium).
:param vm_size: What size of redis cache to deploy. Valid values for C family (C0, C1, C2, C3, C4, C5, C6), for P family (P1, P2, P3, P4)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

And here, if you do like I suggest and parse the size, you will still need this so this is good.

params = RedisCreateOrUpdateParameters(
location,
Sku(sku_name, sku_family, sku_capacity),
Sku(sku, vm_size[0], vm_size[1]),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would recommend vm_size[1:] in case you ever support double digit capacity values.

Copy link
Copy Markdown
Contributor

@troydai troydai left a comment

Choose a reason for hiding this comment

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

Please run check_style --ci before push.

P1 = 'P1'
P2 = 'P2'
P3 = 'P3'
P4 = 'P4'
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.

Are these sizes defined in the SDK? Do we have to hard code the options in CLI? Could this list be impacted by other factors?

register_cli_argument('redis', 'vm_size', **enum_choice_list(VmSize))
register_cli_argument('redis', 'enable_non_ssl_port', action='store_true')
register_cli_argument('redis', 'shard_count', type=int)
register_cli_argument('redis', 'subnet_id') # TODO: Create generic id completer similar to name
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.

I'm sure pylint will reject this line. Two space between same line comments.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Actually, pylint doesn't care. It's PEP8 that hates this... ... ... for some reason.

cli_command(__name__, 'redis show', 'azure.mgmt.redis.operations.redis_operations#RedisOperations.get', cf_redis)
cli_command(__name__, 'redis update-settings', 'azure.cli.command_modules.redis.custom#cli_redis_update_settings', cf_redis)

cli_generic_update_command(__name__, 'redis update', 'azure.mgmt.redis.operations.redis_operations#RedisOperations.get', 'azure.mgmt.redis.operations.redis_operations#RedisOperations.create_or_update', cf_redis, custom_function_op='azure.cli.command_modules.redis.custom#cli_redis_update')
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.

Please break this line.

args = mock_echo_args('redis create',
'--tenant-settings {\"hello\":1} -g wombat -n asldkj --sku-family c -l westus --sku-capacity 1 --sku-name basic') # pylint: disable=line-too-long
'--tenant-settings {\"hello\":1} -g wombat -n asldkj -l westus --sku basic --vm-size C1 ') # pylint: disable=line-too-long
subset = set(dict(
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.

this is short enough now to be put on the same line.

@tjprescott
Copy link
Copy Markdown
Member

@troydai are you good with the changes? If so I'd like to merge this for the release.

@tjprescott tjprescott merged commit 3f4409b into Azure:master Apr 17, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants