Updated MapEvent.AsCDR to initialize the CostDetails. Fixes #2247

This commit is contained in:
Trial97
2020-06-30 11:30:41 +03:00
parent 5a59cb063e
commit b76d626f6f
6 changed files with 46 additions and 7 deletions

View File

@@ -32,7 +32,7 @@
"store_cdrs": false, // store cdrs in storDb
"chargers_conns":["*internal"],
"rals_conns": ["*internal"],
"online_cdr_exports": ["http_localhost", "amqp_localhost", "http_test_file", "amqp_test_file","aws_test_file","sqs_test_file","kafka_localhost","s3_test_file"],
"online_cdr_exports": ["http_localhost", "amqp_localhost", "http_test_file", "amqp_test_file","aws_test_file","sqs_test_file","kafka_localhost","s3_test_file", "eventcost_filter"],
},
"chargers": {
@@ -128,6 +128,14 @@
{"path": "*exp.CGRID", "type": "*composed", "value": "~*req.CGRID"},
],
},
"eventcost_filter": {
"export_format": "*amqp_json_map",
"export_path": "amqp://guest:guest@wrongurl:25672/?queue_id=cgrates_cdrs",
"filters":["*string:~*ec.Cost:100"],
"fields": [
{"path": "*exp.CGRID", "type": "*composed", "value": "~*req.CGRID"},
],
},
},

View File

@@ -30,7 +30,7 @@
"store_cdrs": false, // store cdrs in storDb
"chargers_conns":["*internal"],
"rals_conns": ["*internal"],
"online_cdr_exports": ["http_localhost", "amqp_localhost", "http_test_file", "amqp_test_file","aws_test_file","sqs_test_file","kafka_localhost","s3_test_file"],
"online_cdr_exports": ["http_localhost", "amqp_localhost", "http_test_file", "amqp_test_file","aws_test_file","sqs_test_file","kafka_localhost","s3_test_file", "eventcost_filter"],
},
"chargers": {
@@ -126,6 +126,14 @@
{"path": "*exp.CGRID", "type": "*composed", "value": "~*req.CGRID"},
],
},
"eventcost_filter": {
"export_format": "*amqp_json_map",
"export_path": "amqp://guest:guest@wrongurl:25672/?queue_id=cgrates_cdrs",
"filters":["*string:~*ec.Cost:100"],
"fields": [
{"path": "*exp.CGRID", "type": "*composed", "value": "~*req.CGRID"},
],
},
},

View File

@@ -265,6 +265,11 @@ func (me MapEvent) AsCDR(cfg *config.CGRConfig, tnt, tmz string) (cdr *CDR, err
}
}
}
if cdr.CostDetails == nil {
cdr.CostDetails = NewBareEventCost()
} else {
cdr.CostDetails.initCache()
}
if cfg != nil {
cdr.AddDefaults(cfg)
}

View File

