Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pie #1457

Merged
merged 4 commits into from
Feb 21, 2024
Merged

Pie #1457

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
<div class="row">
<a href="/env/{{ env_name }}/{{ env_stage }}/cluster_replacements/auto_refresh"
type="button" class="btn btn-default btn-block">
<span class="glyphicon glyphicon-leaf" style="color:green;"></span> Set up Auto Refresh <b style="color:blue;">(Preview)</b>
<span class="glyphicon glyphicon-leaf" style="color:green;"></span> Set up Auto Refresh
</a>
</div>
<div class="row">
Expand Down
10 changes: 10 additions & 0 deletions deploy-board/deploy_board/templates/groups/asg_config.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
</div>
</div>

<div id="suspendedProcessesPid"></div>
<div id="scheduledActionsPid"></div>
<div id="scalingPolicyPid"></div>
<div id="alarmMetricPid"></div>
Expand Down Expand Up @@ -102,6 +103,14 @@ function loadAsgScheduledActions() {
});
}

function loadAsgSuspendedProcesses() {
$("#suspendedProcessesPid").addClass("panel panel-default");
var asg_suspended_processes_url = "/groups/{{ group_name }}/autoscaling/get_suspended_processes/";
$.get(asg_suspended_processes_url, function(response) {
$("#suspendedProcessesPid").html(response);
});
}

function loadAsgPolicy() {
$("#scalingPolicyPid").addClass("panel panel-default");
var asg_policy_url = "/groups/{{ group_name }}/autoscaling/get_asg_policy/";
Expand All @@ -121,6 +130,7 @@ function loadAsgAlarms() {
function getAdvancedSetting() {
loadAsgPolicy();
loadAsgScheduledActions();
loadAsgSuspendedProcesses();
loadAsgAlarms();
}

Expand Down
52 changes: 52 additions & 0 deletions deploy-board/deploy_board/templates/groups/asg_processes.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{% load utils %}
{% include "panel_heading.tmpl" with panel_title="Suspended Processes" panel_body_id="asSuspendedProcessId" direction="down" %}
<div id="asSuspendedProcessId" class="collapse in panel-body">

<div class="container-fluid">
<table id="suspendedProcessStatus" class="table">
<tr>
<th>Process Name</th>
<th>State</th>
<th>Click to ...</th>
</tr>
{% for process in process_suspended_status %}
<tr>
<td>
{{ process.name }}
</td>
<td>
{% if process.suspended == True %} <p style="color:red;">Suspended</p> {% else %} <p style="color:green;">Active</p>{% endif %}
</td>
<td>
{% if process.suspended == True %} <input type="button" value="Resume" onclick="updateProcess(this, '{{ process.name }}', false)"> {% else %} <input type="button" value="Suspend" onclick="updateProcess(this, '{{ process.name }}', true)"> {% endif %}
</td>
</tr>
{% endfor%}
</table>
</div>

<script>
function updateProcess(element, name, shouldSuspend) {
var url = ""

if (shouldSuspend == true) {
url = '/groups/{{ group_name }}/autoscaling/suspend_process/' + name;
}
else {
url = '/groups/{{ group_name }}/autoscaling/resume_process/' + name
}

$.ajax({
type: 'POST',
url: url,
data: {'csrfmiddlewaretoken': '{{csrf_token}}'},
success: function (data) {
$("#asSuspendedProcessId").parent().html(data);
}
});

element.value = "Updating ...";
element.disabled = true;
}
</script>
</div>
27 changes: 26 additions & 1 deletion deploy-board/deploy_board/templates/groups/host_az_dist.tmpl
Original file line number Diff line number Diff line change
@@ -1,11 +1,36 @@
{% load utils %}

{% block content %}
<div id="container" style="width: 75%;">
<div id="container" style="width: 100%;">
<h2>Host Distribution Among Availability Zones</h2>
<canvas id="pie-chart"></canvas>
</div>

<div>
<table id="host-dist-stat" class="table">
<tr>
<th>Availability Zone</th>
<th>Host Count</th>
<th>Percentage</th>
</tr>
{% for l, d, p in label_data_percentage %}
<tr>
<td>
{{ l }}
</td>
<td>
{{ d }}
</td>
<td>
{{ p }}%
</td>
</tr>
{% endfor%}
</table>
<p>==============================</p>
<b>Total:</b> {{ total }} hosts
</div>

<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script>
var config = {
Expand Down
6 changes: 6 additions & 0 deletions deploy-board/deploy_board/webapp/arcee_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@
group_view.get_pas_config),
url(r'^groups/(?P<group_name>[a-zA-Z0-9\-_]+)/autoscaling/get_scheduled_actions/$',
group_view.get_scheduled_actions),
url(r'^groups/(?P<group_name>[a-zA-Z0-9\-_]+)/autoscaling/get_suspended_processes/$',
group_view.get_suspended_processes),
url(r'^groups/(?P<group_name>[a-zA-Z0-9\-_]+)/autoscaling/suspend_process/(?P<process_name>[a-zA-Z\-_]+)$',
group_view.suspend_process),
url(r'^groups/(?P<group_name>[a-zA-Z0-9\-_]+)/autoscaling/resume_process/(?P<process_name>[a-zA-Z\-_]+)$',
group_view.resume_process),
url(r'^groups/(?P<group_name>[a-zA-Z0-9\-_]+)/autoscaling/delete_scheduled_actions/$',
group_view.delete_scheduled_actions),
url(r'^groups/(?P<group_name>[a-zA-Z0-9\-_]+)/autoscaling/add_scheduled_actions/$',
Expand Down
43 changes: 41 additions & 2 deletions deploy-board/deploy_board/webapp/group_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -1474,10 +1474,16 @@ def get_host_az_dist(request, group_name):
)

counter = Counter([x['location'] for x in host_az_dist.json()])
labels = list(counter.keys())
data = list(counter.values())
total = sum(data)
percentages = map(lambda x: round((x / total) * 100, 1), data)

return render(request, 'groups/host_az_dist.tmpl', {
'labels': list(counter.keys()),
'data': list(counter.values()),
'labels': labels,
'data': data,
'label_data_percentage': list(zip(labels, data, percentages)),
'total': total
})

def get_health_check_details(request, id):
Expand Down Expand Up @@ -1558,6 +1564,39 @@ def get_scheduled_actions(request, group_name):
})
return HttpResponse(json.dumps(content), content_type="application/json")

