Autoscaling: Add metrics for E2 target tracking scaling (#6314)

This commit is contained in:
Ivan-Lukianov 2023-05-13 21:08:51 +04:00 committed by GitHub
parent f7b2478726
commit 523225d6e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 86 additions and 0 deletions

View File

@ -1022,6 +1022,38 @@ DESCRIBE_SCALING_POLICIES_TEMPLATE = """<DescribePoliciesResponse xmlns="http://
{% if policy.target_tracking_config["CustomizedMetricSpecification"].get("Unit") %}
<Unit>{{ policy.target_tracking_config["CustomizedMetricSpecification"].get("Unit") }}</Unit>
{% endif %}
{% if policy.target_tracking_config["CustomizedMetricSpecification"].get("Metrics") %}
<Metrics>
{% for metric in policy.target_tracking_config["CustomizedMetricSpecification"].get("Metrics", []) %}
<member>
<Id>{{ metric.get("Id") }}</Id>
{% if metric.get("MetricStat") is none %}
<Expression>{{ metric.get("Expression") }}</Expression>
{% endif %}
{% if metric.get("Expression") is none %}
<MetricStat>
<Metric>
<Namespace>{{ metric.get("MetricStat", {}).get("Metric", {}).get("Namespace") }}</Namespace>
<MetricName>{{ metric.get("MetricStat", {}).get("Metric", {}).get("MetricName") }}</MetricName>
<Dimensions>
{% for dim in metric.get("MetricStat", {}).get("Metric", {}).get("Dimensions", []) %}
<member>
<Name>{{ dim.get("Name") }}</Name>
<Value>{{ dim.get("Value") }}</Value>
</member>
{% endfor %}
</Dimensions>
</Metric>
<Stat>{{ metric.get("MetricStat", {}).get("Stat") }}</Stat>
<Unit>{{ metric.get("MetricStat", {}).get("Unit") }}</Unit>
</MetricStat>
{% endif %}
<Label>{{ metric.get("Label") }}</Label>
<ReturnData>{{ 'true' if metric.get("ReturnData") is none else metric.get("ReturnData") }}</ReturnData>
</member>
{% endfor %}
</Metrics>
{% endif %}
</CustomizedMetricSpecification>
{% endif %}
<TargetValue>{{ policy.target_tracking_config.get("TargetValue") }}</TargetValue>

View File

@ -771,6 +771,30 @@ def test_create_autoscaling_policy_with_policytype__targettrackingscaling():
"PredefinedMetricType": "ASGAverageNetworkIn",
},
"TargetValue": 1000000.0,
"CustomizedMetricSpecification": {
"Metrics": [
{
"Label": "Get ASGAverageCPUUtilization",
"Id": "cpu",
"MetricStat": {
"Metric": {
"MetricName": "CPUUtilization",
"Namespace": "AWS/EC2",
"Dimensions": [
{"Name": "AutoScalingGroupName", "Value": asg_name}
],
},
"Stat": "Average",
},
"ReturnData": False,
},
{
"Label": "Calculate square cpu",
"Id": "load",
"Expression": "cpu^2",
},
],
},
},
)
@ -786,6 +810,36 @@ def test_create_autoscaling_policy_with_policytype__targettrackingscaling():
"PredefinedMetricSpecification": {
"PredefinedMetricType": "ASGAverageNetworkIn",
},
"CustomizedMetricSpecification": {
"MetricName": "None",
"Namespace": "None",
"Dimensions": [],
"Statistic": "None",
"Metrics": [
{
"Label": "Get ASGAverageCPUUtilization",
"Id": "cpu",
"MetricStat": {
"Metric": {
"MetricName": "CPUUtilization",
"Namespace": "AWS/EC2",
"Dimensions": [
{"Name": "AutoScalingGroupName", "Value": asg_name}
],
},
"Stat": "Average",
"Unit": "None",
},
"ReturnData": False,
},
{
"Label": "Calculate square cpu",
"Id": "load",
"Expression": "cpu^2",
"ReturnData": True,
},
],
},
"TargetValue": 1000000.0,
}
)