@@ -311,7 +311,7 @@ func TestMapEventAsMapString(t *testing.T) {
func TestMapEventAsCDR(t *testing.T) {
me := NewMapEvent(nil)
expected := &CDR{Cost: -1.0, ExtraFields: make(map[string]string)}
expected := &CDR{Cost: -1.0, ExtraFields: make(map[string]string), CostDetails: NewBareEventCost()}
if rply, err := me.AsCDR(nil, utils.EmptyString, utils.EmptyString); err != nil {
t.Error(err)
} else if !reflect.DeepEqual(expected, rply) {
@@ -330,6 +330,7 @@ func TestMapEventAsCDR(t *testing.T) {
Tenant: cfg.GeneralCfg().DefaultTenant,
Category: cfg.GeneralCfg().DefaultCategory,
ExtraFields: make(map[string]string),
CostDetails: NewBareEventCost(),
}
if rply, err := me.AsCDR(cfg, utils.EmptyString, utils.EmptyString); err != nil {
t.Error(err)
@@ -371,7 +372,8 @@ func TestMapEventAsCDR(t *testing.T) {
me = MapEvent{"ExtraField1": 5, "ExtraField2": "extra"}
expected = &CDR{
Cost: -1.0,
Cost: -1.0,
CostDetails: NewBareEventCost(),
ExtraFields: map[string]string{
"ExtraField1": "5",
"ExtraField2": "extra",
@@ -403,6 +405,7 @@ func TestMapEventAsCDR(t *testing.T) {
Tenant: cfg.GeneralCfg().DefaultTenant,
Category: cfg.GeneralCfg().DefaultCategory,
ExtraInfo: "ACCOUNT_NOT_FOUND",
CostDetails: NewBareEventCost(),
}
if rply, err := me.AsCDR(cfg, utils.EmptyString, utils.EmptyString); err != nil {
t.Error(err)
@@ -446,7 +449,8 @@ func TestMapEventAsCDR(t *testing.T) {
"ExtraField1": "5",
"ExtraField2": "extra",
},
ExtraInfo: "ACCOUNT_NOT_FOUND",
ExtraInfo: "ACCOUNT_NOT_FOUND",
CostDetails: NewBareEventCost(),
}
if rply, err := me.AsCDR(cfg, utils.EmptyString, utils.EmptyString); err != nil {
t.Error(err)
@@ -629,6 +633,7 @@ func TestMapEventAsCDR(t *testing.T) {
},
},
}
ec1.initCache()
me = MapEvent{
"ExtraField1": 5,
"Source": 1001,

View File

@@ -625,7 +625,7 @@ func TestSafEventAsMapString(t *testing.T) {
func TestSafEventAsCDR(t *testing.T) {
se := SafEvent{Me: NewMapEvent(nil)}
expected := &CDR{Cost: -1.0, ExtraFields: make(map[string]string)}
expected := &CDR{Cost: -1.0, ExtraFields: make(map[string]string), CostDetails: NewBareEventCost()}
if rply, err := se.AsCDR(nil, utils.EmptyString, utils.EmptyString); err != nil {
t.Error(err)
} else if !reflect.DeepEqual(expected, rply) {
@@ -644,6 +644,7 @@ func TestSafEventAsCDR(t *testing.T) {
Tenant: cfg.GeneralCfg().DefaultTenant,
Category: cfg.GeneralCfg().DefaultCategory,
ExtraFields: make(map[string]string),
CostDetails: NewBareEventCost(),
}
if rply, err := se.AsCDR(cfg, utils.EmptyString, utils.EmptyString); err != nil {
t.Error(err)
@@ -676,7 +677,8 @@ func TestSafEventAsCDR(t *testing.T) {
}
se = SafEvent{Me: MapEvent{"ExtraField1": 5, "ExtraField2": "extra"}}
expected = &CDR{
Cost: -1.0,
Cost: -1.0,
CostDetails: NewBareEventCost(),
ExtraFields: map[string]string{
"ExtraField1": "5",
"ExtraField2": "extra",
@@ -706,6 +708,7 @@ func TestSafEventAsCDR(t *testing.T) {
RequestType: cfg.GeneralCfg().DefaultReqType,
Tenant: cfg.GeneralCfg().DefaultTenant,
Category: cfg.GeneralCfg().DefaultCategory,
CostDetails: NewBareEventCost(),
}
if rply, err := se.AsCDR(cfg, utils.EmptyString, utils.EmptyString); err != nil {
t.Error(err)
@@ -739,6 +742,7 @@ func TestSafEventAsCDR(t *testing.T) {
ToR: utils.VOICE,
RequestType: cfg.GeneralCfg().DefaultReqType,
Category: cfg.GeneralCfg().DefaultCategory,
CostDetails: NewBareEventCost(),
}
if rply, err := se.AsCDR(cfg, "itsyscom.com", utils.EmptyString); err != nil {
t.Error(err)

View File

@@ -214,6 +214,9 @@ func testCDRsOnExpDisableOnlineExport(t *testing.T) {
RunID: utils.MetaDefault,
Cost: 1.201,
PreRated: true,
CostDetails: &engine.EventCost{
Cost: utils.Float64Pointer(10),
},
}
var reply string
if err := cdrsMasterRpc.Call(utils.CDRsV1ProcessEvent,
@@ -257,6 +260,9 @@ func testCDRsOnExpHttpCdrReplication(t *testing.T) {
RunID: utils.MetaDefault,
Cost: 1.201,
PreRated: true,
CostDetails: &engine.EventCost{
Cost: utils.Float64Pointer(10),
},
}
var reply string
if err := cdrsMasterRpc.Call(utils.CDRsV1ProcessEvent,
@@ -385,6 +391,9 @@ func testCDRsOnExpAMQPReplication(t *testing.T) {
RunID: utils.MetaDefault,
Cost: 1.201,
PreRated: true,
CostDetails: &engine.EventCost{
Cost: utils.Float64Pointer(10),
},
}
var reply string
if err := cdrsMasterRpc.Call(utils.CDRsV1ProcessEvent,