Skip to content

Commit

Permalink
Send ec2 tags from deployd to TAS (#1340)
Browse files Browse the repository at this point in the history
  • Loading branch information
liyaqin1 authored Nov 16, 2023
1 parent 5db1822 commit fba404c
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 5 deletions.
6 changes: 4 additions & 2 deletions deploy-agent/deployd/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ def _read_host_info(self):
# so need to read ec2_tags from facter and parse Autoscaling tag to cover this case
if not self._autoscaling_group:
ec2_tags = facter_data.get(ec2_tags_key)
self._ec2_tags = json.dumps(ec2_tags) if ec2_tags else None
self._autoscaling_group = ec2_tags.get(asg_tag_key) if ec2_tags else None

if not self._stage_type and not self._stage_type_fetched:
Expand All @@ -185,8 +186,8 @@ def _read_host_info(self):

log.info("Host information is loaded. "
"Host name: {}, IP: {}, host id: {}, agent_version={}, autoscaling_group: {}, "
"availability_zone: {}, stage_type: {}, group: {}, account id: {}".format(self._hostname, self._ip, self._id,
self._agent_version, self._autoscaling_group, self._availability_zone, self._stage_type, self._hostgroup, self._account_id))
"availability_zone: {}, ec2_tags: {}, stage_type: {}, group: {}, account id: {}".format(self._hostname, self._ip, self._id,
self._agent_version, self._autoscaling_group, self._availability_zone, self._ec2_tags, self._stage_type, self._hostgroup, self._account_id))

if not self._availability_zone:
log.error("Fail to read host info: availablity zone")
Expand Down Expand Up @@ -214,6 +215,7 @@ def send_reports(self, env_reports=None):
agentVersion=self._agent_version,
autoscalingGroup=self._autoscaling_group,
availabilityZone=self._availability_zone,
ec2Tags=self._ec2_tags,
stageType=self._stage_type,
accountId=self._account_id)

Expand Down
9 changes: 6 additions & 3 deletions deploy-agent/deployd/types/ping_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
class PingRequest(object):

def __init__(self, hostId=None, hostName=None, hostIp=None, groups=None, reports=None,
agentVersion=None, autoscalingGroup=None, availabilityZone=None, stageType=None, accountId=None):
agentVersion=None, autoscalingGroup=None, availabilityZone=None, ec2Tags=None, stageType=None, accountId=None):
self.hostId = hostId
self.hostName = hostName
self.hostIp = hostIp
Expand All @@ -29,6 +29,7 @@ def __init__(self, hostId=None, hostName=None, hostIp=None, groups=None, reports
self.agentVersion = agentVersion
self.autoscalingGroup = autoscalingGroup
self.availabilityZone = availabilityZone
self.ec2Tags = ec2Tags
self.stageType = stageType
self.accountId = accountId

Expand All @@ -49,6 +50,8 @@ def to_json(self):
ping_requests["groups"] = list(self.groups)
if self.accountId:
ping_requests["accountId"] = self.accountId
if self.ec2Tags:
ping_requests["ec2Tags"] = self.ec2Tags

ping_requests["reports"] = []
for report in self.reports:
Expand Down Expand Up @@ -83,6 +86,6 @@ def to_json(self):

def __str__(self):
return "PingRequest(hostId={}, hostName={}, hostIp={}, agentVersion={}, autoscalingGroup={}, " \
"availabilityZone={}, stageType={}, groups={}, accountId={}, reports={})".format(self.hostId, self.hostName,
self.hostIp, self.agentVersion, self.autoscalingGroup, self.availabilityZone, self.stageType,
"availabilityZone={}, ec2Tags={}, stageType={}, groups={}, accountId={}, reports={})".format(self.hostId, self.hostName,
self.hostIp, self.agentVersion, self.autoscalingGroup, self.availabilityZone, self.ec2Tags, self.stageType,
self.groups, self.accountId, ",".join(str(v) for v in self.reports))
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public class PingRequestBean {

private String availabilityZone;

private String ec2Tags;

private String agentVersion;

private EnvType stageType;
Expand Down Expand Up @@ -84,6 +86,14 @@ public void setAvailabilityZone(String availabilityZone){
this.availabilityZone = availabilityZone;
}

public String getEc2Tags() {
return ec2Tags;
}

public void setEc2Tags(String ec2Tags) {
this.ec2Tags = ec2Tags;
}

public String getAgentVersion() {
return agentVersion;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
import java.util.concurrent.ExecutionException;
import java.util.*;

import com.fasterxml.jackson.databind.ObjectMapper;

/**
* This is where we handle agent ping and return deploy goal!
*/
Expand Down Expand Up @@ -601,6 +603,18 @@ public PingResult ping(PingRequestBean pingRequest, boolean rate_limited) throws
String asg = pingRequest.getAutoscalingGroup();
Set<String> groups = this.shardGroups(pingRequest);
String accountId = pingRequest.getAccountId();

// go through ec2Tags
String ec2Tags = pingRequest.getEc2Tags();
LOG.debug("go through ec2 tags: {}", ec2Tags);
if (ec2Tags != null) {
ObjectMapper mapper = new ObjectMapper();
Map<String, String> tags = mapper.readValue(ec2Tags, Map.class);
for (Map.Entry<String, String> entry : tags.entrySet()) {
LOG.debug("key: {}, val: {}", entry.getKey(), entry.getValue());
}
}

//update agent version for host
String agentVersion = pingRequest.getAgentVersion() != null ? pingRequest.getAgentVersion() : "UNKNOWN";

Expand Down

0 comments on commit fba404c

Please sign in to comment.