From ec06fe613c4ed506321d66866a775716fca1a45a Mon Sep 17 00:00:00 2001 From: DanB Date: Thu, 19 Jul 2018 18:21:26 +0200 Subject: [PATCH] New config option - attributes.process_runs --- cmd/cgr-engine/cgr-engine.go | 4 +++- config/attributescfg.go | 4 ++++ config/config.go | 5 +++++ config/config_defaults.go | 1 + config/config_json_test.go | 1 + config/config_test.go | 1 + config/libconfig_json.go | 1 + engine/attributes.go | 7 +++++-- engine/attributes_test.go | 2 +- 9 files changed, 22 insertions(+), 4 deletions(-) diff --git a/cmd/cgr-engine/cgr-engine.go b/cmd/cgr-engine/cgr-engine.go index 022e6d780..d09ec98dd 100644 --- a/cmd/cgr-engine/cgr-engine.go +++ b/cmd/cgr-engine/cgr-engine.go @@ -582,7 +582,9 @@ func startAttributeService(internalAttributeSChan chan rpcclient.RpcClientConnec <-cacheS.GetPrecacheChannel(utils.CacheAttributeProfiles) aS, err := engine.NewAttributeService(dm, filterS, - cfg.AttributeSCfg().StringIndexedFields, cfg.AttributeSCfg().PrefixIndexedFields) + cfg.AttributeSCfg().StringIndexedFields, + cfg.AttributeSCfg().PrefixIndexedFields, + cfg.AttributeSCfg().ProcessRuns) if err != nil { utils.Logger.Crit( fmt.Sprintf("<%s> Could not init, error: %s", diff --git a/config/attributescfg.go b/config/attributescfg.go index 1a3a3ff3a..477d26b46 100644 --- a/config/attributescfg.go +++ b/config/attributescfg.go @@ -23,6 +23,7 @@ type AttributeSCfg struct { Enabled bool StringIndexedFields *[]string PrefixIndexedFields *[]string + ProcessRuns int } func (alS *AttributeSCfg) loadFromJsonCfg(jsnCfg *AttributeSJsonCfg) (err error) { @@ -46,5 +47,8 @@ func (alS *AttributeSCfg) loadFromJsonCfg(jsnCfg *AttributeSJsonCfg) (err error) } alS.PrefixIndexedFields = &pif } + if jsnCfg.Process_runs != nil { + alS.ProcessRuns = *jsnCfg.Process_runs + } return } diff --git a/config/config.go b/config/config.go index 01df70e40..935b87bc2 100755 --- a/config/config.go +++ b/config/config.go @@ -658,6 +658,11 @@ func (self *CGRConfig) checkConfigSanity() error { } } } + if self.attributeSCfg != nil && self.attributeSCfg.Enabled { + if self.attributeSCfg.ProcessRuns < 1 { + return fmt.Errorf("<%s> process_runs needs to be bigger than 0", utils.AttributeS) + } + } if self.chargerSCfg != nil && self.chargerSCfg.Enabled { for _, connCfg := range self.chargerSCfg.AttributeSConns { if connCfg.Address == utils.MetaInternal && diff --git a/config/config_defaults.go b/config/config_defaults.go index 04f618d9e..96b162379 100755 --- a/config/config_defaults.go +++ b/config/config_defaults.go @@ -430,6 +430,7 @@ const CGRATES_CFG_JSON = ` "enabled": false, // starts attribute service: . //"string_indexed_fields": [], // query indexes based on these fields for faster processing "prefix_indexed_fields": [], // query indexes based on these fields for faster processing + "process_runs": 1, // number of run loops when processing event }, diff --git a/config/config_json_test.go b/config/config_json_test.go index 5a04747fe..651a2f157 100755 --- a/config/config_json_test.go +++ b/config/config_json_test.go @@ -705,6 +705,7 @@ func TestDfAttributeServJsonCfg(t *testing.T) { Enabled: utils.BoolPointer(false), String_indexed_fields: nil, Prefix_indexed_fields: &[]string{}, + Process_runs: utils.IntPointer(1), } if cfg, err := dfCgrJsonCfg.AttributeServJsonCfg(); err != nil { t.Error(err) diff --git a/config/config_test.go b/config/config_test.go index f118f9327..5fe044144 100755 --- a/config/config_test.go +++ b/config/config_test.go @@ -805,6 +805,7 @@ func TestCgrCfgJSONDefaultSAttributeSCfg(t *testing.T) { Enabled: false, StringIndexedFields: nil, PrefixIndexedFields: &[]string{}, + ProcessRuns: 1, } if !reflect.DeepEqual(eAliasSCfg, cgrCfg.attributeSCfg) { t.Errorf("received: %+v, expecting: %+v", eAliasSCfg, cgrCfg.attributeSCfg) diff --git a/config/libconfig_json.go b/config/libconfig_json.go index cf82861f3..401096bf3 100755 --- a/config/libconfig_json.go +++ b/config/libconfig_json.go @@ -427,6 +427,7 @@ type AttributeSJsonCfg struct { Enabled *bool String_indexed_fields *[]string Prefix_indexed_fields *[]string + Process_runs *int } // ChargerSJsonCfg service config section diff --git a/engine/attributes.go b/engine/attributes.go index 05991acdf..16860a315 100644 --- a/engine/attributes.go +++ b/engine/attributes.go @@ -25,10 +25,12 @@ import ( ) func NewAttributeService(dm *DataManager, filterS *FilterS, - stringIndexedFields, prefixIndexedFields *[]string) (*AttributeService, error) { + stringIndexedFields, prefixIndexedFields *[]string, + processRuns int) (*AttributeService, error) { return &AttributeService{dm: dm, filterS: filterS, stringIndexedFields: stringIndexedFields, - prefixIndexedFields: prefixIndexedFields}, nil + prefixIndexedFields: prefixIndexedFields, + processRuns: processRuns}, nil } type AttributeService struct { @@ -36,6 +38,7 @@ type AttributeService struct { filterS *FilterS stringIndexedFields *[]string prefixIndexedFields *[]string + processRuns int } // ListenAndServe will initialize the service diff --git a/engine/attributes_test.go b/engine/attributes_test.go index a2f9d2f11..526a86dc2 100644 --- a/engine/attributes_test.go +++ b/engine/attributes_test.go @@ -182,7 +182,7 @@ func TestAttributePopulateAttrService(t *testing.T) { if err != nil { t.Errorf("Error: %+v", err) } - attrService, err = NewAttributeService(dmAtr, &FilterS{dm: dmAtr, cfg: defaultCfg}, nil, nil) + attrService, err = NewAttributeService(dmAtr, &FilterS{dm: dmAtr, cfg: defaultCfg}, nil, nil, 1) if err != nil { t.Errorf("Error: %+v", err) }