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

[GCE] Update hostname to be unique #1737

Merged
merged 4 commits into from
Jul 30, 2015
Merged
Show file tree
Hide file tree
Changes from 3 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
5 changes: 5 additions & 0 deletions checks/collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,11 @@ def _get_hostname_metadata(self):

metadata["hostname"] = get_hostname()

# Add cloud provider aliases
host_aliases = GCE.get_host_aliases(self.agentConfig)
if host_aliases:
metadata['host_aliases'] = host_aliases

return metadata

def _should_send_additional_data(self, data_name):
Expand Down
4 changes: 4 additions & 0 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,10 @@ def get_config(parse_args=True, cfg_path=None, options=None):
if config.has_option("Main", "utf8_decoding"):
agentConfig["utf8_decoding"] = _is_affirmative(config.get("Main", "utf8_decoding"))

agentConfig["gce_updated_hostname"] = False
if config.has_option("Main", "gce_updated_hostname"):
agentConfig["gce_updated_hostname"] = _is_affirmative(config.get("Main", "gce_updated_hostname"))

except ConfigParser.NoSectionError, e:
sys.stderr.write('Config file not found or incorrectly formatted.\n')
sys.exit(2)
Expand Down
3 changes: 3 additions & 0 deletions datadog.conf.example
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ api_key:
# for more information
# collect_instance_metadata: yes

# use unique hostname for GCE hosts. see #1736
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's create a wiki page and add the link

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ping me when this is done

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gce_updated_hostname: yes

# Set the threshold for accepting points to allow anything
# with recent_point_threshold seconds
# Defaults to 30 seconds if no value is provided
Expand Down
18 changes: 16 additions & 2 deletions util.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ class GCE(object):
TIMEOUT = 0.1 # second
SOURCE_TYPE_NAME = 'google cloud platform'
metadata = None
EXCLUDED_ATTRIBUTES = ["sshKeys"]
EXCLUDED_ATTRIBUTES = ["sshKeys", "user-data", "cli-cert", "ipsec-cert", "ssl-cert"]


@staticmethod
Expand Down Expand Up @@ -304,7 +304,21 @@ def get_tags(agentConfig):
def get_hostname(agentConfig):
try:
host_metadata = GCE._get_metadata(agentConfig)
return host_metadata['instance']['hostname'].split('.')[0]
hostname = host_metadata['instance']['hostname']
if agentConfig.get('gce_updated_hostname'):
return hostname
else:
return hostname.split('.')[0]
except Exception:
return None

@staticmethod
def get_host_aliases(agentConfig):
try:
host_metadata = GCE._get_metadata(agentConfig)
project_id = host_metadata['project']['projectId']
instance_name = host_metadata['instance']['hostname'].split('.')[0]
return ['%s.%s' % (instance_name, project_id)]
except Exception:
return None

Expand Down