Skip to content

Commit

Permalink
All flows working
Browse files Browse the repository at this point in the history
  • Loading branch information
knguyen100000010 committed Feb 7, 2024
1 parent bb9e767 commit 2e4be99
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 17 deletions.
24 changes: 14 additions & 10 deletions deploy-board/deploy_board/templates/groups/asg_policy.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,14 @@

<div id="target-tracking-scaling" class="tabcontent">
<h4>Target Tracking Scaling <sup><a href="https://docs.aws.amazon.com/autoscaling/ec2/userguide/as-scaling-target-tracking.html" target="_blank">What is target tracking scaling?</a></sup></h4>
<h5>(With target tracking scaling, you don't need to create alarms directly)</h5>
<div class="alert alert-info">
With target tracking scaling:
<ul>
<li>You don't need to create alarms directly.</li>
<li>You should delete scaling alarms for simple or step scaling.</li>
<li>Only one target tracking scaling policy can be created for each metric.</li>
</ul>
</div>

<div id="targetScalingDisplayId">
<form id="targetScalingDisplayFormId" class="form-horizontal"> {% csrf_token %}
Expand All @@ -285,7 +292,7 @@
{{ policy.targetTrackingScalingConfiguration.predefinedMetricSpecification.predefinedMetricType }}
</h4>
<div>
<button id="deleteItem_{{ alarm.alarmId }}" type="button" style="float:right; margin-left:6px;" class="delete_button metricDeleteBtn btn btn-primary">Delete</button>
<button id="deleteItem_{{ policy.policyName }}" type="button" style="float:right; margin-left:6px;" class="delete_button btn btn-primary">Delete</button>
</div>
</div>

Expand All @@ -309,7 +316,7 @@

<div class="form-group">
<label for="value" class="deployToolTip control-label col-xs-2" data-toggle="tooltip">
Instance Warmup (>= 10 minutes recommended):
Instance Warmup (>= 15 minutes recommended):
</label>
<div class="col-xs-2">
<input class="form-control" id="{{ policy.policyName}}_instanceWarmup" name="{{ policy.policyName}}_instanceWarmup" required="true" type="text" value={{ policy.instanceWarmup }} />
Expand All @@ -327,8 +334,6 @@
</label>
</div>
</div>

<button id="saveTargetScalingBtnId" type="submit" class="btn btn-primary">Save</button>
</div>
</fieldset>
{% csrf_token %}
Expand All @@ -337,13 +342,12 @@

<script>
$(function() {
$('#deleteItem_{{alarm.alarmId}}').click(function () {
$('#deleteItem_{{policy.policyName}}').click(function () {
var btn = $(this);
$.ajax({
type: 'POST',
url: '/groups/{{ group_name }}/autoscaling/delete_metrics/',
data: {'csrfmiddlewaretoken': '{{csrf_token}}',
'alarmId': '{{alarm.alarmId}}'},
url: '/groups/{{ group_name }}/autoscaling/policies/{{policy.policyName}}',
data: {'csrfmiddlewaretoken': '{{csrf_token}}'},
datatype: 'json',
beforeSend: function () {
btn.button('loading');
Expand Down Expand Up @@ -400,7 +404,7 @@ aria-hidden="true">

<div class="form-group">
<label for="value" class="deployToolTip control-label col-xs-2" data-toggle="tooltip">
Instance Warmup (>= 10 minutes recommended):
Instance Warmup (>= 15 minutes recommended):
</label>
<div class="col-xs-2">
<input class="form-control" name="instanceWarmup" required="true" type="text" value="15" />
Expand Down
2 changes: 2 additions & 0 deletions deploy-board/deploy_board/webapp/arcee_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@
group_view.update_asg_config),
url(r'^groups/(?P<group_name>[a-zA-Z0-9\-_]+)/autoscaling/update_policy/$',
group_view.update_policy),
url(r'^groups/(?P<group_name>[a-zA-Z0-9\-_]+)/autoscaling/policies/(?P<policy_name>[a-zA-Z0-9\-_]+)$',
group_view.delete_policy),
url(r'^groups/(?P<group_name>[a-zA-Z0-9\-_]+)/autoscaling/update_pas_config/$',
group_view.update_pas_config),
url(r'^groups/(?P<group_name>[a-zA-Z0-9\-_]+)/autoscaling/get_pas_config/$',
Expand Down
22 changes: 15 additions & 7 deletions deploy-board/deploy_board/webapp/group_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,11 +481,6 @@ def get_policy(request, group_name):
step_scaling_policy["scale_down_adjustments_string"] = scale_down_adjustments_string
step_scaling_policy["scale_up_adjustments_string"] = scale_up_adjustments_string

# if step_scaling_policy["instanceWarmup"]:
# step_scaling_policy["instanceWarmup"] = step_scaling_policy["instanceWarmup"] // 60
# else:
# step_scaling_policy["instanceWarmup"] = 0

content = render_to_string("groups/asg_policy.tmpl", {
"group_name": group_name,
"scalingPolicies": policies["scalingPolicies"],
Expand Down Expand Up @@ -514,12 +509,21 @@ def build_target_scaling_policy(name, metric, target, instance_warmup, disable_s

return policy

def delete_policy(request, group_name, policy_name):
try:
autoscaling_groups_helper.delete_scaling_policy(request, group_name, policy_name)
return redirect("/groups/{}/config/".format(group_name))

Check warning

Code scanning / CodeQL

URL redirection from remote source Medium

Untrusted URL redirection depends on a
user-provided value
.
except:
log.error(traceback.format_exc())
raise

def update_policy(request, group_name):

try:
params = request.POST
policyType = params["policyType"]
scaling_policies = {}
isNewPolicyAdded = False

if policyType == "target-tracking-scaling":
scaling_policies["scalingPolicies"] = []
Expand All @@ -539,8 +543,9 @@ def update_policy(request, group_name):
scaling_policies["scalingPolicies"].append(policy)
else:
# Create new policy
name = "{}-TargetTrackingScaling-{}".format(group_name, metric)
isNewPolicyAdded = True
metric = params["awsMetrics"]
name = "{}-TargetTrackingScaling-{}".format(group_name, metric)
target = params["target"]
instance_warmup = params["instanceWarmup"]
disable_scale_in = False
Expand Down Expand Up @@ -601,7 +606,10 @@ def update_policy(request, group_name):

autoscaling_groups_helper.put_scaling_policies(request, group_name, scaling_policies)

return get_policy(request, group_name)
if isNewPolicyAdded:
return redirect("/groups/{}/config/".format(group_name))

Check warning

Code scanning / CodeQL

URL redirection from remote source Medium

Untrusted URL redirection depends on a
user-provided value
.
else:
return get_policy(request, group_name)
except:
log.error(traceback.format_exc())
raise
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@ def put_scaling_policies(request, cluster_name, policies_info):
return rodimus_client.post("/clusters/%s/autoscaling/policies" % cluster_name, request.teletraan_user_id.token,
data=policies_info)

def delete_scaling_policy(request, cluster_name, policy_name):
return rodimus_client.delete("/clusters/%s/autoscaling/policies/%s" % (cluster_name, policy_name), request.teletraan_user_id.token)


def get_policies(request, cluster_name):
return rodimus_client.get("/clusters/%s/autoscaling/policies" % cluster_name, request.teletraan_user_id.token)
Expand Down

0 comments on commit 2e4be99

Please sign in to comment.