Config indexed_fields for stats and resources

This commit is contained in:
DanB
2017-10-27 13:59:58 +02:00
parent bf3a36ff91
commit 7316ec43da
6 changed files with 22 additions and 0 deletions

View File

@@ -423,6 +423,7 @@ const CGRATES_CFG_JSON = `
"enabled": false, // starts ResourceLimiter service: <true|false>.
"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: <true|false>.
"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
},

View File

@@ -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)

View File

@@ -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)

View File

@@ -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

View File

@@ -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
}

View File

@@ -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
}