From cef071533b917fb5d39146cbafdc97ffcbc30ff6 Mon Sep 17 00:00:00 2001 From: DanB Date: Fri, 16 Sep 2016 16:27:01 +0200 Subject: [PATCH] Adding CDRs sm_cost_retries configuration option --- config/config.go | 4 ++++ config/config_defaults.go | 1 + config/config_json_test.go | 1 + config/libconfig_json.go | 1 + engine/cdrs.go | 2 +- 5 files changed, 8 insertions(+), 1 deletion(-) diff --git a/config/config.go b/config/config.go index 3f7e5ff55..26bd29a52 100644 --- a/config/config.go +++ b/config/config.go @@ -233,6 +233,7 @@ type CGRConfig struct { CDRSExtraFields []*utils.RSRField // Extra fields to store in CDRs CDRSStoreCdrs bool // store cdrs in storDb CDRScdrAccountSummary bool + CDRSSMCostRetries int CDRSRaterConns []*HaPoolConfig // address where to reach the Rater for cost calculation: <""|internal|x.y.z.y:1234> CDRSPubSubSConns []*HaPoolConfig // address where to reach the pubsub service: <""|internal|x.y.z.y:1234> CDRSUserSConns []*HaPoolConfig // address where to reach the users service: <""|internal|x.y.z.y:1234> @@ -841,6 +842,9 @@ func (self *CGRConfig) loadFromJsonCfg(jsnCfg *CgrJsonCfg) error { if jsnCdrsCfg.Cdr_account_summary != nil { self.CDRScdrAccountSummary = *jsnCdrsCfg.Cdr_account_summary } + if jsnCdrsCfg.Sm_cost_retries != nil { + self.CDRSSMCostRetries = *jsnCdrsCfg.Sm_cost_retries + } if jsnCdrsCfg.Rals_conns != nil { self.CDRSRaterConns = make([]*HaPoolConfig, len(*jsnCdrsCfg.Rals_conns)) for idx, jsnHaCfg := range *jsnCdrsCfg.Rals_conns { diff --git a/config/config_defaults.go b/config/config_defaults.go index ccf6042df..e67878b2e 100644 --- a/config/config_defaults.go +++ b/config/config_defaults.go @@ -134,6 +134,7 @@ const CGRATES_CFG_JSON = ` "extra_fields": [], // extra fields to store in CDRs for non-generic CDRs "store_cdrs": true, // store cdrs in storDb "cdr_account_summary": false, // add account information from dataDB + "sm_cost_retries": 5, // number of queries to sm_costs before recalculating CDR "rals_conns": [ {"address": "*internal"} // address where to reach the Rater for cost calculation, empty to disable functionality: <""|*internal|x.y.z.y:1234> ], diff --git a/config/config_json_test.go b/config/config_json_test.go index ee4997639..ca9a1576c 100644 --- a/config/config_json_test.go +++ b/config/config_json_test.go @@ -177,6 +177,7 @@ func TestDfCdrsJsonCfg(t *testing.T) { Extra_fields: utils.StringSlicePointer([]string{}), Store_cdrs: utils.BoolPointer(true), Cdr_account_summary: utils.BoolPointer(false), + Sm_cost_retries: utils.IntPointer(5), Rals_conns: &[]*HaPoolJsonCfg{ &HaPoolJsonCfg{ Address: utils.StringPointer("*internal"), diff --git a/config/libconfig_json.go b/config/libconfig_json.go index 710b36998..4826d9601 100644 --- a/config/libconfig_json.go +++ b/config/libconfig_json.go @@ -88,6 +88,7 @@ type CdrsJsonCfg struct { Extra_fields *[]string Store_cdrs *bool Cdr_account_summary *bool + Sm_cost_retries *int Rals_conns *[]*HaPoolJsonCfg Pubsubs_conns *[]*HaPoolJsonCfg Users_conns *[]*HaPoolJsonCfg diff --git a/engine/cdrs.go b/engine/cdrs.go index efe971d19..c6c951770 100644 --- a/engine/cdrs.go +++ b/engine/cdrs.go @@ -365,7 +365,7 @@ func (self *CdrServer) rateCDR(cdr *CDR) ([]*CDR, error) { // Should be previously calculated and stored in DB delay := utils.Fib() var smCosts []*SMCost - for i := 0; i < 4; i++ { + for i := 0; i < self.cgrCfg.CDRSSMCostRetries; i++ { smCosts, err = self.cdrDb.GetSMCosts(cdr.CGRID, cdr.RunID, cdr.OriginHost, cdr.ExtraFields[utils.OriginIDPrefix]) if err == nil && len(smCosts) != 0 { break