From 7f4657cfc5d1b71a8259e0008289f6dda19dd21b Mon Sep 17 00:00:00 2001 From: nick Date: Tue, 21 Jan 2025 17:38:49 -0600 Subject: [PATCH] Regex matching for YAML configuration --- ldms/python/ldmsd/parser_util.py | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/ldms/python/ldmsd/parser_util.py b/ldms/python/ldmsd/parser_util.py index 0f55156c1..1604e0338 100644 --- a/ldms/python/ldmsd/parser_util.py +++ b/ldms/python/ldmsd/parser_util.py @@ -217,6 +217,18 @@ def perm_handler(perm_str): perm_handler.octal_pattern = re.compile('^0?[0-7]{1,3}') class YamlCfg(object): + def get_group(self, group): + daemons_ = None + for daemons in self.cluster_config['daemons']: + if group == daemons['names'] or group in expand_names(daemons['names']): + if group != daemons['names']: + group = daemons['names'] + daemons_ = daemons + if daemons_ is None: + raise ValueError(f'Daemons regex {daemons["names"]} does not match daemon regex "{group}"\n') + return group + + def build_daemons(self, config): """Generate a daemon spec list from YAML config @@ -419,19 +431,13 @@ def build_aggregators(self, config): check_required([ 'daemons' ], agg_spec, '"aggregators" entry') names = expand_names(agg_spec['daemons']) - group = agg_spec['daemons'] + group = self.get_group(agg_spec['daemons']) plugins = check_opt('plugins', agg_spec) if plugins: if plugins is not list: raise ValueError(f'"plugins" must be a list of plugin instance names"\n') for plugin in plugins: check_plugin_config(plugin, self.plugins) - daemons_ = None - for daemons in config['daemons']: - if group == daemons['names']: - daemons_ = daemons - if daemons_ is None: - raise ValueError(f'Daemons regex {daemons["names"]} does not match daemon regex "{group}"\n') if group not in aggregators: aggregators[group] = {} subscribe = check_opt('subscribe', agg_spec) @@ -467,6 +473,7 @@ def build_producers(self, config): for prod in agg['peers']: check_required([ 'endpoints', 'reconnect', 'type', ], prod, '"peers" entry') + group = self.get_group(agg['daemons']) # Use endpoints for producer names and remove names attribute? if prod['daemons'] not in self.daemons: dmn_grps = prod['daemons'].split(',') @@ -477,7 +484,6 @@ def build_producers(self, config): for daemons, endpoints in zip(dmn_grps, eps): names = expand_names(endpoints) endpoints = expand_names(endpoints) - group = agg['daemons'] smplr_dmns = expand_names(daemons) if group not in producers: producers[group] = {} @@ -531,6 +537,7 @@ def build_updaters(self, config): peer_list += agg['peers'] if 'prdcr_listen' in agg: peer_list += agg['prdcr_listen'] + group = self.get_group(agg['daemons']) for prod in peer_list: if 'updaters' not in prod: continue @@ -549,7 +556,6 @@ def build_updaters(self, config): updtr_sets = check_opt('sets', updtr_spec) if updtr_sets and type(updtr_sets) is not list: raise ValueError(f'Error parsing YAML configuration in "updaters". "sets" must be a list of dictionaries') - group = agg['daemons'] if group not in updaters: updaters[group] = {} grp_updaters = updaters[group] @@ -563,7 +569,10 @@ def build_updaters(self, config): if type(prod_regex) is not str and prod_regex is not None: raise TypeError(f'Error: Configuration error in keyword "producers". Only regex string values are valid.') if prod_regex is None: - prod_regex = expand_names(prod['endpoints']) + if 'endpoints' in prod: + prod_regex = expand_names(prod['endpoints']) + else: + prod_regex = ".*" updtr = { 'name' : updtr_name, 'interval' : check_intrvl_str(updtr_spec['interval']),