Updated *acc and *tcc metrics

This commit is contained in:
Trial97
2021-05-19 11:48:09 +03:00
committed by Dan Christian Bogos
parent 49a5ee839a
commit 1175f5fdc6
4 changed files with 19 additions and 1 deletions

View File

@@ -556,6 +556,8 @@ func (acc *StatACC) AddEvent(evID string, ev utils.DataProvider) (err error) {
return
} else if cost, err = utils.IfaceAsFloat64(val); err != nil {
return
} else if cost < 0 {
return utils.ErrPrefix(utils.ErrNegative, utils.Cost)
}
acc.Sum += cost
if val, has := acc.Events[evID]; !has {
@@ -686,6 +688,8 @@ func (tcc *StatTCC) AddEvent(evID string, ev utils.DataProvider) (err error) {
return
} else if cost, err = utils.IfaceAsFloat64(val); err != nil {
return
} else if cost < 0 {
return utils.ErrPrefix(utils.ErrNegative, utils.Cost)
}
tcc.Sum += cost
if val, has := tcc.Events[evID]; !has {

View File

@@ -1052,6 +1052,12 @@ func TestACCGetStringValue(t *testing.T) {
if strVal := acc.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != utils.NotAvailable {
t.Errorf("wrong acc value: %s", strVal)
}
expErr := "NEGATIVE:Cost"
if err := acc.AddEvent(ev5.ID, utils.MapStorage{utils.MetaReq: utils.MapStorage{
utils.Cost: -1,
}}); err == nil || err.Error() != expErr {
t.Errorf("Expected error: %s received %v", expErr, err)
}
}
func TestACCGetStringValue2(t *testing.T) {
@@ -1322,6 +1328,13 @@ func TestTCCGetStringValue(t *testing.T) {
if strVal := tcc.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != utils.NotAvailable {
t.Errorf("wrong tcc value: %s", strVal)
}
expErr := "NEGATIVE:Cost"
if err := tcc.AddEvent(ev5.ID, utils.MapStorage{utils.MetaReq: utils.MapStorage{
utils.Cost: -1,
}}); err == nil || err.Error() != expErr {
t.Errorf("Expected error: %s received %v", expErr, err)
}
}
func TestTCCGetStringValue2(t *testing.T) {

View File

@@ -6,7 +6,7 @@ cgrates (1.0) UNRELEASED; urgency=medium
* [ERs] Added *opts.*partial to control if the event is partial or not
* [AttributeS] Added any_context config to control the matching attributes
* [DispatcherS] Added any_subsyste config to control the matching dispatchers
* [StatS] AverageCallCost and TotalCallCost now returns error for negative Cost field
-- DanB <danb@cgrates.org> Thu, 4 May 2021 12:05:00 +0200

View File

@@ -73,6 +73,7 @@ var (
ErrMaxConcurentRPCExceededNoCaps = errors.New("max concurent rpc exceeded") // on internal we return this error for concureq
ErrMaxConcurentRPCExceeded = errors.New("MAX_CONCURENT_RPC_EXCEEDED") // but the codec will rewrite it with this one to be sure that we corectly dealocate the request
ErrMaxIterationsReached = errors.New("maximum iterations reached")
ErrNegative = errors.New("NEGATIVE")
ErrMap = map[string]error{
ErrNoMoreData.Error(): ErrNoMoreData,