Skip to content

Commit

Permalink
ignore some error logs when loading public hostname/ip from amazon me…
Browse files Browse the repository at this point in the history
…tadata service.
  • Loading branch information
keijack committed May 5, 2021
1 parent 3b46083 commit 1df7213
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
5 changes: 3 additions & 2 deletions py_eureka_client/__aws_info_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,15 @@ def __check_connectivity(self):
_logger.warn(f"Cannot connect to amazon metadata services in address [{_AWS_METADATA_SERVICE_IP}]")
return False

def get_ec2_metadata(self, meta_path, default_value=""):
def get_ec2_metadata(self, meta_path, default_value="", ignore_error=False):
if not self.__can_access:
_logger.warn(f"Cannot connect to amazon metadata services in address [{_AWS_METADATA_SERVICE_IP}], return default value. ")
return default_value
try:
return http_client.load(f"{_AWS_METADATA_SERVICE_URL}meta-data/{meta_path}")[0]
except Exception:
_logger.exception(f"error when loading metadata from aws {meta_path}")
log_excep = _logger.debug if ignore_error else _logger.exception
log_excep(f"error when loading metadata from aws {meta_path}")
return default_value

def get_instance_identity_document(self, default_value={}):
Expand Down
2 changes: 1 addition & 1 deletion py_eureka_client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@
SOFTWARE.
"""

version="0.9.8"
version="0.9.9"
6 changes: 3 additions & 3 deletions py_eureka_client/eureka_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1034,9 +1034,9 @@ def __load_ec2_metadata_dict(self):
'instance-type': amazon_info.get_ec2_metadata('instance-type'),
'local-ipv4': amazon_info.get_ec2_metadata('local-ipv4'),
'local-hostname': amazon_info.get_ec2_metadata('local-hostname'),
'availability-zone': amazon_info.get_ec2_metadata('placement/availability-zone'),
'public-hostname': amazon_info.get_ec2_metadata('public-hostname'),
'public-ipv4': amazon_info.get_ec2_metadata('public-ipv4'),
'availability-zone': amazon_info.get_ec2_metadata('placement/availability-zone', ignore_error=True),
'public-hostname': amazon_info.get_ec2_metadata('public-hostname', ignore_error=True),
'public-ipv4': amazon_info.get_ec2_metadata('public-ipv4', ignore_error=True),
'mac': mac,
'vpcId': vpc_id
}
Expand Down

0 comments on commit 1df7213

Please sign in to comment.