From 7316ec43dade692e2290e058afc30acaf8bd057a Mon Sep 17 00:00:00 2001 From: DanB Date: Fri, 27 Oct 2017 13:59:58 +0200 Subject: [PATCH] Config indexed_fields for stats and resources --- config/config_defaults.go | 2 ++ config/config_json_test.go | 2 ++ config/config_test.go | 2 ++ config/libconfig_json.go | 2 ++ config/reslimitercfg.go | 7 +++++++ config/statscfg.go | 7 +++++++ 6 files changed, 22 insertions(+) diff --git a/config/config_defaults.go b/config/config_defaults.go index ce276e536..7e9770909 100755 --- a/config/config_defaults.go +++ b/config/config_defaults.go @@ -423,6 +423,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 }, @@ -430,6 +431,7 @@ 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 }, diff --git a/config/config_json_test.go b/config/config_json_test.go index be2770f07..eab834c6b 100755 --- a/config/config_json_test.go +++ b/config/config_json_test.go @@ -692,6 +692,7 @@ func TestDfResourceLimiterSJsonCfg(t *testing.T) { Enabled: utils.BoolPointer(false), Thresholds_conns: &[]*HaPoolJsonCfg{}, Store_interval: utils.StringPointer(""), + Indexed_fields: utils.StringSlicePointer([]string{}), } if cfg, err := dfCgrJsonCfg.ResourceSJsonCfg(); err != nil { t.Error(err) @@ -705,6 +706,7 @@ func TestDfStatServiceJsonCfg(t *testing.T) { Enabled: utils.BoolPointer(false), Store_interval: utils.StringPointer(""), Thresholds_conns: &[]*HaPoolJsonCfg{}, + Indexed_fields: utils.StringSlicePointer([]string{}), } if cfg, err := dfCgrJsonCfg.StatSJsonCfg(); err != nil { t.Error(err) diff --git a/config/config_test.go b/config/config_test.go index ce1480c83..4f189524a 100755 --- a/config/config_test.go +++ b/config/config_test.go @@ -579,6 +579,7 @@ func TestCgrCfgJSONDefaultsResLimCfg(t *testing.T) { Enabled: false, ThresholdSConns: []*HaPoolConfig{}, StoreInterval: 0, + IndexedFields: []string{}, } if !reflect.DeepEqual(cgrCfg.resourceSCfg, eResLiCfg) { t.Errorf("expecting: %s, received: %s", utils.ToJSON(eResLiCfg), utils.ToJSON(cgrCfg.resourceSCfg)) @@ -591,6 +592,7 @@ func TestCgrCfgJSONDefaultStatsCfg(t *testing.T) { Enabled: false, StoreInterval: 0, ThresholdSConns: []*HaPoolConfig{}, + IndexedFields: []string{}, } if !reflect.DeepEqual(cgrCfg.statsCfg, eStatsCfg) { t.Errorf("received: %+v, expecting: %+v", cgrCfg.statsCfg, eStatsCfg) diff --git a/config/libconfig_json.go b/config/libconfig_json.go index fbfe82f14..ceec45116 100755 --- a/config/libconfig_json.go +++ b/config/libconfig_json.go @@ -391,6 +391,7 @@ type ResourceSJsonCfg struct { Enabled *bool Thresholds_conns *[]*HaPoolJsonCfg Store_interval *string + Indexed_fields *[]string } // Stat service config section @@ -398,6 +399,7 @@ type StatServJsonCfg struct { Enabled *bool Store_interval *string Thresholds_conns *[]*HaPoolJsonCfg + Indexed_fields *[]string } // Threshold service config section diff --git a/config/reslimitercfg.go b/config/reslimitercfg.go index b4bf57a81..09b988903 100644 --- a/config/reslimitercfg.go +++ b/config/reslimitercfg.go @@ -28,6 +28,7 @@ type ResourceSConfig struct { Enabled bool ThresholdSConns []*HaPoolConfig // Connections towards StatS StoreInterval time.Duration // Dump regularly from cache into dataDB + IndexedFields []string } func (rlcfg *ResourceSConfig) loadFromJsonCfg(jsnCfg *ResourceSJsonCfg) (err error) { @@ -49,5 +50,11 @@ 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 + } + } return nil } diff --git a/config/statscfg.go b/config/statscfg.go index a75c3c92f..4c078188b 100644 --- a/config/statscfg.go +++ b/config/statscfg.go @@ -28,6 +28,7 @@ type StatSCfg struct { Enabled bool StoreInterval time.Duration // Dump regularly from cache into dataDB ThresholdSConns []*HaPoolConfig + IndexedFields []string } func (st *StatSCfg) loadFromJsonCfg(jsnCfg *StatServJsonCfg) (err error) { @@ -49,5 +50,11 @@ 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 + } + } return nil }