mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-15 13:19:53 +05:00
Added opts exporterIDs to analyzers + tests
This commit is contained in:
committed by
Dan Christian Bogos
parent
3bc00a6235
commit
94292cc35b
@@ -33,6 +33,11 @@ type AnalyzerSCfg struct {
|
||||
TTL time.Duration
|
||||
EEsConns []string
|
||||
CleanupInterval time.Duration
|
||||
Opts *AnalyzerSOpts
|
||||
}
|
||||
|
||||
type AnalyzerSOpts struct {
|
||||
ExporterIDs []*utils.DynamicStringSliceOpt
|
||||
}
|
||||
|
||||
// loadAnalyzerCgrCfg loads the Analyzer section of the configuration
|
||||
@@ -44,6 +49,15 @@ func (alS *AnalyzerSCfg) Load(ctx *context.Context, jsnCfg ConfigDB, _ *CGRConfi
|
||||
return alS.loadFromJSONCfg(jsnAnalyzerCgrCfg)
|
||||
}
|
||||
|
||||
func (anzOpts *AnalyzerSOpts) loadFromJSONCfg(jsonAnzOpts *AnalyzerSOptsJson) {
|
||||
if jsonAnzOpts == nil {
|
||||
return
|
||||
}
|
||||
if jsonAnzOpts.ExporterIDs != nil {
|
||||
anzOpts.ExporterIDs = append(anzOpts.ExporterIDs, jsonAnzOpts.ExporterIDs...)
|
||||
}
|
||||
}
|
||||
|
||||
func (alS *AnalyzerSCfg) loadFromJSONCfg(jsnCfg *AnalyzerSJsonCfg) (err error) {
|
||||
if jsnCfg == nil {
|
||||
return
|
||||
@@ -70,17 +84,24 @@ func (alS *AnalyzerSCfg) loadFromJSONCfg(jsnCfg *AnalyzerSJsonCfg) (err error) {
|
||||
return
|
||||
}
|
||||
}
|
||||
if jsnCfg.Opts != nil {
|
||||
alS.Opts.loadFromJSONCfg(jsnCfg.Opts)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// AsMapInterface returns the config as a map[string]interface{}
|
||||
func (alS AnalyzerSCfg) AsMapInterface(string) interface{} {
|
||||
opts := map[string]interface{}{
|
||||
utils.MetaExporterIDs: alS.Opts.ExporterIDs,
|
||||
}
|
||||
mp := map[string]interface{}{
|
||||
utils.EnabledCfg: alS.Enabled,
|
||||
utils.DBPathCfg: alS.DBPath,
|
||||
utils.IndexTypeCfg: alS.IndexType,
|
||||
utils.TTLCfg: alS.TTL.String(),
|
||||
utils.CleanupIntervalCfg: alS.CleanupInterval.String(),
|
||||
utils.OptsCfg: opts,
|
||||
}
|
||||
if alS.EEsConns != nil {
|
||||
mp[utils.EEsConnsCfg] = getInternalJSONConns(alS.EEsConns)
|
||||
@@ -99,6 +120,7 @@ func (alS AnalyzerSCfg) Clone() (cln *AnalyzerSCfg) {
|
||||
IndexType: alS.IndexType,
|
||||
TTL: alS.TTL,
|
||||
CleanupInterval: alS.CleanupInterval,
|
||||
Opts: alS.Opts.Clone(),
|
||||
}
|
||||
if alS.EEsConns != nil {
|
||||
cln.EEsConns = utils.CloneStringSlice(alS.EEsConns)
|
||||
@@ -106,6 +128,19 @@ func (alS AnalyzerSCfg) Clone() (cln *AnalyzerSCfg) {
|
||||
return
|
||||
}
|
||||
|
||||
func (anzOpts *AnalyzerSOpts) Clone() *AnalyzerSOpts {
|
||||
if anzOpts == nil {
|
||||
return nil
|
||||
}
|
||||
return &AnalyzerSOpts{
|
||||
ExporterIDs: utils.CloneDynamicStringSliceOpt(anzOpts.ExporterIDs),
|
||||
}
|
||||
}
|
||||
|
||||
type AnalyzerSOptsJson struct {
|
||||
ExporterIDs []*utils.DynamicStringSliceOpt `json:"*exporterIDs"`
|
||||
}
|
||||
|
||||
// Analyzer service json config section
|
||||
type AnalyzerSJsonCfg struct {
|
||||
Enabled *bool
|
||||
@@ -114,6 +149,17 @@ type AnalyzerSJsonCfg struct {
|
||||
Ttl *string
|
||||
Ees_conns *[]string
|
||||
Cleanup_interval *string
|
||||
Opts *AnalyzerSOptsJson
|
||||
}
|
||||
|
||||
func diffAnalyzerSOptsJsonCfg(d *AnalyzerSOptsJson, v1, v2 *AnalyzerSOpts) *AnalyzerSOptsJson {
|
||||
if d == nil {
|
||||
d = new(AnalyzerSOptsJson)
|
||||
}
|
||||
if !utils.DynamicStringSliceOptEqual(v1.ExporterIDs, v2.ExporterIDs) {
|
||||
d.ExporterIDs = v2.ExporterIDs
|
||||
}
|
||||
return d
|
||||
}
|
||||
|
||||
func diffAnalyzerSJsonCfg(d *AnalyzerSJsonCfg, v1, v2 *AnalyzerSCfg) *AnalyzerSJsonCfg {
|
||||
@@ -138,5 +184,6 @@ func diffAnalyzerSJsonCfg(d *AnalyzerSJsonCfg, v1, v2 *AnalyzerSCfg) *AnalyzerSJ
|
||||
if v1.CleanupInterval != v2.CleanupInterval {
|
||||
d.Cleanup_interval = utils.StringPointer(v2.CleanupInterval.String())
|
||||
}
|
||||
d.Opts = diffAnalyzerSOptsJsonCfg(d.Opts, v1.Opts, v2.Opts)
|
||||
return d
|
||||
}
|
||||
|
||||
@@ -36,6 +36,9 @@ func TestAnalyzerSCfgloadFromJsonCfg(t *testing.T) {
|
||||
IndexType: utils.MetaScorch,
|
||||
EEsConns: []string{},
|
||||
TTL: 24 * time.Hour,
|
||||
Opts: &AnalyzerSOpts{
|
||||
ExporterIDs: []*utils.DynamicStringSliceOpt{},
|
||||
},
|
||||
}
|
||||
jsnCfg := NewDefaultCGRConfig()
|
||||
if err = jsnCfg.analyzerSCfg.loadFromJSONCfg(jsonCfg); err != nil {
|
||||
@@ -61,6 +64,9 @@ func TestAnalyzerSCfgAsMapInterface(t *testing.T) {
|
||||
utils.IndexTypeCfg: utils.MetaScorch,
|
||||
utils.EEsConnsCfg: []string{},
|
||||
utils.TTLCfg: "24h0m0s",
|
||||
utils.OptsCfg: map[string]interface{}{
|
||||
utils.MetaExporterIDs: []*utils.DynamicStringSliceOpt{},
|
||||
},
|
||||
}
|
||||
if cgrCfg, err := NewCGRConfigFromJSONStringWithDefaults(cfgJSONStr); err != nil {
|
||||
t.Error(err)
|
||||
@@ -84,6 +90,9 @@ func TestAnalyzerSCfgAsMapInterface1(t *testing.T) {
|
||||
utils.IndexTypeCfg: utils.MetaScorch,
|
||||
utils.EEsConnsCfg: []string{"*localhost"},
|
||||
utils.TTLCfg: "24h0m0s",
|
||||
utils.OptsCfg: map[string]interface{}{
|
||||
utils.MetaExporterIDs: []*utils.DynamicStringSliceOpt{},
|
||||
},
|
||||
}
|
||||
if cgrCfg, err := NewCGRConfigFromJSONStringWithDefaults(cfgJSONStr); err != nil {
|
||||
t.Error(err)
|
||||
@@ -136,6 +145,7 @@ func TestDiffAnalyzerSJsonCfg(t *testing.T) {
|
||||
IndexType: utils.MetaPrefix,
|
||||
TTL: 2 * time.Minute,
|
||||
CleanupInterval: time.Hour,
|
||||
Opts: &AnalyzerSOpts{},
|
||||
}
|
||||
|
||||
v2 := &AnalyzerSCfg{
|
||||
@@ -145,6 +155,7 @@ func TestDiffAnalyzerSJsonCfg(t *testing.T) {
|
||||
TTL: 3 * time.Minute,
|
||||
EEsConns: []string{"*internal"},
|
||||
CleanupInterval: 30 * time.Minute,
|
||||
Opts: &AnalyzerSOpts{},
|
||||
}
|
||||
|
||||
expected := &AnalyzerSJsonCfg{
|
||||
@@ -154,6 +165,7 @@ func TestDiffAnalyzerSJsonCfg(t *testing.T) {
|
||||
Ttl: utils.StringPointer("3m0s"),
|
||||
Ees_conns: &[]string{"*internal"},
|
||||
Cleanup_interval: utils.StringPointer("30m0s"),
|
||||
Opts: &AnalyzerSOptsJson{},
|
||||
}
|
||||
|
||||
rcv := diffAnalyzerSJsonCfg(d, v1, v2)
|
||||
@@ -162,7 +174,9 @@ func TestDiffAnalyzerSJsonCfg(t *testing.T) {
|
||||
}
|
||||
|
||||
v2 = v1
|
||||
expected2 := &AnalyzerSJsonCfg{}
|
||||
expected2 := &AnalyzerSJsonCfg{
|
||||
Opts: &AnalyzerSOptsJson{},
|
||||
}
|
||||
rcv = diffAnalyzerSJsonCfg(d, v1, v2)
|
||||
if !reflect.DeepEqual(rcv, expected2) {
|
||||
t.Errorf("Expected %v \n but received \n %v", utils.ToJSON(expected2), utils.ToJSON(rcv))
|
||||
|
||||
@@ -125,7 +125,11 @@ func newCGRConfig(config []byte) (cfg *CGRConfig, err error) {
|
||||
Stats: []*utils.DynamicBoolOpt{},
|
||||
Thresholds: []*utils.DynamicBoolOpt{},
|
||||
}},
|
||||
analyzerSCfg: new(AnalyzerSCfg),
|
||||
analyzerSCfg: &AnalyzerSCfg{
|
||||
Opts: &AnalyzerSOpts{
|
||||
ExporterIDs: []*utils.DynamicStringSliceOpt{},
|
||||
},
|
||||
},
|
||||
sessionSCfg: &SessionSCfg{
|
||||
STIRCfg: new(STIRcfg),
|
||||
DefaultUsage: make(map[string]time.Duration),
|
||||
|
||||
@@ -1517,6 +1517,15 @@ const CGRATES_CFG_JSON = `
|
||||
"ttl": "24h", // time to wait before removing the API capture
|
||||
"ees_conns": [], // connections to EEs
|
||||
"cleanup_interval": "1h", // the interval we clean the db
|
||||
"opts":{ //
|
||||
"*exporterIDs": [
|
||||
// {
|
||||
// "Tenant": "*any",
|
||||
// "FilterIDs": [],
|
||||
// "Value": [],
|
||||
// },
|
||||
],
|
||||
},
|
||||
},
|
||||
|
||||
|
||||
|
||||
@@ -1937,6 +1937,9 @@ func TestDfAnalyzerCfg(t *testing.T) {
|
||||
Index_type: utils.StringPointer(utils.MetaScorch),
|
||||
Ees_conns: &[]string{},
|
||||
Ttl: utils.StringPointer("24h"),
|
||||
Opts: &AnalyzerSOptsJson{
|
||||
ExporterIDs: []*utils.DynamicStringSliceOpt{},
|
||||
},
|
||||
}
|
||||
dfCgrJSONCfg, err := NewCgrJsonCfgFromBytes([]byte(CGRATES_CFG_JSON))
|
||||
if err != nil {
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -243,12 +243,11 @@ func (GeneralCfg) SName() string { return GeneralJSON }
|
||||
func (gencfg GeneralCfg) CloneSection() Section { return gencfg.Clone() }
|
||||
|
||||
func (generalOpts *GeneralOpts) Clone() *GeneralOpts {
|
||||
var thIDs []*utils.DynamicStringSliceOpt
|
||||
if generalOpts.ExporterIDs != nil {
|
||||
thIDs = utils.CloneDynamicStringSliceOpt(generalOpts.ExporterIDs)
|
||||
if generalOpts == nil {
|
||||
return nil
|
||||
}
|
||||
return &GeneralOpts{
|
||||
ExporterIDs: thIDs,
|
||||
ExporterIDs: utils.CloneDynamicStringSliceOpt(generalOpts.ExporterIDs),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -447,7 +447,9 @@ func TestGeneralCfgCloneSection(t *testing.T) {
|
||||
RSRSep: "",
|
||||
DefaultCaching: utils.MetaClear,
|
||||
FailedPostsTTL: 5,
|
||||
Opts: &GeneralOpts{},
|
||||
Opts: &GeneralOpts{
|
||||
ExporterIDs: []*utils.DynamicStringSliceOpt{},
|
||||
},
|
||||
}
|
||||
|
||||
rcv := gnrCfg.CloneSection()
|
||||
|
||||
@@ -496,7 +496,7 @@ func testConfigSReload(t *testing.T) {
|
||||
} else if cfgStr != rpl32 {
|
||||
t.Errorf("\nExpected %+v ,\n received: %+v", utils.ToIJSON(cfgStr), utils.ToIJSON(rpl32))
|
||||
}
|
||||
cfgStr = "{\"analyzers\":{\"cleanup_interval\":\"1h0m0s\",\"db_path\":\"/var/spool/cgrates/analyzers\",\"ees_conns\":[],\"enabled\":false,\"index_type\":\"*scorch\",\"ttl\":\"24h0m0s\"}}"
|
||||
cfgStr = "{\"analyzers\":{\"cleanup_interval\":\"1h0m0s\",\"db_path\":\"/var/spool/cgrates/analyzers\",\"ees_conns\":[],\"enabled\":false,\"index_type\":\"*scorch\",\"opts\":{\"*exporterIDs\":[]},\"ttl\":\"24h0m0s\"}}"
|
||||
var rpl33 string
|
||||
if err := testRPC.Call(context.Background(), utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{
|
||||
Tenant: "cgrates.org",
|
||||
|
||||
@@ -949,7 +949,7 @@ func testSectConfigSReloadAnalyzer(t *testing.T) {
|
||||
} else if reply != utils.OK {
|
||||
t.Errorf("Expected OK received: %+v", reply)
|
||||
}
|
||||
cfgStr := "{\"analyzers\":{\"cleanup_interval\":\"1h0m0s\",\"db_path\":\"/var/spool/cgrates/analyzers\",\"ees_conns\":[],\"enabled\":false,\"index_type\":\"*scorch\",\"ttl\":\"24h0m0s\"}}"
|
||||
cfgStr := "{\"analyzers\":{\"cleanup_interval\":\"1h0m0s\",\"db_path\":\"/var/spool/cgrates/analyzers\",\"ees_conns\":[],\"enabled\":false,\"index_type\":\"*scorch\",\"opts\":{\"*exporterIDs\":[]},\"ttl\":\"24h0m0s\"}}"
|
||||
var rpl string
|
||||
if err := testSectRPC.Call(context.Background(), utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{
|
||||
Tenant: "cgrates.org",
|
||||
|
||||
Reference in New Issue
Block a user