Skip to content

Commit

Permalink
Add the version of an AgentCheck as a property (#4228)
Browse files Browse the repository at this point in the history
  • Loading branch information
ofek authored Jul 30, 2019
1 parent 592fbda commit 82a010c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
17 changes: 17 additions & 0 deletions datadog_checks_base/datadog_checks/base/checks/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# All rights reserved
# Licensed under a 3-clause BSD style license (see LICENSE)
import copy
import importlib
import inspect
import json
import logging
Expand Down Expand Up @@ -133,6 +134,9 @@ class except the :py:meth:`check` method but sometimes it might be useful for a
# Only new checks or checks on Agent 6.13+ can and should use this for HTTP requests.
self._http = None

# Save the dynamically detected integration version
self._check_version = None

# TODO: Remove with Agent 5
# Set proxy settings
self.proxies = self._get_requests_proxy()
Expand Down Expand Up @@ -201,6 +205,19 @@ def http(self):

return self._http

@property
def check_version(self):
if self._check_version is None:
# 'datadog_checks.<PACKAGE>.<MODULE>...'
module_parts = self.__module__.split('.')
package_path = '.'.join(module_parts[:2])
package = importlib.import_module(package_path)

# Provide a default just in case
self._check_version = getattr(package, '__version__', '0.0.0')

return self._check_version

@property
def in_developer_mode(self):
self._log_deprecation('in_developer_mode')
Expand Down
7 changes: 7 additions & 0 deletions datadog_checks_base/tests/test_agent_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from six import PY3

from datadog_checks.base import AgentCheck
from datadog_checks.base import __version__ as base_package_version
from datadog_checks.base.checks.base import datadog_agent


Expand All @@ -28,6 +29,12 @@ def test_instance():
assert check.instances == [{'bar': 'baz'}]


def test_check_version():
check = AgentCheck()

assert check.check_version == base_package_version


def test_load_config():
assert AgentCheck.load_config("raw_foo: bar") == {'raw_foo': 'bar'}

Expand Down

0 comments on commit 82a010c

Please sign in to comment.