mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Resolve merge problems and update tests from model_helpers
This commit is contained in:
committed by
Dan Christian Bogos
parent
76272b9b01
commit
d1957d1871
@@ -227,14 +227,10 @@ cgrates.org,ResGroup22,FLTR_ACNT_dan,2014-07-29T15:00:00Z,3600s,2,premium_call,t
|
||||
`
|
||||
stats = `
|
||||
#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,FLTR_1,2014-07-29T15:00:00Z,100,1s,2,*sum#Value,,true,true,20,Th1;Th2
|
||||
cgrates.org,TestStats,,,,,,*sum#Usage,,,,,
|
||||
cgrates.org,TestStats,,,,,,*average#Value,,,,,
|
||||
cgrates.org,TestStats2,FLTR_1,2014-07-29T15:00:00Z,100,1s,2,*sum#Value;,,true,true,20,Th
|
||||
cgrates.org,TestStats2,,,,,,*sum#Usage,,,,,
|
||||
cgrates.org,TestStats2,,,,,,*average#Value,,,,,
|
||||
cgrates.org,TestStats2,,,,,,*average#Usage,,,,,
|
||||
cgrates.org,TestStats2,,,,,,*sum#Cost;*average#Cost,*string:Account:1001,,,,
|
||||
cgrates.org,TestStats,FLTR_1,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,
|
||||
`
|
||||
|
||||
thresholds = `
|
||||
@@ -337,7 +333,7 @@ func init() {
|
||||
log.Print("error in LoadChargerProfiles:", err)
|
||||
}
|
||||
if err := csvr.LoadDispatcherProfiles(); err != nil {
|
||||
log.Print("error in LoadChargerProfiles:", err)
|
||||
log.Print("error in LoadDispatcherProfiles:", err)
|
||||
}
|
||||
csvr.WriteToDatabase(false, false, false)
|
||||
Cache.Clear(nil)
|
||||
|
||||
@@ -1310,6 +1310,7 @@ type TpStats []*TpStat
|
||||
func (models TpStats) AsTPStats() (result []*utils.TPStatProfile) {
|
||||
filterMap := make(map[string]utils.StringMap)
|
||||
thresholdMap := make(map[string]utils.StringMap)
|
||||
statMetricsMap := make(map[string]map[string]*utils.MetricWithFilters)
|
||||
mst := make(map[string]*utils.TPStatProfile)
|
||||
for _, model := range models {
|
||||
key := &utils.TenantID{Tenant: model.Tenant, ID: model.ID}
|
||||
@@ -1325,6 +1326,7 @@ func (models TpStats) AsTPStats() (result []*utils.TPStatProfile) {
|
||||
TTL: model.TTL,
|
||||
Weight: model.Weight,
|
||||
QueueLength: model.QueueLength,
|
||||
Metrics: make([]*utils.MetricWithFilters, 0),
|
||||
}
|
||||
}
|
||||
if model.ThresholdIDs != "" {
|
||||
@@ -1356,14 +1358,22 @@ func (models TpStats) AsTPStats() (result []*utils.TPStatProfile) {
|
||||
}
|
||||
}
|
||||
if model.MetricIDs != "" {
|
||||
if _, has := statMetricsMap[key.TenantID()]; !has {
|
||||
statMetricsMap[key.TenantID()] = make(map[string]*utils.MetricWithFilters)
|
||||
}
|
||||
metricIDsSplit := strings.Split(model.MetricIDs, utils.INFIELD_SEP)
|
||||
for i, metricID := range metricIDsSplit {
|
||||
st.Metrics = append(st.Metrics, &utils.MetricWithFilters{
|
||||
MetricID: metricID,
|
||||
})
|
||||
if model.MetricFilterIDs != "" {
|
||||
st.Metrics[i].FilterIDs = strings.Split(model.MetricFilterIDs, utils.INFIELD_SEP)
|
||||
for _, metricID := range metricIDsSplit {
|
||||
stsMetric, found := statMetricsMap[key.TenantID()][metricID]
|
||||
if !found {
|
||||
stsMetric = &utils.MetricWithFilters{
|
||||
MetricID: metricID,
|
||||
}
|
||||
}
|
||||
if model.MetricFilterIDs != "" {
|
||||
filterIDs := strings.Split(model.MetricFilterIDs, utils.INFIELD_SEP)
|
||||
stsMetric.FilterIDs = append(stsMetric.FilterIDs, filterIDs...)
|
||||
}
|
||||
statMetricsMap[key.TenantID()][metricID] = stsMetric
|
||||
}
|
||||
}
|
||||
mst[key.TenantID()] = st
|
||||
@@ -1378,6 +1388,9 @@ func (models TpStats) AsTPStats() (result []*utils.TPStatProfile) {
|
||||
for threshold := range thresholdMap[tntID] {
|
||||
result[i].ThresholdIDs = append(result[i].ThresholdIDs, threshold)
|
||||
}
|
||||
for _, metric := range statMetricsMap[tntID] {
|
||||
result[i].Metrics = append(result[i].Metrics, metric)
|
||||
}
|
||||
i++
|
||||
}
|
||||
return
|
||||
|
||||
@@ -590,254 +590,184 @@ func TestAPItoModelResource(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// func TestTPStatsAsTPStats(t *testing.T) {
|
||||
// tps := []*TpStat{
|
||||
// &TpStat{
|
||||
// Tpid: "TEST_TPID",
|
||||
// Tenant: "cgrates.org",
|
||||
// ID: "Stats1",
|
||||
// FilterIDs: "FLTR_1",
|
||||
// ActivationInterval: "2014-07-29T15:00:00Z",
|
||||
// QueueLength: 100,
|
||||
// TTL: "1s",
|
||||
// MinItems: 2,
|
||||
// MetricIDs: "*asr;*acc;*tcc;*acd;*tcd;*pdd",
|
||||
// Stored: true,
|
||||
// Blocker: true,
|
||||
// Weight: 20.0,
|
||||
// },
|
||||
// &TpStat{
|
||||
// Tpid: "TEST_TPID",
|
||||
// Tenant: "cgrates.org",
|
||||
// ID: "Stats1",
|
||||
// FilterIDs: "FLTR_1",
|
||||
// ActivationInterval: "2014-07-29T15:00:00Z",
|
||||
// QueueLength: 100,
|
||||
// TTL: "1s",
|
||||
// MinItems: 2,
|
||||
// MetricIDs: "*sum#BalanceValue;*average#BalanceValue;*tcc",
|
||||
// ThresholdIDs: "THRESH3",
|
||||
// Stored: true,
|
||||
// Blocker: true,
|
||||
// Weight: 20.0,
|
||||
// },
|
||||
// &TpStat{
|
||||
// Tpid: "TEST_TPID",
|
||||
// Tenant: "itsyscom.com",
|
||||
// ID: "Stats1",
|
||||
// FilterIDs: "FLTR_1",
|
||||
// ActivationInterval: "2014-07-29T15:00:00Z",
|
||||
// QueueLength: 100,
|
||||
// TTL: "1s",
|
||||
// MinItems: 2,
|
||||
// MetricIDs: "*sum#BalanceValue;*average#BalanceValue;*tcc",
|
||||
// ThresholdIDs: "THRESH4",
|
||||
// Stored: true,
|
||||
// Blocker: true,
|
||||
// Weight: 20.0,
|
||||
// },
|
||||
// }
|
||||
// eTPs := []*utils.TPStatProfile{
|
||||
// &utils.TPStatProfile{
|
||||
// TPid: tps[0].Tpid,
|
||||
// Tenant: tps[0].Tenant,
|
||||
// ID: tps[0].ID,
|
||||
// FilterIDs: []string{"FLTR_1"},
|
||||
// ActivationInterval: &utils.TPActivationInterval{
|
||||
// ActivationTime: tps[0].ActivationInterval,
|
||||
// },
|
||||
// QueueLength: tps[0].QueueLength,
|
||||
// TTL: tps[0].TTL,
|
||||
// Metrics: []*utils.MetricWithFilters{
|
||||
// &utils.MetricWithFilters{
|
||||
// MetricID: "*asr",
|
||||
// },
|
||||
// &utils.MetricWithFilters{
|
||||
// MetricID: "*acc",
|
||||
// },
|
||||
// &utils.MetricWithFilters{
|
||||
// MetricID: "*tcc",
|
||||
// },
|
||||
// &utils.MetricWithFilters{
|
||||
// MetricID: "*acd",
|
||||
// },
|
||||
// &utils.MetricWithFilters{
|
||||
// MetricID: "*tcd",
|
||||
// },
|
||||
// &utils.MetricWithFilters{
|
||||
// MetricID: "*pdd",
|
||||
// },
|
||||
// &utils.MetricWithFilters{
|
||||
// MetricID: "*sum#BalanceValue",
|
||||
// },
|
||||
// &utils.MetricWithFilters{
|
||||
// MetricID: "*average#BalanceValue",
|
||||
// },
|
||||
// &utils.MetricWithFilters{
|
||||
// MetricID: "*tcc",
|
||||
// },
|
||||
// },
|
||||
// MinItems: tps[0].MinItems,
|
||||
// ThresholdIDs: []string{"THRESH3"},
|
||||
// Stored: tps[0].Stored,
|
||||
// Blocker: tps[0].Blocker,
|
||||
// Weight: tps[0].Weight,
|
||||
// },
|
||||
// &utils.TPStatProfile{
|
||||
// TPid: tps[0].Tpid,
|
||||
// ID: tps[0].ID,
|
||||
// Tenant: tps[2].Tenant,
|
||||
// FilterIDs: []string{"FLTR_1"},
|
||||
// ActivationInterval: &utils.TPActivationInterval{
|
||||
// ActivationTime: tps[0].ActivationInterval,
|
||||
// },
|
||||
// QueueLength: tps[0].QueueLength,
|
||||
// TTL: tps[0].TTL,
|
||||
// Metrics: []*utils.MetricWithFilters{
|
||||
// &utils.MetricWithFilters{
|
||||
// MetricID: "*sum#BalanceValue",
|
||||
// },
|
||||
// &utils.MetricWithFilters{
|
||||
// MetricID: "*average#BalanceValue",
|
||||
// },
|
||||
// &utils.MetricWithFilters{
|
||||
// MetricID: "*tcc",
|
||||
// },
|
||||
// },
|
||||
// MinItems: tps[0].MinItems,
|
||||
// ThresholdIDs: []string{"THRESH4"},
|
||||
// Stored: tps[0].Stored,
|
||||
// Blocker: tps[0].Blocker,
|
||||
// Weight: tps[0].Weight,
|
||||
// },
|
||||
// }
|
||||
// rcvTPs := TpStats(tps).AsTPStats()
|
||||
// if len(rcvTPs) != 2 {
|
||||
// t.Errorf("Expecting: 2, received: %+v", len(rcvTPs))
|
||||
// } else if !reflect.DeepEqual(rcvTPs, eTPs) {
|
||||
// t.Errorf("Expecting: %+v, \n received: %+v", utils.ToJSON(eTPs), utils.ToJSON(rcvTPs))
|
||||
// }
|
||||
// }
|
||||
func TestTPStatsAsTPStats(t *testing.T) {
|
||||
tps := TpStats{
|
||||
&TpStat{
|
||||
Tpid: "TEST_TPID",
|
||||
Tenant: "cgrates.org",
|
||||
ID: "Stats1",
|
||||
FilterIDs: "FLTR_1",
|
||||
ActivationInterval: "2014-07-29T15:00:00Z",
|
||||
QueueLength: 100,
|
||||
TTL: "1s",
|
||||
MinItems: 2,
|
||||
MetricIDs: "*asr;*acc;*tcc;*acd;*tcd;*pdd",
|
||||
Stored: true,
|
||||
Blocker: true,
|
||||
Weight: 20.0,
|
||||
},
|
||||
&TpStat{
|
||||
Tpid: "TEST_TPID",
|
||||
Tenant: "cgrates.org",
|
||||
ID: "Stats1",
|
||||
FilterIDs: "FLTR_1",
|
||||
ActivationInterval: "2014-07-29T15:00:00Z",
|
||||
QueueLength: 100,
|
||||
TTL: "1s",
|
||||
MinItems: 2,
|
||||
MetricIDs: "*sum#BalanceValue;*average#BalanceValue;*tcc",
|
||||
ThresholdIDs: "THRESH3",
|
||||
Stored: true,
|
||||
Blocker: true,
|
||||
Weight: 20.0,
|
||||
},
|
||||
&TpStat{
|
||||
Tpid: "TEST_TPID",
|
||||
Tenant: "itsyscom.com",
|
||||
ID: "Stats1",
|
||||
FilterIDs: "FLTR_1",
|
||||
ActivationInterval: "2014-07-29T15:00:00Z",
|
||||
QueueLength: 100,
|
||||
TTL: "1s",
|
||||
MinItems: 2,
|
||||
MetricIDs: "*sum#BalanceValue;*average#BalanceValue;*tcc",
|
||||
ThresholdIDs: "THRESH4",
|
||||
Stored: true,
|
||||
Blocker: true,
|
||||
Weight: 20.0,
|
||||
},
|
||||
}
|
||||
rcvTPs := tps.AsTPStats()
|
||||
if len(rcvTPs) != 2 {
|
||||
t.Errorf("Expecting: 2, received: %+v", len(rcvTPs))
|
||||
}
|
||||
for _, rcvTP := range rcvTPs {
|
||||
if rcvTP.Tenant == "cgrates.org" {
|
||||
if len(rcvTP.Metrics) != 8 {
|
||||
t.Errorf("Expecting: 8, received: %+v", len(rcvTP.Metrics))
|
||||
}
|
||||
} else {
|
||||
if len(rcvTP.Metrics) != 3 {
|
||||
t.Errorf("Expecting: 3, received: %+v", len(rcvTP.Metrics))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// func TestAPItoTPStats(t *testing.T) {
|
||||
// tps := &utils.TPStatProfile{
|
||||
// TPid: testTPID,
|
||||
// ID: "Stats1",
|
||||
// FilterIDs: []string{"FLTR_1"},
|
||||
// ActivationInterval: &utils.TPActivationInterval{ActivationTime: "2014-07-29T15:00:00Z"},
|
||||
// QueueLength: 100,
|
||||
// TTL: "1s",
|
||||
// Metrics: []*utils.MetricWithFilters{
|
||||
// &utils.MetricWithFilters{
|
||||
// MetricID: "*sum#BalanceValue",
|
||||
// },
|
||||
// &utils.MetricWithFilters{
|
||||
// MetricID: "*average#BalanceValue",
|
||||
// },
|
||||
// &utils.MetricWithFilters{
|
||||
// MetricID: "*tcc",
|
||||
// },
|
||||
// },
|
||||
// MinItems: 1,
|
||||
// ThresholdIDs: []string{"THRESH1", "THRESH2"},
|
||||
// Stored: false,
|
||||
// Blocker: false,
|
||||
// Weight: 20.0,
|
||||
// }
|
||||
func TestAPItoTPStats(t *testing.T) {
|
||||
tps := &utils.TPStatProfile{
|
||||
TPid: testTPID,
|
||||
ID: "Stats1",
|
||||
FilterIDs: []string{"FLTR_1"},
|
||||
ActivationInterval: &utils.TPActivationInterval{ActivationTime: "2014-07-29T15:00:00Z"},
|
||||
QueueLength: 100,
|
||||
TTL: "1s",
|
||||
Metrics: []*utils.MetricWithFilters{
|
||||
&utils.MetricWithFilters{
|
||||
MetricID: "*sum#BalanceValue",
|
||||
},
|
||||
&utils.MetricWithFilters{
|
||||
MetricID: "*average#BalanceValue",
|
||||
},
|
||||
&utils.MetricWithFilters{
|
||||
MetricID: "*tcc",
|
||||
},
|
||||
},
|
||||
MinItems: 1,
|
||||
ThresholdIDs: []string{"THRESH1", "THRESH2"},
|
||||
Stored: false,
|
||||
Blocker: false,
|
||||
Weight: 20.0,
|
||||
}
|
||||
eTPs := &StatQueueProfile{ID: tps.ID,
|
||||
QueueLength: tps.QueueLength,
|
||||
Metrics: []*MetricWithFilters{
|
||||
&MetricWithFilters{
|
||||
MetricID: "*sum#BalanceValue",
|
||||
},
|
||||
&MetricWithFilters{
|
||||
MetricID: "*average#BalanceValue",
|
||||
},
|
||||
&MetricWithFilters{
|
||||
MetricID: "*tcc",
|
||||
},
|
||||
},
|
||||
ThresholdIDs: []string{"THRESH1", "THRESH2"},
|
||||
FilterIDs: []string{"FLTR_1"},
|
||||
Stored: tps.Stored,
|
||||
Blocker: tps.Blocker,
|
||||
Weight: 20.0,
|
||||
MinItems: tps.MinItems,
|
||||
}
|
||||
if eTPs.TTL, err = utils.ParseDurationWithNanosecs(tps.TTL); err != nil {
|
||||
t.Errorf("Got error: %+v", err)
|
||||
}
|
||||
at, _ := utils.ParseTimeDetectLayout("2014-07-29T15:00:00Z", "UTC")
|
||||
eTPs.ActivationInterval = &utils.ActivationInterval{ActivationTime: at}
|
||||
|
||||
// eTPs := &StatQueueProfile{ID: tps.ID,
|
||||
// QueueLength: tps.QueueLength,
|
||||
// Metrics: []*MetricWithFilters{
|
||||
// &MetricWithFilters{
|
||||
// MetricID: "*sum#BalanceValue",
|
||||
// },
|
||||
// &MetricWithFilters{
|
||||
// MetricID: "*average#BalanceValue",
|
||||
// },
|
||||
// &MetricWithFilters{
|
||||
// MetricID: "*tcc",
|
||||
// },
|
||||
// },
|
||||
// ThresholdIDs: []string{"THRESH1", "THRESH2"},
|
||||
// FilterIDs: []string{"FLTR_1"},
|
||||
// Stored: tps.Stored,
|
||||
// Blocker: tps.Blocker,
|
||||
// Weight: 20.0,
|
||||
// MinItems: tps.MinItems,
|
||||
// }
|
||||
// if eTPs.TTL, err = utils.ParseDurationWithNanosecs(tps.TTL); err != nil {
|
||||
// t.Errorf("Got error: %+v", err)
|
||||
// }
|
||||
// at, _ := utils.ParseTimeDetectLayout("2014-07-29T15:00:00Z", "UTC")
|
||||
// eTPs.ActivationInterval = &utils.ActivationInterval{ActivationTime: at}
|
||||
if st, err := APItoStats(tps, "UTC"); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(eTPs, st) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", eTPs, st)
|
||||
}
|
||||
}
|
||||
|
||||
// if st, err := APItoStats(tps, "UTC"); err != nil {
|
||||
// t.Error(err)
|
||||
// } else if !reflect.DeepEqual(eTPs, st) {
|
||||
// t.Errorf("Expecting: %+v, received: %+v", eTPs, st)
|
||||
// }
|
||||
// }
|
||||
|
||||
// func TestAPItoModelStats(t *testing.T) {
|
||||
// tpS := &utils.TPStatProfile{
|
||||
// TPid: "TPS1",
|
||||
// Tenant: "cgrates.org",
|
||||
// ID: "Stat1",
|
||||
// FilterIDs: []string{"*string:Account:1002"},
|
||||
// ActivationInterval: &utils.TPActivationInterval{
|
||||
// ActivationTime: "2014-07-29T15:00:00Z",
|
||||
// ExpiryTime: "",
|
||||
// },
|
||||
// QueueLength: 100,
|
||||
// TTL: "1s",
|
||||
// Metrics: []*utils.MetricWithFilters{
|
||||
// &utils.MetricWithFilters{
|
||||
// MetricID: "*tcc",
|
||||
// },
|
||||
// &utils.MetricWithFilters{
|
||||
// MetricID: "*average#Usage",
|
||||
// },
|
||||
// },
|
||||
// Blocker: true,
|
||||
// Stored: true,
|
||||
// Weight: 20,
|
||||
// MinItems: 2,
|
||||
// ThresholdIDs: []string{"Th1", "Th2", "Th3", "Th4"},
|
||||
// }
|
||||
// rcv := APItoModelStats(tpS)
|
||||
// eRcv := []*TpStat{
|
||||
// &TpStat{
|
||||
// Tpid: "TPS1",
|
||||
// Tenant: "cgrates.org",
|
||||
// ID: "Stat1",
|
||||
// FilterIDs: "*string:Account:1002",
|
||||
// ActivationInterval: "2014-07-29T15:00:00Z",
|
||||
// QueueLength: 100,
|
||||
// TTL: "1s",
|
||||
// MinItems: 2,
|
||||
// MetricIDs: "*tcc;*sum:Value;*average:Value;*sum:Cost;*average:Usage",
|
||||
// ThresholdIDs: "Th1;Th2;Th3;Th4",
|
||||
// Stored: true,
|
||||
// Blocker: true,
|
||||
// Weight: 20.0,
|
||||
// },
|
||||
// }
|
||||
// if !reflect.DeepEqual(eRcv[0].Tenant, rcv[0].Tenant) {
|
||||
// t.Errorf("Expecting: %+v, received: %+v", eRcv[0].Tenant, rcv[0].Tenant)
|
||||
// } else if !reflect.DeepEqual(eRcv[0].ID, rcv[0].ID) {
|
||||
// t.Errorf("Expecting: %+v, received: %+v", eRcv[0].ID, rcv[0].ID)
|
||||
// } else if !reflect.DeepEqual(eRcv[0].FilterIDs, rcv[0].FilterIDs) {
|
||||
// t.Errorf("Expecting: %+v, received: %+v", eRcv[0].FilterIDs, rcv[0].FilterIDs)
|
||||
// } else if !reflect.DeepEqual(eRcv[0].ActivationInterval, rcv[0].ActivationInterval) {
|
||||
// t.Errorf("Expecting: %+v, received: %+v", eRcv[0].ActivationInterval, rcv[0].ActivationInterval)
|
||||
// } else if !reflect.DeepEqual(eRcv[0].QueueLength, rcv[0].QueueLength) {
|
||||
// t.Errorf("Expecting: %+v, received: %+v", eRcv[0].QueueLength, rcv[0].QueueLength)
|
||||
// } else if !reflect.DeepEqual(len(eRcv[0].MetricIDs), len(rcv[0].MetricIDs)) {
|
||||
// t.Errorf("Expecting: %+v, received: %+v", len(eRcv[0].MetricIDs), len(rcv[0].MetricIDs))
|
||||
// } else if !reflect.DeepEqual(len(eRcv[0].ThresholdIDs), len(rcv[0].ThresholdIDs)) {
|
||||
// t.Errorf("Expecting: %+v, received: %+v", len(eRcv[0].ThresholdIDs), len(rcv[0].ThresholdIDs))
|
||||
// }
|
||||
// }
|
||||
func TestAPItoModelStats(t *testing.T) {
|
||||
tpS := &utils.TPStatProfile{
|
||||
TPid: "TPS1",
|
||||
Tenant: "cgrates.org",
|
||||
ID: "Stat1",
|
||||
FilterIDs: []string{"*string:Account:1002"},
|
||||
ActivationInterval: &utils.TPActivationInterval{
|
||||
ActivationTime: "2014-07-29T15:00:00Z",
|
||||
ExpiryTime: "",
|
||||
},
|
||||
QueueLength: 100,
|
||||
TTL: "1s",
|
||||
Metrics: []*utils.MetricWithFilters{
|
||||
&utils.MetricWithFilters{
|
||||
MetricID: "*tcc",
|
||||
},
|
||||
&utils.MetricWithFilters{
|
||||
MetricID: "*average#Usage",
|
||||
},
|
||||
},
|
||||
Blocker: true,
|
||||
Stored: true,
|
||||
Weight: 20,
|
||||
MinItems: 2,
|
||||
ThresholdIDs: []string{"Th1"},
|
||||
}
|
||||
rcv := APItoModelStats(tpS)
|
||||
eRcv := TpStats{
|
||||
&TpStat{
|
||||
Tpid: "TPS1",
|
||||
Tenant: "cgrates.org",
|
||||
ID: "Stat1",
|
||||
FilterIDs: "*string:Account:1002",
|
||||
ActivationInterval: "2014-07-29T15:00:00Z",
|
||||
QueueLength: 100,
|
||||
TTL: "1s",
|
||||
MinItems: 2,
|
||||
MetricIDs: "*tcc",
|
||||
Stored: true,
|
||||
Blocker: true,
|
||||
Weight: 20.0,
|
||||
ThresholdIDs: "Th1",
|
||||
},
|
||||
&TpStat{
|
||||
Tpid: "TPS1",
|
||||
Tenant: "cgrates.org",
|
||||
ID: "Stat1",
|
||||
MetricIDs: "*average#Usage",
|
||||
},
|
||||
}
|
||||
if len(rcv) != len(eRcv) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", len(eRcv), len(rcv))
|
||||
} else if !reflect.DeepEqual(eRcv, rcv) {
|
||||
t.Errorf("Expecting: %+v, \n received: %+v", utils.ToJSON(eRcv), utils.ToJSON(rcv))
|
||||
}
|
||||
}
|
||||
|
||||
func TestTPThresholdsAsTPThreshold(t *testing.T) {
|
||||
tps := []*TpThreshold{
|
||||
|
||||
@@ -379,7 +379,7 @@ func (ms *MongoStorage) GetTPResources(tpid, tenant, id string) ([]*utils.TPReso
|
||||
filter["tenant"] = tenant
|
||||
}
|
||||
var results []*utils.TPResourceProfile
|
||||
err := ms.query( func(sctx mongo.SessionContext) (err error) {
|
||||
err := ms.query(func(sctx mongo.SessionContext) (err error) {
|
||||
cur, err := ms.getCol(utils.TBLTPResources).Find(sctx, filter)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -411,7 +411,7 @@ func (ms *MongoStorage) GetTPStats(tpid, tenant, id string) ([]*utils.TPStatProf
|
||||
filter["tenant"] = tenant
|
||||
}
|
||||
var results []*utils.TPStatProfile
|
||||
err := ms.query( func(sctx mongo.SessionContext) (err error) {
|
||||
err := ms.query(func(sctx mongo.SessionContext) (err error) {
|
||||
cur, err := ms.getCol(utils.TBLTPStats).Find(sctx, filter)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -1178,19 +1178,8 @@ func (ms *MongoStorage) GetTPThresholds(tpid, tenant, id string) ([]*utils.TPThr
|
||||
if tenant != "" {
|
||||
filter["tenant"] = tenant
|
||||
}
|
||||
<<<<<<< HEAD
|
||||
var results []*utils.TPThreshold
|
||||
<<<<<<< HEAD
|
||||
err := ms.query(func(sctx mongo.SessionContext) (err error) {
|
||||
=======
|
||||
ctxSession, ctxSessionCancel := context.WithTimeout(ms.ctx, ms.ctxTTL)
|
||||
defer ctxSessionCancel()
|
||||
err := ms.client.UseSession(ctxSession, func(sctx mongo.SessionContext) (err error) {
|
||||
=======
|
||||
var results []*utils.TPThresholdProfile
|
||||
err := ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) {
|
||||
>>>>>>> Make Engine build
|
||||
>>>>>>> Make Engine build
|
||||
cur, err := ms.getCol(utils.TBLTPThresholds).Find(sctx, filter)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -1572,12 +1572,12 @@ func (tpr *TpReader) WriteToDatabase(flush, verbose, disable_reverse bool) (err
|
||||
for _, sqTntID := range tpr.statQueues {
|
||||
metrics := make(map[string]StatMetric)
|
||||
for _, metric := range tpr.sqProfiles[utils.TenantID{Tenant: sqTntID.Tenant, ID: sqTntID.ID}].Metrics {
|
||||
if statMetric, err := NewStatMetric(metric.MetricID,
|
||||
if stsMetric, err := NewStatMetric(metric.MetricID,
|
||||
tpr.sqProfiles[utils.TenantID{Tenant: sqTntID.Tenant, ID: sqTntID.ID}].MinItems,
|
||||
metric.FilterIDs); err != nil {
|
||||
return err
|
||||
} else {
|
||||
metrics[metric.MetricID] = statMetric
|
||||
metrics[metric.MetricID] = stsMetric
|
||||
}
|
||||
}
|
||||
sq := &StatQueue{Tenant: sqTntID.Tenant, ID: sqTntID.ID, SQMetrics: metrics}
|
||||
|
||||
@@ -577,9 +577,9 @@ cgrates.org,THD_ACNT_1002,*string:Account:1002,2014-07-29T15:00:00Z,-1,1,1s,true
|
||||
|
||||
func TestLoaderProcessStats(t *testing.T) {
|
||||
statsCSV := `
|
||||
#Tenant[0],Id[1],FilterIDs[2],ActivationInterval[3],QueueLength[4],TTL[5],Metrics[6],Blocker[7],Stored[8],Weight[9],MinItems[10],ThresholdIDs[11]
|
||||
cgrates.org,Stats1,*string:Account:1001;*string:Account:1002,2014-07-29T15:00:00Z,100,1s,*asr;*acc;*tcc;*acd;*tcd;*pdd,true,true,20,2,THRESH1;THRESH2
|
||||
cgrates.org,Stats1,*string:Account:1003,2014-07-29T15:00:00Z,100,1s,*sum#Value;*average#Value,true,true,20,2,THRESH1;THRESH2
|
||||
#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,*string:Account:1001;*string:Account:1002,2014-07-29T15:00:00Z,100,1s,2,*asr;*acc;*tcc;*acd;*tcd;*pdd,,true,true,20,THRESH1;THRESH2
|
||||
cgrates.org,Stats1,*string:Account:1003,2014-07-29T15:00:00Z,100,1s,2,*sum#Value;*average#Value,,true,true,20,THRESH1;THRESH2
|
||||
`
|
||||
data, _ := engine.NewMapStorage()
|
||||
ldr := &Loader{
|
||||
@@ -616,30 +616,35 @@ cgrates.org,Stats1,*string:Account:1003,2014-07-29T15:00:00Z,100,1s,*sum#Value;*
|
||||
FieldId: "TTL",
|
||||
Type: utils.META_COMPOSED,
|
||||
Value: config.NewRSRParsersMustCompile("~5", true, utils.INFIELD_SEP)},
|
||||
&config.FCTemplate{Tag: "Metrics",
|
||||
FieldId: "Metrics",
|
||||
Type: utils.META_COMPOSED,
|
||||
Value: config.NewRSRParsersMustCompile("~6", true, utils.INFIELD_SEP)},
|
||||
&config.FCTemplate{Tag: "Blocker",
|
||||
FieldId: "Blocker",
|
||||
Type: utils.META_COMPOSED,
|
||||
Value: config.NewRSRParsersMustCompile("~7", true, utils.INFIELD_SEP)},
|
||||
&config.FCTemplate{Tag: "Stored",
|
||||
FieldId: "Stored",
|
||||
Type: utils.META_COMPOSED,
|
||||
Value: config.NewRSRParsersMustCompile("~8", true, utils.INFIELD_SEP)},
|
||||
&config.FCTemplate{Tag: "Weight",
|
||||
FieldId: "Weight",
|
||||
Type: utils.META_COMPOSED,
|
||||
Value: config.NewRSRParsersMustCompile("~9", true, utils.INFIELD_SEP)},
|
||||
&config.FCTemplate{Tag: "MinItems",
|
||||
FieldId: "MinItems",
|
||||
Type: utils.META_COMPOSED,
|
||||
Value: config.NewRSRParsersMustCompile("~6", true, utils.INFIELD_SEP)},
|
||||
&config.FCTemplate{Tag: "Metrics",
|
||||
FieldId: "Metrics",
|
||||
Type: utils.META_COMPOSED,
|
||||
Value: config.NewRSRParsersMustCompile("~7", true, utils.INFIELD_SEP)},
|
||||
&config.FCTemplate{Tag: "MetricFilterIDs",
|
||||
FieldId: "MetricFilterIDs",
|
||||
Type: utils.META_COMPOSED,
|
||||
Value: config.NewRSRParsersMustCompile("~8", true, utils.INFIELD_SEP)},
|
||||
&config.FCTemplate{Tag: "Stored",
|
||||
FieldId: "Stored",
|
||||
Type: utils.META_COMPOSED,
|
||||
Value: config.NewRSRParsersMustCompile("~9", true, utils.INFIELD_SEP)},
|
||||
&config.FCTemplate{Tag: "Blocker",
|
||||
FieldId: "Blocker",
|
||||
Type: utils.META_COMPOSED,
|
||||
Value: config.NewRSRParsersMustCompile("~10", true, utils.INFIELD_SEP)},
|
||||
&config.FCTemplate{Tag: "Weight",
|
||||
FieldId: "Weight",
|
||||
Type: utils.META_COMPOSED,
|
||||
Value: config.NewRSRParsersMustCompile("~11", true, utils.INFIELD_SEP)},
|
||||
|
||||
&config.FCTemplate{Tag: "ThresholdIDs",
|
||||
FieldId: "ThresholdIDs",
|
||||
Type: utils.META_COMPOSED,
|
||||
Value: config.NewRSRParsersMustCompile("~11", true, utils.INFIELD_SEP)},
|
||||
Value: config.NewRSRParsersMustCompile("~12", true, utils.INFIELD_SEP)},
|
||||
},
|
||||
}
|
||||
rdr := ioutil.NopCloser(strings.NewReader(statsCSV))
|
||||
|
||||
@@ -91,10 +91,16 @@ func TestV1StatsAsStats(t *testing.T) {
|
||||
FilterIDs: []string{v1Sts.Id},
|
||||
QueueLength: 10,
|
||||
TTL: time.Duration(0) * time.Second,
|
||||
Metrics: []string{
|
||||
"*asr",
|
||||
"*acd",
|
||||
"*acc",
|
||||
Metrics: []*engine.MetricWithFilters{
|
||||
&engine.MetricWithFilters{
|
||||
MetricID: "*asr",
|
||||
},
|
||||
&engine.MetricWithFilters{
|
||||
MetricID: "*acd",
|
||||
},
|
||||
&engine.MetricWithFilters{
|
||||
MetricID: "*acc",
|
||||
},
|
||||
},
|
||||
Blocker: false,
|
||||
ThresholdIDs: []string{"TestB"},
|
||||
|
||||
Reference in New Issue
Block a user