mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-17 22:29:55 +05:00
Add new trends config option: scheduled_ids
This commit is contained in:
committed by
Dan Christian Bogos
parent
9b8ac3199b
commit
5b039c1d0b
@@ -1178,6 +1178,7 @@ const CGRATES_CFG_JSON = `
|
||||
"enabled": false, // starts TrendS service: <true|false>.
|
||||
"stats_conns": [], // connections to StatS ,empty to disable stats functionality: <""|*internal|$rpc_conns_id>
|
||||
"thresholds_conns": [], // connections to ThresholdS ,empty to disable stats functionality: <""|*internal|$rpc_conns_id>
|
||||
"scheduled_ids": {}
|
||||
},
|
||||
|
||||
"rankings":{ // RankingS config
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -189,3 +189,15 @@ func diffMapString(d, v1, v2 map[string]string) map[string]string {
|
||||
}
|
||||
return d
|
||||
}
|
||||
|
||||
func diffMapStringSlice(d, v1, v2 map[string][]string) map[string][]string {
|
||||
if d == nil {
|
||||
d = make(map[string][]string)
|
||||
}
|
||||
for k, v := range v2 {
|
||||
if val, has := v1[k]; !has || !slices.Equal(val, v) {
|
||||
d[k] = v
|
||||
}
|
||||
}
|
||||
return d
|
||||
}
|
||||
|
||||
@@ -399,3 +399,65 @@ func TestRadiusAgentCloneSection(t *testing.T) {
|
||||
t.Errorf("Expected %v \n but received \n %v", utils.ToJSON(exp), utils.ToJSON(rcv))
|
||||
}
|
||||
}
|
||||
|
||||
func TestDiffMapStringSlice(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
d map[string][]string
|
||||
v1 map[string][]string
|
||||
v2 map[string][]string
|
||||
want map[string][]string
|
||||
}{
|
||||
{
|
||||
name: "Empty maps",
|
||||
d: nil,
|
||||
v1: map[string][]string{},
|
||||
v2: map[string][]string{},
|
||||
want: map[string][]string{},
|
||||
},
|
||||
{
|
||||
name: "v1 has no key from v2",
|
||||
d: nil,
|
||||
v1: map[string][]string{},
|
||||
v2: map[string][]string{"tenant1": {"id1", "id2"}},
|
||||
want: map[string][]string{"tenant1": {"id1", "id2"}},
|
||||
},
|
||||
{
|
||||
name: "Different values for the same key",
|
||||
d: nil,
|
||||
v1: map[string][]string{"tenant1": {"id1", "id2"}},
|
||||
v2: map[string][]string{"tenant1": {"id3", "id4"}},
|
||||
want: map[string][]string{"tenant1": {"id3", "id4"}},
|
||||
},
|
||||
{
|
||||
name: "Same key with equal values",
|
||||
d: nil,
|
||||
v1: map[string][]string{"tenant1": {"id1", "id2"}},
|
||||
v2: map[string][]string{"tenant1": {"id1", "id2"}},
|
||||
want: map[string][]string{},
|
||||
},
|
||||
{
|
||||
name: "d is not nil, adds differences from v2",
|
||||
d: map[string][]string{"existing": {"val3"}},
|
||||
v1: map[string][]string{"tenant1": {"id1", "id2"}},
|
||||
v2: map[string][]string{"tenant1": {"id3", "id4"}, "tenant2": {"id4", "id5"}},
|
||||
want: map[string][]string{"existing": {"val3"}, "tenant1": {"id3", "id4"}, "tenant2": {"id4", "id5"}},
|
||||
},
|
||||
{
|
||||
name: "Adding multiple tenants",
|
||||
d: nil,
|
||||
v1: map[string][]string{"tenant1": {"id1", "id2"}},
|
||||
v2: map[string][]string{"tenant1": {"id1", "id2"}, "tenant2": {"id4", "id5"}},
|
||||
want: map[string][]string{"tenant2": {"id4", "id5"}},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got := diffMapStringSlice(tt.d, tt.v1, tt.v2)
|
||||
if !reflect.DeepEqual(got, tt.want) {
|
||||
t.Errorf("diffMapStringSlice() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ type TrendSCfg struct {
|
||||
Enabled bool
|
||||
StatSConns []string
|
||||
ThresholdSConns []string
|
||||
ScheduledIDs map[string][]string
|
||||
}
|
||||
|
||||
func (t *TrendSCfg) Load(ctx *context.Context, jsnCfg ConfigDB, _ *CGRConfig) (err error) {
|
||||
@@ -52,6 +53,9 @@ func (t *TrendSCfg) loadFromJSONCfg(jsnCfg *TrendSJsonCfg) (err error) {
|
||||
if jsnCfg.Thresholds_conns != nil {
|
||||
t.ThresholdSConns = updateInternalConns(*jsnCfg.Thresholds_conns, utils.MetaThresholds)
|
||||
}
|
||||
if jsnCfg.Scheduled_ids != nil {
|
||||
t.ScheduledIDs = jsnCfg.Scheduled_ids
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -66,6 +70,9 @@ func (t *TrendSCfg) AsMapInterface(string) any {
|
||||
if t.ThresholdSConns != nil {
|
||||
mp[utils.ThresholdSConnsCfg] = getInternalJSONConns(t.ThresholdSConns)
|
||||
}
|
||||
if t.ScheduledIDs != nil {
|
||||
mp[utils.ScheduledIDsCfg] = t.ScheduledIDs
|
||||
}
|
||||
return mp
|
||||
}
|
||||
|
||||
@@ -82,6 +89,12 @@ func (t *TrendSCfg) Clone() (cln *TrendSCfg) {
|
||||
if t.ThresholdSConns != nil {
|
||||
cln.ThresholdSConns = slices.Clone(t.ThresholdSConns)
|
||||
}
|
||||
if t.ScheduledIDs != nil {
|
||||
cln.ScheduledIDs = make(map[string][]string)
|
||||
for key, value := range t.ScheduledIDs {
|
||||
cln.ScheduledIDs[key] = slices.Clone(value)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -89,6 +102,7 @@ type TrendSJsonCfg struct {
|
||||
Enabled *bool
|
||||
Stats_conns *[]string
|
||||
Thresholds_conns *[]string
|
||||
Scheduled_ids map[string][]string
|
||||
}
|
||||
|
||||
func diffTrendsJsonCfg(d *TrendSJsonCfg, v1, v2 *TrendSCfg) *TrendSJsonCfg {
|
||||
@@ -104,5 +118,7 @@ func diffTrendsJsonCfg(d *TrendSJsonCfg, v1, v2 *TrendSCfg) *TrendSJsonCfg {
|
||||
if !slices.Equal(v1.ThresholdSConns, v2.ThresholdSConns) {
|
||||
d.Thresholds_conns = utils.SliceStringPointer(getInternalJSONConns(v2.ThresholdSConns))
|
||||
}
|
||||
d.Scheduled_ids = diffMapStringSlice(d.Scheduled_ids, v1.ScheduledIDs, v2.ScheduledIDs)
|
||||
|
||||
return d
|
||||
}
|
||||
|
||||
@@ -1993,6 +1993,7 @@ const (
|
||||
EnabledCfg = "enabled"
|
||||
ThresholdSConnsCfg = "thresholds_conns"
|
||||
CacheSConnsCfg = "caches_conns"
|
||||
ScheduledIDsCfg = "scheduled_ids"
|
||||
)
|
||||
|
||||
// Efs
|
||||
|
||||
Reference in New Issue
Block a user