Skip to content

Commit

Permalink
[Container app] az containerapp create/update: Fix `--scale-rule-tc…
Browse files Browse the repository at this point in the history
…p-concurrency` for TCP scale rule (#28889)
  • Loading branch information
Greedygre authored May 8, 2024
1 parent 26e8c72 commit 6abde5e
Show file tree
Hide file tree
Showing 12 changed files with 10,405 additions and 6,951 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -624,19 +624,30 @@ def set_up_scale_rule(self):
scale_rule_def = ScaleRuleModel
curr_metadata = {}
if self.get_argument_scale_rule_http_concurrency():
if scale_rule_type in ('http', 'tcp'):
if scale_rule_type == 'http':
curr_metadata["concurrentRequests"] = str(scale_rule_http_concurrency)
elif scale_rule_type == 'tcp':
curr_metadata["concurrentConnections"] = str(scale_rule_http_concurrency)
metadata_def = parse_metadata_flags(scale_rule_metadata, curr_metadata)
auth_def = parse_auth_flags(scale_rule_auth)
if scale_rule_type == "http":
scale_rule_def["name"] = scale_rule_name
scale_rule_def["custom"] = None
scale_rule_def["tcp"] = None
scale_rule_def["http"] = {}
scale_rule_def["http"]["metadata"] = metadata_def
scale_rule_def["http"]["auth"] = auth_def
elif scale_rule_type == "tcp":
scale_rule_def["name"] = scale_rule_name
scale_rule_def["custom"] = None
scale_rule_def["http"] = None
scale_rule_def["tcp"] = {}
scale_rule_def["tcp"]["metadata"] = metadata_def
scale_rule_def["tcp"]["auth"] = auth_def
else:
scale_rule_def["name"] = scale_rule_name
scale_rule_def["http"] = None
scale_rule_def["tcp"] = None
scale_rule_def["custom"] = {}
scale_rule_def["custom"]["type"] = scale_rule_type
scale_rule_def["custom"]["metadata"] = metadata_def
Expand Down
13 changes: 12 additions & 1 deletion src/azure-cli/azure/cli/command_modules/containerapp/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -598,19 +598,30 @@ def update_containerapp_logic(cmd,
scale_rule_def = ScaleRuleModel
curr_metadata = {}
if scale_rule_http_concurrency:
if scale_rule_type in ('http', 'tcp'):
if scale_rule_type == 'http':
curr_metadata["concurrentRequests"] = str(scale_rule_http_concurrency)
elif scale_rule_type == 'tcp':
curr_metadata["concurrentConnections"] = str(scale_rule_http_concurrency)
metadata_def = parse_metadata_flags(scale_rule_metadata, curr_metadata)
auth_def = parse_auth_flags(scale_rule_auth)
if scale_rule_type == "http":
scale_rule_def["name"] = scale_rule_name
scale_rule_def["custom"] = None
scale_rule_def["tcp"] = None
scale_rule_def["http"] = {}
scale_rule_def["http"]["metadata"] = metadata_def
scale_rule_def["http"]["auth"] = auth_def
elif scale_rule_type == "tcp":
scale_rule_def["name"] = scale_rule_name
scale_rule_def["custom"] = None
scale_rule_def["http"] = None
scale_rule_def["tcp"] = {}
scale_rule_def["tcp"]["metadata"] = metadata_def
scale_rule_def["tcp"]["auth"] = auth_def
else:
scale_rule_def["name"] = scale_rule_name
scale_rule_def["http"] = None
scale_rule_def["tcp"] = None
scale_rule_def["custom"] = {}
scale_rule_def["custom"]["type"] = scale_rule_type
scale_rule_def["custom"]["metadata"] = metadata_def
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,40 @@ def test_containerapp_tcp_ingress(self, resource_group, laworkspace_customer_id,
JMESPathCheck('exposedPort', 3020),
])

app = self.create_random_name(prefix='containerapp', length=24)

self.cmd(
f'containerapp create -g {resource_group} -n {app} --image redis --ingress external --target-port 6379 --environment {env_name} --transport tcp --scale-rule-type tcp --scale-rule-name tcp-scale-rule --scale-rule-tcp-concurrency 50 --scale-rule-auth trigger=secretref --scale-rule-metadata key=value',
checks=[
JMESPathCheck("properties.configuration.ingress.transport", "Tcp"),
JMESPathCheck("properties.provisioningState", "Succeeded"),
JMESPathCheck("properties.template.scale.rules[0].name", "tcp-scale-rule"),
JMESPathCheck("properties.template.scale.rules[0].tcp.auth[0].triggerParameter", "trigger"),
JMESPathCheck("properties.template.scale.rules[0].tcp.auth[0].secretRef", "secretref"),
])
# the metadata is not returned in create/update command, we should use show command to check
self.cmd(f'containerapp show -g {resource_group} -n {app}', checks=[
JMESPathCheck("properties.template.scale.rules[0].name", "tcp-scale-rule"),
JMESPathCheck("properties.template.scale.rules[0].tcp.metadata.concurrentConnections", "50"),
JMESPathCheck("properties.template.scale.rules[0].tcp.metadata.key", "value")
])
self.cmd(
f'containerapp update -g {resource_group} -n {app} --scale-rule-name tcp-scale-rule --scale-rule-type tcp --scale-rule-tcp-concurrency 2 --scale-rule-auth "apiKey=api-key" "appKey=app-key"',
checks=[
JMESPathCheck("properties.configuration.ingress.transport", "Tcp"),
JMESPathCheck("properties.provisioningState", "Succeeded"),
JMESPathCheck("properties.template.scale.rules[0].name", "tcp-scale-rule"),
JMESPathCheck("properties.template.scale.rules[0].tcp.auth[0].triggerParameter", "apiKey"),
JMESPathCheck("properties.template.scale.rules[0].tcp.auth[0].secretRef", "api-key"),
JMESPathCheck("properties.template.scale.rules[0].tcp.auth[1].triggerParameter", "appKey"),
JMESPathCheck("properties.template.scale.rules[0].tcp.auth[1].secretRef", "app-key"),
])
# the metadata is not returned in create/update command, we should use show command to check
self.cmd(f'containerapp show -g {resource_group} -n {app}', checks=[
JMESPathCheck("properties.template.scale.rules[0].name", "tcp-scale-rule"),
JMESPathCheck("properties.template.scale.rules[0].tcp.metadata.concurrentConnections", "2"),
])

@AllowLargeResponse(8192)
@ResourceGroupPreparer(location="northeurope")
def test_containerapp_ip_restrictions(self, resource_group):
Expand Down Expand Up @@ -1199,6 +1233,45 @@ def test_containerapp_scale_update(self, resource_group):
JMESPathCheck("properties.template.scale.rules[0].custom.auth[1].secretRef", "app-key"),
])

