@@ -127,11 +127,45 @@ def _build_parser() -> argparse.ArgumentParser:
127127# Config loading
128128# ---------------------------------------------------------------------------
129129
130+ _SINGLETON_KEYS = {"telemetry" , "sample_period_milliseconds" , "inspector" , "observer" }
131+ _LIST_KEYS = {"generator" , "blackhole" , "target_metrics" }
132+
133+
134+ def _merge_raw_configs (base : dict , overlay : dict ) -> dict :
135+ for key , val in overlay .items ():
136+ if key in _SINGLETON_KEYS :
137+ if key in base :
138+ raise ValueError (f"'{ key } ' defined in multiple config files" )
139+ base [key ] = val
140+ elif key in _LIST_KEYS :
141+ base .setdefault (key , []).extend (val if isinstance (val , list ) else [val ])
142+ else :
143+ base [key ] = val
144+ return base
145+
146+
130147def _load_raw_config (config_path : str ) -> dict :
131148 lading_config_env = os .environ .get ("LADING_CONFIG" )
132149 if lading_config_env :
133150 return yaml .safe_load (lading_config_env )
134- with open (config_path ) as f :
151+ p = os .path .abspath (config_path )
152+ if os .path .isdir (p ):
153+ yaml_files = sorted (
154+ entry .path
155+ for entry in os .scandir (p )
156+ if entry .is_file ()
157+ and entry .name .endswith (".yaml" )
158+ and not entry .name .startswith ("." )
159+ )
160+ if not yaml_files :
161+ raise ValueError (f"No .yaml config files found in directory: { p } " )
162+ merged : dict = {}
163+ for path in yaml_files :
164+ with open (path ) as f :
165+ partial = yaml .safe_load (f ) or {}
166+ merged = _merge_raw_configs (merged , partial )
167+ return merged
168+ with open (p ) as f :
135169 return yaml .safe_load (f )
136170
137171
0 commit comments