From 40d56f2781e5e902c3328f3cfd05fcd5665e6bab Mon Sep 17 00:00:00 2001 From: porosnicuadrian Date: Wed, 9 Mar 2022 15:40:39 +0200 Subject: [PATCH] Tested *json dataConverter on sql exporter --- data/conf/samples/ees/cgrates.json | 13 +-- ees/sql_it_test.go | 136 ++++++++++++++++++++++++++++- engine/argees.go | 1 - 3 files changed, 139 insertions(+), 11 deletions(-) diff --git a/data/conf/samples/ees/cgrates.json b/data/conf/samples/ees/cgrates.json index 8881c970f..e895f3f98 100644 --- a/data/conf/samples/ees/cgrates.json +++ b/data/conf/samples/ees/cgrates.json @@ -80,7 +80,7 @@ "attempts": 1, "field_separator": ",", "fields":[ - {"tag": "Number", "path": "*hdr.Number", "type": "*constant", "value": "NumberOfEvent"}, + {"tag": "Number", "path": "*hdr.Number", "type": "*constant", "value": "NumberOfEvent"}, {"tag": "CGRID", "path": "*hdr.CGRID", "type": "*constant", "value": "CGRID"}, {"tag": "RunID", "path": "*hdr.RunID", "type": "*constant", "value": "RunID"}, {"tag": "ToR", "path": "*hdr.ToR", "type": "*constant", "value": "ToR"}, @@ -96,9 +96,9 @@ {"tag": "Usage", "path": "*hdr.Usage", "type": "*constant", "value": "Usage"}, {"tag": "Cost", "path": "*hdr.Cost", "type": "*constant", "value": "Cost"}, {"tag": "RatingPlan", "path": "*hdr.RatingPlan", "type": "*constant", "value": "RatingPlan"}, - {"tag": "RatingPlanSubject", "path": "*hdr.RatingPlanSubject", "type": "*constant", "value": "RatingPlanSubject"}, + {"tag": "RatingPlanSubject", "path": "*hdr.RatingPlanSubject", "type": "*constant", "value": "RatingPlanSubject"}, - {"tag": "Number", "path": "*exp.Number", "type": "*variable", "value": "~*dc.NumberOfEvents"}, + {"tag": "Number", "path": "*exp.Number", "type": "*variable", "value": "~*dc.NumberOfEvents"}, {"tag": "CGRID", "path": "*exp.CGRID", "type": "*variable", "value": "~*req.CGRID"}, {"tag": "RunID", "path": "*exp.RunID", "type": "*variable", "value": "~*req.RunID"}, {"tag": "ToR", "path": "*exp.ToR", "type": "*variable", "value": "~*req.ToR"}, @@ -115,12 +115,12 @@ {"tag": "Usage", "path": "*exp.Usage", "type": "*variable", "value": "~*req.Usage"}, {"tag": "Cost", "path": "*exp.Cost", "type": "*variable", "value": "~*req.Cost{*round:4}"}, {"tag": "RatingPlan", "path": "*exp.RatingPlan", "type": "*variable", "value": "~*ec.CostDetails.Charges[0].Rating.RatingFilter.RatingPlanID"}, - {"tag": "RatingPlanSubject", "path": "*exp.RatingPlanSubject", "type": "*variable", "value": "~*ec.CostDetails.Charges[0].Rating.RatingFilter.Subject"}, - + {"tag": "RatingPlanSubject", "path": "*exp.RatingPlanSubject", "type": "*variable", "value": "~*ec.CostDetails.Charges[0].Rating.RatingFilter.Subject"}, + {"tag": "NumberOfEvents", "path": "*trl.NumberOfEvents", "type": "*variable", "value": "~*dc.NumberOfEvents"}, {"tag": "TotalDuration", "path": "*trl.TotalDuration", "type": "*variable", "value": "~*dc.TotalDuration"}, {"tag": "TotalSMSUsage", "path": "*trl.TotalSMSUsage", "type": "*variable", "value": "~*dc.TotalSMSUsage"}, - {"tag": "TotalCost", "path": "*trl.TotalCost", "type": "*variable", "value": "~*dc.TotalCost{*round:4}"}, + {"tag": "TotalCost", "path": "*trl.TotalCost", "type": "*variable", "value": "~*dc.TotalCost{*round:4}"}, ], }, { @@ -400,6 +400,7 @@ {"tag": "AnswerTime", "path": "*exp.*row", "type": "*group", "value": "~*req.AnswerTime"}, {"tag": "Usage", "path": "*exp.*row", "type": "*group", "value": "~*req.Usage"}, {"tag": "Cost", "path": "*exp.*row", "type": "*group", "value": "~*req.Cost{*round:4}"}, + {"tag": "CostDetails", "path": "*exp.*row", "type": "*group", "value": "~*req.CostDetails{*json}"}, ] }, { diff --git a/ees/sql_it_test.go b/ees/sql_it_test.go index 2db913bf2..34dfedde7 100644 --- a/ees/sql_it_test.go +++ b/ees/sql_it_test.go @@ -71,10 +71,11 @@ func TestSqlEeExport(t *testing.T) { // create a struct serve as model for *sql exporter type testModelSql struct { - Cgrid string - AnswerTime time.Time - Usage int64 - Cost float64 + Cgrid string + AnswerTime time.Time + Usage int64 + Cost float64 + CostDetails string } func (*testModelSql) TableName() string { @@ -143,6 +144,132 @@ func testSqlEeRPCConn(t *testing.T) { } func testSqlEeExportEventFull(t *testing.T) { + cd := &engine.EventCost{ + Cost: utils.Float64Pointer(0.264933), + CGRID: "d8534def2b7067f4f5ad4f7ec7bbcc94bb46111a", + Rates: engine.ChargedRates{ + "3db483c": engine.RateGroups{ + { + Value: 0.1574, + RateUnit: 60000000000, + RateIncrement: 30000000000, + GroupIntervalStart: 0, + }, + { + Value: 0.1574, + RateUnit: 60000000000, + RateIncrement: 1000000000, + GroupIntervalStart: 30000000000, + }, + }, + }, + RunID: "*default", + Usage: utils.DurationPointer(101 * time.Second), + Rating: engine.Rating{ + "7f3d423": &engine.RatingUnit{ + MaxCost: 40, + RatesID: "3db483c", + TimingID: "128e970", + ConnectFee: 0, + RoundingMethod: "*up", + MaxCostStrategy: "*disconnect", + RatingFiltersID: "f8e95f2", + RoundingDecimals: 4, + }, + }, + Charges: []*engine.ChargingInterval{ + { + RatingID: "7f3d423", + Increments: []*engine.ChargingIncrement{ + { + Cost: 0.0787, + Usage: 30000000000, + AccountingID: "fee8a3a", + CompressFactor: 1, + }, + }, + CompressFactor: 1, + }, + { + RatingID: "7f3d423", + Increments: []*engine.ChargingIncrement{ + { + Cost: 0.002623, + Usage: 1000000000, + AccountingID: "3463957", + CompressFactor: 71, + }, + }, + CompressFactor: 1, + }, + }, + Timings: engine.ChargedTimings{ + "128e970": &engine.ChargedTiming{ + StartTime: "00:00:00", + }, + }, + StartTime: time.Date(2019, 12, 06, 11, 57, 32, 0, time.UTC), + Accounting: engine.Accounting{ + "3463957": &engine.BalanceCharge{ + Units: 0.002623, + RatingID: "", + AccountID: "cgrates.org:1001", + BalanceUUID: "154419f2-45e0-4629-a203-06034ccb493f", + ExtraChargeID: "", + }, + "fee8a3a": &engine.BalanceCharge{ + Units: 0.0787, + RatingID: "", + AccountID: "cgrates.org:1001", + BalanceUUID: "154419f2-45e0-4629-a203-06034ccb493f", + ExtraChargeID: "", + }, + }, + RatingFilters: engine.RatingFilters{ + "f8e95f2": engine.RatingMatchedFilters{ + "Subject": "*out:cgrates.org:mo_call_UK_Mobile_O2_GBRCN:*any", + "RatingPlanID": "RP_MO_CALL_44800", + "DestinationID": "DST_44800", + "DestinationPrefix": "44800", + }, + }, + AccountSummary: &engine.AccountSummary{ + ID: "234189200129930", + Tenant: "cgrates.org", + Disabled: false, + AllowNegative: false, + BalanceSummaries: engine.BalanceSummaries{ + &engine.BalanceSummary{ + ID: "MOBILE_DATA", + Type: "*data", + UUID: "08a05723-5849-41b9-b6a9-8ee362539280", + Value: 3221225472, + Disabled: false, + }, + &engine.BalanceSummary{ + ID: "MOBILE_SMS", + Type: "*sms", + UUID: "06a87f20-3774-4eeb-826e-a79c5f175fd3", + Value: 247, + Disabled: false, + }, + &engine.BalanceSummary{ + ID: "MOBILE_VOICE", + Type: "*voice", + UUID: "4ad16621-6e22-4e35-958e-5e1ff93ad7b7", + Value: 14270000000000, + Disabled: false, + }, + &engine.BalanceSummary{ + ID: "MONETARY_POSTPAID", + Type: "*monetary", + UUID: "154419f2-45e0-4629-a203-06034ccb493f", + Value: 50, + Disabled: false, + }, + }, + }, + } eventVoice := &engine.CGREventWithEeIDs{ EeIDs: []string{"SQLExporterFull"}, CGREvent: &utils.CGREvent{ @@ -165,6 +292,7 @@ func testSqlEeExportEventFull(t *testing.T) { utils.Usage: 10 * time.Second, utils.RunID: utils.MetaDefault, utils.Cost: 1.01, + utils.CostDetails: utils.ToJSON(cd), "ExtraFields": map[string]string{"extra1": "val_extra1", "extra2": "val_extra2", "extra3": "val_extra3"}, }, diff --git a/engine/argees.go b/engine/argees.go index fa9546c42..c759e9671 100644 --- a/engine/argees.go +++ b/engine/argees.go @@ -52,7 +52,6 @@ func (cgr *CGREventWithEeIDs) UnmarshalJSON(data []byte) (err error) { cgr.CGREvent = cgrEv // check if we have CostDetails and modify it's type (by default it was map[string]interface{} by unrmarshaling, now it will be EventCost) if ecEv, has := cgrEv.Event[utils.CostDetails]; has { - // ee var bts []byte switch ecEv.(type) { case string: