From 76bc26c726ff3d50f5c3f2e398ca423ee65de6f2 Mon Sep 17 00:00:00 2001 From: DanB Date: Tue, 31 Oct 2017 20:26:31 +0100 Subject: [PATCH] RALs max_computed_usage config option --- config/config.go | 9 +++++++++ config/config_defaults.go | 8 +++++++- config/config_json_test.go | 22 +++++++++++++++++----- config/config_test.go | 9 +++++++++ config/libconfig_json.go | 1 + 5 files changed, 43 insertions(+), 6 deletions(-) diff --git a/config/config.go b/config/config.go index 72788f5f0..2d025ef6d 100755 --- a/config/config.go +++ b/config/config.go @@ -65,6 +65,7 @@ func SetCgrConfig(cfg *CGRConfig) { func NewDefaultCGRConfig() (*CGRConfig, error) { cfg := new(CGRConfig) + cfg.RALsMaxComputedUsage = make(map[string]time.Duration) cfg.InstanceID = utils.GenUUID() cfg.DataFolderPath = "/usr/share/cgrates/" cfg.SmGenericConfig = new(SmGenericConfig) @@ -238,6 +239,7 @@ type CGRConfig struct { RALsAliasSConns []*HaPoolConfig RpSubjectPrefixMatching bool // enables prefix matching for the rating profile subject LcrSubjectPrefixMatching bool // enables prefix matching for the lcr subject + RALsMaxComputedUsage map[string]time.Duration SchedulerEnabled bool CDRSEnabled bool // Enable CDR Server service CDRSExtraFields []*utils.RSRField // Extra fields to store in CDRs @@ -917,6 +919,13 @@ func (self *CGRConfig) loadFromJsonCfg(jsnCfg *CgrJsonCfg) (err error) { if jsnRALsCfg.Lcr_subject_prefix_matching != nil { self.LcrSubjectPrefixMatching = *jsnRALsCfg.Lcr_subject_prefix_matching } + if jsnRALsCfg.Max_computed_usage != nil { + for k, v := range *jsnRALsCfg.Max_computed_usage { + if self.RALsMaxComputedUsage[k], err = utils.ParseDurationWithNanosecs(v); err != nil { + return + } + } + } } if jsnSchedCfg != nil && jsnSchedCfg.Enabled != nil { self.SchedulerEnabled = *jsnSchedCfg.Enabled diff --git a/config/config_defaults.go b/config/config_defaults.go index 47312a995..d0a2dc4f7 100755 --- a/config/config_defaults.go +++ b/config/config_defaults.go @@ -138,7 +138,13 @@ const CGRATES_CFG_JSON = ` "users_conns": [], // address where to reach the user service, empty to disable user profile functionality: <""|*internal|x.y.z.y:1234> "aliases_conns": [], // address where to reach the aliases service, empty to disable aliases functionality: <""|*internal|x.y.z.y:1234> "rp_subject_prefix_matching": false, // enables prefix matching for the rating profile subject - "lcr_subject_prefix_matching": false // enables prefix matching for the lcr subject + "lcr_subject_prefix_matching": false, // enables prefix matching for the lcr subject + "max_computed_usage": { // do not compute usage higher than this, prevents memory overload + "*any": "189h", + "*voice": "72h", + "*data": "107374182400", + "*sms": "10000" + }, }, diff --git a/config/config_json_test.go b/config/config_json_test.go index 96213618d..3f523547b 100755 --- a/config/config_json_test.go +++ b/config/config_json_test.go @@ -195,11 +195,23 @@ func TestDfStorDBJsonCfg(t *testing.T) { } func TestDfRalsJsonCfg(t *testing.T) { - eCfg := &RalsJsonCfg{Enabled: utils.BoolPointer(false), Thresholds_conns: &[]*HaPoolJsonCfg{}, - Cdrstats_conns: &[]*HaPoolJsonCfg{}, Stats_conns: &[]*HaPoolJsonCfg{}, - Historys_conns: &[]*HaPoolJsonCfg{}, Pubsubs_conns: &[]*HaPoolJsonCfg{}, - Users_conns: &[]*HaPoolJsonCfg{}, Aliases_conns: &[]*HaPoolJsonCfg{}, - Rp_subject_prefix_matching: utils.BoolPointer(false), Lcr_subject_prefix_matching: utils.BoolPointer(false)} + eCfg := &RalsJsonCfg{ + Enabled: utils.BoolPointer(false), + Thresholds_conns: &[]*HaPoolJsonCfg{}, + Cdrstats_conns: &[]*HaPoolJsonCfg{}, + Stats_conns: &[]*HaPoolJsonCfg{}, + Historys_conns: &[]*HaPoolJsonCfg{}, + Pubsubs_conns: &[]*HaPoolJsonCfg{}, + Users_conns: &[]*HaPoolJsonCfg{}, + Aliases_conns: &[]*HaPoolJsonCfg{}, + Rp_subject_prefix_matching: utils.BoolPointer(false), + Lcr_subject_prefix_matching: utils.BoolPointer(false), + Max_computed_usage: &map[string]string{ + utils.ANY: "189h", + utils.VOICE: "72h", + utils.DATA: "107374182400", + utils.SMS: "10000"}, + } if cfg, err := dfCgrJsonCfg.RalsJsonCfg(); err != nil { t.Error(err) } else if !reflect.DeepEqual(eCfg, cfg) { diff --git a/config/config_test.go b/config/config_test.go index a94433941..45beaa529 100755 --- a/config/config_test.go +++ b/config/config_test.go @@ -318,6 +318,15 @@ func TestCgrCfgJSONDefaultsRALs(t *testing.T) { if cgrCfg.LcrSubjectPrefixMatching != false { t.Error(cgrCfg.LcrSubjectPrefixMatching) } + eMaxCU := map[string]time.Duration{ + utils.ANY: time.Duration(189 * time.Hour), + utils.VOICE: time.Duration(72 * time.Hour), + utils.DATA: time.Duration(107374182400), + utils.SMS: time.Duration(10000), + } + if !reflect.DeepEqual(eMaxCU, cgrCfg.RALsMaxComputedUsage) { + t.Errorf("Expecting: %+v, received: %+v", eMaxCU, cgrCfg.RALsMaxComputedUsage) + } } func TestCgrCfgJSONDefaultsScheduler(t *testing.T) { diff --git a/config/libconfig_json.go b/config/libconfig_json.go index 5e464ecfc..42ff3ff64 100755 --- a/config/libconfig_json.go +++ b/config/libconfig_json.go @@ -89,6 +89,7 @@ type RalsJsonCfg struct { Users_conns *[]*HaPoolJsonCfg Rp_subject_prefix_matching *bool Lcr_subject_prefix_matching *bool + Max_computed_usage *map[string]string } // Scheduler config section