@@ -1788,7 +1788,10 @@ def format_context(context_match, context_format):
17881788 fom_vars = {}
17891789 for k , v in fom_match .groupdict ().items ():
17901790 fom_vars [k ] = v
1791- fom_name = self .expander .expand_var (fom , extra_vars = fom_vars )
1791+ if fom_conf ["fom_name_expanded" ] is not None :
1792+ fom_name = fom_conf ["fom_name_expanded" ]
1793+ else :
1794+ fom_name = self .expander .expand_var (fom , extra_vars = fom_vars )
17921795
17931796 if fom_conf ["group" ] in fom_conf ["regex" ].groupindex :
17941797 logger .debug (" --- Matched fom %s" % fom_name )
@@ -1808,9 +1811,12 @@ def format_context(context_match, context_format):
18081811 if context not in fom_values :
18091812 fom_values [context ] = {}
18101813 fom_val = fom_match .group (fom_conf ["group" ])
1811- fom_unit = self .expander .expand_var (
1812- fom_conf ["units" ], extra_vars = fom_vars
1813- )
1814+ if fom_conf ["units_expanded" ] is not None :
1815+ fom_unit = fom_conf ["units" ]
1816+ else :
1817+ fom_unit = self .expander .expand_var (
1818+ fom_conf ["units" ], extra_vars = fom_vars
1819+ )
18141820 fom_values [context ][fom_name ] = {
18151821 "value" : fom_val ,
18161822 "units" : fom_unit ,
@@ -2250,6 +2256,12 @@ def _analysis_dicts(self, criteria_list):
22502256 files [log_path ]["contexts" ].extend (conf ["contexts" ])
22512257 files [log_path ]["foms" ].append (fom )
22522258
2259+ def _try_expand_var_or_none (var : str , expander ):
2260+ try :
2261+ return expander .expand_var (var , allow_passthrough = False )
2262+ except ramble .expander .RambleSyntaxError :
2263+ return None
2264+
22532265 foms [fom ] = {
22542266 "regex" : re .compile (r"%s" % self .expander .expand_var (conf ["regex" ])),
22552267 "contexts" : [],
@@ -2258,6 +2270,10 @@ def _analysis_dicts(self, criteria_list):
22582270 "origin" : conf ["origin" ],
22592271 "origin_type" : conf ["origin_type" ],
22602272 "fom_type" : conf ["fom_type" ].to_dict (),
2273+ # If expansion works (i.e., it doesn't rely on the matched fom groups),
2274+ # then cache it here to avoid repeated expansion later.
2275+ "units_expanded" : _try_expand_var_or_none (conf ["units" ], self .expander ),
2276+ "fom_name_expanded" : _try_expand_var_or_none (fom , self .expander ),
22612277 }
22622278 if conf ["contexts" ]:
22632279 foms [fom ]["contexts" ].extend (conf ["contexts" ])
0 commit comments