mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Add StatIDs option for Stat ProcessEvent
This commit is contained in:
committed by
Dan Christian Bogos
parent
4c0f575302
commit
cf24c1919f
@@ -65,7 +65,7 @@ func (dSts *DispatcherStatSv1) Ping(ign string, reply *string) error {
|
||||
}
|
||||
|
||||
// GetStatQueuesForEvent implements StatSv1GetStatQueuesForEvent
|
||||
func (dSts *DispatcherStatSv1) GetStatQueuesForEvent(args *dispatcher.CGREvWithApiKey, reply *[]string) error {
|
||||
func (dSts *DispatcherStatSv1) GetStatQueuesForEvent(args *dispatcher.ArgsStatProcessEventWithApiKey, reply *[]string) error {
|
||||
return dSts.dS.StatSv1GetStatQueuesForEvent(args, reply)
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ func (dSts *DispatcherStatSv1) GetQueueStringMetrics(args *dispatcher.TntIDWithA
|
||||
}
|
||||
|
||||
// GetQueueStringMetrics implements StatSv1ProcessEvent
|
||||
func (dSts *DispatcherStatSv1) ProcessEvent(args *dispatcher.CGREvWithApiKey, reply *[]string) error {
|
||||
func (dSts *DispatcherStatSv1) ProcessEvent(args *dispatcher.ArgsStatProcessEventWithApiKey, reply *[]string) error {
|
||||
return dSts.dS.StatSv1ProcessEvent(args, reply)
|
||||
}
|
||||
|
||||
|
||||
@@ -111,13 +111,13 @@ func (stsv1 *StatSv1) GetQueueIDs(tenant string, qIDs *[]string) error {
|
||||
}
|
||||
|
||||
// ProcessEvent returns processes a new Event
|
||||
func (stsv1 *StatSv1) ProcessEvent(ev *utils.CGREvent, reply *[]string) error {
|
||||
return stsv1.sS.V1ProcessEvent(ev, reply)
|
||||
func (stsv1 *StatSv1) ProcessEvent(args *engine.StatsArgsProcessEvent, reply *[]string) error {
|
||||
return stsv1.sS.V1ProcessEvent(args, reply)
|
||||
}
|
||||
|
||||
// GetQueueIDs returns the list of queues IDs in the system
|
||||
func (stsv1 *StatSv1) GetStatQueuesForEvent(ev *utils.CGREvent, reply *[]string) (err error) {
|
||||
return stsv1.sS.V1GetStatQueuesForEvent(ev, reply)
|
||||
func (stsv1 *StatSv1) GetStatQueuesForEvent(args *engine.StatsArgsProcessEvent, reply *[]string) (err error) {
|
||||
return stsv1.sS.V1GetStatQueuesForEvent(args, reply)
|
||||
}
|
||||
|
||||
// GetStringMetrics returns the string metrics for a Queue
|
||||
|
||||
@@ -178,16 +178,17 @@ func testV1STSGetStats(t *testing.T) {
|
||||
func testV1STSProcessEvent(t *testing.T) {
|
||||
var reply []string
|
||||
expected := []string{"Stats1"}
|
||||
ev1 := utils.CGREvent{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "event1",
|
||||
Event: map[string]interface{}{
|
||||
utils.Account: "1001",
|
||||
utils.AnswerTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
|
||||
utils.Usage: time.Duration(135 * time.Second),
|
||||
utils.COST: 123.0,
|
||||
utils.PDD: time.Duration(12 * time.Second)}}
|
||||
if err := stsV1Rpc.Call(utils.StatSv1ProcessEvent, &ev1, &reply); err != nil {
|
||||
args := engine.StatsArgsProcessEvent{
|
||||
CGREvent: utils.CGREvent{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "event1",
|
||||
Event: map[string]interface{}{
|
||||
utils.Account: "1001",
|
||||
utils.AnswerTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
|
||||
utils.Usage: time.Duration(135 * time.Second),
|
||||
utils.COST: 123.0,
|
||||
utils.PDD: time.Duration(12 * time.Second)}}}
|
||||
if err := stsV1Rpc.Call(utils.StatSv1ProcessEvent, &args, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(reply, expected) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", expected, reply)
|
||||
@@ -213,26 +214,28 @@ func testV1STSProcessEvent(t *testing.T) {
|
||||
t.Errorf("expecting: %+v, received reply: %s", expectedMetrics, metrics)
|
||||
}
|
||||
|
||||
ev2 := utils.CGREvent{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "event2",
|
||||
Event: map[string]interface{}{
|
||||
utils.Account: "1002",
|
||||
utils.AnswerTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
|
||||
utils.Usage: time.Duration(45 * time.Second)}}
|
||||
if err := stsV1Rpc.Call(utils.StatSv1ProcessEvent, &ev2, &reply); err != nil {
|
||||
args2 := engine.StatsArgsProcessEvent{
|
||||
CGREvent: utils.CGREvent{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "event2",
|
||||
Event: map[string]interface{}{
|
||||
utils.Account: "1002",
|
||||
utils.AnswerTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
|
||||
utils.Usage: time.Duration(45 * time.Second)}}}
|
||||
if err := stsV1Rpc.Call(utils.StatSv1ProcessEvent, &args2, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(reply, expected) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", expected, reply)
|
||||
}
|
||||
ev3 := &utils.CGREvent{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "event3",
|
||||
Event: map[string]interface{}{
|
||||
utils.Account: "1002",
|
||||
utils.SetupTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
|
||||
utils.Usage: 0}}
|
||||
if err := stsV1Rpc.Call(utils.StatSv1ProcessEvent, &ev3, &reply); err != nil {
|
||||
args3 := engine.StatsArgsProcessEvent{
|
||||
CGREvent: utils.CGREvent{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "event3",
|
||||
Event: map[string]interface{}{
|
||||
utils.Account: "1002",
|
||||
utils.SetupTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
|
||||
utils.Usage: 0}}}
|
||||
if err := stsV1Rpc.Call(utils.StatSv1ProcessEvent, &args3, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(reply, expected) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", expected, reply)
|
||||
|
||||
@@ -29,7 +29,7 @@ func init() {
|
||||
c := &CmdStatsQueueForEvent{
|
||||
name: "stats_for_event",
|
||||
rpcMethod: utils.StatSv1GetStatQueuesForEvent,
|
||||
rpcParams: &dispatcher.CGREvWithApiKey{},
|
||||
rpcParams: &dispatcher.ArgsStatProcessEventWithApiKey{},
|
||||
}
|
||||
commands[c.Name()] = c
|
||||
c.CommandExecuter = &CommandExecuter{c}
|
||||
@@ -39,7 +39,7 @@ func init() {
|
||||
type CmdStatsQueueForEvent struct {
|
||||
name string
|
||||
rpcMethod string
|
||||
rpcParams *dispatcher.CGREvWithApiKey
|
||||
rpcParams *dispatcher.ArgsStatProcessEventWithApiKey
|
||||
*CommandExecuter
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ func (self *CmdStatsQueueForEvent) RpcMethod() string {
|
||||
|
||||
func (self *CmdStatsQueueForEvent) RpcParams(reset bool) interface{} {
|
||||
if reset || self.rpcParams == nil {
|
||||
self.rpcParams = &dispatcher.CGREvWithApiKey{}
|
||||
self.rpcParams = &dispatcher.ArgsStatProcessEventWithApiKey{}
|
||||
}
|
||||
return self.rpcParams
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ func init() {
|
||||
c := &CmdStatQueueProcessEvent{
|
||||
name: "stats_process_event",
|
||||
rpcMethod: utils.StatSv1ProcessEvent,
|
||||
rpcParams: &dispatcher.CGREvWithApiKey{},
|
||||
rpcParams: &dispatcher.ArgsStatProcessEventWithApiKey{},
|
||||
}
|
||||
commands[c.Name()] = c
|
||||
c.CommandExecuter = &CommandExecuter{c}
|
||||
@@ -39,7 +39,7 @@ func init() {
|
||||
type CmdStatQueueProcessEvent struct {
|
||||
name string
|
||||
rpcMethod string
|
||||
rpcParams *dispatcher.CGREvWithApiKey
|
||||
rpcParams *dispatcher.ArgsStatProcessEventWithApiKey
|
||||
*CommandExecuter
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ func (self *CmdStatQueueProcessEvent) RpcMethod() string {
|
||||
|
||||
func (self *CmdStatQueueProcessEvent) RpcParams(reset bool) interface{} {
|
||||
if reset || self.rpcParams == nil {
|
||||
self.rpcParams = &dispatcher.CGREvWithApiKey{}
|
||||
self.rpcParams = &dispatcher.ArgsStatProcessEventWithApiKey{}
|
||||
}
|
||||
return self.rpcParams
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ func (dS *DispatcherService) StatSv1Ping(ign string, reply *string) error {
|
||||
return dS.statS.Call(utils.StatSv1Ping, ign, reply)
|
||||
}
|
||||
|
||||
func (dS *DispatcherService) StatSv1GetStatQueuesForEvent(args *CGREvWithApiKey,
|
||||
func (dS *DispatcherService) StatSv1GetStatQueuesForEvent(args *ArgsStatProcessEventWithApiKey,
|
||||
reply *[]string) (err error) {
|
||||
if dS.statS == nil {
|
||||
return utils.NewErrNotConnected(utils.StatS)
|
||||
@@ -40,7 +40,7 @@ func (dS *DispatcherService) StatSv1GetStatQueuesForEvent(args *CGREvWithApiKey,
|
||||
args.APIKey, args.CGREvent.Time); err != nil {
|
||||
return
|
||||
}
|
||||
return dS.statS.Call(utils.StatSv1GetStatQueuesForEvent, args.CGREvent, reply)
|
||||
return dS.statS.Call(utils.StatSv1GetStatQueuesForEvent, args, reply)
|
||||
}
|
||||
|
||||
func (dS *DispatcherService) StatSv1GetQueueStringMetrics(args *TntIDWithApiKey,
|
||||
@@ -56,7 +56,7 @@ func (dS *DispatcherService) StatSv1GetQueueStringMetrics(args *TntIDWithApiKey,
|
||||
return dS.statS.Call(utils.StatSv1GetQueueStringMetrics, args.TenantID, reply)
|
||||
}
|
||||
|
||||
func (dS *DispatcherService) StatSv1ProcessEvent(args *CGREvWithApiKey,
|
||||
func (dS *DispatcherService) StatSv1ProcessEvent(args *ArgsStatProcessEventWithApiKey,
|
||||
reply *[]string) (err error) {
|
||||
if dS.statS == nil {
|
||||
return utils.NewErrNotConnected(utils.StatS)
|
||||
@@ -65,5 +65,5 @@ func (dS *DispatcherService) StatSv1ProcessEvent(args *CGREvWithApiKey,
|
||||
args.APIKey, args.CGREvent.Time); err != nil {
|
||||
return
|
||||
}
|
||||
return dS.statS.Call(utils.StatSv1ProcessEvent, args.CGREvent, reply)
|
||||
return dS.statS.Call(utils.StatSv1ProcessEvent, args, reply)
|
||||
}
|
||||
|
||||
@@ -182,18 +182,19 @@ func testDspStsAddStsibutesWithPermision(t *testing.T) {
|
||||
|
||||
func testDspStsTestAuthKey(t *testing.T) {
|
||||
var reply []string
|
||||
args := CGREvWithApiKey{
|
||||
args := ArgsStatProcessEventWithApiKey{
|
||||
APIKey: "12345",
|
||||
CGREvent: utils.CGREvent{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "event1",
|
||||
Event: map[string]interface{}{
|
||||
utils.Account: "1001",
|
||||
utils.AnswerTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
|
||||
utils.Usage: time.Duration(135 * time.Second),
|
||||
utils.COST: 123.0,
|
||||
utils.PDD: time.Duration(12 * time.Second)}},
|
||||
}
|
||||
StatsArgsProcessEvent: engine.StatsArgsProcessEvent{
|
||||
CGREvent: utils.CGREvent{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "event1",
|
||||
Event: map[string]interface{}{
|
||||
utils.Account: "1001",
|
||||
utils.AnswerTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
|
||||
utils.Usage: time.Duration(135 * time.Second),
|
||||
utils.COST: 123.0,
|
||||
utils.PDD: time.Duration(12 * time.Second)}},
|
||||
}}
|
||||
if err := dspStsRPC.Call(utils.StatSv1ProcessEvent,
|
||||
args, &reply); err.Error() != utils.ErrUnauthorizedApi.Error() {
|
||||
t.Error(err)
|
||||
@@ -255,17 +256,19 @@ func testDspStsTestAuthKey2(t *testing.T) {
|
||||
var reply []string
|
||||
var metrics map[string]string
|
||||
expected := []string{"Stats2"}
|
||||
args := CGREvWithApiKey{
|
||||
args := ArgsStatProcessEventWithApiKey{
|
||||
APIKey: "12345",
|
||||
CGREvent: utils.CGREvent{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "event1",
|
||||
Event: map[string]interface{}{
|
||||
utils.Account: "1001",
|
||||
utils.AnswerTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
|
||||
utils.Usage: time.Duration(135 * time.Second),
|
||||
utils.COST: 123.0,
|
||||
utils.RunID: utils.DEFAULT_RUNID,
|
||||
StatsArgsProcessEvent: engine.StatsArgsProcessEvent{
|
||||
CGREvent: utils.CGREvent{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "event1",
|
||||
Event: map[string]interface{}{
|
||||
utils.Account: "1001",
|
||||
utils.AnswerTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
|
||||
utils.Usage: time.Duration(135 * time.Second),
|
||||
utils.COST: 123.0,
|
||||
utils.RunID: utils.DEFAULT_RUNID,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -294,17 +297,19 @@ func testDspStsTestAuthKey2(t *testing.T) {
|
||||
t.Errorf("expecting: %+v, received reply: %s", expectedMetrics, metrics)
|
||||
}
|
||||
|
||||
args = CGREvWithApiKey{
|
||||
args = ArgsStatProcessEventWithApiKey{
|
||||
APIKey: "12345",
|
||||
CGREvent: utils.CGREvent{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "event1",
|
||||
Event: map[string]interface{}{
|
||||
utils.Account: "1002",
|
||||
utils.AnswerTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
|
||||
utils.Usage: time.Duration(45 * time.Second),
|
||||
utils.RunID: utils.DEFAULT_RUNID,
|
||||
utils.COST: 10.0,
|
||||
StatsArgsProcessEvent: engine.StatsArgsProcessEvent{
|
||||
CGREvent: utils.CGREvent{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "event1",
|
||||
Event: map[string]interface{}{
|
||||
utils.Account: "1002",
|
||||
utils.AnswerTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
|
||||
utils.Usage: time.Duration(45 * time.Second),
|
||||
utils.RunID: utils.DEFAULT_RUNID,
|
||||
utils.COST: 10.0,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -68,6 +68,11 @@ type ArgsGetSuppliersWithApiKey struct {
|
||||
engine.ArgsGetSuppliers
|
||||
}
|
||||
|
||||
type ArgsStatProcessEventWithApiKey struct {
|
||||
APIKey string
|
||||
engine.StatsArgsProcessEvent
|
||||
}
|
||||
|
||||
type AuthorizeArgsWithApiKey struct {
|
||||
APIKey string
|
||||
sessions.V1AuthorizeArgs
|
||||
|
||||
@@ -209,7 +209,8 @@ func (self *CdrServer) processCdr(cdr *CDR) (err error) {
|
||||
}
|
||||
if self.stats != nil {
|
||||
var reply []string
|
||||
go self.stats.Call(utils.StatSv1ProcessEvent, cdr.AsCGREvent(), &reply)
|
||||
|
||||
go self.stats.Call(utils.StatSv1ProcessEvent, &StatsArgsProcessEvent{CGREvent: *cdr.AsCGREvent()}, &reply)
|
||||
}
|
||||
if len(self.cgrCfg.CDRSOnlineCDRExports) != 0 { // Replicate raw CDR
|
||||
self.replicateCDRs([]*CDR{cdr})
|
||||
@@ -296,7 +297,7 @@ func (self *CdrServer) deriveRateStoreStatsReplicate(cdr *CDR, store, cdrstats,
|
||||
}
|
||||
if self.stats != nil {
|
||||
var reply []string
|
||||
go self.stats.Call(utils.StatSv1ProcessEvent, ratedCDR.AsCGREvent(), &reply)
|
||||
go self.stats.Call(utils.StatSv1ProcessEvent, &StatsArgsProcessEvent{CGREvent: *ratedCDR.AsCGREvent()}, &reply)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -677,7 +678,7 @@ func (cdrS *CdrServer) thdSProcessEvent(cgrEv *utils.CGREvent) {
|
||||
// statSProcessEvent will send the event to StatS if the connection is configured
|
||||
func (cdrS *CdrServer) statSProcessEvent(cgrEv *utils.CGREvent) {
|
||||
var reply []string
|
||||
if err := cdrS.stats.Call(utils.StatSv1ProcessEvent, cgrEv, &reply); err != nil &&
|
||||
if err := cdrS.stats.Call(utils.StatSv1ProcessEvent, &StatsArgsProcessEvent{CGREvent: *cgrEv}, &reply); err != nil &&
|
||||
err.Error() != utils.ErrNotFound.Error() {
|
||||
utils.Logger.Warning(
|
||||
fmt.Sprintf("<%s> error: %s processing CDR event %+v with %s.",
|
||||
|
||||
@@ -145,27 +145,33 @@ func (sS *StatService) StoreStatQueue(sq *StatQueue) (err error) {
|
||||
}
|
||||
|
||||
// matchingStatQueuesForEvent returns ordered list of matching resources which are active by the time of the call
|
||||
func (sS *StatService) matchingStatQueuesForEvent(ev *utils.CGREvent) (sqs StatQueues, err error) {
|
||||
func (sS *StatService) matchingStatQueuesForEvent(args *StatsArgsProcessEvent) (sqs StatQueues, err error) {
|
||||
matchingSQs := make(map[string]*StatQueue)
|
||||
sqIDs, err := matchingItemIDsForEvent(ev.Event, sS.stringIndexedFields, sS.prefixIndexedFields,
|
||||
sS.dm, utils.CacheStatFilterIndexes, ev.Tenant, sS.filterS.cfg.FilterSCfg().IndexedSelects)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
var sqIDs []string
|
||||
if len(args.StatIDs) != 0 {
|
||||
sqIDs = args.StatIDs
|
||||
} else {
|
||||
mapIDs, err := matchingItemIDsForEvent(args.Event, sS.stringIndexedFields, sS.prefixIndexedFields,
|
||||
sS.dm, utils.CacheStatFilterIndexes, args.Tenant, sS.filterS.cfg.FilterSCfg().IndexedSelects)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
sqIDs = mapIDs.Slice()
|
||||
}
|
||||
for sqID := range sqIDs {
|
||||
sqPrfl, err := sS.dm.GetStatQueueProfile(ev.Tenant, sqID, false, utils.NonTransactional)
|
||||
for _, sqID := range sqIDs {
|
||||
sqPrfl, err := sS.dm.GetStatQueueProfile(args.Tenant, sqID, false, utils.NonTransactional)
|
||||
if err != nil {
|
||||
if err == utils.ErrNotFound {
|
||||
continue
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
if sqPrfl.ActivationInterval != nil && ev.Time != nil &&
|
||||
!sqPrfl.ActivationInterval.IsActiveAtTime(*ev.Time) { // not active
|
||||
if sqPrfl.ActivationInterval != nil && args.Time != nil &&
|
||||
!sqPrfl.ActivationInterval.IsActiveAtTime(*args.Time) { // not active
|
||||
continue
|
||||
}
|
||||
if pass, err := sS.filterS.Pass(ev.Tenant, sqPrfl.FilterIDs,
|
||||
config.NewNavigableMap(ev.Event)); err != nil {
|
||||
if pass, err := sS.filterS.Pass(args.Tenant, sqPrfl.FilterIDs,
|
||||
config.NewNavigableMap(args.Event)); err != nil {
|
||||
return nil, err
|
||||
} else if !pass {
|
||||
continue
|
||||
@@ -209,10 +215,15 @@ func (ss *StatService) Call(serviceMethod string, args interface{}, reply interf
|
||||
return utils.RPCCall(ss, serviceMethod, args, reply)
|
||||
}
|
||||
|
||||
type StatsArgsProcessEvent struct {
|
||||
StatIDs []string
|
||||
utils.CGREvent
|
||||
}
|
||||
|
||||
// processEvent processes a new event, dispatching to matching queues
|
||||
// queues matching are also cached to speed up
|
||||
func (sS *StatService) processEvent(ev *utils.CGREvent) (statQueueIDs []string, err error) {
|
||||
matchSQs, err := sS.matchingStatQueuesForEvent(ev)
|
||||
func (sS *StatService) processEvent(args *StatsArgsProcessEvent) (statQueueIDs []string, err error) {
|
||||
matchSQs, err := sS.matchingStatQueuesForEvent(args)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -225,12 +236,12 @@ func (sS *StatService) processEvent(ev *utils.CGREvent) (statQueueIDs []string,
|
||||
stsIDs = append(stsIDs, sq.ID)
|
||||
lkID := utils.StatQueuePrefix + sq.TenantID()
|
||||
guardian.Guardian.GuardIDs(config.CgrConfig().LockingTimeout, lkID)
|
||||
err = sq.ProcessEvent(ev)
|
||||
err = sq.ProcessEvent(&args.CGREvent)
|
||||
guardian.Guardian.UnguardIDs(lkID)
|
||||
if err != nil {
|
||||
utils.Logger.Warning(
|
||||
fmt.Sprintf("<StatS> Queue: %s, ignoring event: %s, error: %s",
|
||||
sq.TenantID(), ev.TenantID(), err.Error()))
|
||||
sq.TenantID(), args.TenantID(), err.Error()))
|
||||
withErrors = true
|
||||
}
|
||||
if sS.storeInterval != 0 && sq.dirty != nil { // don't save
|
||||
@@ -280,13 +291,13 @@ func (sS *StatService) processEvent(ev *utils.CGREvent) (statQueueIDs []string,
|
||||
}
|
||||
|
||||
// V1ProcessEvent implements StatV1 method for processing an Event
|
||||
func (sS *StatService) V1ProcessEvent(ev *utils.CGREvent, reply *[]string) (err error) {
|
||||
if missing := utils.MissingStructFields(ev, []string{"Tenant", "ID"}); len(missing) != 0 { //Params missing
|
||||
func (sS *StatService) V1ProcessEvent(args *StatsArgsProcessEvent, reply *[]string) (err error) {
|
||||
if missing := utils.MissingStructFields(args, []string{"Tenant", "ID"}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
} else if ev.Event == nil {
|
||||
} else if args.Event == nil {
|
||||
return utils.NewErrMandatoryIeMissing("Event")
|
||||
}
|
||||
if ids, err := sS.processEvent(ev); err != nil {
|
||||
if ids, err := sS.processEvent(args); err != nil {
|
||||
return err
|
||||
} else {
|
||||
*reply = ids
|
||||
@@ -295,14 +306,14 @@ func (sS *StatService) V1ProcessEvent(ev *utils.CGREvent, reply *[]string) (err
|
||||
}
|
||||
|
||||
// V1StatQueuesForEvent implements StatV1 method for processing an Event
|
||||
func (sS *StatService) V1GetStatQueuesForEvent(ev *utils.CGREvent, reply *[]string) (err error) {
|
||||
if missing := utils.MissingStructFields(ev, []string{"Tenant", "ID"}); len(missing) != 0 { //Params missing
|
||||
func (sS *StatService) V1GetStatQueuesForEvent(args *StatsArgsProcessEvent, reply *[]string) (err error) {
|
||||
if missing := utils.MissingStructFields(args, []string{"Tenant", "ID"}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
} else if ev.Event == nil {
|
||||
} else if args.Event == nil {
|
||||
return utils.NewErrMandatoryIeMissing("Event")
|
||||
}
|
||||
var sQs StatQueues
|
||||
if sQs, err = sS.matchingStatQueuesForEvent(ev); err != nil {
|
||||
if sQs, err = sS.matchingStatQueuesForEvent(args); err != nil {
|
||||
return
|
||||
} else {
|
||||
ids := make([]string, len(sQs))
|
||||
|
||||
@@ -101,38 +101,44 @@ var (
|
||||
&StatQueue{Tenant: "cgrates.org", ID: "StatQueueProfile2", sqPrfl: sqps[1]},
|
||||
&StatQueue{Tenant: "cgrates.org", ID: "StatQueueProfilePrefix", sqPrfl: sqps[2]},
|
||||
}
|
||||
statsEvs = []*utils.CGREvent{
|
||||
&utils.CGREvent{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "event1",
|
||||
Event: map[string]interface{}{
|
||||
"Stats": "StatQueueProfile1",
|
||||
utils.AnswerTime: time.Date(2014, 7, 14, 14, 30, 0, 0, time.UTC),
|
||||
"UsageInterval": "1s",
|
||||
"PddInterval": "1s",
|
||||
"Weight": "9.0",
|
||||
utils.Usage: time.Duration(135 * time.Second),
|
||||
utils.COST: 123.0,
|
||||
statsEvs = []*StatsArgsProcessEvent{
|
||||
&StatsArgsProcessEvent{
|
||||
CGREvent: utils.CGREvent{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "event1",
|
||||
Event: map[string]interface{}{
|
||||
"Stats": "StatQueueProfile1",
|
||||
utils.AnswerTime: time.Date(2014, 7, 14, 14, 30, 0, 0, time.UTC),
|
||||
"UsageInterval": "1s",
|
||||
"PddInterval": "1s",
|
||||
"Weight": "9.0",
|
||||
utils.Usage: time.Duration(135 * time.Second),
|
||||
utils.COST: 123.0,
|
||||
},
|
||||
},
|
||||
},
|
||||
&utils.CGREvent{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "event2",
|
||||
Event: map[string]interface{}{
|
||||
"Stats": "StatQueueProfile2",
|
||||
utils.AnswerTime: time.Date(2014, 7, 14, 14, 30, 0, 0, time.UTC),
|
||||
"UsageInterval": "1s",
|
||||
"PddInterval": "1s",
|
||||
"Weight": "15.0",
|
||||
utils.Usage: time.Duration(45 * time.Second),
|
||||
&StatsArgsProcessEvent{
|
||||
CGREvent: utils.CGREvent{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "event2",
|
||||
Event: map[string]interface{}{
|
||||
"Stats": "StatQueueProfile2",
|
||||
utils.AnswerTime: time.Date(2014, 7, 14, 14, 30, 0, 0, time.UTC),
|
||||
"UsageInterval": "1s",
|
||||
"PddInterval": "1s",
|
||||
"Weight": "15.0",
|
||||
utils.Usage: time.Duration(45 * time.Second),
|
||||
},
|
||||
},
|
||||
},
|
||||
&utils.CGREvent{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "event3",
|
||||
Event: map[string]interface{}{
|
||||
"Stats": "StatQueueProfilePrefix",
|
||||
utils.Usage: time.Duration(30 * time.Second),
|
||||
&StatsArgsProcessEvent{
|
||||
CGREvent: utils.CGREvent{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "event3",
|
||||
Event: map[string]interface{}{
|
||||
"Stats": "StatQueueProfilePrefix",
|
||||
utils.Usage: time.Duration(30 * time.Second),
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -1675,7 +1675,7 @@ func (smg *SMGeneric) BiRPCv1AuthorizeEvent(clnt rpcclient.RpcClientConnection,
|
||||
return utils.NewErrNotConnected(utils.StatService)
|
||||
}
|
||||
var statReply []string
|
||||
if err := smg.statS.Call(utils.StatSv1ProcessEvent, &args.CGREvent, &statReply); err != nil &&
|
||||
if err := smg.statS.Call(utils.StatSv1ProcessEvent, &engine.StatsArgsProcessEvent{CGREvent: args.CGREvent}, &statReply); err != nil &&
|
||||
err.Error() != utils.ErrNotFound.Error() {
|
||||
utils.Logger.Warning(
|
||||
fmt.Sprintf("<SessionS> error: %s processing event %+v with StatS.", err.Error(), args.CGREvent))
|
||||
@@ -1880,7 +1880,7 @@ func (smg *SMGeneric) BiRPCv1InitiateSession(clnt rpcclient.RpcClientConnection,
|
||||
return utils.NewErrNotConnected(utils.StatService)
|
||||
}
|
||||
var statReply []string
|
||||
if err := smg.statS.Call(utils.StatSv1ProcessEvent, &args.CGREvent, &statReply); err != nil &&
|
||||
if err := smg.statS.Call(utils.StatSv1ProcessEvent, &engine.StatsArgsProcessEvent{CGREvent: args.CGREvent}, &statReply); err != nil &&
|
||||
err.Error() != utils.ErrNotFound.Error() {
|
||||
utils.Logger.Warning(
|
||||
fmt.Sprintf("<SessionS> error: %s processing event %+v with StatS.", err.Error(), args.CGREvent))
|
||||
@@ -2098,7 +2098,7 @@ func (smg *SMGeneric) BiRPCv1TerminateSession(clnt rpcclient.RpcClientConnection
|
||||
}
|
||||
if smg.statS != nil && args.ProcessStats {
|
||||
var statReply []string
|
||||
if err := smg.statS.Call(utils.StatSv1ProcessEvent, &args.CGREvent, &statReply); err != nil &&
|
||||
if err := smg.statS.Call(utils.StatSv1ProcessEvent, &engine.StatsArgsProcessEvent{CGREvent: args.CGREvent}, &statReply); err != nil &&
|
||||
err.Error() != utils.ErrNotFound.Error() {
|
||||
utils.Logger.Warning(
|
||||
fmt.Sprintf("<SessionS> error: %s processing event %+v with StatS.", err.Error(), args.CGREvent))
|
||||
|
||||
@@ -1057,6 +1057,7 @@ type CDRsFilter struct {
|
||||
Unscoped bool // Include soft-deleted records in results
|
||||
Count bool // If true count the items instead of returning data
|
||||
Paginator
|
||||
//OrderBy asc/desc
|
||||
}
|
||||
|
||||
// RPCCDRsFilter is a filter used in Rpc calls
|
||||
|
||||
Reference in New Issue
Block a user