def get_suspended_processes(request, group_name):
suspended_processes = autoscaling_groups_helper.get_disabled_asg_actions(request, group_name)
all_processes = autoscaling_groups_helper.get_available_scaling_process(request, group_name)
all_processes.sort()

process_suspended_status = []

for p in all_processes:
if p in suspended_processes:
process_suspended_status.append({"name": p, "suspended": True})
else:
process_suspended_status.append({"name": p, "suspended": False})

content = render_to_string("groups/asg_processes.tmpl", {
'group_name': group_name,
'process_suspended_status': process_suspended_status,
'csrf_token': get_token(request),
})
return HttpResponse(json.dumps(content), content_type="application/json")

def suspend_process(request, group_name, process_name):
update_request = {}
update_request["suspend"] = [process_name]
autoscaling_groups_helper.update_scaling_process(request, group_name, update_request)

return get_suspended_processes(request, group_name)

def resume_process(request, group_name, process_name):
update_request = {}
update_request["resume"] = [process_name]
autoscaling_groups_helper.update_scaling_process(request, group_name, update_request)

return get_suspended_processes(request, group_name)

def delete_scheduled_actions(request, group_name):
params = request.POST
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,12 @@ def disable_scaling_down_event(request, cluster_name):
def get_disabled_asg_actions(request, cluster_name):
return rodimus_client.get("/clusters/%s/autoscaling/action" % cluster_name, request.teletraan_user_id.token)

def update_scaling_process(request, cluster_name, update_request):
return rodimus_client.post("/clusters/%s/autoscaling/processes" % cluster_name, request.teletraan_user_id.token,
data=update_request)

def get_available_scaling_process(request, cluster_name):
return rodimus_client.get("/clusters/%s/autoscaling/available-processes" % cluster_name, request.teletraan_user_id.token)

# Asg Alarms
def put_scaling_policies(request, cluster_name, policies_info):
Expand Down
Loading