Make created language persistant

This commit is contained in:
Holger Obermaier 2022-02-16 08:40:57 +01:00
parent 542520d2c0
commit 248c815a1c

View File

@ -62,6 +62,10 @@ var metricCacheLanguage = gval.NewLanguage(
gval.Function("getCpuList", getCpuListOfNode), gval.Function("getCpuList", getCpuListOfNode),
gval.Function("getCpuListOfType", getCpuListOfType), gval.Function("getCpuListOfType", getCpuListOfType),
) )
var language gval.Language = gval.NewLanguage(
gval.Full(),
metricCacheLanguage,
)
func (c *metricAggregator) Init(output chan lp.CCMetric) error { func (c *metricAggregator) Init(output chan lp.CCMetric) error {
c.output = output c.output = output
@ -288,10 +292,6 @@ func EvalBoolCondition(condition string, params map[string]interface{}) (bool, e
strings.ReplaceAll( strings.ReplaceAll(
strings.ReplaceAll( strings.ReplaceAll(
condition, "'", "\""), "%", "\\") condition, "'", "\""), "%", "\\")
language := gval.NewLanguage(
gval.Full(),
metricCacheLanguage,
)
value, err := gval.Evaluate(newcond, params, language) value, err := gval.Evaluate(newcond, params, language)
if err != nil { if err != nil {
return false, err return false, err
@ -321,10 +321,6 @@ func EvalFloat64Condition(condition string, params map[string]interface{}) (floa
var endResult float64 = math.NaN() var endResult float64 = math.NaN()
newcond := strings.ReplaceAll(condition, "'", "\"") newcond := strings.ReplaceAll(condition, "'", "\"")
newcond = strings.ReplaceAll(newcond, "%", "\\") newcond = strings.ReplaceAll(newcond, "%", "\\")
language := gval.NewLanguage(
gval.Full(),
metricCacheLanguage,
)
value, err := gval.Evaluate(newcond, params, language) value, err := gval.Evaluate(newcond, params, language)
if err != nil { if err != nil {
cclog.ComponentDebug("MetricRouter", condition, " = ", err.Error()) cclog.ComponentDebug("MetricRouter", condition, " = ", err.Error())