diff --git a/cmd/cgr-engine/cgr-engine.go b/cmd/cgr-engine/cgr-engine.go index 8a627185e..31fd78b36 100644 --- a/cmd/cgr-engine/cgr-engine.go +++ b/cmd/cgr-engine/cgr-engine.go @@ -527,7 +527,7 @@ func startAttributeService(internalAttributeSChan chan rpcclient.RpcClientConnec dm *engine.DataManager, server *utils.Server, exitChan chan bool, filterSChan chan *engine.FilterS) { filterS := <-filterSChan filterSChan <- filterS - aS, err := engine.NewAttributeService(dm, filterS, cfg.AttributeSCfg().IndexedFields) + aS, err := engine.NewAttributeService(dm, filterS, cfg.AttributeSCfg().StringIndexedFields) if err != nil { utils.Logger.Crit(fmt.Sprintf("<%s> Could not init, error: %s", utils.AttributeS, err.Error())) exitChan <- true @@ -561,7 +561,7 @@ func startResourceService(internalRsChan, internalThresholdSChan chan rpcclient. return } } - rS, err := engine.NewResourceService(dm, cfg.ResourceSCfg().StoreInterval, thdSConn, filterS, cfg.ResourceSCfg().IndexedFields) + rS, err := engine.NewResourceService(dm, cfg.ResourceSCfg().StoreInterval, thdSConn, filterS, cfg.ResourceSCfg().StringIndexedFields) if err != nil { utils.Logger.Crit(fmt.Sprintf(" Could not init, error: %s", err.Error())) exitChan <- true @@ -598,7 +598,7 @@ func startStatService(internalStatSChan, internalThresholdSChan chan rpcclient.R return } } - sS, err := engine.NewStatService(dm, cfg.StatSCfg().StoreInterval, thdSConn, filterS, cfg.StatSCfg().IndexedFields) + sS, err := engine.NewStatService(dm, cfg.StatSCfg().StoreInterval, thdSConn, filterS, cfg.StatSCfg().StringIndexedFields) if err != nil { utils.Logger.Crit(fmt.Sprintf(" Could not init, error: %s", err.Error())) exitChan <- true @@ -623,7 +623,7 @@ func startThresholdService(internalThresholdSChan chan rpcclient.RpcClientConnec dm *engine.DataManager, server *utils.Server, exitChan chan bool, filterSChan chan *engine.FilterS) { filterS := <-filterSChan filterSChan <- filterS - tS, err := engine.NewThresholdService(dm, cfg.ThresholdSCfg().IndexedFields, + tS, err := engine.NewThresholdService(dm, cfg.ThresholdSCfg().StringIndexedFields, cfg.ThresholdSCfg().StoreInterval, filterS) if err != nil { utils.Logger.Crit(fmt.Sprintf(" Could not init, error: %s", err.Error())) @@ -676,7 +676,7 @@ func startSupplierService(internalSupplierSChan, internalRsChan, internalStatSCh } } splS, err := engine.NewSupplierService(dm, cfg.DefaultTimezone, filterS, - cfg.SupplierSCfg().IndexedFields, resourceSConn, statSConn) + cfg.SupplierSCfg().StringIndexedFields, resourceSConn, statSConn) if err != nil { utils.Logger.Crit(fmt.Sprintf("<%s> Could not init, error: %s", utils.SupplierS, err.Error())) diff --git a/config/aliascfg.go b/config/aliascfg.go index d56f847bd..d8592aa45 100644 --- a/config/aliascfg.go +++ b/config/aliascfg.go @@ -20,8 +20,8 @@ package config // SupplierSCfg is the configuration of supplier service type AttributeSCfg struct { - Enabled bool - IndexedFields []string + Enabled bool + StringIndexedFields []string } func (alS *AttributeSCfg) loadFromJsonCfg(jsnCfg *AttributeSJsonCfg) (err error) { @@ -31,10 +31,10 @@ func (alS *AttributeSCfg) loadFromJsonCfg(jsnCfg *AttributeSJsonCfg) (err error) if jsnCfg.Enabled != nil { alS.Enabled = *jsnCfg.Enabled } - if jsnCfg.Indexed_fields != nil { - alS.IndexedFields = make([]string, len(*jsnCfg.Indexed_fields)) - for i, fID := range *jsnCfg.Indexed_fields { - alS.IndexedFields[i] = fID + if jsnCfg.String_indexed_fields != nil { + alS.StringIndexedFields = make([]string, len(*jsnCfg.String_indexed_fields)) + for i, fID := range *jsnCfg.String_indexed_fields { + alS.StringIndexedFields[i] = fID } } return diff --git a/config/config_defaults.go b/config/config_defaults.go index 048ed4af4..49fe6ea13 100755 --- a/config/config_defaults.go +++ b/config/config_defaults.go @@ -430,7 +430,7 @@ const CGRATES_CFG_JSON = ` "attributes": { // Attribute service "enabled": false, // starts attribute service: . - "indexed_fields": [], // query indexes based on these fields for faster processing + "string_indexed_fields": [], // query indexes based on these fields for faster processing }, @@ -438,7 +438,7 @@ const CGRATES_CFG_JSON = ` "enabled": false, // starts ResourceLimiter service: . "store_interval": "", // dump cache regularly to dataDB, 0 - dump at start/shutdown: <""|$dur> "thresholds_conns": [], // address where to reach the thresholds service, empty to disable thresholds functionality: <""|*internal|x.y.z.y:1234> - "indexed_fields": [], // query indexes based on these fields for faster processing + "string_indexed_fields": [], // query indexes based on these fields for faster processing }, @@ -446,20 +446,20 @@ const CGRATES_CFG_JSON = ` "enabled": false, // starts Stat service: . "store_interval": "", // dump cache regularly to dataDB, 0 - dump at start/shutdown: <""|$dur> "thresholds_conns": [], // address where to reach the thresholds service, empty to disable thresholds functionality: <""|*internal|x.y.z.y:1234> - "indexed_fields": [], // query indexes based on these fields for faster processing + "string_indexed_fields": [], // query indexes based on these fields for faster processing }, "thresholds": { // Threshold service (*new) "enabled": false, // starts ThresholdS service: . "store_interval": "", // dump cache regularly to dataDB, 0 - dump at start/shutdown: <""|$dur> - "indexed_fields": [], // query indexes based on these fields for faster processing + "string_indexed_fields": [], // query indexes based on these fields for faster processing }, "suppliers": { // Supplier service (*new) "enabled": false, // starts SupplierS service: . - "indexed_fields": [], // query indexes based on these fields for faster processing + "string_indexed_fields": [], // query indexes based on these fields for faster processing "rals_conns": [ {"address": "*internal"}, // address where to reach the RALs for cost/accounting <*internal> ], diff --git a/config/config_json_test.go b/config/config_json_test.go index bbc551073..24ed03b1f 100755 --- a/config/config_json_test.go +++ b/config/config_json_test.go @@ -716,8 +716,8 @@ func TestDfUserServJsonCfg(t *testing.T) { func TestDfAttributeServJsonCfg(t *testing.T) { eCfg := &AttributeSJsonCfg{ - Enabled: utils.BoolPointer(false), - Indexed_fields: utils.StringSlicePointer([]string{}), + Enabled: utils.BoolPointer(false), + String_indexed_fields: utils.StringSlicePointer([]string{}), } if cfg, err := dfCgrJsonCfg.AttributeServJsonCfg(); err != nil { t.Error(err) @@ -739,10 +739,10 @@ func TestDfFilterSJsonCfg(t *testing.T) { func TestDfResourceLimiterSJsonCfg(t *testing.T) { eCfg := &ResourceSJsonCfg{ - Enabled: utils.BoolPointer(false), - Thresholds_conns: &[]*HaPoolJsonCfg{}, - Store_interval: utils.StringPointer(""), - Indexed_fields: utils.StringSlicePointer([]string{}), + Enabled: utils.BoolPointer(false), + Thresholds_conns: &[]*HaPoolJsonCfg{}, + Store_interval: utils.StringPointer(""), + String_indexed_fields: utils.StringSlicePointer([]string{}), } if cfg, err := dfCgrJsonCfg.ResourceSJsonCfg(); err != nil { t.Error(err) @@ -753,10 +753,10 @@ func TestDfResourceLimiterSJsonCfg(t *testing.T) { func TestDfStatServiceJsonCfg(t *testing.T) { eCfg := &StatServJsonCfg{ - Enabled: utils.BoolPointer(false), - Store_interval: utils.StringPointer(""), - Thresholds_conns: &[]*HaPoolJsonCfg{}, - Indexed_fields: utils.StringSlicePointer([]string{}), + Enabled: utils.BoolPointer(false), + Store_interval: utils.StringPointer(""), + Thresholds_conns: &[]*HaPoolJsonCfg{}, + String_indexed_fields: utils.StringSlicePointer([]string{}), } if cfg, err := dfCgrJsonCfg.StatSJsonCfg(); err != nil { t.Error(err) @@ -767,9 +767,9 @@ func TestDfStatServiceJsonCfg(t *testing.T) { func TestDfThresholdSJsonCfg(t *testing.T) { eCfg := &ThresholdSJsonCfg{ - Enabled: utils.BoolPointer(false), - Store_interval: utils.StringPointer(""), - Indexed_fields: utils.StringSlicePointer([]string{}), + Enabled: utils.BoolPointer(false), + Store_interval: utils.StringPointer(""), + String_indexed_fields: utils.StringSlicePointer([]string{}), } if cfg, err := dfCgrJsonCfg.ThresholdSJsonCfg(); err != nil { t.Error(err) @@ -780,8 +780,8 @@ func TestDfThresholdSJsonCfg(t *testing.T) { func TestDfSupplierSJsonCfg(t *testing.T) { eCfg := &SupplierSJsonCfg{ - Enabled: utils.BoolPointer(false), - Indexed_fields: utils.StringSlicePointer([]string{}), + Enabled: utils.BoolPointer(false), + String_indexed_fields: utils.StringSlicePointer([]string{}), Rals_conns: &[]*HaPoolJsonCfg{ &HaPoolJsonCfg{ Address: utils.StringPointer("*internal"), diff --git a/config/config_test.go b/config/config_test.go index 69ad0fad9..a07174eaf 100755 --- a/config/config_test.go +++ b/config/config_test.go @@ -658,8 +658,8 @@ func TestCgrCfgJSONDefaultFiltersCfg(t *testing.T) { func TestCgrCfgJSONDefaultSAttributeSCfg(t *testing.T) { eAliasSCfg := &AttributeSCfg{ - Enabled: false, - IndexedFields: []string{}, + Enabled: false, + StringIndexedFields: []string{}, } if !reflect.DeepEqual(eAliasSCfg, cgrCfg.attributeSCfg) { t.Errorf("received: %+v, expecting: %+v", eAliasSCfg, cgrCfg.attributeSCfg) @@ -668,10 +668,10 @@ func TestCgrCfgJSONDefaultSAttributeSCfg(t *testing.T) { func TestCgrCfgJSONDefaultsResLimCfg(t *testing.T) { eResLiCfg := &ResourceSConfig{ - Enabled: false, - ThresholdSConns: []*HaPoolConfig{}, - StoreInterval: 0, - IndexedFields: []string{}, + Enabled: false, + ThresholdSConns: []*HaPoolConfig{}, + StoreInterval: 0, + StringIndexedFields: []string{}, } if !reflect.DeepEqual(cgrCfg.resourceSCfg, eResLiCfg) { t.Errorf("expecting: %s, received: %s", utils.ToJSON(eResLiCfg), utils.ToJSON(cgrCfg.resourceSCfg)) @@ -681,10 +681,10 @@ func TestCgrCfgJSONDefaultsResLimCfg(t *testing.T) { func TestCgrCfgJSONDefaultStatsCfg(t *testing.T) { eStatsCfg := &StatSCfg{ - Enabled: false, - StoreInterval: 0, - ThresholdSConns: []*HaPoolConfig{}, - IndexedFields: []string{}, + Enabled: false, + StoreInterval: 0, + ThresholdSConns: []*HaPoolConfig{}, + StringIndexedFields: []string{}, } if !reflect.DeepEqual(cgrCfg.statsCfg, eStatsCfg) { t.Errorf("received: %+v, expecting: %+v", cgrCfg.statsCfg, eStatsCfg) @@ -693,9 +693,9 @@ func TestCgrCfgJSONDefaultStatsCfg(t *testing.T) { func TestCgrCfgJSONDefaultThresholdSCfg(t *testing.T) { eThresholdSCfg := &ThresholdSCfg{ - Enabled: false, - StoreInterval: 0, - IndexedFields: []string{}, + Enabled: false, + StoreInterval: 0, + StringIndexedFields: []string{}, } if !reflect.DeepEqual(eThresholdSCfg, cgrCfg.thresholdSCfg) { t.Errorf("received: %+v, expecting: %+v", eThresholdSCfg, cgrCfg.thresholdSCfg) @@ -704,8 +704,8 @@ func TestCgrCfgJSONDefaultThresholdSCfg(t *testing.T) { func TestCgrCfgJSONDefaultSupplierSCfg(t *testing.T) { eSupplSCfg := &SupplierSCfg{ - Enabled: false, - IndexedFields: []string{}, + Enabled: false, + StringIndexedFields: []string{}, RALsConns: []*HaPoolConfig{ &HaPoolConfig{Address: "*internal"}, }, diff --git a/config/libconfig_json.go b/config/libconfig_json.go index 31db4159f..839a66294 100755 --- a/config/libconfig_json.go +++ b/config/libconfig_json.go @@ -389,40 +389,40 @@ type UserServJsonCfg struct { // Attribute service config section type AttributeSJsonCfg struct { - Enabled *bool - Indexed_fields *[]string + Enabled *bool + String_indexed_fields *[]string } // ResourceLimiter service config section type ResourceSJsonCfg struct { - Enabled *bool - Thresholds_conns *[]*HaPoolJsonCfg - Store_interval *string - Indexed_fields *[]string + Enabled *bool + Thresholds_conns *[]*HaPoolJsonCfg + Store_interval *string + String_indexed_fields *[]string } // Stat service config section type StatServJsonCfg struct { - Enabled *bool - Store_interval *string - Thresholds_conns *[]*HaPoolJsonCfg - Indexed_fields *[]string + Enabled *bool + Store_interval *string + Thresholds_conns *[]*HaPoolJsonCfg + String_indexed_fields *[]string } // Threshold service config section type ThresholdSJsonCfg struct { - Enabled *bool - Store_interval *string - Indexed_fields *[]string + Enabled *bool + Store_interval *string + String_indexed_fields *[]string } // Supplier service config section type SupplierSJsonCfg struct { - Enabled *bool - Indexed_fields *[]string - Rals_conns *[]*HaPoolJsonCfg - Resources_conns *[]*HaPoolJsonCfg - Stats_conns *[]*HaPoolJsonCfg + Enabled *bool + String_indexed_fields *[]string + Rals_conns *[]*HaPoolJsonCfg + Resources_conns *[]*HaPoolJsonCfg + Stats_conns *[]*HaPoolJsonCfg } // Mailer config section diff --git a/config/reslimitercfg.go b/config/reslimitercfg.go index 3ed767136..cf0ada2ac 100644 --- a/config/reslimitercfg.go +++ b/config/reslimitercfg.go @@ -25,10 +25,10 @@ import ( ) type ResourceSConfig struct { - Enabled bool - ThresholdSConns []*HaPoolConfig // Connections towards StatS - StoreInterval time.Duration // Dump regularly from cache into dataDB - IndexedFields []string + Enabled bool + ThresholdSConns []*HaPoolConfig // Connections towards StatS + StoreInterval time.Duration // Dump regularly from cache into dataDB + StringIndexedFields []string } func (rlcfg *ResourceSConfig) loadFromJsonCfg(jsnCfg *ResourceSJsonCfg) (err error) { @@ -50,10 +50,10 @@ func (rlcfg *ResourceSConfig) loadFromJsonCfg(jsnCfg *ResourceSJsonCfg) (err err return } } - if jsnCfg.Indexed_fields != nil { - rlcfg.IndexedFields = make([]string, len(*jsnCfg.Indexed_fields)) - for i, fID := range *jsnCfg.Indexed_fields { - rlcfg.IndexedFields[i] = fID + if jsnCfg.String_indexed_fields != nil { + rlcfg.StringIndexedFields = make([]string, len(*jsnCfg.String_indexed_fields)) + for i, fID := range *jsnCfg.String_indexed_fields { + rlcfg.StringIndexedFields[i] = fID } } return nil diff --git a/config/statscfg.go b/config/statscfg.go index 2863d0967..4816bd805 100644 --- a/config/statscfg.go +++ b/config/statscfg.go @@ -25,10 +25,10 @@ import ( ) type StatSCfg struct { - Enabled bool - StoreInterval time.Duration // Dump regularly from cache into dataDB - ThresholdSConns []*HaPoolConfig - IndexedFields []string + Enabled bool + StoreInterval time.Duration // Dump regularly from cache into dataDB + ThresholdSConns []*HaPoolConfig + StringIndexedFields []string } func (st *StatSCfg) loadFromJsonCfg(jsnCfg *StatServJsonCfg) (err error) { @@ -50,10 +50,10 @@ func (st *StatSCfg) loadFromJsonCfg(jsnCfg *StatServJsonCfg) (err error) { st.ThresholdSConns[idx].loadFromJsonCfg(jsnHaCfg) } } - if jsnCfg.Indexed_fields != nil { - st.IndexedFields = make([]string, len(*jsnCfg.Indexed_fields)) - for i, fID := range *jsnCfg.Indexed_fields { - st.IndexedFields[i] = fID + if jsnCfg.String_indexed_fields != nil { + st.StringIndexedFields = make([]string, len(*jsnCfg.String_indexed_fields)) + for i, fID := range *jsnCfg.String_indexed_fields { + st.StringIndexedFields[i] = fID } } return nil diff --git a/config/supplierscfg.go b/config/supplierscfg.go index 7e980b0a4..114abb8a2 100644 --- a/config/supplierscfg.go +++ b/config/supplierscfg.go @@ -20,11 +20,11 @@ package config // SupplierSCfg is the configuration of supplier service type SupplierSCfg struct { - Enabled bool - IndexedFields []string - RALsConns []*HaPoolConfig - ResourceSConns []*HaPoolConfig - StatSConns []*HaPoolConfig + Enabled bool + StringIndexedFields []string + RALsConns []*HaPoolConfig + ResourceSConns []*HaPoolConfig + StatSConns []*HaPoolConfig } func (spl *SupplierSCfg) loadFromJsonCfg(jsnCfg *SupplierSJsonCfg) (err error) { @@ -34,10 +34,10 @@ func (spl *SupplierSCfg) loadFromJsonCfg(jsnCfg *SupplierSJsonCfg) (err error) { if jsnCfg.Enabled != nil { spl.Enabled = *jsnCfg.Enabled } - if jsnCfg.Indexed_fields != nil { - spl.IndexedFields = make([]string, len(*jsnCfg.Indexed_fields)) - for i, fID := range *jsnCfg.Indexed_fields { - spl.IndexedFields[i] = fID + if jsnCfg.String_indexed_fields != nil { + spl.StringIndexedFields = make([]string, len(*jsnCfg.String_indexed_fields)) + for i, fID := range *jsnCfg.String_indexed_fields { + spl.StringIndexedFields[i] = fID } } if jsnCfg.Rals_conns != nil { diff --git a/config/thresholdscfg.go b/config/thresholdscfg.go index 257d7b9e0..9cdc928c7 100644 --- a/config/thresholdscfg.go +++ b/config/thresholdscfg.go @@ -25,9 +25,9 @@ import ( ) type ThresholdSCfg struct { - Enabled bool - StoreInterval time.Duration // Dump regularly from cache into dataDB - IndexedFields []string + Enabled bool + StoreInterval time.Duration // Dump regularly from cache into dataDB + StringIndexedFields []string } func (t *ThresholdSCfg) loadFromJsonCfg(jsnCfg *ThresholdSJsonCfg) (err error) { @@ -42,10 +42,10 @@ func (t *ThresholdSCfg) loadFromJsonCfg(jsnCfg *ThresholdSJsonCfg) (err error) { return err } } - if jsnCfg.Indexed_fields != nil { - t.IndexedFields = make([]string, len(*jsnCfg.Indexed_fields)) - for i, fID := range *jsnCfg.Indexed_fields { - t.IndexedFields[i] = fID + if jsnCfg.String_indexed_fields != nil { + t.StringIndexedFields = make([]string, len(*jsnCfg.String_indexed_fields)) + for i, fID := range *jsnCfg.String_indexed_fields { + t.StringIndexedFields[i] = fID } } return nil diff --git a/data/conf/samples/tutmongo/cgrates.json b/data/conf/samples/tutmongo/cgrates.json index e03d4f62d..ff4f89907 100644 --- a/data/conf/samples/tutmongo/cgrates.json +++ b/data/conf/samples/tutmongo/cgrates.json @@ -164,7 +164,7 @@ "attributes": { // Attribute service "enabled": true, // starts Alias service: . - "indexed_fields": [], // query indexes based on these fields for faster processing + "string_indexed_fields": [], // query indexes based on these fields for faster processing }, diff --git a/data/conf/samples/tutmysql/cgrates.json b/data/conf/samples/tutmysql/cgrates.json index d37b039f1..88d7b915b 100644 --- a/data/conf/samples/tutmysql/cgrates.json +++ b/data/conf/samples/tutmysql/cgrates.json @@ -128,7 +128,7 @@ "attributes": { // Attribute service "enabled": true, // starts Alias service: . - "indexed_fields": [], // query indexes based on these fields for faster processing + "string_indexed_fields": [], // query indexes based on these fields for faster processing }, diff --git a/engine/attributes.go b/engine/attributes.go index 201da449e..741b37ea0 100644 --- a/engine/attributes.go +++ b/engine/attributes.go @@ -27,14 +27,14 @@ import ( "github.com/cgrates/cgrates/utils" ) -func NewAttributeService(dm *DataManager, filterS *FilterS, indexedFields []string) (*AttributeService, error) { - return &AttributeService{dm: dm, filterS: filterS, indexedFields: indexedFields}, nil +func NewAttributeService(dm *DataManager, filterS *FilterS, stringIndexedFields []string) (*AttributeService, error) { + return &AttributeService{dm: dm, filterS: filterS, stringIndexedFields: stringIndexedFields}, nil } type AttributeService struct { - dm *DataManager - filterS *FilterS - indexedFields []string + dm *DataManager + filterS *FilterS + stringIndexedFields []string } // ListenAndServe will initialize the service @@ -61,7 +61,7 @@ func (alS *AttributeService) matchingAttributeProfilesForEvent(ev *utils.CGREven } attrIdxKey = utils.ConcatenatedKey(ev.Tenant, contextVal) matchingAPs := make(map[string]*AttributeProfile) - aPrflIDs, err := matchingItemIDsForEvent(ev.Event, alS.indexedFields, + aPrflIDs, err := matchingItemIDsForEvent(ev.Event, alS.stringIndexedFields, alS.dm, utils.AttributeFilterIndexes+attrIdxKey, MetaString) if err != nil { return nil, err diff --git a/engine/attributes_test.go b/engine/attributes_test.go index acd7f9c52..1ecc60836 100644 --- a/engine/attributes_test.go +++ b/engine/attributes_test.go @@ -113,9 +113,9 @@ func testPopulateAttrService(t *testing.T) { dmAtr.SetFilter(filter1) dmAtr.SetFilter(filter2) srv = AttributeService{ - dm: dmAtr, - filterS: &FilterS{dm: dmAtr}, - indexedFields: []string{"attributeprofile1", "attributeprofile2"}, + dm: dmAtr, + filterS: &FilterS{dm: dmAtr}, + stringIndexedFields: []string{"attributeprofile1", "attributeprofile2"}, } sev = &utils.CGREvent{ Tenant: "cgrates.org", diff --git a/engine/resources.go b/engine/resources.go index b763ad004..72fecb5cb 100755 --- a/engine/resources.go +++ b/engine/resources.go @@ -279,7 +279,7 @@ func (rs Resources) allocateResource(ru *ResourceUsage, dryRun bool) (alcMessage // Pas the config as a whole so we can ask access concurrently func NewResourceService(dm *DataManager, storeInterval time.Duration, - thdS rpcclient.RpcClientConnection, filterS *FilterS, indexedFields []string) (*ResourceService, error) { + thdS rpcclient.RpcClientConnection, filterS *FilterS, stringIndexedFields []string) (*ResourceService, error) { if thdS != nil && reflect.ValueOf(thdS).IsNil() { thdS = nil } @@ -293,16 +293,16 @@ func NewResourceService(dm *DataManager, storeInterval time.Duration, // ResourceService is the service handling resources type ResourceService struct { - dm *DataManager // So we can load the data in cache and index it - thdS rpcclient.RpcClientConnection // allows applying filters based on stats - filterS *FilterS - indexedFields []string // speed up query on indexes - lcEventResources map[string][]*utils.TenantID // cache recording resources for events in alocation phase - lcERMux sync.RWMutex // protects the lcEventResources - storedResources utils.StringMap // keep a record of resources which need saving, map[resID]bool - srMux sync.RWMutex // protects storedResources - storeInterval time.Duration // interval to dump data on - stopBackup chan struct{} // control storing process + dm *DataManager // So we can load the data in cache and index it + thdS rpcclient.RpcClientConnection // allows applying filters based on stats + filterS *FilterS + stringIndexedFields []string // speed up query on indexes + lcEventResources map[string][]*utils.TenantID // cache recording resources for events in alocation phase + lcERMux sync.RWMutex // protects the lcEventResources + storedResources utils.StringMap // keep a record of resources which need saving, map[resID]bool + srMux sync.RWMutex // protects storedResources + storeInterval time.Duration // interval to dump data on + stopBackup chan struct{} // control storing process } // Called to start the service @@ -434,7 +434,7 @@ func (rS *ResourceService) cachedResourcesForEvent(evUUID string) (rs Resources) // matchingResourcesForEvent returns ordered list of matching resources which are active by the time of the call func (rS *ResourceService) matchingResourcesForEvent(tenant string, ev map[string]interface{}) (rs Resources, err error) { matchingResources := make(map[string]*Resource) - rIDs, err := matchingItemIDsForEvent(ev, rS.indexedFields, rS.dm, utils.ResourceFilterIndexes+tenant, MetaString) + rIDs, err := matchingItemIDsForEvent(ev, rS.stringIndexedFields, rS.dm, utils.ResourceFilterIndexes+tenant, MetaString) if err != nil { return nil, err } diff --git a/engine/resources_test.go b/engine/resources_test.go index a52f19f9c..19a208c65 100644 --- a/engine/resources_test.go +++ b/engine/resources_test.go @@ -265,9 +265,9 @@ func TestV1AuthorizeResourceMissingStruct(t *testing.T) { dmresmiss := NewDataManager(data) rserv := &ResourceService{ - dm: dmresmiss, - filterS: &FilterS{dm: dmresmiss}, - indexedFields: []string{}, // speed up query on indexes + dm: dmresmiss, + filterS: &FilterS{dm: dmresmiss}, + stringIndexedFields: []string{}, // speed up query on indexes } var reply *string argsMissingTenant := utils.ArgRSv1ResourceUsage{ diff --git a/engine/stats.go b/engine/stats.go index 9c13768bd..f47e71ca0 100644 --- a/engine/stats.go +++ b/engine/stats.go @@ -34,30 +34,30 @@ import ( // NewStatService initializes a StatService func NewStatService(dm *DataManager, storeInterval time.Duration, - thdS rpcclient.RpcClientConnection, filterS *FilterS, indexedFields []string) (ss *StatService, err error) { + thdS rpcclient.RpcClientConnection, filterS *FilterS, stringIndexedFields []string) (ss *StatService, err error) { if thdS != nil && reflect.ValueOf(thdS).IsNil() { // fix nil value in interface thdS = nil } return &StatService{ - dm: dm, - storeInterval: storeInterval, - thdS: thdS, - filterS: filterS, - indexedFields: indexedFields, - storedStatQueues: make(utils.StringMap), - stopBackup: make(chan struct{})}, nil + dm: dm, + storeInterval: storeInterval, + thdS: thdS, + filterS: filterS, + stringIndexedFields: stringIndexedFields, + storedStatQueues: make(utils.StringMap), + stopBackup: make(chan struct{})}, nil } // StatService builds stats for events type StatService struct { - dm *DataManager - storeInterval time.Duration - thdS rpcclient.RpcClientConnection // rpc connection towards ThresholdS - filterS *FilterS - indexedFields []string - stopBackup chan struct{} - storedStatQueues utils.StringMap // keep a record of stats which need saving, map[statsTenantID]bool - ssqMux sync.RWMutex // protects storedStatQueues + dm *DataManager + storeInterval time.Duration + thdS rpcclient.RpcClientConnection // rpc connection towards ThresholdS + filterS *FilterS + stringIndexedFields []string + stopBackup chan struct{} + storedStatQueues utils.StringMap // keep a record of stats which need saving, map[statsTenantID]bool + ssqMux sync.RWMutex // protects storedStatQueues } // ListenAndServe loops keeps the service alive @@ -141,7 +141,7 @@ func (sS *StatService) StoreStatQueue(sq *StatQueue) (err error) { // matchingStatQueuesForEvent returns ordered list of matching resources which are active by the time of the call func (sS *StatService) matchingStatQueuesForEvent(ev *utils.CGREvent) (sqs StatQueues, err error) { matchingSQs := make(map[string]*StatQueue) - sqIDs, err := matchingItemIDsForEvent(ev.Event, sS.indexedFields, sS.dm, utils.StatFilterIndexes+ev.Tenant, MetaString) + sqIDs, err := matchingItemIDsForEvent(ev.Event, sS.stringIndexedFields, sS.dm, utils.StatFilterIndexes+ev.Tenant, MetaString) if err != nil { return nil, err } diff --git a/engine/suppliers.go b/engine/suppliers.go index 010d4dcec..f2c01f67c 100644 --- a/engine/suppliers.go +++ b/engine/suppliers.go @@ -70,15 +70,15 @@ func (lps SupplierProfiles) Sort() { // NewLCRService initializes a LCRService func NewSupplierService(dm *DataManager, timezone string, - filterS *FilterS, indexedFields []string, resourceS, + filterS *FilterS, stringIndexedFields []string, resourceS, statS rpcclient.RpcClientConnection) (spS *SupplierService, err error) { spS = &SupplierService{ - dm: dm, - timezone: timezone, - filterS: filterS, - resourceS: resourceS, - statS: statS, - indexedFields: indexedFields} + dm: dm, + timezone: timezone, + filterS: filterS, + resourceS: resourceS, + statS: statS, + stringIndexedFields: stringIndexedFields} if spS.sorter, err = NewSupplierSortDispatcher(spS); err != nil { return nil, err } @@ -87,10 +87,10 @@ func NewSupplierService(dm *DataManager, timezone string, // SupplierService is the service computing Supplier queries type SupplierService struct { - dm *DataManager - timezone string - filterS *FilterS - indexedFields []string + dm *DataManager + timezone string + filterS *FilterS + stringIndexedFields []string resourceS, statS rpcclient.RpcClientConnection sorter SupplierSortDispatcher @@ -114,7 +114,7 @@ func (spS *SupplierService) Shutdown() error { // matchingSupplierProfilesForEvent returns ordered list of matching resources which are active by the time of the call func (spS *SupplierService) matchingSupplierProfilesForEvent(ev *utils.CGREvent) (sPrfls SupplierProfiles, err error) { matchingLPs := make(map[string]*SupplierProfile) - sPrflIDs, err := matchingItemIDsForEvent(ev.Event, spS.indexedFields, + sPrflIDs, err := matchingItemIDsForEvent(ev.Event, spS.stringIndexedFields, spS.dm, utils.SupplierFilterIndexes+ev.Tenant, MetaString) if err != nil { return nil, err diff --git a/engine/suppliers_test.go b/engine/suppliers_test.go index 8c0d3ec02..aaffb6b1f 100644 --- a/engine/suppliers_test.go +++ b/engine/suppliers_test.go @@ -187,10 +187,10 @@ func TestSuppliersPopulateSupplierService(t *testing.T) { ssd := make(map[string]SuppliersSorter) ssd[utils.MetaWeight] = NewWeightSorter() splserv = SupplierService{ - dm: dmspl, - filterS: &FilterS{dm: dmspl}, - indexedFields: []string{"supplierprofile1", "supplierprofile2"}, - sorter: ssd, + dm: dmspl, + filterS: &FilterS{dm: dmspl}, + stringIndexedFields: []string{"supplierprofile1", "supplierprofile2"}, + sorter: ssd, } ssd[utils.MetaLeastCost] = NewLeastCostSorter(&splserv) argPagEv = &ArgsGetSuppliers{ diff --git a/engine/thresholds.go b/engine/thresholds.go index df9b4cdbf..96c2bbd51 100644 --- a/engine/thresholds.go +++ b/engine/thresholds.go @@ -112,25 +112,25 @@ func (ts Thresholds) Sort() { sort.Slice(ts, func(i, j int) bool { return ts[i].tPrfl.Weight > ts[j].tPrfl.Weight }) } -func NewThresholdService(dm *DataManager, indexedFields []string, storeInterval time.Duration, +func NewThresholdService(dm *DataManager, stringIndexedFields []string, storeInterval time.Duration, filterS *FilterS) (tS *ThresholdService, err error) { return &ThresholdService{dm: dm, - indexedFields: indexedFields, - storeInterval: storeInterval, - filterS: filterS, - stopBackup: make(chan struct{}), - storedTdIDs: make(utils.StringMap)}, nil + stringIndexedFields: stringIndexedFields, + storeInterval: storeInterval, + filterS: filterS, + stopBackup: make(chan struct{}), + storedTdIDs: make(utils.StringMap)}, nil } // ThresholdService manages Threshold execution and storing them to dataDB type ThresholdService struct { - dm *DataManager - indexedFields []string // fields considered when searching for matching thresholds - storeInterval time.Duration - filterS *FilterS - stopBackup chan struct{} - storedTdIDs utils.StringMap // keep a record of stats which need saving, map[statsTenantID]bool - stMux sync.RWMutex // protects storedTdIDs + dm *DataManager + stringIndexedFields []string // fields considered when searching for matching thresholds + storeInterval time.Duration + filterS *FilterS + stopBackup chan struct{} + storedTdIDs utils.StringMap // keep a record of stats which need saving, map[statsTenantID]bool + stMux sync.RWMutex // protects storedTdIDs } // Called to start the service @@ -219,7 +219,7 @@ func (tS *ThresholdService) matchingThresholdsForEvent(args *ArgsProcessEvent) ( if len(args.ThresholdIDs) != 0 { tIDs = args.ThresholdIDs } else { - tIDsMap, err := matchingItemIDsForEvent(args.Event, tS.indexedFields, tS.dm, utils.ThresholdFilterIndexes+args.Tenant, MetaString) + tIDsMap, err := matchingItemIDsForEvent(args.Event, tS.stringIndexedFields, tS.dm, utils.ThresholdFilterIndexes+args.Tenant, MetaString) if err != nil { return nil, err }