From 704aa541c21a2911e6065ffa0f1fa704ebfb4d3d Mon Sep 17 00:00:00 2001 From: TeoV Date: Mon, 15 Jun 2020 18:02:33 +0300 Subject: [PATCH] Update config for rateS --- config/config_defaults.go | 4 +++ config/config_json_test.go | 14 ++++++--- config/config_test.go | 14 ++++++--- config/libconfig_json.go | 14 ++++++--- config/ratescfg.go | 63 ++++++++++++++++++++++++++++++++------ rates/rates.go | 14 ++++----- utils/consts.go | 6 ++++ 7 files changed, 97 insertions(+), 32 deletions(-) diff --git a/config/config_defaults.go b/config/config_defaults.go index 6079c823f..0c2f0f452 100755 --- a/config/config_defaults.go +++ b/config/config_defaults.go @@ -926,6 +926,10 @@ const CGRATES_CFG_JSON = ` //"string_indexed_fields": [], // query indexes based on these fields for faster processing "prefix_indexed_fields": [], // query indexes based on these fields for faster processing "nested_fields": false, // determines which field is checked when matching indexed filters(true: all; false: only the one on the first level) + "rate_indexed_selects": true, // enable profile matching exclusively on indexes + //"rate_string_indexed_fields": [], // query indexes based on these fields for faster processing + "rate_prefix_indexed_fields": [], // query indexes based on these fields for faster processing + "rate_nested_fields": false, // determines which field is checked when matching indexed filters(true: all; false: only the one on the first level) }, "sip_agent": { // SIP Agents, only used for redirections diff --git a/config/config_json_test.go b/config/config_json_test.go index 96cd0c477..adb938652 100755 --- a/config/config_json_test.go +++ b/config/config_json_test.go @@ -2035,11 +2035,15 @@ func TestDfEventExporterCfg(t *testing.T) { func TestDfRateSJsonCfg(t *testing.T) { eCfg := &RateSJsonCfg{ - Enabled: utils.BoolPointer(false), - Indexed_selects: utils.BoolPointer(true), - String_indexed_fields: nil, - Prefix_indexed_fields: &[]string{}, - Nested_fields: utils.BoolPointer(false), + Enabled: utils.BoolPointer(false), + Indexed_selects: utils.BoolPointer(true), + String_indexed_fields: nil, + Prefix_indexed_fields: &[]string{}, + Nested_fields: utils.BoolPointer(false), + Rate_indexed_selects: utils.BoolPointer(true), + Rate_string_indexed_fields: nil, + Rate_prefix_indexed_fields: &[]string{}, + Rate_nested_fields: utils.BoolPointer(false), } if cfg, err := dfCgrJsonCfg.RateCfgJson(); err != nil { t.Error(err) diff --git a/config/config_test.go b/config/config_test.go index 2ced7b726..caf1c06bf 100755 --- a/config/config_test.go +++ b/config/config_test.go @@ -1889,11 +1889,15 @@ func TestCgrCfgJSONDefaultApierCfg(t *testing.T) { func TestCgrCfgJSONDefaultRateCfg(t *testing.T) { eCfg := &RateSCfg{ - Enabled: false, - IndexedSelects: true, - StringIndexedFields: nil, - PrefixIndexedFields: &[]string{}, - NestedFields: false, + Enabled: false, + IndexedSelects: true, + StringIndexedFields: nil, + PrefixIndexedFields: &[]string{}, + NestedFields: false, + RateIndexedSelects: true, + RateStringIndexedFields: nil, + RatePrefixIndexedFields: &[]string{}, + RateNestedFields: false, } if !reflect.DeepEqual(cgrCfg.rateSCfg, eCfg) { t.Errorf("received: %+v, expecting: %+v", cgrCfg.rateSCfg, eCfg) diff --git a/config/libconfig_json.go b/config/libconfig_json.go index d47c5c759..b4051f6b6 100755 --- a/config/libconfig_json.go +++ b/config/libconfig_json.go @@ -608,11 +608,15 @@ type STIRJsonCfg struct { } type RateSJsonCfg struct { - Enabled *bool - Indexed_selects *bool - String_indexed_fields *[]string - Prefix_indexed_fields *[]string - Nested_fields *bool // applies when indexed fields is not defined + Enabled *bool + Indexed_selects *bool + String_indexed_fields *[]string + Prefix_indexed_fields *[]string + Nested_fields *bool // applies when indexed fields is not defined + Rate_indexed_selects *bool + Rate_string_indexed_fields *[]string + Rate_prefix_indexed_fields *[]string + Rate_nested_fields *bool // applies when indexed fields is not defined } // SIPAgentJsonCfg diff --git a/config/ratescfg.go b/config/ratescfg.go index cfa673d67..bfe0433fa 100644 --- a/config/ratescfg.go +++ b/config/ratescfg.go @@ -23,11 +23,15 @@ import ( ) type RateSCfg struct { - Enabled bool - IndexedSelects bool - StringIndexedFields *[]string - PrefixIndexedFields *[]string - NestedFields bool + Enabled bool + IndexedSelects bool + StringIndexedFields *[]string + PrefixIndexedFields *[]string + NestedFields bool + RateIndexedSelects bool + RateStringIndexedFields *[]string + RatePrefixIndexedFields *[]string + RateNestedFields bool } func (rCfg *RateSCfg) loadFromJsonCfg(jsnCfg *RateSJsonCfg) (err error) { @@ -57,6 +61,27 @@ func (rCfg *RateSCfg) loadFromJsonCfg(jsnCfg *RateSJsonCfg) (err error) { if jsnCfg.Nested_fields != nil { rCfg.NestedFields = *jsnCfg.Nested_fields } + + if jsnCfg.Rate_indexed_selects != nil { + rCfg.RateIndexedSelects = *jsnCfg.Rate_indexed_selects + } + if jsnCfg.Rate_string_indexed_fields != nil { + sif := make([]string, len(*jsnCfg.Rate_string_indexed_fields)) + for i, fID := range *jsnCfg.Rate_string_indexed_fields { + sif[i] = fID + } + rCfg.RateStringIndexedFields = &sif + } + if jsnCfg.Rate_prefix_indexed_fields != nil { + pif := make([]string, len(*jsnCfg.Rate_prefix_indexed_fields)) + for i, fID := range *jsnCfg.Rate_prefix_indexed_fields { + pif[i] = fID + } + rCfg.RatePrefixIndexedFields = &pif + } + if jsnCfg.Rate_nested_fields != nil { + rCfg.RateNestedFields = *jsnCfg.Rate_nested_fields + } return } @@ -75,11 +100,29 @@ func (rCfg *RateSCfg) AsMapInterface() map[string]interface{} { prefixIndexedFields[i] = item } } + rateStringIndexedFields := []string{} + if rCfg.RateStringIndexedFields != nil { + rateStringIndexedFields = make([]string, len(*rCfg.RateStringIndexedFields)) + for i, item := range *rCfg.RateStringIndexedFields { + rateStringIndexedFields[i] = item + } + } + ratePrefixIndexedFields := []string{} + if rCfg.RatePrefixIndexedFields != nil { + ratePrefixIndexedFields = make([]string, len(*rCfg.RatePrefixIndexedFields)) + for i, item := range *rCfg.RatePrefixIndexedFields { + ratePrefixIndexedFields[i] = item + } + } return map[string]interface{}{ - utils.EnabledCfg: rCfg.Enabled, - utils.IndexedSelectsCfg: rCfg.IndexedSelects, - utils.StringIndexedFieldsCfg: stringIndexedFields, - utils.PrefixIndexedFieldsCfg: prefixIndexedFields, - utils.NestedFieldsCfg: rCfg.NestedFields, + utils.EnabledCfg: rCfg.Enabled, + utils.IndexedSelectsCfg: rCfg.IndexedSelects, + utils.StringIndexedFieldsCfg: stringIndexedFields, + utils.PrefixIndexedFieldsCfg: prefixIndexedFields, + utils.NestedFieldsCfg: rCfg.NestedFields, + utils.RateIndexedSelectsCfg: rCfg.RateIndexedSelects, + utils.RateStringIndexedFieldsCfg: rateStringIndexedFields, + utils.RatePrefixIndexedFieldsCfg: ratePrefixIndexedFields, + utils.RateNestedFieldsCfg: rCfg.RateNestedFields, } } diff --git a/rates/rates.go b/rates/rates.go index 0398409a7..91501576f 100644 --- a/rates/rates.go +++ b/rates/rates.go @@ -83,8 +83,8 @@ func (rS *RateS) matchingRateProfileForEvent(args *ArgsCostForEvent) (rtPfl *eng rS.dm, utils.CacheRateProfilesFilterIndexes, args.CGREvent.Tenant, - rS.cfg.RouteSCfg().IndexedSelects, - rS.cfg.RouteSCfg().NestedFields, + rS.cfg.RateSCfg().IndexedSelects, + rS.cfg.RateSCfg().NestedFields, ); err != nil { return } @@ -129,13 +129,13 @@ func (rS *RateS) matchingRatesForEvent(rtPfl *engine.RateProfile, cgrEv *utils.C var rtIDs utils.StringMap if rtIDs, err = engine.MatchingItemIDsForEvent( cgrEv.Event, - rS.cfg.RateSCfg().StringIndexedFields, - rS.cfg.RateSCfg().PrefixIndexedFields, + rS.cfg.RateSCfg().RateStringIndexedFields, + rS.cfg.RateSCfg().RatePrefixIndexedFields, rS.dm, - utils.CacheRateProfilesFilterIndexes, + utils.CacheRateFilterIndexes, cgrEv.Tenant, - rS.cfg.RouteSCfg().IndexedSelects, - rS.cfg.RouteSCfg().NestedFields, + rS.cfg.RateSCfg().RateIndexedSelects, + rS.cfg.RateSCfg().RateNestedFields, ); err != nil { return } diff --git a/utils/consts.go b/utils/consts.go index 43300107b..a5eb4a3d7 100755 --- a/utils/consts.go +++ b/utils/consts.go @@ -1971,6 +1971,12 @@ const ( TransportCfg = "transport" StrategyCfg = "strategy" Dynaprepaid_actionplansCfg = "dynaprepaid_actionplans" + + //RateSCfg + RateIndexedSelectsCfg = "rate_indexed_selects" + RateNestedFieldsCfg = "rate_nested_fields" + RateStringIndexedFieldsCfg = "rate_string_indexed_fields" + RatePrefixIndexedFieldsCfg = "rate_prefix_indexed_fields" ) // FC Template