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

Fix hosts spinning indefinitely #1446

Merged
merged 24 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from 16 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
30 changes: 25 additions & 5 deletions deploy-board/deploy_board/templates/hosts/host_details.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@

<div id="hostDetailId" class="collapse in panel-body table-responsive">
<table class="table table-striped table-bordered table-condensed table-hover">
<tr>
<tr>
{% if account_id and account_id != "null" %}
<th class="col-lg-1">Acccount Id</th>
{% endif %}
<th class="col-lg-1">Host Name</th>
<th class="col-lg-2">Host Id</th>
<th class="col-lg-2">Host Group</th>
<th class="col-lg-2">Ip Address</th>
<th class="col-lg-1">Status</th>
<th class="col-lg-1">State</th>
<th class="col-lg-2">Create Date</th>
<th class="col-lg-2">Last Update</th>
</tr>
Expand All @@ -85,8 +85,12 @@
</tr>
{% endfor %}
</table>
<div class="row">
{% if pinterest %}
<a href="javascript:void(0)" id="seeMoreLink">See more host details</a>
<div class="row">
<a href="javascript:void(0)" id="seeMoreLink">See more host details</a>
<a class="pull-right" href="#" data-toggle="modal" data-target="#rawHostInfoModal">Raw Host Info</a>
</div>
<div id="moreHostDetails" hidden="true">
{% for key, value in host_details.items %}
<div class="row">
Expand Down Expand Up @@ -117,9 +121,25 @@
<a href="{{ host_information_url }}/instance/{{ host_id }}">click here</a>
{% endif %}
</div>
{% endif %}
</div>

<div id="rawHostInfoModal" class="modal fade" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
<h4 class="modal-title">Raw Host Info</h4>
</div>
<div class="modal-body">
{% for host in hosts %}
<code>{{ host }}</code>
{% endfor %}
</div>
</div>
</div>
</div>
</div>
{% endif %}
</div>
</div>

<script>
Expand Down
12 changes: 10 additions & 2 deletions deploy-board/deploy_board/webapp/agent_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@
# -*- coding: utf-8 -*-
"""Helper functions to help generate agents views
"""
from deploy_board.webapp.helpers import agents_helper
from .common import is_agent_failed
from .helpers import builds_helper, deploys_helper, environs_helper, environ_hosts_helper
from deploy_board.settings import IS_PINTEREST
import time
from collections import OrderedDict
from functools import cmp_to_key


# Constants used to distinguish the action to generate the host report
TOTAL_ALIVE_HOST_REPORT = "TOTAL_ALIVE_HOST_REPORT"
UNKNOWN_HOST_REPORT = "UNKNOWN_HOST_REPORT"
Expand All @@ -38,10 +40,11 @@


class AgentStatistics(object):
def __init__(self, agent=None, isCurrent=False, isStale=False):
def __init__(self, agent=None, isCurrent=False, isStale=False, isShamed=False):
tylerwowen marked this conversation as resolved.
Show resolved Hide resolved
self.agent = agent
self.isCurrent = isCurrent
self.isStale = isStale
self.isShamed = isShamed


class DeployStatistics(object):
Expand Down Expand Up @@ -108,7 +111,12 @@ def addToEnvReport(request, deployStats, agent, env):
if duration >= DEFAULT_STALE_THRESHOLD:
isStale = True

return AgentStatistics(agent=agent, isCurrent=isCurrent, isStale=isStale)
isShamed = False
agent_ec2_tags = agents_helper.get_agent_ec2_tags(request, env['envName'], env['stageName'])
if agent_ec2_tags and agent_ec2_tags.get("service_mapping") == "shame":
isShamed = True

return AgentStatistics(agent=agent, isCurrent=isCurrent, isStale=isStale, isShamed=isShamed)
gzpcho marked this conversation as resolved.
Show resolved Hide resolved


def _compare_agent_status(agentStats1, agentStats2):
Expand Down
15 changes: 9 additions & 6 deletions deploy-board/deploy_board/webapp/helpers/agents_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#
# http://www.apache.org/licenses/LICENSE-2.0
#
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand Down Expand Up @@ -42,8 +42,8 @@ def retry_deploy(request, env_name, stage_name, host_id):

def reset_all_environments(request, host_id):
return deployclient.put(
"/agents/id/%s" % (host_id,),
request.teletraan_user_id.token,
"/agents/id/%s" % (host_id,),
request.teletraan_user_id.token,
data={"state": "RESET"},
)

Expand All @@ -59,8 +59,11 @@ def resume_deploy(request, env_name, stage_name, host_id):

def get_agents_by_host(request, host_name):
return deployclient.get("/agents/%s" % host_name, request.teletraan_user_id.token)


def get_agents_total_by_env(request, env_id):
return deployclient.get("/agents/env/%s/total" % env_id, request.teletraan_user_id.token)


def get_agent_ec2_tags(request, env_name, stage_name):
return deployclient.get(f"/env/{env_name}/{stage_name}/host_ec2_tags", request.teletraan_user_id_token)

20 changes: 14 additions & 6 deletions deploy-board/deploy_board/webapp/templatetags/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,11 +468,11 @@ def successRatePercentage(deploy):
return trunc(deploy["subAcctSucHostNum"] * 100 / deploy["subAcctTotalHostNum"])
elif deploy.get("account") == AWS_PRIMARY_ACCOUNT:
if deploy["primaryAcctTotalHostNum"] != 0:
return trunc(deploy["primaryAcctSucHostNum"] * 100 / deploy["primaryAcctTotalHostNum"])
return trunc(deploy["primaryAcctSucHostNum"] * 100 / deploy["primaryAcctTotalHostNum"])
elif deploy.get("account") == "others":
if deploy["otherAcctTotalHostNum"] != 0:
return trunc(deploy["otherAcctSucHostNum"] * 100 / deploy["otherAcctTotalHostNum"])
else:
return trunc(deploy["otherAcctSucHostNum"] * 100 / deploy["otherAcctTotalHostNum"])
else:
if deploy["total"] != 0:
return trunc(deploy["successTotal"] * 100 / deploy["total"])
return 0
Expand Down Expand Up @@ -634,10 +634,14 @@ def agentIcon(agentStats):
return 'fa-recycle fa-spin'

# normal state
if agent['deployStage'] == "SERVING_BUILD" and agentStats.isCurrent:
return 'fa-check'

if agentStats.isCurrent:
if agent['deployStage'] == "SERVING_BUILD":
return 'fa-check'
if agentStats.isStale or agentStats.isShamed or (
agent['state']== "PROVISIONED" and
agent["ip"] is None
):
return 'fa-exclamation-triangle'
return 'fa-spinner fa-spin'

return 'fa-clock-o'
Expand All @@ -654,6 +658,8 @@ def hostButton(host):
@register.filter("hostIcon")
def hostIcon(host):
if host['state'] == 'PROVISIONED':
if host["ip"] is None:
gzpcho marked this conversation as resolved.
Show resolved Hide resolved
return 'fa-exclamation-triangle'
return 'fa-refresh fa-spin'

if host['state'] == 'ACTIVE':
Expand All @@ -666,6 +672,8 @@ def hostIcon(host):
def hostTip(host):
hostname = host['hostName']
if host['state'] == 'PROVISIONED':
if host["ip"] is None:
return "{}: Host is provisioning, but failure occured and requires manual termination or restart".format(hostname)
return '{}: Host is provisioning, click for more information'.format(hostname)

if host['state'] == 'ACTIVE':
Expand Down
Loading