add config sanity checks for prometheus_agent

This commit is contained in:
ionutboangiu
2025-03-21 22:02:43 +02:00
committed by Dan Christian Bogos
parent 347ea9d988
commit ea3ebcc6dd
2 changed files with 26 additions and 0 deletions

View File

@@ -1094,6 +1094,9 @@ func (cfg *CGRConfig) checkConfigSanity() error {
return fmt.Errorf("<%s> the CleanupInterval needs to be bigger than 0", utils.AnalyzerS)
}
}
if err := cfg.prometheusAgentCfg.validate(cfg); err != nil {
return err
}
return nil
}

View File

@@ -19,7 +19,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
package config
import (
"fmt"
"slices"
"strings"
"github.com/cgrates/birpc/context"
"github.com/cgrates/cgrates/utils"
@@ -113,6 +115,27 @@ func (c PrometheusAgentCfg) Clone() *PrometheusAgentCfg {
}
}
func (c PrometheusAgentCfg) validate(cfg *CGRConfig) error {
if !c.Enabled {
return nil
}
for _, connID := range c.StatSConns {
if strings.HasPrefix(connID, utils.MetaInternal) && !cfg.statsCfg.Enabled {
return fmt.Errorf("<%s> not enabled but requested by <%s> component", utils.StatService, utils.PrometheusAgent)
}
if _, has := cfg.rpcConns[connID]; !has && !strings.HasPrefix(connID, utils.MetaInternal) {
return fmt.Errorf("<%s> connection with id: <%s> not defined", utils.PrometheusAgent, connID)
}
}
if len(c.CoreSConns) > 0 {
if c.CollectGoMetrics || c.CollectProcessMetrics {
return fmt.Errorf("<%s> collect_go_metrics and collect_process_metrics cannot be enabled when using CoreSConns",
utils.PrometheusAgent)
}
}
return nil
}
func diffPrometheusAgentJsonCfg(d *PrometheusAgentJsonCfg, v1, v2 *PrometheusAgentCfg) *PrometheusAgentJsonCfg {
if d == nil {
d = new(PrometheusAgentJsonCfg)