@AllowLargeResponse(8192)
@ResourceGroupPreparer(location="westeurope")
def test_containerapp_scale_type_tcp(self, resource_group):
self.cmd('configure --defaults location={}'.format(TEST_LOCATION))

app = self.create_random_name(prefix='aca', length=24)

env = prepare_containerapp_env_for_app_e2e_tests(self)

self.cmd(
f'containerapp create -g {resource_group} -n {app} --image redis --ingress internal --target-port 6379 --transport tcp --environment {env} --transport tcp --scale-rule-type tcp --scale-rule-name tcp-scale-rule --scale-rule-tcp-concurrency 50 --scale-rule-auth trigger=secretref --scale-rule-metadata key=value',
checks=[
JMESPathCheck("properties.configuration.ingress.transport", "Tcp"),
JMESPathCheck("properties.provisioningState", "Succeeded"),
JMESPathCheck("properties.template.scale.rules[0].name", "tcp-scale-rule"),
JMESPathCheck("properties.template.scale.rules[0].tcp.auth[0].triggerParameter", "trigger"),
JMESPathCheck("properties.template.scale.rules[0].tcp.auth[0].secretRef", "secretref"),
])
# the metadata is not returned in create/update command, we should use show command to check
self.cmd(f'containerapp show -g {resource_group} -n {app}', checks=[
JMESPathCheck("properties.template.scale.rules[0].name", "tcp-scale-rule"),
JMESPathCheck("properties.template.scale.rules[0].tcp.metadata.concurrentConnections", "50"),
JMESPathCheck("properties.template.scale.rules[0].tcp.metadata.key", "value")
])
self.cmd(
f'containerapp update -g {resource_group} -n {app} --scale-rule-name tcp-scale-rule --scale-rule-type tcp --scale-rule-tcp-concurrency 2 --scale-rule-auth "apiKey=api-key" "appKey=app-key"',
checks=[
JMESPathCheck("properties.template.scale.rules[0].name", "tcp-scale-rule"),
JMESPathCheck("properties.template.scale.rules[0].tcp.auth[0].triggerParameter", "apiKey"),
JMESPathCheck("properties.template.scale.rules[0].tcp.auth[0].secretRef", "api-key"),
JMESPathCheck("properties.template.scale.rules[0].tcp.auth[1].triggerParameter", "appKey"),
JMESPathCheck("properties.template.scale.rules[0].tcp.auth[1].secretRef", "app-key"),
])
# the metadata is not returned in create/update command, we should use show command to check
self.cmd(f'containerapp show -g {resource_group} -n {app}', checks=[
JMESPathCheck("properties.template.scale.rules[0].name", "tcp-scale-rule"),
JMESPathCheck("properties.template.scale.rules[0].tcp.metadata.concurrentConnections", "2"),
])

@AllowLargeResponse(8192)
@ResourceGroupPreparer(location="westeurope")
def test_containerapp_scale_update_azure_queue(self, resource_group):
Expand Down

0 comments on commit 6abde5e

Please sign in to comment.