added new fields

This commit is contained in:
Edwardro22
2017-08-01 16:24:38 +03:00
parent 335e3febb2
commit 85000b4ca3
16 changed files with 89 additions and 32 deletions

View File

@@ -1272,7 +1272,7 @@ func TestApierResetDataAfterLoadFromFolder(t *testing.T) {
rcvStats.LcrProfiles != 0 ||
rcvStats.Aliases != 1 ||
rcvStats.ReverseAliases != 2 ||
rcvStats.ResourceLimits != 0 {
rcvStats.ResourceLimits != 3 {
t.Errorf("Expecting: %+v, received: %+v", expStats, rcvStats)
}
}

View File

@@ -407,6 +407,8 @@ CREATE TABLE tp_resource_limits (
`usage_ttl` varchar(32) NOT NULL,
`limit` varchar(64) NOT NULL,
`allocation_message` varchar(64) NOT NULL,
`blocker` BOOLEAN NOT NULL,
`stored` BOOLEAN NOT NULL,
`weight` decimal(8,2) NOT NULL,
`action_trigger_ids` varchar(64) NOT NULL,
`created_at` TIMESTAMP,
@@ -433,6 +435,8 @@ CREATE TABLE tp_stats (
`metrics` varchar(64) NOT NULL,
`store` BOOLEAN NOT NULL,
`thresholds` varchar(64) NOT NULL,
`blocker` BOOLEAN NOT NULL,
`stored` BOOLEAN NOT NULL,
`weight` decimal(8,2) NOT NULL,
`created_at` TIMESTAMP,
PRIMARY KEY (`id`),

View File

@@ -403,6 +403,8 @@ CREATE TABLE tp_resource_limits (
"usage_ttl" varchar(32) NOT NULL,
"limit" varchar(64) NOT NULL,
"allocation_message" varchar(64) NOT NULL,
"blocker" BOOLEAN NOT NULL,
"stored" BOOLEAN NOT NULL,
"weight" NUMERIC(8,2) NOT NULL,
"action_trigger_ids" varchar(64) NOT NULL,
"created_at" TIMESTAMP WITH TIME ZONE
@@ -429,6 +431,8 @@ CREATE TABLE tp_stats (
"metrics" varchar(64) NOT NULL,
"store" BOOLEAN NOT NULL,
"thresholds" varchar(64) NOT NULL,
"blocker" BOOLEAN NOT NULL,
"stored" BOOLEAN NOT NULL,
"weight" decimal(8,2) NOT NULL,
"created_at" TIMESTAMP WITH TIME ZONE
);

12
data/tariffplans/testtp/ResourceLimits.csv Normal file → Executable file
View File

@@ -1,6 +1,6 @@
#Id,FilterType,FilterFieldName,FilterFieldValues,ActivationInterval,TTL,Limit,AllocationReply,Weight,ActionTriggers
ResGroup1,*string,Account,1001;1002,2014-07-29T15:00:00Z,1s,7,,20,
ResGroup1,*string_prefix,Destination,10;20,,,,,,
ResGroup1,*rsr_fields,,Subject(~^1.*1$);Destination(1002),,,,,,
ResGroup2,*destinations,Destination,DST_FS,2014-07-29T15:00:00Z,3600s,8,SPECIAL_1002,10,
ResGroup3,*cdr_stats,,CDRST1:*min_ASR:34;CDRST_1001:*min_ASR:20,,,,,,
#Id,FilterType,FilterFieldName,FilterFieldValues,ActivationInterval,TTL,Limit,AllocationReply,Blocker,Stored,Weight,ActionTriggers
ResGroup1,*string,Account,1001;1002,2014-07-29T15:00:00Z,1s,7,,true,true,20,
ResGroup1,*string_prefix,Destination,10;20,,,,,,,,
ResGroup1,*rsr_fields,,Subject(~^1.*1$);Destination(1002),,,,,,,,
ResGroup2,*destinations,Destination,DST_FS,2014-07-29T15:00:00Z,3600s,8,SPECIAL_1002,true,true,10,
ResGroup3,*cdr_stats,,CDRST1:*min_ASR:34;CDRST_1001:*min_ASR:20,,,,,,,,
1 #Id FilterType FilterFieldName FilterFieldValues ActivationInterval TTL Limit AllocationReply Blocker Stored Weight ActionTriggers
2 ResGroup1 *string Account 1001;1002 2014-07-29T15:00:00Z 1s 7 true true 20
3 ResGroup1 *string_prefix Destination 10;20
4 ResGroup1 *rsr_fields Subject(~^1.*1$);Destination(1002)
5 ResGroup2 *destinations Destination DST_FS 2014-07-29T15:00:00Z 3600s 8 SPECIAL_1002 true true 10
6 ResGroup3 *cdr_stats CDRST1:*min_ASR:34;CDRST_1001:*min_ASR:20

4
data/tariffplans/testtp/Stats.csv Normal file → Executable file
View File

@@ -1,2 +1,2 @@
#Id,FilterType,FilterFieldName,FilterFieldValues,ActivationInterval,QueueLength,TTL,Metrics,Store,Thresholds,Weight
Stats1,*string,Account,1001;1002,2014-07-29T15:00:00Z,100,1s,*asr;*acd;*acc,true,THRESH1;THRESH2,20
#Id,FilterType,FilterFieldName,FilterFieldValues,ActivationInterval,QueueLength,TTL,Metrics,Store,Thresholds,Blocker,Stored,Weight
Stats1,*string,Account,1001;1002,2014-07-29T15:00:00Z,100,1s,*asr;*acd;*acc,true,THRESH1;THRESH2,true,true,20
1 #Id FilterType FilterFieldName FilterFieldValues ActivationInterval QueueLength TTL Metrics Store Thresholds Blocker Stored Weight
2 Stats1 *string Account 1001;1002 2014-07-29T15:00:00Z 100 1s *asr;*acd;*acc true THRESH1;THRESH2 true true 20

12
data/tariffplans/tutorial/ResourceLimits.csv Normal file → Executable file
View File

@@ -1,6 +1,6 @@
#Id,FilterType,FilterFieldName,FilterFieldValues,ActivationInterval,TTL,Limit,AllocationReply,Weight,ActionTriggers
ResGroup1,*string,Account,1001;1002,2014-07-29T15:00:00Z,1s,7,,20,
ResGroup1,*string_prefix,Destination,10;20,,,,,,
ResGroup1,*rsr_fields,,Subject(~^1.*1$);Destination(1002),,,,,,
ResGroup2,*destinations,Destination,DST_FS,2014-07-29T15:00:00Z,3600s,8,SPECIAL_1002,10,
ResGroup3,*cdr_stats,,CDRST1:*min_ASR:34;CDRST_1001:*min_ASR:20,,,,,,
#Id,FilterType,FilterFieldName,FilterFieldValues,ActivationInterval,TTL,Limit,AllocationReply,Blocker,Stored,Weight,ActionTriggers
ResGroup1,*string,Account,1001;1002,2014-07-29T15:00:00Z,1s,7,,true,true,20,
ResGroup1,*string_prefix,Destination,10;20,,,,,,,,
ResGroup1,*rsr_fields,,Subject(~^1.*1$);Destination(1002),,,,,,,,
ResGroup2,*destinations,Destination,DST_FS,2014-07-29T15:00:00Z,3600s,8,SPECIAL_1002,true,true,10,
ResGroup3,*cdr_stats,,CDRST1:*min_ASR:34;CDRST_1001:*min_ASR:20,,,,,,,,
1 #Id FilterType FilterFieldName FilterFieldValues ActivationInterval TTL Limit AllocationReply Blocker Stored Weight ActionTriggers
2 ResGroup1 *string Account 1001;1002 2014-07-29T15:00:00Z 1s 7 true true 20
3 ResGroup1 *string_prefix Destination 10;20
4 ResGroup1 *rsr_fields Subject(~^1.*1$);Destination(1002)
5 ResGroup2 *destinations Destination DST_FS 2014-07-29T15:00:00Z 3600s 8 SPECIAL_1002 true true 10
6 ResGroup3 *cdr_stats CDRST1:*min_ASR:34;CDRST_1001:*min_ASR:20

4
data/tariffplans/tutorial/Stats.csv Normal file → Executable file
View File

@@ -1,2 +1,2 @@
#Id,FilterType,FilterFieldName,FilterFieldValues,ActivationInterval,QueueLength,TTL,Metrics,Store,Thresholds,Weight
Stats1,*string,Account,1001;1002,2014-07-29T15:00:00Z,100,1s,*asr;*acd;*acc,true,THRESH1;THRESH2,20
#Id,FilterType,FilterFieldName,FilterFieldValues,ActivationInterval,QueueLength,TTL,Metrics,Store,Thresholds,Blocker,Stored,Weight
Stats1,*string,Account,1001;1002,2014-07-29T15:00:00Z,100,1s,*asr;*acd;*acc,true,THRESH1;THRESH2,true,true,20
1 #Id FilterType FilterFieldName FilterFieldValues ActivationInterval QueueLength TTL Metrics Store Thresholds Blocker Stored Weight
2 Stats1 *string Account 1001;1002 2014-07-29T15:00:00Z 100 1s *asr;*acd;*acc true THRESH1;THRESH2 true true 20

View File

@@ -268,14 +268,14 @@ cgrates.org,mas,true,another,value,10
resLimits = `
#Id,FilterType,FilterFieldName,FilterFieldValues,ActivationInterval,TTL,Limit,AllocationMessage,Weight,ActionTriggers
ResGroup21,*string,HdrAccount,1001;1002,2014-07-29T15:00:00Z,1s,2,call,10,
ResGroup21,*string_prefix,HdrDestination,10;20,,,,,,
ResGroup21,*rsr_fields,,HdrSubject(~^1.*1$);HdrDestination(1002),,,,,,
ResGroup22,*destinations,HdrDestination,DST_FS,2014-07-29T15:00:00Z,3600s,2,premium_call,10,
ResGroup21,*string,HdrAccount,1001;1002,2014-07-29T15:00:00Z,1s,2,call,true,true,10,
ResGroup21,*string_prefix,HdrDestination,10;20,,,,,,,,
ResGroup21,*rsr_fields,,HdrSubject(~^1.*1$);HdrDestination(1002),,,,,,,,
ResGroup22,*destinations,HdrDestination,DST_FS,2014-07-29T15:00:00Z,3600s,2,premium_call,true,true,10,
`
stats = `
#Id,FilterType,FilterFieldName,FilterFieldValues,ActivationInterval,QueueLength,TTL,Metrics,Store,Thresholds,Weight
Stats1,*string,Account,1001;1002,2014-07-29T15:00:00Z,100,1s,*asr;*acd;*acc,true,THRESH1;THRESH2,20
Stats1,*string,Account,1001;1002,2014-07-29T15:00:00Z,100,1s,*asr;*acd;*acc,true,THRESH1;THRESH2,true,true,20
`
)
@@ -1408,6 +1408,8 @@ func TestLoadResourceLimits(t *testing.T) {
},
UsageTTL: "3600s",
AllocationMessage: "premium_call",
Blocker: true,
Stored: true,
Weight: 10,
Limit: "2",
},
@@ -1436,6 +1438,8 @@ func TestLoadStats(t *testing.T) {
Metrics: []string{"*asr", "*acd", "*acc"},
Store: true,
Thresholds: []string{"THRESH1", "THRESH2"},
Blocker: true,
Stored: true,
Weight: 20,
},
}

0
engine/loader_it_test.go Normal file → Executable file
View File

View File

@@ -1819,8 +1819,10 @@ func (tps TpResourceLimits) AsTPResourceLimits() (result []*utils.TPResourceLimi
rl, found := mrl[tp.Tag]
if !found {
rl = &utils.TPResourceLimit{
TPid: tp.Tpid,
ID: tp.Tag,
TPid: tp.Tpid,
ID: tp.Tag,
Blocker: tp.Blocker,
Stored: tp.Stored,
}
}
if tp.UsageTTL != "" {
@@ -1913,6 +1915,8 @@ func APItoResourceLimit(tpRL *utils.TPResourceLimit, timezone string) (rl *Resou
rl = &ResourceLimit{
ID: tpRL.ID,
Weight: tpRL.Weight,
Blocker: tpRL.Blocker,
Stored: tpRL.Stored,
Filters: make([]*RequestFilter, len(tpRL.Filters)),
Usage: make(map[string]*ResourceUsage),
}
@@ -1949,8 +1953,10 @@ func (tps TpStatsS) AsTPStats() (result []*utils.TPStats) {
st, found := mst[tp.Tag]
if !found {
st = &utils.TPStats{
TPid: tp.Tpid,
ID: tp.Tag,
TPid: tp.Tpid,
ID: tp.Tag,
Blocker: tp.Blocker,
Stored: tp.Stored,
}
}
if tp.QueueLength != 0 {
@@ -2015,6 +2021,8 @@ func APItoModelStats(st *utils.TPStats) (mdls TpStatsS) {
}
if i == 0 {
mdl.TTL = st.TTL
mdl.Blocker = st.Blocker
mdl.Stored = st.Stored
mdl.Weight = st.Weight
mdl.QueueLength = st.QueueLength
mdl.Store = st.Store
@@ -2053,6 +2061,8 @@ func APItoTPStats(tpST *utils.TPStats, timezone string) (st *StatsQueue, err err
QueueLength: tpST.QueueLength,
Store: tpST.Store,
Weight: tpST.Weight,
Blocker: tpST.Blocker,
Stored: tpST.Stored,
Filters: make([]*RequestFilter, len(tpST.Filters)),
}
if tpST.TTL != "" {

View File

@@ -676,6 +676,8 @@ func TestTpResourceLimitsAsTPResourceLimits(t *testing.T) {
FilterFieldName: "Destination",
FilterFieldValues: "+49151;+49161",
ActivationInterval: "2014-07-29T15:00:00Z",
Stored: false,
Blocker: false,
Weight: 10.0,
Limit: "45",
ActionTriggerIds: "WARN_RES1;WARN_RES2"},
@@ -693,6 +695,8 @@ func TestTpResourceLimitsAsTPResourceLimits(t *testing.T) {
FilterFieldName: "Destination",
FilterFieldValues: "+40",
ActivationInterval: "2014-07-29T15:00:00Z",
Stored: false,
Blocker: false,
Weight: 10.0,
Limit: "20"},
}
@@ -715,6 +719,8 @@ func TestTpResourceLimitsAsTPResourceLimits(t *testing.T) {
ActivationInterval: &utils.TPActivationInterval{
ActivationTime: tps[0].ActivationInterval,
},
Stored: tps[0].Stored,
Blocker: tps[0].Blocker,
Weight: tps[0].Weight,
Limit: tps[0].Limit,
ActionTriggerIDs: []string{"WARN_RES1", "WARN_RES2", "WARN3"},
@@ -732,8 +738,10 @@ func TestTpResourceLimitsAsTPResourceLimits(t *testing.T) {
ActivationInterval: &utils.TPActivationInterval{
ActivationTime: tps[2].ActivationInterval,
},
Weight: tps[2].Weight,
Limit: tps[2].Limit,
Stored: tps[2].Stored,
Blocker: tps[2].Blocker,
Weight: tps[2].Weight,
Limit: tps[2].Limit,
},
}
rcvTPs := TpResourceLimits(tps).AsTPResourceLimits()
@@ -753,10 +761,15 @@ func TestAPItoResourceLimit(t *testing.T) {
&utils.TPRequestFilter{Type: MetaRSRFields, Values: []string{"Subject(~^1.*1$)", "Destination(1002)"}},
},
ActivationInterval: &utils.TPActivationInterval{ActivationTime: "2014-07-29T15:00:00Z"},
Stored: false,
Blocker: false,
Weight: 10,
Limit: "2",
}
eRL := &ResourceLimit{ID: tpRL.ID,
eRL := &ResourceLimit{
ID: tpRL.ID,
Stored: tpRL.Stored,
Blocker: tpRL.Blocker,
Weight: tpRL.Weight,
Filters: make([]*RequestFilter, len(tpRL.Filters)),
Usage: make(map[string]*ResourceUsage)}
@@ -797,6 +810,8 @@ func TestTPStatsAsTPStats(t *testing.T) {
Metrics: "*asr;*acd;*acc",
Store: true,
Thresholds: "THRESH1;THRESH2",
Stored: false,
Blocker: false,
Weight: 20.0,
},
}
@@ -819,6 +834,8 @@ func TestTPStatsAsTPStats(t *testing.T) {
Metrics: []string{"*asr", "*acd", "*acc"},
Store: tps[0].Store,
Thresholds: []string{"THRESH1", "THRESH2"},
Stored: tps[0].Stored,
Blocker: tps[0].Blocker,
Weight: tps[0].Weight,
},
}
@@ -841,6 +858,8 @@ func TestAPItoTPStats(t *testing.T) {
Metrics: []string{"*asr", "*acd", "*acc"},
Store: true,
Thresholds: []string{"THRESH1", "THRESH2"},
Stored: false,
Blocker: false,
Weight: 20.0,
}
@@ -850,6 +869,8 @@ func TestAPItoTPStats(t *testing.T) {
Store: tps.Store,
Thresholds: []string{"THRESH1", "THRESH2"},
Filters: make([]*RequestFilter, len(tps.Filters)),
Stored: tps.Stored,
Blocker: tps.Blocker,
Weight: 20.0,
}
if eTPs.TTL, err = utils.ParseDurationWithSecs(tps.TTL); err != nil {

View File

@@ -461,8 +461,10 @@ type TpResourceLimit struct {
UsageTTL string `index:"5" re:""`
Limit string `index:"6" re:""`
AllocationMessage string `index:"7" re:""`
Weight float64 `index:"8" re:"\d+\.?\d*"`
ActionTriggerIds string `index:"9" re:""`
Blocker bool `index:"8" re:""`
Stored bool `index:"9" re:""`
Weight float64 `index:"10" re:"\d+\.?\d*"`
ActionTriggerIds string `index:"11" re:""`
CreatedAt time.Time
}
@@ -489,6 +491,8 @@ type TpStats struct {
Metrics string `index:"7" re:""`
Store bool `index:"8" re:""`
Thresholds string `index:"9" re:""`
Weight float64 `index:"10" re:"\d+\.?\d*"`
Blocker bool `index:"10" re:""`
Stored bool `index:"11" re:""`
Weight float64 `index:"12" re:"\d+\.?\d*"`
CreatedAt time.Time
}

2
engine/reslimiter.go Normal file → Executable file
View File

@@ -42,6 +42,8 @@ type ResourceLimit struct {
Filters []*RequestFilter // Filters for the request
ActivationInterval *utils.ActivationInterval // Time when this limit becomes active and expires
ExpiryTime time.Time
Blocker bool // blocker flag to stop processing on filters matched
Stored bool
Weight float64 // Weight to sort the ResourceLimits
Limit float64 // Limit value
ActionTriggers ActionTriggers // Thresholds to check after changing Limit

View File

@@ -48,6 +48,8 @@ type StatsQueue struct {
Metrics []string // list of metrics to build
Store bool // store to DB
Thresholds []string // list of thresholds to be checked after changes
Blocker bool // blocker flag to stop processing on filters matched
Stored bool
Weight float64
}

0
engine/stordb_it_test.go Normal file → Executable file
View File

View File

@@ -703,6 +703,8 @@ type CacheStats struct {
Aliases int
ReverseAliases int
ResourceLimits int
//Stats int
//thresholds int
}
type AttrExpFileCdrs struct {
@@ -1269,6 +1271,8 @@ type TPResourceLimit struct {
UsageTTL string
Limit string // Limit value
AllocationMessage string
Blocker bool // blocker flag to stop processing on filters matched
Stored bool
Weight float64 // Weight to sort the ResourceLimits
ActionTriggerIDs []string // Thresholds to check after changing Limit
}
@@ -1334,5 +1338,7 @@ type TPStats struct {
Metrics []string
Store bool
Thresholds []string
Blocker bool // blocker flag to stop processing on filters matched
Stored bool
Weight float64
}