diff --git a/config/aliascfg.go b/config/aliascfg.go index d8592aa45..4ee114b12 100644 --- a/config/aliascfg.go +++ b/config/aliascfg.go @@ -20,8 +20,9 @@ package config // SupplierSCfg is the configuration of supplier service type AttributeSCfg struct { - Enabled bool - StringIndexedFields []string + Enabled bool + StringIndexedFields []string + StringPrefixIndexedFields []string } func (alS *AttributeSCfg) loadFromJsonCfg(jsnCfg *AttributeSJsonCfg) (err error) { @@ -37,5 +38,11 @@ func (alS *AttributeSCfg) loadFromJsonCfg(jsnCfg *AttributeSJsonCfg) (err error) alS.StringIndexedFields[i] = fID } } + if jsnCfg.Stringprefix_indexed_fields != nil { + alS.StringPrefixIndexedFields = make([]string, len(*jsnCfg.Stringprefix_indexed_fields)) + for i, fID := range *jsnCfg.Stringprefix_indexed_fields { + alS.StringPrefixIndexedFields[i] = fID + } + } return } diff --git a/config/config_defaults.go b/config/config_defaults.go index 49fe6ea13..092766743 100755 --- a/config/config_defaults.go +++ b/config/config_defaults.go @@ -428,43 +428,48 @@ const CGRATES_CFG_JSON = ` }, -"attributes": { // Attribute service - "enabled": false, // starts attribute service: . +"attributes": { // Attribute service + "enabled": false, // starts attribute service: . "string_indexed_fields": [], // query indexes based on these fields for faster processing + "stringprefix_indexed_fields": [], // query indexes based on these fields for faster processing }, -"resources": { // Resource service (*new) - "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> +"resources": { // Resource service (*new) + "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> "string_indexed_fields": [], // query indexes based on these fields for faster processing + "stringprefix_indexed_fields": [], // query indexes based on these fields for faster processing }, -"stats": { // Stat service (*new) - "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> +"stats": { // Stat service (*new) + "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> "string_indexed_fields": [], // query indexes based on these fields for faster processing + "stringprefix_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> +"thresholds": { // Threshold service (*new) + "enabled": false, // starts ThresholdS service: . + "store_interval": "", // dump cache regularly to dataDB, 0 - dump at start/shutdown: <""|$dur> "string_indexed_fields": [], // query indexes based on these fields for faster processing + "stringprefix_indexed_fields": [], // query indexes based on these fields for faster processing }, -"suppliers": { // Supplier service (*new) - "enabled": false, // starts SupplierS service: . +"suppliers": { // Supplier service (*new) + "enabled": false, // starts SupplierS service: . "string_indexed_fields": [], // query indexes based on these fields for faster processing + "stringprefix_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> + {"address": "*internal"}, // address where to reach the RALs for cost/accounting <*internal> ], - "resources_conns": [], // address where to reach the Resource service, empty to disable functionality: <""|*internal|x.y.z.y:1234> - "stats_conns": [], // address where to reach the Stat service, empty to disable stats functionality: <""|*internal|x.y.z.y:1234> + "resources_conns": [], // address where to reach the Resource service, empty to disable functionality: <""|*internal|x.y.z.y:1234> + "stats_conns": [], // address where to reach the Stat service, empty to disable stats functionality: <""|*internal|x.y.z.y:1234> }, diff --git a/config/config_json_test.go b/config/config_json_test.go index 24ed03b1f..ea9963c27 100755 --- a/config/config_json_test.go +++ b/config/config_json_test.go @@ -716,8 +716,9 @@ func TestDfUserServJsonCfg(t *testing.T) { func TestDfAttributeServJsonCfg(t *testing.T) { eCfg := &AttributeSJsonCfg{ - Enabled: utils.BoolPointer(false), - String_indexed_fields: utils.StringSlicePointer([]string{}), + Enabled: utils.BoolPointer(false), + String_indexed_fields: utils.StringSlicePointer([]string{}), + Stringprefix_indexed_fields: utils.StringSlicePointer([]string{}), } if cfg, err := dfCgrJsonCfg.AttributeServJsonCfg(); err != nil { t.Error(err) @@ -739,10 +740,11 @@ func TestDfFilterSJsonCfg(t *testing.T) { func TestDfResourceLimiterSJsonCfg(t *testing.T) { eCfg := &ResourceSJsonCfg{ - Enabled: utils.BoolPointer(false), - Thresholds_conns: &[]*HaPoolJsonCfg{}, - Store_interval: utils.StringPointer(""), - String_indexed_fields: utils.StringSlicePointer([]string{}), + Enabled: utils.BoolPointer(false), + Thresholds_conns: &[]*HaPoolJsonCfg{}, + Store_interval: utils.StringPointer(""), + String_indexed_fields: utils.StringSlicePointer([]string{}), + Stringprefix_indexed_fields: utils.StringSlicePointer([]string{}), } if cfg, err := dfCgrJsonCfg.ResourceSJsonCfg(); err != nil { t.Error(err) @@ -753,10 +755,11 @@ func TestDfResourceLimiterSJsonCfg(t *testing.T) { func TestDfStatServiceJsonCfg(t *testing.T) { eCfg := &StatServJsonCfg{ - Enabled: utils.BoolPointer(false), - Store_interval: utils.StringPointer(""), - Thresholds_conns: &[]*HaPoolJsonCfg{}, - String_indexed_fields: utils.StringSlicePointer([]string{}), + Enabled: utils.BoolPointer(false), + Store_interval: utils.StringPointer(""), + Thresholds_conns: &[]*HaPoolJsonCfg{}, + String_indexed_fields: utils.StringSlicePointer([]string{}), + Stringprefix_indexed_fields: utils.StringSlicePointer([]string{}), } if cfg, err := dfCgrJsonCfg.StatSJsonCfg(); err != nil { t.Error(err) @@ -767,21 +770,23 @@ func TestDfStatServiceJsonCfg(t *testing.T) { func TestDfThresholdSJsonCfg(t *testing.T) { eCfg := &ThresholdSJsonCfg{ - Enabled: utils.BoolPointer(false), - Store_interval: utils.StringPointer(""), - String_indexed_fields: utils.StringSlicePointer([]string{}), + Enabled: utils.BoolPointer(false), + Store_interval: utils.StringPointer(""), + String_indexed_fields: utils.StringSlicePointer([]string{}), + Stringprefix_indexed_fields: utils.StringSlicePointer([]string{}), } if cfg, err := dfCgrJsonCfg.ThresholdSJsonCfg(); err != nil { t.Error(err) } else if !reflect.DeepEqual(eCfg, cfg) { - t.Errorf("expecting: %+v, received: %+v", eCfg, cfg) + t.Errorf("expecting: %+v, received: %+v", utils.ToJSON(eCfg), utils.ToJSON(cfg)) } } func TestDfSupplierSJsonCfg(t *testing.T) { eCfg := &SupplierSJsonCfg{ - Enabled: utils.BoolPointer(false), - String_indexed_fields: utils.StringSlicePointer([]string{}), + Enabled: utils.BoolPointer(false), + String_indexed_fields: utils.StringSlicePointer([]string{}), + Stringprefix_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 a07174eaf..ee85d9860 100755 --- a/config/config_test.go +++ b/config/config_test.go @@ -658,8 +658,9 @@ func TestCgrCfgJSONDefaultFiltersCfg(t *testing.T) { func TestCgrCfgJSONDefaultSAttributeSCfg(t *testing.T) { eAliasSCfg := &AttributeSCfg{ - Enabled: false, - StringIndexedFields: []string{}, + Enabled: false, + StringIndexedFields: []string{}, + StringPrefixIndexedFields: []string{}, } if !reflect.DeepEqual(eAliasSCfg, cgrCfg.attributeSCfg) { t.Errorf("received: %+v, expecting: %+v", eAliasSCfg, cgrCfg.attributeSCfg) @@ -668,10 +669,11 @@ func TestCgrCfgJSONDefaultSAttributeSCfg(t *testing.T) { func TestCgrCfgJSONDefaultsResLimCfg(t *testing.T) { eResLiCfg := &ResourceSConfig{ - Enabled: false, - ThresholdSConns: []*HaPoolConfig{}, - StoreInterval: 0, - StringIndexedFields: []string{}, + Enabled: false, + ThresholdSConns: []*HaPoolConfig{}, + StoreInterval: 0, + StringIndexedFields: []string{}, + StringPrefixIndexedFields: []string{}, } if !reflect.DeepEqual(cgrCfg.resourceSCfg, eResLiCfg) { t.Errorf("expecting: %s, received: %s", utils.ToJSON(eResLiCfg), utils.ToJSON(cgrCfg.resourceSCfg)) @@ -681,10 +683,11 @@ func TestCgrCfgJSONDefaultsResLimCfg(t *testing.T) { func TestCgrCfgJSONDefaultStatsCfg(t *testing.T) { eStatsCfg := &StatSCfg{ - Enabled: false, - StoreInterval: 0, - ThresholdSConns: []*HaPoolConfig{}, - StringIndexedFields: []string{}, + Enabled: false, + StoreInterval: 0, + ThresholdSConns: []*HaPoolConfig{}, + StringIndexedFields: []string{}, + StringPrefixIndexedFields: []string{}, } if !reflect.DeepEqual(cgrCfg.statsCfg, eStatsCfg) { t.Errorf("received: %+v, expecting: %+v", cgrCfg.statsCfg, eStatsCfg) @@ -693,9 +696,10 @@ func TestCgrCfgJSONDefaultStatsCfg(t *testing.T) { func TestCgrCfgJSONDefaultThresholdSCfg(t *testing.T) { eThresholdSCfg := &ThresholdSCfg{ - Enabled: false, - StoreInterval: 0, - StringIndexedFields: []string{}, + Enabled: false, + StoreInterval: 0, + StringIndexedFields: []string{}, + StringPrefixIndexedFields: []string{}, } if !reflect.DeepEqual(eThresholdSCfg, cgrCfg.thresholdSCfg) { t.Errorf("received: %+v, expecting: %+v", eThresholdSCfg, cgrCfg.thresholdSCfg) @@ -704,8 +708,10 @@ func TestCgrCfgJSONDefaultThresholdSCfg(t *testing.T) { func TestCgrCfgJSONDefaultSupplierSCfg(t *testing.T) { eSupplSCfg := &SupplierSCfg{ - Enabled: false, - StringIndexedFields: []string{}, + Enabled: false, + StringIndexedFields: []string{}, + StringPrefixIndexedFields: []string{}, + RALsConns: []*HaPoolConfig{ &HaPoolConfig{Address: "*internal"}, }, diff --git a/config/libconfig_json.go b/config/libconfig_json.go index 839a66294..003c4496f 100755 --- a/config/libconfig_json.go +++ b/config/libconfig_json.go @@ -389,40 +389,45 @@ type UserServJsonCfg struct { // Attribute service config section type AttributeSJsonCfg struct { - Enabled *bool - String_indexed_fields *[]string + Enabled *bool + String_indexed_fields *[]string + Stringprefix_indexed_fields *[]string } // ResourceLimiter service config section type ResourceSJsonCfg struct { - Enabled *bool - Thresholds_conns *[]*HaPoolJsonCfg - Store_interval *string - String_indexed_fields *[]string + Enabled *bool + Thresholds_conns *[]*HaPoolJsonCfg + Store_interval *string + String_indexed_fields *[]string + Stringprefix_indexed_fields *[]string } // Stat service config section type StatServJsonCfg struct { - Enabled *bool - Store_interval *string - Thresholds_conns *[]*HaPoolJsonCfg - String_indexed_fields *[]string + Enabled *bool + Store_interval *string + Thresholds_conns *[]*HaPoolJsonCfg + String_indexed_fields *[]string + Stringprefix_indexed_fields *[]string } // Threshold service config section type ThresholdSJsonCfg struct { - Enabled *bool - Store_interval *string - String_indexed_fields *[]string + Enabled *bool + Store_interval *string + String_indexed_fields *[]string + Stringprefix_indexed_fields *[]string } // Supplier service config section type SupplierSJsonCfg struct { - Enabled *bool - String_indexed_fields *[]string - Rals_conns *[]*HaPoolJsonCfg - Resources_conns *[]*HaPoolJsonCfg - Stats_conns *[]*HaPoolJsonCfg + Enabled *bool + String_indexed_fields *[]string + Stringprefix_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 cf0ada2ac..77f237aef 100644 --- a/config/reslimitercfg.go +++ b/config/reslimitercfg.go @@ -25,10 +25,11 @@ import ( ) type ResourceSConfig struct { - Enabled bool - ThresholdSConns []*HaPoolConfig // Connections towards StatS - StoreInterval time.Duration // Dump regularly from cache into dataDB - StringIndexedFields []string + Enabled bool + ThresholdSConns []*HaPoolConfig // Connections towards StatS + StoreInterval time.Duration // Dump regularly from cache into dataDB + StringIndexedFields []string + StringPrefixIndexedFields []string } func (rlcfg *ResourceSConfig) loadFromJsonCfg(jsnCfg *ResourceSJsonCfg) (err error) { @@ -56,5 +57,11 @@ func (rlcfg *ResourceSConfig) loadFromJsonCfg(jsnCfg *ResourceSJsonCfg) (err err rlcfg.StringIndexedFields[i] = fID } } + if jsnCfg.Stringprefix_indexed_fields != nil { + rlcfg.StringPrefixIndexedFields = make([]string, len(*jsnCfg.Stringprefix_indexed_fields)) + for i, fID := range *jsnCfg.Stringprefix_indexed_fields { + rlcfg.StringPrefixIndexedFields[i] = fID + } + } return nil } diff --git a/config/statscfg.go b/config/statscfg.go index 4816bd805..2db69af38 100644 --- a/config/statscfg.go +++ b/config/statscfg.go @@ -25,10 +25,11 @@ import ( ) type StatSCfg struct { - Enabled bool - StoreInterval time.Duration // Dump regularly from cache into dataDB - ThresholdSConns []*HaPoolConfig - StringIndexedFields []string + Enabled bool + StoreInterval time.Duration // Dump regularly from cache into dataDB + ThresholdSConns []*HaPoolConfig + StringIndexedFields []string + StringPrefixIndexedFields []string } func (st *StatSCfg) loadFromJsonCfg(jsnCfg *StatServJsonCfg) (err error) { @@ -56,5 +57,11 @@ func (st *StatSCfg) loadFromJsonCfg(jsnCfg *StatServJsonCfg) (err error) { st.StringIndexedFields[i] = fID } } + if jsnCfg.Stringprefix_indexed_fields != nil { + st.StringPrefixIndexedFields = make([]string, len(*jsnCfg.Stringprefix_indexed_fields)) + for i, fID := range *jsnCfg.Stringprefix_indexed_fields { + st.StringPrefixIndexedFields[i] = fID + } + } return nil } diff --git a/config/supplierscfg.go b/config/supplierscfg.go index 114abb8a2..aa51f7a57 100644 --- a/config/supplierscfg.go +++ b/config/supplierscfg.go @@ -20,11 +20,12 @@ package config // SupplierSCfg is the configuration of supplier service type SupplierSCfg struct { - Enabled bool - StringIndexedFields []string - RALsConns []*HaPoolConfig - ResourceSConns []*HaPoolConfig - StatSConns []*HaPoolConfig + Enabled bool + StringIndexedFields []string + StringPrefixIndexedFields []string + RALsConns []*HaPoolConfig + ResourceSConns []*HaPoolConfig + StatSConns []*HaPoolConfig } func (spl *SupplierSCfg) loadFromJsonCfg(jsnCfg *SupplierSJsonCfg) (err error) { @@ -40,6 +41,12 @@ func (spl *SupplierSCfg) loadFromJsonCfg(jsnCfg *SupplierSJsonCfg) (err error) { spl.StringIndexedFields[i] = fID } } + if jsnCfg.Stringprefix_indexed_fields != nil { + spl.StringPrefixIndexedFields = make([]string, len(*jsnCfg.Stringprefix_indexed_fields)) + for i, fID := range *jsnCfg.Stringprefix_indexed_fields { + spl.StringPrefixIndexedFields[i] = fID + } + } if jsnCfg.Rals_conns != nil { spl.RALsConns = make([]*HaPoolConfig, len(*jsnCfg.Rals_conns)) for idx, jsnHaCfg := range *jsnCfg.Rals_conns { diff --git a/config/thresholdscfg.go b/config/thresholdscfg.go index 9cdc928c7..7ea13671c 100644 --- a/config/thresholdscfg.go +++ b/config/thresholdscfg.go @@ -25,9 +25,10 @@ import ( ) type ThresholdSCfg struct { - Enabled bool - StoreInterval time.Duration // Dump regularly from cache into dataDB - StringIndexedFields []string + Enabled bool + StoreInterval time.Duration // Dump regularly from cache into dataDB + StringIndexedFields []string + StringPrefixIndexedFields []string } func (t *ThresholdSCfg) loadFromJsonCfg(jsnCfg *ThresholdSJsonCfg) (err error) { @@ -48,5 +49,11 @@ func (t *ThresholdSCfg) loadFromJsonCfg(jsnCfg *ThresholdSJsonCfg) (err error) { t.StringIndexedFields[i] = fID } } + if jsnCfg.Stringprefix_indexed_fields != nil { + t.StringPrefixIndexedFields = make([]string, len(*jsnCfg.Stringprefix_indexed_fields)) + for i, fID := range *jsnCfg.Stringprefix_indexed_fields { + t.StringPrefixIndexedFields[i] = fID + } + } return nil } diff --git a/data/conf/samples/tutmongo/cgrates.json b/data/conf/samples/tutmongo/cgrates.json index ff4f89907..7d371256f 100644 --- a/data/conf/samples/tutmongo/cgrates.json +++ b/data/conf/samples/tutmongo/cgrates.json @@ -165,6 +165,7 @@ "attributes": { // Attribute service "enabled": true, // starts Alias service: . "string_indexed_fields": [], // query indexes based on these fields for faster processing + "stringprefix_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 88d7b915b..de289913e 100644 --- a/data/conf/samples/tutmysql/cgrates.json +++ b/data/conf/samples/tutmysql/cgrates.json @@ -126,9 +126,10 @@ }, -"attributes": { // Attribute service - "enabled": true, // starts Alias service: . +"attributes": { // Attribute service + "enabled": true, // starts Alias service: . "string_indexed_fields": [], // query indexes based on these fields for faster processing + "stringprefix_indexed_fields": [], // query indexes based on these fields for faster processing },