mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-22 07:38:45 +05:00
Stop sending BalanceUpdate events to thresholds/stats
This commit is contained in:
committed by
Dan Christian Bogos
parent
d6c5ddf08e
commit
a5d29d5d7b
@@ -554,34 +554,6 @@ func (acc *Account) debitCreditBalance(cd *CallDescriptor, count bool, dryRun bo
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// in case of going to negative we send the default balance to thresholdS to be processed
|
||||
if len(config.CgrConfig().RalsCfg().ThresholdSConns) != 0 {
|
||||
defaultBalance := acc.GetDefaultMoneyBalance()
|
||||
acntTnt := utils.NewTenantID(acc.ID)
|
||||
thEv := &utils.CGREvent{
|
||||
Tenant: acntTnt.Tenant,
|
||||
ID: utils.GenUUID(),
|
||||
Event: map[string]any{
|
||||
utils.EventType: utils.BalanceUpdate,
|
||||
utils.EventSource: utils.AccountService,
|
||||
utils.AccountField: acntTnt.ID,
|
||||
utils.BalanceID: defaultBalance.ID,
|
||||
utils.Units: defaultBalance.Value,
|
||||
},
|
||||
APIOpts: map[string]any{
|
||||
utils.MetaEventType: utils.BalanceUpdate,
|
||||
},
|
||||
}
|
||||
var tIDs []string
|
||||
if err := connMgr.Call(context.TODO(), config.CgrConfig().RalsCfg().ThresholdSConns,
|
||||
utils.ThresholdSv1ProcessEvent, thEv, &tIDs); err != nil &&
|
||||
err.Error() != utils.ErrNotFound.Error() {
|
||||
utils.Logger.Warning(
|
||||
fmt.Sprintf("<AccountS> error: <%s> processing balance event <%+v> with ThresholdS.",
|
||||
err.Error(), utils.ToJSON(thEv)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
COMMIT:
|
||||
|
||||
@@ -29,8 +29,6 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/cgrates/birpc"
|
||||
"github.com/cgrates/birpc/context"
|
||||
"github.com/cgrates/cgrates/config"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
@@ -3020,68 +3018,6 @@ func TestAcountSetBalanceAction(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestDebitCreditBalance(t *testing.T) {
|
||||
cfg := config.NewDefaultCGRConfig()
|
||||
db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items)
|
||||
dm := NewDataManager(db, cfg.CacheCfg(), nil)
|
||||
fltrs := NewFilterS(cfg, nil, dm)
|
||||
tmpConn := connMgr
|
||||
utils.Logger.SetLogLevel(4)
|
||||
utils.Logger.SetSyslog(nil)
|
||||
buf := new(bytes.Buffer)
|
||||
log.SetOutput(buf)
|
||||
defer func() {
|
||||
utils.Logger.SetLogLevel(0)
|
||||
log.SetOutput(os.Stderr)
|
||||
connMgr = tmpConn
|
||||
config.SetCgrConfig(config.NewDefaultCGRConfig())
|
||||
}()
|
||||
cfg.RalsCfg().ThresholdSConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaThresholds)}
|
||||
clientConn := make(chan birpc.ClientConnector, 1)
|
||||
clientConn <- &ccMock{
|
||||
calls: map[string]func(ctx *context.Context, args any, reply any) error{
|
||||
utils.ThresholdSv1ProcessEvent: func(ctx *context.Context, args, reply any) error {
|
||||
rpl := &[]string{"id"}
|
||||
*reply.(*[]string) = *rpl
|
||||
return errors.New("Can't process Event")
|
||||
},
|
||||
},
|
||||
}
|
||||
connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{
|
||||
utils.ConcatenatedKey(utils.MetaInternal, utils.MetaThresholds): clientConn,
|
||||
})
|
||||
cd := &CallDescriptor{
|
||||
Tenant: "cgrates.org",
|
||||
Category: "call",
|
||||
TimeStart: time.Date(2015, 9, 24, 10, 48, 0, 0, time.UTC),
|
||||
TimeEnd: time.Date(2015, 9, 24, 10, 58, 1, 0, time.UTC),
|
||||
Destination: "4444",
|
||||
Subject: "dy",
|
||||
Account: "dy",
|
||||
ToR: utils.MetaVoice,
|
||||
DurationIndex: 600,
|
||||
}
|
||||
acc := &Account{
|
||||
ID: "vdf:broker",
|
||||
BalanceMap: map[string]Balances{
|
||||
utils.MetaVoice: {
|
||||
&Balance{Value: 20 * float64(time.Second),
|
||||
DestinationIDs: utils.NewStringMap("NAT"),
|
||||
Weight: 10, RatingSubject: "rif"},
|
||||
&Balance{Value: 100 * float64(time.Second),
|
||||
DestinationIDs: utils.NewStringMap("RET"), Weight: 20},
|
||||
}},
|
||||
}
|
||||
config.SetCgrConfig(cfg)
|
||||
SetConnManager(connMgr)
|
||||
expLog := `processing balance event`
|
||||
if _, err := acc.debitCreditBalance(cd, true, true, true, fltrs); err != nil {
|
||||
t.Error(err)
|
||||
} else if rcvLog := buf.String(); !strings.Contains(rcvLog, expLog) {
|
||||
t.Errorf("Logger %v,doesn't contain %v", utils.ToJSON(rcvLog), utils.ToJSON(expLog))
|
||||
}
|
||||
}
|
||||
|
||||
func TestAccGetAllBalancesForPrefixLogg(t *testing.T) {
|
||||
tmp := Cache
|
||||
utils.Logger.SetLogLevel(4)
|
||||
|
||||
Reference in New Issue
Block a user