mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Update format for metrics ( *sum:~FieldName )
This commit is contained in:
committed by
Dan Christian Bogos
parent
657ad793d6
commit
4a65133a1a
@@ -528,7 +528,7 @@ func testV1FIdxCaSetStatQueueProfile(t *testing.T) {
|
||||
TTL: time.Duration(10) * time.Second,
|
||||
Metrics: []*engine.MetricWithFilters{
|
||||
&engine.MetricWithFilters{
|
||||
MetricID: "*sum#Val",
|
||||
MetricID: "*sum:~Val",
|
||||
},
|
||||
},
|
||||
ThresholdIDs: []string{"Val1", "Val2"},
|
||||
@@ -665,7 +665,7 @@ func testV1FIdxCaUpdateStatQueueProfile(t *testing.T) {
|
||||
TTL: time.Duration(10) * time.Second,
|
||||
Metrics: []*engine.MetricWithFilters{
|
||||
&engine.MetricWithFilters{
|
||||
MetricID: "*sum#Val",
|
||||
MetricID: "*sum:~Val",
|
||||
},
|
||||
},
|
||||
ThresholdIDs: []string{"*none"},
|
||||
|
||||
@@ -156,8 +156,8 @@ func testV1STSGetStats(t *testing.T) {
|
||||
utils.MetaTCD: utils.NOT_AVAILABLE,
|
||||
utils.MetaACC: utils.NOT_AVAILABLE,
|
||||
utils.MetaPDD: utils.NOT_AVAILABLE,
|
||||
utils.StatsJoin(utils.MetaSum, utils.Usage): utils.NOT_AVAILABLE,
|
||||
utils.StatsJoin(utils.MetaAverage, utils.Usage): utils.NOT_AVAILABLE,
|
||||
utils.ConcatenatedKey(utils.MetaSum, utils.DynamicDataPrefix+utils.Usage): utils.NOT_AVAILABLE,
|
||||
utils.ConcatenatedKey(utils.MetaAverage, utils.DynamicDataPrefix+utils.Usage): utils.NOT_AVAILABLE,
|
||||
}
|
||||
if err := stsV1Rpc.Call(utils.StatSv1GetQueueStringMetrics,
|
||||
&utils.TenantID{Tenant: "cgrates.org", ID: expectedIDs[0]}, &metrics); err != nil {
|
||||
@@ -193,8 +193,8 @@ func testV1STSProcessEvent(t *testing.T) {
|
||||
utils.MetaTCD: utils.NOT_AVAILABLE,
|
||||
utils.MetaACC: utils.NOT_AVAILABLE,
|
||||
utils.MetaPDD: utils.NOT_AVAILABLE,
|
||||
utils.StatsJoin(utils.MetaSum, utils.Usage): utils.NOT_AVAILABLE,
|
||||
utils.StatsJoin(utils.MetaAverage, utils.Usage): utils.NOT_AVAILABLE,
|
||||
utils.ConcatenatedKey(utils.MetaSum, utils.DynamicDataPrefix+utils.Usage): utils.NOT_AVAILABLE,
|
||||
utils.ConcatenatedKey(utils.MetaAverage, utils.DynamicDataPrefix+utils.Usage): utils.NOT_AVAILABLE,
|
||||
}
|
||||
var metrics map[string]string
|
||||
if err := stsV1Rpc.Call(utils.StatSv1GetQueueStringMetrics,
|
||||
@@ -212,8 +212,8 @@ func testV1STSProcessEvent(t *testing.T) {
|
||||
utils.MetaTCD: -1.0,
|
||||
utils.MetaACC: -1.0,
|
||||
utils.MetaPDD: -1.0,
|
||||
utils.StatsJoin(utils.MetaSum, utils.Usage): -1.0,
|
||||
utils.StatsJoin(utils.MetaAverage, utils.Usage): -1.0,
|
||||
utils.ConcatenatedKey(utils.MetaSum, utils.DynamicDataPrefix+utils.Usage): -1.0,
|
||||
utils.ConcatenatedKey(utils.MetaAverage, utils.DynamicDataPrefix+utils.Usage): -1.0,
|
||||
}
|
||||
var floatMetrics map[string]float64
|
||||
if err := stsV1Rpc.Call(utils.StatSv1GetQueueFloatMetrics,
|
||||
@@ -258,8 +258,8 @@ func testV1STSProcessEvent(t *testing.T) {
|
||||
utils.MetaTCD: "3m0s",
|
||||
utils.MetaTCC: "135.1",
|
||||
utils.MetaPDD: utils.NOT_AVAILABLE,
|
||||
utils.StatsJoin(utils.MetaSum, utils.Usage): "180000000000",
|
||||
utils.StatsJoin(utils.MetaAverage, utils.Usage): "60000000000",
|
||||
utils.ConcatenatedKey(utils.MetaSum, utils.DynamicDataPrefix+utils.Usage): "180000000000",
|
||||
utils.ConcatenatedKey(utils.MetaAverage, utils.DynamicDataPrefix+utils.Usage): "60000000000",
|
||||
}
|
||||
var metrics2 map[string]string
|
||||
if err := stsV1Rpc.Call(utils.StatSv1GetQueueStringMetrics, &utils.TenantID{Tenant: "cgrates.org", ID: "Stats1"}, &metrics2); err != nil {
|
||||
@@ -275,8 +275,8 @@ func testV1STSProcessEvent(t *testing.T) {
|
||||
utils.MetaTCD: 180,
|
||||
utils.MetaACC: 45.03333,
|
||||
utils.MetaPDD: -1.0,
|
||||
utils.StatsJoin(utils.MetaSum, utils.Usage): 180000000000,
|
||||
utils.StatsJoin(utils.MetaAverage, utils.Usage): 60000000000,
|
||||
utils.ConcatenatedKey(utils.MetaSum, utils.DynamicDataPrefix+utils.Usage): 180000000000,
|
||||
utils.ConcatenatedKey(utils.MetaAverage, utils.DynamicDataPrefix+utils.Usage): 60000000000,
|
||||
}
|
||||
var floatMetrics2 map[string]float64
|
||||
if err := stsV1Rpc.Call(utils.StatSv1GetQueueFloatMetrics, &utils.TenantID{Tenant: "cgrates.org", ID: "Stats1"}, &floatMetrics2); err != nil {
|
||||
@@ -306,8 +306,8 @@ func testV1STSGetStatsAfterRestart(t *testing.T) {
|
||||
utils.MetaTCD: "3m0s",
|
||||
utils.MetaTCC: "135.1",
|
||||
utils.MetaPDD: utils.NOT_AVAILABLE,
|
||||
utils.StatsJoin(utils.MetaSum, utils.Usage): "180000000000",
|
||||
utils.StatsJoin(utils.MetaAverage, utils.Usage): "60000000000",
|
||||
utils.ConcatenatedKey(utils.MetaSum, utils.DynamicDataPrefix+utils.Usage): "180000000000",
|
||||
utils.ConcatenatedKey(utils.MetaAverage, utils.DynamicDataPrefix+utils.Usage): "60000000000",
|
||||
}
|
||||
var metrics2 map[string]string
|
||||
if err := stsV1Rpc.Call(utils.StatSv1GetQueueStringMetrics, &utils.TenantID{Tenant: "cgrates.org", ID: "Stats1"}, &metrics2); err != nil {
|
||||
@@ -476,7 +476,7 @@ func testV1STSProcessMetricsWithFilter(t *testing.T) {
|
||||
FilterIDs: []string{"*gt:~Usage:5s"},
|
||||
},
|
||||
&engine.MetricWithFilters{
|
||||
MetricID: "*sum#CustomValue",
|
||||
MetricID: "*sum:~CustomValue",
|
||||
FilterIDs: []string{"*exists:~CustomValue:", "*gte:~CustomValue:10.0"},
|
||||
},
|
||||
},
|
||||
@@ -508,7 +508,7 @@ func testV1STSProcessMetricsWithFilter(t *testing.T) {
|
||||
expectedMetrics := map[string]string{
|
||||
utils.MetaACD: utils.NOT_AVAILABLE,
|
||||
utils.MetaTCD: utils.NOT_AVAILABLE,
|
||||
utils.StatsJoin(utils.MetaSum, "CustomValue"): utils.NOT_AVAILABLE,
|
||||
utils.ConcatenatedKey(utils.MetaSum, "~CustomValue"): utils.NOT_AVAILABLE,
|
||||
}
|
||||
if err := stsV1Rpc.Call(utils.StatSv1GetQueueStringMetrics,
|
||||
&utils.TenantID{Tenant: "cgrates.org", ID: expectedIDs[0]}, &metrics); err != nil {
|
||||
@@ -536,7 +536,7 @@ func testV1STSProcessMetricsWithFilter(t *testing.T) {
|
||||
expectedMetrics = map[string]string{
|
||||
utils.MetaACD: utils.NOT_AVAILABLE,
|
||||
utils.MetaTCD: "6s",
|
||||
utils.StatsJoin(utils.MetaSum, "CustomValue"): utils.NOT_AVAILABLE,
|
||||
utils.ConcatenatedKey(utils.MetaSum, "~CustomValue"): utils.NOT_AVAILABLE,
|
||||
}
|
||||
if err := stsV1Rpc.Call(utils.StatSv1GetQueueStringMetrics,
|
||||
&utils.TenantID{Tenant: "cgrates.org", ID: expectedIDs[0]}, &metrics); err != nil {
|
||||
@@ -562,7 +562,7 @@ func testV1STSProcessMetricsWithFilter(t *testing.T) {
|
||||
expectedMetrics = map[string]string{
|
||||
utils.MetaACD: "12s",
|
||||
utils.MetaTCD: "18s",
|
||||
utils.StatsJoin(utils.MetaSum, "CustomValue"): "10",
|
||||
utils.ConcatenatedKey(utils.MetaSum, "~CustomValue"): "10",
|
||||
}
|
||||
if err := stsV1Rpc.Call(utils.StatSv1GetQueueStringMetrics,
|
||||
&utils.TenantID{Tenant: "cgrates.org", ID: expectedIDs[0]}, &metrics); err != nil {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#Tenant[0],Id[1],FilterIDs[2],ActivationInterval[3],QueueLength[4],TTL[5],MinItems[6],Metrics[7],MetricFilterIDs[8],Stored[9],Blocker[10],Weight[11],ThresholdIDs[12]
|
||||
cgrates.org,Stats1,FLTR_STS1,2014-07-29T15:00:00Z,100,1s,2,*asr;*acc;*tcc;*acd;*tcd,,true,false,20,*none
|
||||
cgrates.org,Stats1,,,,,,*sum#Usage;*average#Usage,,,,,
|
||||
cgrates.org,Stats1,,,,,,*sum:~Usage;*average:~Usage,,,,,
|
||||
cgrates.org,Stats1,,,,,,*pdd,*exists:~PDD:,,,,
|
||||
|
@@ -1,4 +1,4 @@
|
||||
#Tenant[0],Id[1],FilterIDs[2],ActivationInterval[3],QueueLength[4],TTL[5],MinItems[6],Metrics[7],MetricFilterIDs[8],Stored[9],Blocker[10],Weight[11],ThresholdIDs[12]
|
||||
cgrates.org,Stats1,FLTR_STS1,2014-07-29T15:00:00Z,100,1s,2,*asr;*acc;*tcc;*acd;*tcd,,true,false,20,*none
|
||||
cgrates.org,Stats1,,,,,,*sum#Usage;*average#Usage,,,,,
|
||||
cgrates.org,Stats1,,,,,,*sum:~Usage;*average:~Usage,,,,,
|
||||
cgrates.org,Stats1,,,,,,*pdd,*exists:~PDD:,,,,
|
||||
|
@@ -1,3 +1,3 @@
|
||||
#Tenant[0],Id[1],FilterIDs[2],ActivationInterval[3],QueueLength[4],TTL[5],MinItems[6],Metrics[7],MetricFilterIDs[8],Stored[9],Blocker[10],Weight[11],ThresholdIDs[12]
|
||||
cgrates.org,Stats1,FLTR_STS1,2014-07-29T15:00:00Z,100,1s,2,*asr;*acc;*tcc;*acd;*tcd;*pdd,,true,true,20,THRESH1;THRESH2
|
||||
cgrates.org,Stats1,FLTR_STS1,2014-07-29T15:00:00Z,100,1s,2,*sum#Value;*average#Value,,true,true,20,THRESH1;THRESH2
|
||||
cgrates.org,Stats1,FLTR_STS1,2014-07-29T15:00:00Z,100,1s,2,*sum:~Value;*average:~Value,,true,true,20,THRESH1;THRESH2
|
||||
|
||||
|
@@ -235,10 +235,10 @@ cgrates.org,ResGroup22,*string:~Account:dan,2014-07-29T15:00:00Z,3600s,2,premium
|
||||
`
|
||||
StatsCSVContent = `
|
||||
#Tenant[0],Id[1],FilterIDs[2],ActivationInterval[3],QueueLength[4],TTL[5],MinItems[6],Metrics[7],MetricFilterIDs[8],Stored[9],Blocker[10],Weight[11],ThresholdIDs[12]
|
||||
cgrates.org,TestStats,*string:~Account:1001,2014-07-29T15:00:00Z,100,1s,2,*sum#Value;*average#Value,,true,true,20,Th1;Th2
|
||||
cgrates.org,TestStats,,,,,2,*sum#Usage,,true,true,20,
|
||||
cgrates.org,TestStats2,FLTR_1,2014-07-29T15:00:00Z,100,1s,2,*sum#Value;*sum#Usage;*average#Value;*average#Usage,,true,true,20,Th
|
||||
cgrates.org,TestStats2,,,,,2,*sum#Cost;*average#Cost,,true,true,20,
|
||||
cgrates.org,TestStats,*string:~Account:1001,2014-07-29T15:00:00Z,100,1s,2,*sum:~Value;*average:~Value,,true,true,20,Th1;Th2
|
||||
cgrates.org,TestStats,,,,,2,*sum:~Usage,,true,true,20,
|
||||
cgrates.org,TestStats2,FLTR_1,2014-07-29T15:00:00Z,100,1s,2,*sum:~Value;*sum:~Usage;*average:~Value;*average:~Usage,,true,true,20,Th
|
||||
cgrates.org,TestStats2,,,,,2,*sum:~Cost;*average:~Cost,,true,true,20,
|
||||
`
|
||||
|
||||
ThresholdsCSVContent = `
|
||||
|
||||
@@ -21,6 +21,7 @@ package engine
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/cgrates/cgrates/config"
|
||||
@@ -58,8 +59,8 @@ func NewStatMetric(metricID string, minItems int, filterIDs []string) (sm StatMe
|
||||
utils.MetaDistinct: NewStatDistinct,
|
||||
}
|
||||
// split the metricID
|
||||
// in case of *sum we have *sum#FieldName
|
||||
metricSplit := utils.SplitStats(metricID)
|
||||
// in case of *sum we have *sum:~FieldName
|
||||
metricSplit := utils.SplitConcatenatedKey(metricID)
|
||||
if _, has := metrics[metricSplit[0]]; !has {
|
||||
return nil, fmt.Errorf("unsupported metric type <%s>", metricSplit[0])
|
||||
}
|
||||
@@ -1036,11 +1037,20 @@ func (sum *StatSum) GetFloat64Value() (v float64) {
|
||||
|
||||
func (sum *StatSum) AddEvent(ev *utils.CGREvent) (err error) {
|
||||
var val float64
|
||||
if val, err = ev.FieldAsFloat64(sum.FieldName); err != nil {
|
||||
if err == utils.ErrNotFound {
|
||||
err = utils.ErrPrefix(err, sum.FieldName)
|
||||
if strings.HasPrefix(sum.FieldName, utils.DynamicDataPrefix) {
|
||||
//Remove the dynamic prefix and check in event for field
|
||||
field := sum.FieldName[1:]
|
||||
if val, err = ev.FieldAsFloat64(field); err != nil {
|
||||
if err == utils.ErrNotFound {
|
||||
err = utils.ErrPrefix(err, field)
|
||||
}
|
||||
return
|
||||
}
|
||||
} else { // in case we don't receive FieldName we consider that we receive a number
|
||||
val, err = utils.IfaceAsFloat64(sum.FieldName)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
sum.Sum += val
|
||||
if v, has := sum.Events[ev.ID]; !has {
|
||||
@@ -1164,11 +1174,20 @@ func (avg *StatAverage) GetFloat64Value() (v float64) {
|
||||
|
||||
func (avg *StatAverage) AddEvent(ev *utils.CGREvent) (err error) {
|
||||
var val float64
|
||||
if val, err = ev.FieldAsFloat64(avg.FieldName); err != nil {
|
||||
if err == utils.ErrNotFound {
|
||||
err = utils.ErrPrefix(err, avg.FieldName)
|
||||
if strings.HasPrefix(avg.FieldName, utils.DynamicDataPrefix) {
|
||||
//Remove the dynamic prefix and check in event for field
|
||||
field := avg.FieldName[1:]
|
||||
if val, err = ev.FieldAsFloat64(field); err != nil {
|
||||
if err == utils.ErrNotFound {
|
||||
err = utils.ErrPrefix(err, field)
|
||||
}
|
||||
return
|
||||
}
|
||||
} else { // in case we don't receive FieldName we consider that we receive a number
|
||||
val, err = utils.IfaceAsFloat64(avg.FieldName)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
avg.Sum += val
|
||||
if v, has := avg.Events[ev.ID]; !has {
|
||||
@@ -1284,7 +1303,9 @@ func (dst *StatDistinct) GetFloat64Value() (v float64) {
|
||||
|
||||
func (dst *StatDistinct) AddEvent(ev *utils.CGREvent) (err error) {
|
||||
var fieldValue string
|
||||
if fieldValue, err = ev.FieldAsString(dst.FieldName); err != nil {
|
||||
// simply remove the Dynamic prefix and do normal process
|
||||
field := dst.FieldName[1:]
|
||||
if fieldValue, err = ev.FieldAsString(field); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -2077,7 +2077,7 @@ func TestDDCGetCompressFactor(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestStatSumGetFloat64Value(t *testing.T) {
|
||||
statSum, _ := NewStatSum(2, "Cost", []string{})
|
||||
statSum, _ := NewStatSum(2, "~Cost", []string{})
|
||||
ev := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_1",
|
||||
Event: map[string]interface{}{
|
||||
"Cost": "20",
|
||||
@@ -2140,7 +2140,7 @@ func TestStatSumGetFloat64Value(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestStatSumGetStringValue(t *testing.T) {
|
||||
statSum, _ := NewStatSum(2, "Cost", []string{})
|
||||
statSum, _ := NewStatSum(2, "~Cost", []string{})
|
||||
ev := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_1",
|
||||
Event: map[string]interface{}{
|
||||
"Cost": "20",
|
||||
@@ -2185,7 +2185,7 @@ func TestStatSumGetStringValue(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestStatSumGetStringValue2(t *testing.T) {
|
||||
statSum, _ := NewStatSum(2, "Cost", []string{})
|
||||
statSum, _ := NewStatSum(2, "~Cost", []string{})
|
||||
ev1 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_1",
|
||||
Event: map[string]interface{}{"Cost": 12.3}}
|
||||
if err := statSum.AddEvent(ev1); err != nil {
|
||||
@@ -2209,7 +2209,7 @@ func TestStatSumGetStringValue2(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestStatSumGetStringValue3(t *testing.T) {
|
||||
statSum := &StatSum{Events: make(map[string]*StatWithCompress), MinItems: 2, FilterIDs: []string{}, FieldName: "Cost"}
|
||||
statSum := &StatSum{Events: make(map[string]*StatWithCompress), MinItems: 2, FilterIDs: []string{}, FieldName: "~Cost"}
|
||||
expected := &StatSum{
|
||||
Events: map[string]*StatWithCompress{
|
||||
"EVENT_1": &StatWithCompress{Stat: 12.2, CompressFactor: 2},
|
||||
@@ -2217,7 +2217,7 @@ func TestStatSumGetStringValue3(t *testing.T) {
|
||||
},
|
||||
MinItems: 2,
|
||||
FilterIDs: []string{},
|
||||
FieldName: "Cost",
|
||||
FieldName: "~Cost",
|
||||
Count: 3,
|
||||
Sum: 42.7,
|
||||
}
|
||||
@@ -2255,7 +2255,7 @@ func TestStatSumGetStringValue3(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestStatSumCompress(t *testing.T) {
|
||||
sum := &StatSum{Events: make(map[string]*StatWithCompress), FieldName: "Cost",
|
||||
sum := &StatSum{Events: make(map[string]*StatWithCompress), FieldName: "~Cost",
|
||||
MinItems: 2, FilterIDs: []string{}}
|
||||
expected := &StatSum{
|
||||
Events: map[string]*StatWithCompress{
|
||||
@@ -2265,7 +2265,7 @@ func TestStatSumCompress(t *testing.T) {
|
||||
MinItems: 2,
|
||||
FilterIDs: []string{},
|
||||
Sum: 24.4,
|
||||
FieldName: "Cost",
|
||||
FieldName: "~Cost",
|
||||
Count: 2,
|
||||
}
|
||||
expected.GetStringValue("")
|
||||
@@ -2293,7 +2293,7 @@ func TestStatSumCompress(t *testing.T) {
|
||||
},
|
||||
MinItems: 2,
|
||||
FilterIDs: []string{},
|
||||
FieldName: "Cost",
|
||||
FieldName: "~Cost",
|
||||
Sum: 24.4,
|
||||
Count: 2,
|
||||
}
|
||||
@@ -2330,7 +2330,7 @@ func TestStatSumGetCompressFactor(t *testing.T) {
|
||||
"EVENT_1": 1,
|
||||
"EVENT_2": 1,
|
||||
}
|
||||
sum, _ := NewStatSum(2, "Cost", []string{})
|
||||
sum, _ := NewStatSum(2, "~Cost", []string{})
|
||||
ev := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_1",
|
||||
Event: map[string]interface{}{"Cost": 18.2}}
|
||||
ev2 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_2",
|
||||
@@ -2357,7 +2357,7 @@ func TestStatSumGetCompressFactor(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestStatAverageGetFloat64Value(t *testing.T) {
|
||||
statAvg, _ := NewStatAverage(2, "Cost", []string{})
|
||||
statAvg, _ := NewStatAverage(2, "~Cost", []string{})
|
||||
ev := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_1",
|
||||
Event: map[string]interface{}{
|
||||
"Cost": "20",
|
||||
@@ -2418,7 +2418,7 @@ func TestStatAverageGetFloat64Value(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestStatAverageGetStringValue(t *testing.T) {
|
||||
statAvg, _ := NewStatAverage(2, "Cost", []string{})
|
||||
statAvg, _ := NewStatAverage(2, "~Cost", []string{})
|
||||
ev := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_1",
|
||||
Event: map[string]interface{}{
|
||||
"Cost": "20",
|
||||
@@ -2463,7 +2463,7 @@ func TestStatAverageGetStringValue(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestStatAverageGetStringValue2(t *testing.T) {
|
||||
statAvg, _ := NewStatAverage(2, "Cost", []string{})
|
||||
statAvg, _ := NewStatAverage(2, "~Cost", []string{})
|
||||
ev1 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_1",
|
||||
Event: map[string]interface{}{"Cost": 12.3}}
|
||||
if err := statAvg.AddEvent(ev1); err != nil {
|
||||
@@ -2487,7 +2487,7 @@ func TestStatAverageGetStringValue2(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestStatAverageGetStringValue3(t *testing.T) {
|
||||
statAvg := &StatAverage{Events: make(map[string]*StatWithCompress), MinItems: 2, FilterIDs: []string{}, FieldName: "Cost"}
|
||||
statAvg := &StatAverage{Events: make(map[string]*StatWithCompress), MinItems: 2, FilterIDs: []string{}, FieldName: "~Cost"}
|
||||
expected := &StatAverage{
|
||||
Events: map[string]*StatWithCompress{
|
||||
"EVENT_1": &StatWithCompress{Stat: 12.2, CompressFactor: 2},
|
||||
@@ -2495,7 +2495,7 @@ func TestStatAverageGetStringValue3(t *testing.T) {
|
||||
},
|
||||
MinItems: 2,
|
||||
FilterIDs: []string{},
|
||||
FieldName: "Cost",
|
||||
FieldName: "~Cost",
|
||||
Count: 3,
|
||||
Sum: 42.7,
|
||||
}
|
||||
@@ -2533,7 +2533,7 @@ func TestStatAverageGetStringValue3(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestStatAverageCompress(t *testing.T) {
|
||||
avg := &StatAverage{Events: make(map[string]*StatWithCompress), FieldName: "Cost",
|
||||
avg := &StatAverage{Events: make(map[string]*StatWithCompress), FieldName: "~Cost",
|
||||
MinItems: 2, FilterIDs: []string{}}
|
||||
expected := &StatAverage{
|
||||
Events: map[string]*StatWithCompress{
|
||||
@@ -2543,7 +2543,7 @@ func TestStatAverageCompress(t *testing.T) {
|
||||
MinItems: 2,
|
||||
FilterIDs: []string{},
|
||||
Sum: 24.4,
|
||||
FieldName: "Cost",
|
||||
FieldName: "~Cost",
|
||||
Count: 2,
|
||||
}
|
||||
expected.GetStringValue("")
|
||||
@@ -2571,7 +2571,7 @@ func TestStatAverageCompress(t *testing.T) {
|
||||
},
|
||||
MinItems: 2,
|
||||
FilterIDs: []string{},
|
||||
FieldName: "Cost",
|
||||
FieldName: "~Cost",
|
||||
Sum: 24.4,
|
||||
Count: 2,
|
||||
}
|
||||
@@ -2608,7 +2608,7 @@ func TestStatAverageGetCompressFactor(t *testing.T) {
|
||||
"EVENT_1": 1,
|
||||
"EVENT_2": 1,
|
||||
}
|
||||
avg, _ := NewStatAverage(2, "Cost", []string{})
|
||||
avg, _ := NewStatAverage(2, "~Cost", []string{})
|
||||
ev := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_1",
|
||||
Event: map[string]interface{}{"Cost": 18.2}}
|
||||
ev2 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_2",
|
||||
@@ -2635,7 +2635,7 @@ func TestStatAverageGetCompressFactor(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestStatDistinctGetFloat64Value(t *testing.T) {
|
||||
statDistinct, _ := NewStatDistinct(2, "Usage", []string{})
|
||||
statDistinct, _ := NewStatDistinct(2, "~Usage", []string{})
|
||||
ev := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_1",
|
||||
Event: map[string]interface{}{"Usage": time.Duration(10 * time.Second)}}
|
||||
statDistinct.AddEvent(ev)
|
||||
@@ -2686,7 +2686,7 @@ func TestStatDistinctGetFloat64Value(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestStatDistinctGetStringValue(t *testing.T) {
|
||||
statDistinct, _ := NewStatDistinct(2, "Cost", []string{})
|
||||
statDistinct, _ := NewStatDistinct(2, "~Cost", []string{})
|
||||
ev := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_1",
|
||||
Event: map[string]interface{}{"Cost": "20"}}
|
||||
if strVal := statDistinct.GetStringValue(""); strVal != utils.NOT_AVAILABLE {
|
||||
@@ -2721,7 +2721,7 @@ func TestStatDistinctGetStringValue(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestStatDistinctGetStringValue2(t *testing.T) {
|
||||
statDistinct, _ := NewStatDistinct(2, "Cost", []string{})
|
||||
statDistinct, _ := NewStatDistinct(2, "~Cost", []string{})
|
||||
ev := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_1",
|
||||
Event: map[string]interface{}{"Cost": "20"}}
|
||||
if strVal := statDistinct.GetStringValue(""); strVal != utils.NOT_AVAILABLE {
|
||||
@@ -2750,7 +2750,7 @@ func TestStatDistinctCompress(t *testing.T) {
|
||||
FieldValues: make(map[string]map[string]struct{}),
|
||||
MinItems: 2,
|
||||
FilterIDs: []string{},
|
||||
FieldName: utils.Destination,
|
||||
FieldName: utils.DynamicDataPrefix + utils.Destination,
|
||||
}
|
||||
expected := &StatDistinct{
|
||||
Events: map[string]map[string]int64{
|
||||
@@ -2771,7 +2771,7 @@ func TestStatDistinctCompress(t *testing.T) {
|
||||
},
|
||||
MinItems: 2,
|
||||
FilterIDs: []string{},
|
||||
FieldName: utils.Destination,
|
||||
FieldName: utils.DynamicDataPrefix + utils.Destination,
|
||||
Count: 3,
|
||||
}
|
||||
expected.GetStringValue("")
|
||||
@@ -2811,7 +2811,7 @@ func TestStatDistinctGetCompressFactor(t *testing.T) {
|
||||
"EVENT_1": 1,
|
||||
"EVENT_2": 1,
|
||||
}
|
||||
ddc, _ := NewStatDistinct(2, utils.Destination, []string{})
|
||||
ddc, _ := NewStatDistinct(2, utils.DynamicDataPrefix+utils.Destination, []string{})
|
||||
|
||||
ev := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_1",
|
||||
Event: map[string]interface{}{utils.Destination: "1002"}}
|
||||
@@ -2983,7 +2983,7 @@ func TestDCCMarshal(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestStatSumMarshal(t *testing.T) {
|
||||
statSum, _ := NewStatSum(2, "Cost", []string{})
|
||||
statSum, _ := NewStatSum(2, "~Cost", []string{})
|
||||
ev := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_1",
|
||||
Event: map[string]interface{}{
|
||||
"Cost": "20",
|
||||
@@ -2993,7 +2993,7 @@ func TestStatSumMarshal(t *testing.T) {
|
||||
utils.Destination: "1002"}}
|
||||
statSum.AddEvent(ev)
|
||||
var nstatSum StatSum
|
||||
expected := []byte(`{"FilterIDs":[],"Sum":20,"Count":1,"Events":{"EVENT_1":{"Stat":20,"CompressFactor":1}},"MinItems":2,"FieldName":"Cost"}`)
|
||||
expected := []byte(`{"FilterIDs":[],"Sum":20,"Count":1,"Events":{"EVENT_1":{"Stat":20,"CompressFactor":1}},"MinItems":2,"FieldName":"~Cost"}`)
|
||||
if b, err := statSum.Marshal(&jMarshaler); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(expected, b) {
|
||||
@@ -3006,7 +3006,7 @@ func TestStatSumMarshal(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestStatAverageMarshal(t *testing.T) {
|
||||
statAvg, _ := NewStatAverage(2, "Cost", []string{})
|
||||
statAvg, _ := NewStatAverage(2, "~Cost", []string{})
|
||||
ev := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_1",
|
||||
Event: map[string]interface{}{
|
||||
"Cost": "20",
|
||||
@@ -3016,7 +3016,7 @@ func TestStatAverageMarshal(t *testing.T) {
|
||||
utils.Destination: "1002"}}
|
||||
statAvg.AddEvent(ev)
|
||||
var nstatAvg StatAverage
|
||||
expected := []byte(`{"FilterIDs":[],"Sum":20,"Count":1,"Events":{"EVENT_1":{"Stat":20,"CompressFactor":1}},"MinItems":2,"FieldName":"Cost"}`)
|
||||
expected := []byte(`{"FilterIDs":[],"Sum":20,"Count":1,"Events":{"EVENT_1":{"Stat":20,"CompressFactor":1}},"MinItems":2,"FieldName":"~Cost"}`)
|
||||
if b, err := statAvg.Marshal(&jMarshaler); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(expected, b) {
|
||||
@@ -3029,7 +3029,7 @@ func TestStatAverageMarshal(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestStatDistrictMarshal(t *testing.T) {
|
||||
statDistinct, _ := NewStatDistinct(2, "Usage", []string{})
|
||||
statDistinct, _ := NewStatDistinct(2, "~Usage", []string{})
|
||||
ev := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_1",
|
||||
Event: map[string]interface{}{
|
||||
"Cost": "20",
|
||||
@@ -3039,7 +3039,7 @@ func TestStatDistrictMarshal(t *testing.T) {
|
||||
utils.Destination: "1002"}}
|
||||
statDistinct.AddEvent(ev)
|
||||
var nStatDistinct StatDistinct
|
||||
expected := []byte(`{"FilterIDs":[],"FieldValues":{"10s":{"EVENT_1":{}}},"Events":{"EVENT_1":{"10s":1}},"MinItems":2,"FieldName":"Usage","Count":1}`)
|
||||
expected := []byte(`{"FilterIDs":[],"FieldValues":{"10s":{"EVENT_1":{}}},"Events":{"EVENT_1":{"10s":1}},"MinItems":2,"FieldName":"~Usage","Count":1}`)
|
||||
if b, err := statDistinct.Marshal(&jMarshaler); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(expected, b) {
|
||||
|
||||
@@ -472,7 +472,7 @@ func testV2CDRsSetStats(t *testing.T) {
|
||||
// QueueLength: 10,
|
||||
Metrics: []*engine.MetricWithFilters{
|
||||
&engine.MetricWithFilters{
|
||||
MetricID: "*sum#Usage",
|
||||
MetricID: "*sum:~Usage",
|
||||
},
|
||||
},
|
||||
ThresholdIDs: []string{utils.META_NONE},
|
||||
@@ -585,7 +585,7 @@ func testV2CDRsGetStats1(t *testing.T) {
|
||||
expectedIDs := []string{"STS_PoccessCDR"}
|
||||
var metrics map[string]string
|
||||
expectedMetrics := map[string]string{
|
||||
utils.StatsJoin(utils.MetaSum, utils.Usage): utils.NOT_AVAILABLE,
|
||||
utils.ConcatenatedKey(utils.MetaSum, utils.DynamicDataPrefix+utils.Usage): utils.NOT_AVAILABLE,
|
||||
}
|
||||
if err := cdrsRpc.Call(utils.StatSv1GetQueueStringMetrics,
|
||||
&utils.TenantID{Tenant: "cgrates.org", ID: expectedIDs[0]}, &metrics); err != nil {
|
||||
@@ -650,7 +650,7 @@ func testV2CDRsGetStats2(t *testing.T) {
|
||||
expectedIDs := []string{"STS_PoccessCDR"}
|
||||
var metrics map[string]string
|
||||
expectedMetrics := map[string]string{
|
||||
utils.StatsJoin(utils.MetaSum, utils.Usage): "60000000000",
|
||||
utils.ConcatenatedKey(utils.MetaSum, utils.DynamicDataPrefix+utils.Usage): "60000000000",
|
||||
}
|
||||
if err := cdrsRpc.Call(utils.StatSv1GetQueueStringMetrics,
|
||||
&utils.TenantID{Tenant: "cgrates.org", ID: expectedIDs[0]}, &metrics); err != nil {
|
||||
|
||||
@@ -635,13 +635,13 @@ func TestLoaderProcessStats(t *testing.T) {
|
||||
TTL: time.Duration(1 * time.Second),
|
||||
Metrics: []*engine.MetricWithFilters{
|
||||
&engine.MetricWithFilters{
|
||||
MetricID: "*sum#Value",
|
||||
MetricID: "*sum:~Value",
|
||||
},
|
||||
&engine.MetricWithFilters{
|
||||
MetricID: "*average#Value",
|
||||
MetricID: "*average:~Value",
|
||||
},
|
||||
&engine.MetricWithFilters{
|
||||
MetricID: "*sum#Usage",
|
||||
MetricID: "*sum:~Usage",
|
||||
},
|
||||
},
|
||||
ThresholdIDs: []string{"Th1", "Th2"},
|
||||
|
||||
@@ -359,14 +359,6 @@ func SplitConcatenatedKey(key string) []string {
|
||||
return strings.Split(key, CONCATENATED_KEY_SEP)
|
||||
}
|
||||
|
||||
func StatsJoin(keyVals ...string) string {
|
||||
return strings.Join(keyVals, STATS_CHAR)
|
||||
}
|
||||
|
||||
func SplitStats(key string) []string {
|
||||
return strings.Split(key, STATS_CHAR)
|
||||
}
|
||||
|
||||
func InfieldJoin(vals ...string) string {
|
||||
return strings.Join(vals, INFIELD_SEP)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user