Skip to content

Commit

Permalink
Prevent alarm created without scaling policy (#1448)
Browse files Browse the repository at this point in the history
* refuse to create alarm without scaling policy

* add messages
  • Loading branch information
knguyen100000010 committed Feb 13, 2024
1 parent 9c79b44 commit 89498d4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
10 changes: 8 additions & 2 deletions deploy-board/deploy_board/templates/groups/asg_config.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
{% include "groups/group_side_panel.html" %}
</div>


{% endblock %}

{% block new-builds-panel %}
Expand All @@ -26,7 +25,14 @@

{% block main %}


{% if storage %}
{% for message in storage %}
<div class="alert alert-warning" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<strong>Warning!</strong> {{ message | safe}}
</div>
{% endfor %}
{% endif %}

{% if not is_cmp %}
<div id="launchConfigPid" class="panel panel-default">
Expand Down
9 changes: 9 additions & 0 deletions deploy-board/deploy_board/webapp/group_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from django.template.loader import render_to_string
from django.http import HttpResponse
from django.contrib import messages
from django.contrib.messages import get_messages
import json
import logging
import traceback
Expand Down Expand Up @@ -794,6 +795,13 @@ def add_alarms(request, group_name):
alarm_info["metricSource"] = params["awsMetrics"]
alarm_info["groupName"] = group_name

if len(alarm_info["scalingPolicies"]) == 0:
# Technically, an alarm can be created without an action (e.g. scaling policy)
# However, in the current context, an alarm must have an associated scaling policy.
# In this case, there is no scaling policy, so refuse to create new alarm.
messages.add_message(request, messages.ERROR, 'Alarm could not be created because there was no {} policy.'.format(policy_type))
return redirect("/groups/{}/config/".format(group_name))

autoscaling_groups_helper.add_alarm(request, group_name, [alarm_info])

return redirect("/groups/{}/config/".format(group_name))
Expand Down Expand Up @@ -1180,6 +1188,7 @@ def get(self, request, group_name):
"pas_config": pas_config,
"is_cmp": is_cmp,
"disallow_autoscaling": _disallow_autoscaling(curr_image),
"storage": get_messages(request)
})


Expand Down

0 comments on commit 89498d4

Please sign in to comment.