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

Hostname lookup in debug and on/off setup #428

Merged
merged 7 commits into from
Oct 2, 2019
Merged
Show file tree
Hide file tree
Changes from 6 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
15 changes: 13 additions & 2 deletions datadog/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
logging.getLogger('datadog.threadstats').addHandler(NullHandler())


def initialize(api_key=None, app_key=None, host_name=None, api_host=None,
def initialize(api_key=None, app_key=None, host_name=None, hostname_from_config=True, api_host=None,
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd honestly put the new argument at the very end of the argument list, because it someone is doing right now initialize("xxx", "yyy", None, "some_api_host"), this would break their code. Optional arguments should always be added to the end.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 Done in the last commit

statsd_host=None, statsd_port=None, statsd_use_default_route=False,
statsd_socket_path=None, statsd_namespace=None, return_raw_response=False, **kwargs):
"""
Expand All @@ -41,9 +41,16 @@ def initialize(api_key=None, app_key=None, host_name=None, api_host=None,
:param app_key: Datadog application key
:type app_key: string

:param host_name: Set a specific hostname
:type host_name: string

:param hostname_from_config: Set the hostname from the Datadog agent config (agent 5). Will be deprecated
:type hostname_from_config: boolean

:param proxies: Proxy to use to connect to Datadog API;
for example, 'proxies': {'http': "http:<user>:<pass>@<ip>:<port>/"}
:type proxies: dictionary mapping protocol to the URL of the proxy.

:param api_host: Datadog API endpoint
:type api_host: url

Expand Down Expand Up @@ -80,7 +87,11 @@ def initialize(api_key=None, app_key=None, host_name=None, api_host=None,
api._application_key or
os.environ.get('DATADOG_APP_KEY', os.environ.get('DD_APP_KEY'))
)
api._host_name = host_name or api._host_name or get_hostname()
bkabrda marked this conversation as resolved.
Show resolved Hide resolved
api._hostname_from_config = hostname_from_config
if api._hostname_from_config:
api._host_name = host_name or api._host_name or get_hostname()
else:
api._host_name = host_name or api._host_name
api._api_host = api_host or api._api_host or os.environ.get('DATADOG_HOST', 'https://api.datadoghq.com')

# Statsd configuration
Expand Down
1 change: 1 addition & 0 deletions datadog/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
_api_version = 'v1'
_api_host = None
_host_name = None
_hostname_from_config = True
_cacert = True

# HTTP(S) settings
Expand Down
5 changes: 4 additions & 1 deletion datadog/util/hostname.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,12 @@ def get_hostname():
config = get_config()
config_hostname = config.get('hostname')
if config_hostname and is_valid_hostname(config_hostname):
log.warning("Hostname lookup from agent configuration will be deprecated "
"in an upcoming version of datadogpy. Set hostname_from_config to False "
"to get rid of this warning")
return config_hostname
except CfgNotFound:
log.info("No agent or invalid configuration file found")
log.warning("No agent or invalid configuration file found")

# Try to get GCE instance name
if hostname is None:
Expand Down