@@ -1234,12 +1234,9 @@ def load_check_directory(agentConfig, hostname):
12341234 agentConfig ['checksd_hostname' ] = hostname
12351235 osname = get_os ()
12361236
1237- # the TRACE_CONFIG flag is used by the configcheck to trace config object loading and
1238- # where they come from (service discovery, auto config or config file)
1239- if agentConfig .get (TRACE_CONFIG ):
1240- configs_and_sources = {
1241- # check_name: (config_source, config)
1242- }
1237+ configs_and_sources = {
1238+ # check_name: [ (config_source, config), ... ]
1239+ }
12431240
12441241 deprecated_checks .update (_deprecated_configs (agentConfig ))
12451242
@@ -1254,31 +1251,40 @@ def load_check_directory(agentConfig, hostname):
12541251 if not conf_is_valid :
12551252 continue
12561253
1257- if agentConfig .get (TRACE_CONFIG ):
1258- configs_and_sources [check_name ] = (CONFIG_FROM_FILE , check_config )
1259-
1260- # load the check
1261- load_success , load_failure = load_check_from_places (check_config , check_name , checks_places , agentConfig )
1262-
1263- initialized_checks .update (load_success )
1264- init_failed_checks .update (load_failure )
1254+ configs_and_sources [check_name ] = [ (CONFIG_FROM_FILE , check_config ) ]
12651255
12661256 for check_name , service_disco_check_config in _service_disco_configs (agentConfig ).iteritems ():
1267- # ignore this config from service disco if the check has been loaded through a file config
1268- if check_name in initialized_checks or \
1269- check_name in init_failed_checks or \
1270- check_name in JMX_CHECKS :
1271- continue
1272-
12731257 sd_init_config , sd_instances = service_disco_check_config [1 ]
1274- if agentConfig .get (TRACE_CONFIG ):
1275- configs_and_sources [check_name ] = (
1258+
1259+ # If a container or other discovered source wants to use the same check
1260+ # as defined in a file, append it to the instance list.
1261+ # The init_config will be from the first instance found, whether that's
1262+ # a file or the first container seen.
1263+ if configs_and_sources .get (check_name ) is None :
1264+ configs_and_sources [check_name ] = [ (
12761265 service_disco_check_config [0 ],
1277- {'init_config' : sd_init_config , 'instances' : sd_instances })
1266+ {'init_config' : sd_init_config , 'instances' : sd_instances }
1267+ ) ]
1268+ else :
1269+ configs_and_sources [check_name ].append ( (
1270+ service_disco_check_config [0 ],
1271+ {'init_config' : sd_init_config , 'instances' : sd_instances }) )
12781272
1279- check_config = {'init_config' : sd_init_config , 'instances' : sd_instances }
1273+ # If called from utils/configcheck.py, return the list of checks that were found
1274+ if agentConfig .get (TRACE_CONFIG ):
1275+ return configs_and_sources
12801276
1281- # load the check
1277+ # Merge the configs from multiple sources into the first element of each check_name list
1278+ for check_name , check_configs in configs_and_sources .iteritems ():
1279+ if len (check_configs ) > 1 :
1280+ for config in check_configs [1 :]:
1281+ configs_and_sources [check_name ][0 ][1 ]['instances' ].extend (config [1 ]['instances' ])
1282+ log .warning ('Different versions of `init_config` found for check %s. '
1283+ 'Keeping the first one found.' % check_name )
1284+
1285+ # Load the checks
1286+ for check_name , checks in configs_and_sources .iteritems ():
1287+ check_config = checks [0 ][1 ]
12821288 load_success , load_failure = load_check_from_places (check_config , check_name , checks_places , agentConfig )
12831289
12841290 initialized_checks .update (load_success )
0 commit comments