mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Add max_increments option in config in rals section
This commit is contained in:
committed by
Dan Christian Bogos
parent
6994300b0b
commit
ed29e92835
@@ -175,6 +175,7 @@ const CGRATES_CFG_JSON = `
|
||||
"*data": "107374182400",
|
||||
"*sms": "10000"
|
||||
},
|
||||
"max_increments": 1000000,
|
||||
"balance_rating_subject":{ // default rating subject in case that balance rating subject is empty
|
||||
"*any": "*zero1ns",
|
||||
"*voice": "*zero1s",
|
||||
|
||||
@@ -238,6 +238,7 @@ func TestDfRalsJsonCfg(t *testing.T) {
|
||||
utils.VOICE: "72h",
|
||||
utils.DATA: "107374182400",
|
||||
utils.SMS: "10000"},
|
||||
Max_increments: utils.IntPointer(1000000),
|
||||
Balance_rating_subject: &map[string]string{
|
||||
utils.ANY: "*zero1ns",
|
||||
utils.VOICE: "*zero1s",
|
||||
|
||||
@@ -473,6 +473,9 @@ func TestCgrCfgJSONDefaultsRALs(t *testing.T) {
|
||||
if !reflect.DeepEqual(eMaxCU, cgrCfg.RalsCfg().RALsMaxComputedUsage) {
|
||||
t.Errorf("Expecting: %+v , received: %+v", eMaxCU, cgrCfg.RalsCfg().RALsMaxComputedUsage)
|
||||
}
|
||||
if cgrCfg.RalsCfg().RALsMaxIncrements != int(1000000) {
|
||||
t.Errorf("Expecting: 1000000 , received: %+v", cgrCfg.RalsCfg().RALsMaxIncrements)
|
||||
}
|
||||
eBalRatingSbj := map[string]string{
|
||||
utils.ANY: "*zero1ns",
|
||||
utils.VOICE: "*zero1s",
|
||||
|
||||
@@ -105,6 +105,7 @@ type RalsJsonCfg struct {
|
||||
Rp_subject_prefix_matching *bool
|
||||
Remove_expired *bool
|
||||
Max_computed_usage *map[string]string
|
||||
Max_increments *int
|
||||
Balance_rating_subject *map[string]string
|
||||
}
|
||||
|
||||
|
||||
@@ -33,6 +33,7 @@ type RalsCfg struct {
|
||||
RemoveExpired bool
|
||||
RALsMaxComputedUsage map[string]time.Duration
|
||||
RALsBalanceRatingSubject map[string]string
|
||||
RALsMaxIncrements int
|
||||
}
|
||||
|
||||
//loadFromJsonCfg loads Rals config from JsonCfg
|
||||
@@ -70,6 +71,9 @@ func (ralsCfg *RalsCfg) loadFromJsonCfg(jsnRALsCfg *RalsJsonCfg) (err error) {
|
||||
}
|
||||
}
|
||||
}
|
||||
if jsnRALsCfg.Max_increments != nil {
|
||||
ralsCfg.RALsMaxIncrements = *jsnRALsCfg.Max_increments
|
||||
}
|
||||
if jsnRALsCfg.Balance_rating_subject != nil {
|
||||
for k, v := range *jsnRALsCfg.Balance_rating_subject {
|
||||
ralsCfg.RALsBalanceRatingSubject[k] = v
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
|
||||
"rals": {
|
||||
"enabled": true,
|
||||
"max_increments":3000000,
|
||||
},
|
||||
|
||||
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
|
||||
"rals": {
|
||||
"enabled": true,
|
||||
"max_increments":3000000,
|
||||
},
|
||||
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
"thresholds_conns": [
|
||||
{"address": "*internal"}
|
||||
],
|
||||
"max_increments":3000000,
|
||||
},
|
||||
|
||||
|
||||
|
||||
@@ -19,9 +19,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
package engine
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"time"
|
||||
|
||||
"github.com/cgrates/cgrates/config"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
@@ -461,6 +463,10 @@ func (ts *TimeSpan) createIncrementsSlice() {
|
||||
// because ts cost is rounded
|
||||
//incrementCost := rate / rateUnit.Seconds() * rateIncrement.Seconds()
|
||||
nbIncrements := int(ts.GetDuration() / rateIncrement)
|
||||
if nbIncrements > config.CgrConfig().RalsCfg().RALsMaxIncrements {
|
||||
utils.Logger.Warning(fmt.Sprintf("error: <%s with %+v>, when creating increments slice", utils.ErrMaxIncrementsExceeded, nbIncrements))
|
||||
return
|
||||
}
|
||||
incrementCost := ts.CalculateCost() / float64(nbIncrements)
|
||||
incrementCost = utils.Round(incrementCost, globalRoundingDecimals, utils.ROUNDING_MIDDLE)
|
||||
for s := 0; s < nbIncrements; s++ {
|
||||
|
||||
@@ -79,6 +79,7 @@ var (
|
||||
DispatcherErrorPrefix = "DISPATCHER_ERROR"
|
||||
ErrUnsupportedFormat = errors.New("UNSUPPORTED_FORMAT")
|
||||
ErrNoDatabaseConn = errors.New("NO_DATA_BASE_CONNECTION")
|
||||
ErrMaxIncrementsExceeded = errors.New("MAX_INCREMENTS_EXCEEDED")
|
||||
)
|
||||
|
||||
// NewCGRError initialises a new CGRError
|
||||
|
||||
Reference in New Issue
Block a user