From b9c795a4c8e738591d2155f0ce46cf01848380ae Mon Sep 17 00:00:00 2001 From: Jaime Fullaondo Date: Wed, 23 Aug 2017 12:39:54 +0200 Subject: [PATCH 1/2] [info] `unknown` ver if failed module load, `custom` if custom check. [info] custom is more appropriate. [info] allow manual override of check version. --- checks/__init__.py | 11 +++++++---- checks/collector.py | 2 +- config.py | 18 +++++++++++++++--- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/checks/__init__.py b/checks/__init__.py index c89cc93daf..50e7430c82 100644 --- a/checks/__init__.py +++ b/checks/__init__.py @@ -379,14 +379,17 @@ def __init__(self, name, init_config, agentConfig, instances=None): def set_manifest_path(self, manifest_path): self.manifest_path = manifest_path - def set_check_version(self, manifest=None): - version = AGENT_VERSION + def set_check_version(self, version=None, manifest=None): + _version = AGENT_VERSION + + if version: + _version = version if manifest is not None: - version = "{core}:{sdk}".format(core=AGENT_VERSION, + _version = "{core}:{sdk}".format(core=AGENT_VERSION, sdk=manifest.get('version', 'unknown')) - self.check_version = version + self.check_version = _version def get_instance_proxy(self, instance, uri): proxies = self.proxies.copy() diff --git a/checks/collector.py b/checks/collector.py index 99bb99d938..08a7e83cd0 100644 --- a/checks/collector.py +++ b/checks/collector.py @@ -475,7 +475,7 @@ def run(self, checksd=None, start_event=True, configs_reloaded=False): if not self.continue_running: return check_status = CheckStatus(check_name, None, None, None, None, - check_version=info.get('version'), + check_version=info.get('version', 'unknown'), init_failed_error=info['error'], init_failed_traceback=info['traceback']) check_statuses.append(check_status) diff --git a/config.py b/config.py index 7b81b41ba3..e057b3f592 100644 --- a/config.py +++ b/config.py @@ -973,7 +973,8 @@ def get_valid_check_class(check_name, check_path): return True, check_class, {} -def _initialize_check(check_config, check_name, check_class, agentConfig, manifest_path): +def _initialize_check(check_config, check_name, check_class, agentConfig, + manifest_path, version_override=None): init_config = check_config.get('init_config') or {} instances = check_config['instances'] try: @@ -989,7 +990,11 @@ def _initialize_check(check_config, check_name, check_class, agentConfig, manife if manifest_path: check.set_manifest_path(manifest_path) - check.set_check_version(load_manifest(manifest_path)) + + if not version_override: + check.set_check_version(manifest=load_manifest(manifest_path)) + else: + check.set_check_version(version=version_override) except Exception as e: log.exception('Unable to initialize check %s' % check_name) traceback_message = traceback.format_exc() @@ -997,6 +1002,8 @@ def _initialize_check(check_config, check_name, check_class, agentConfig, manife if manifest is not None: check_version = '{core}:{vers}'.format(core=AGENT_VERSION, vers=manifest.get('version', 'unknown')) + elif version_override: + check_version = version_override else: check_version = AGENT_VERSION @@ -1066,8 +1073,13 @@ def load_check_from_places(check_config, check_name, checks_places, agentConfig) log.warn("The SDK check (%s) was designed for a different agent core " "or couldnt be validated - behavior is undefined" % check_name) + version_override = None + if not manifest_path and agentConfig['additional_checksd'] in check_path: + version_override = 'custom' # custom check + + load_success, load_failure = _initialize_check( - check_config, check_name, check_class, agentConfig, manifest_path + check_config, check_name, check_class, agentConfig, manifest_path, version_override ) _update_python_path(check_config) From c2b86cc8f80377e41b530020f5885a33b5c15fd3 Mon Sep 17 00:00:00 2001 From: Jaime Fullaondo Date: Wed, 23 Aug 2017 14:43:28 +0200 Subject: [PATCH 2/2] [info] pick the nit :) --- checks/__init__.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/checks/__init__.py b/checks/__init__.py index 50e7430c82..0b6ab80399 100644 --- a/checks/__init__.py +++ b/checks/__init__.py @@ -380,10 +380,7 @@ def set_manifest_path(self, manifest_path): self.manifest_path = manifest_path def set_check_version(self, version=None, manifest=None): - _version = AGENT_VERSION - - if version: - _version = version + _version = version or AGENT_VERSION if manifest is not None: _version = "{core}:{sdk}".format(core=AGENT_VERSION,