From 777580a06e6d4a20909b2d3105f2b81d6e1ca0ad Mon Sep 17 00:00:00 2001 From: ionutboangiu Date: Fri, 5 Nov 2021 15:06:21 +0200 Subject: [PATCH] Add opts field for thresholds cfg struct and use the CGREvent instead of the ArgsProcessEvent struct --- apier/v1/api_interfaces.go | 4 +- apier/v1/dispatcher.go | 4 +- apier/v1/filterindexecache_it_test.go | 188 ++++----- apier/v1/remote_it_test.go | 36 +- apier/v1/replicate_it_test.go | 24 +- apier/v1/thresholds.go | 4 +- apier/v1/thresholds_it_test.go | 358 ++++++++--------- config/config.go | 2 +- config/config_defaults.go | 4 + config/libconfig_json.go | 6 + config/thresholdscfg.go | 34 ++ console/thresholds_for_event.go | 8 +- console/thresholds_process_event.go | 14 +- dispatchers/thresholds.go | 20 +- dispatchers/thresholds_it_test.go | 20 +- dispatchers/thresholds_test.go | 24 +- engine/account.go | 28 +- engine/cdrs.go | 4 +- engine/resources.go | 20 +- engine/stats.go | 18 +- engine/stats_test.go | 24 +- engine/thresholds.go | 62 +-- engine/thresholds_test.go | 377 +++++++----------- engine/z_actions_it_test.go | 66 ++- engine/z_resources_test.go | 48 +-- general_tests/filtered_replication_it_test.go | 12 +- general_tests/filters_it_test.go | 72 ++-- general_tests/rpccaching_it_test.go | 64 ++- general_tests/sessions_race_test.go | 6 +- sessions/sessions.go | 9 +- utils/consts.go | 5 +- 31 files changed, 699 insertions(+), 866 deletions(-) diff --git a/apier/v1/api_interfaces.go b/apier/v1/api_interfaces.go index 2f30fc3bb..a10faf7d1 100644 --- a/apier/v1/api_interfaces.go +++ b/apier/v1/api_interfaces.go @@ -31,9 +31,9 @@ import ( type ThresholdSv1Interface interface { GetThresholdIDs(tenant *utils.TenantWithAPIOpts, tIDs *[]string) error - GetThresholdsForEvent(args *engine.ThresholdsArgsProcessEvent, reply *engine.Thresholds) error + GetThresholdsForEvent(args *utils.CGREvent, reply *engine.Thresholds) error GetThreshold(tntID *utils.TenantIDWithAPIOpts, t *engine.Threshold) error - ProcessEvent(args *engine.ThresholdsArgsProcessEvent, tIDs *[]string) error + ProcessEvent(args *utils.CGREvent, tIDs *[]string) error Ping(ign *utils.CGREvent, reply *string) error } diff --git a/apier/v1/dispatcher.go b/apier/v1/dispatcher.go index a16a47774..96a24f10f 100644 --- a/apier/v1/dispatcher.go +++ b/apier/v1/dispatcher.go @@ -227,13 +227,13 @@ func (dT *DispatcherThresholdSv1) Ping(args *utils.CGREvent, reply *string) erro } // GetThresholdsForEvent implements ThresholdSv1GetThresholdsForEvent -func (dT *DispatcherThresholdSv1) GetThresholdsForEvent(tntID *engine.ThresholdsArgsProcessEvent, +func (dT *DispatcherThresholdSv1) GetThresholdsForEvent(tntID *utils.CGREvent, t *engine.Thresholds) error { return dT.dS.ThresholdSv1GetThresholdsForEvent(tntID, t) } // ProcessEvent implements ThresholdSv1ProcessEvent -func (dT *DispatcherThresholdSv1) ProcessEvent(args *engine.ThresholdsArgsProcessEvent, +func (dT *DispatcherThresholdSv1) ProcessEvent(args *utils.CGREvent, tIDs *[]string) error { return dT.dS.ThresholdSv1ProcessEvent(args, tIDs) } diff --git a/apier/v1/filterindexecache_it_test.go b/apier/v1/filterindexecache_it_test.go index 2a012514c..314474102 100644 --- a/apier/v1/filterindexecache_it_test.go +++ b/apier/v1/filterindexecache_it_test.go @@ -144,17 +144,15 @@ func testV1FIdxCaFromFolder(t *testing.T) { //ThresholdProfile func testV1FIdxCaProcessEventWithNotFound(t *testing.T) { - tEv := &engine.ThresholdsArgsProcessEvent{ - CGREvent: &utils.CGREvent{ - Tenant: "cgrates.org", - ID: "event1", - Event: map[string]interface{}{ - utils.EventType: utils.BalanceUpdate, - utils.AccountField: "1001", - }, - APIOpts: map[string]interface{}{ - utils.MetaEventType: utils.BalanceUpdate, - }, + tEv := &utils.CGREvent{ + Tenant: "cgrates.org", + ID: "event1", + Event: map[string]interface{}{ + utils.EventType: utils.BalanceUpdate, + utils.AccountField: "1001", + }, + APIOpts: map[string]interface{}{ + utils.MetaEventType: utils.BalanceUpdate, }, } var thIDs []string @@ -214,18 +212,16 @@ func testV1FIdxCaSetThresholdProfile(t *testing.T) { t.Error("Unexpected reply returned", result) } //matches TEST_PROFILE1 - tEv := &engine.ThresholdsArgsProcessEvent{ - ThresholdIDs: []string{"TEST_PROFILE1"}, - CGREvent: &utils.CGREvent{ - Tenant: "cgrates.org", - ID: "event1", - Event: map[string]interface{}{ - utils.EventType: utils.BalanceUpdate, - utils.AccountField: "1001", - }, - APIOpts: map[string]interface{}{ - utils.MetaEventType: utils.BalanceUpdate, - }, + tEv := &utils.CGREvent{ + Tenant: "cgrates.org", + ID: "event1", + Event: map[string]interface{}{ + utils.EventType: utils.BalanceUpdate, + utils.AccountField: "1001", + }, + APIOpts: map[string]interface{}{ + utils.MetaEventType: utils.BalanceUpdate, + utils.OptsThresholdsProfileIDs: []string{"TEST_PROFILE1"}, }, } var thIDs []string @@ -241,20 +237,18 @@ func testV1FIdxCaSetThresholdProfile(t *testing.T) { func testV1FIdxCaGetThresholdFromTP(t *testing.T) { //matches THD_ACNT_BALANCE_1 - tEv := &engine.ThresholdsArgsProcessEvent{ - ThresholdIDs: []string{"THD_ACNT_BALANCE_1"}, - CGREvent: &utils.CGREvent{ - Tenant: "cgrates.org", - ID: "event1", - Event: map[string]interface{}{ - utils.EventType: utils.BalanceUpdate, - utils.AccountField: "1001", - utils.BalanceID: utils.MetaDefault, - utils.Units: 12.3, - }, - APIOpts: map[string]interface{}{ - utils.MetaEventType: utils.BalanceUpdate, - }, + tEv := &utils.CGREvent{ + Tenant: "cgrates.org", + ID: "event1", + Event: map[string]interface{}{ + utils.EventType: utils.BalanceUpdate, + utils.AccountField: "1001", + utils.BalanceID: utils.MetaDefault, + utils.Units: 12.3, + }, + APIOpts: map[string]interface{}{ + utils.MetaEventType: utils.BalanceUpdate, + utils.OptsThresholdsProfileIDs: []string{"THD_ACNT_BALANCE_1"}, }, } var thIDs []string @@ -317,17 +311,15 @@ func testV1FIdxCaUpdateThresholdProfile(t *testing.T) { t.Error("Unexpected reply returned", result) } //make sure doesn't match the thresholdprofile after update - tEv := &engine.ThresholdsArgsProcessEvent{ - CGREvent: &utils.CGREvent{ - Tenant: "cgrates.org", - ID: "event1", - Event: map[string]interface{}{ - utils.EventType: utils.AccountUpdate, - utils.AccountField: "1001", - }, - APIOpts: map[string]interface{}{ - utils.MetaEventType: utils.AccountUpdate, - }, + tEv := &utils.CGREvent{ + Tenant: "cgrates.org", + ID: "event1", + Event: map[string]interface{}{ + utils.EventType: utils.AccountUpdate, + utils.AccountField: "1001", + }, + APIOpts: map[string]interface{}{ + utils.MetaEventType: utils.AccountUpdate, }, } var thIDs []string @@ -338,17 +330,15 @@ func testV1FIdxCaUpdateThresholdProfile(t *testing.T) { t.Error(err) } //matches thresholdprofile after update - tEv2 := &engine.ThresholdsArgsProcessEvent{ - CGREvent: &utils.CGREvent{ - Tenant: "cgrates.org", - ID: "event1", - Event: map[string]interface{}{ - utils.EventType: utils.AccountUpdate, - utils.AccountField: "1002", - }, - APIOpts: map[string]interface{}{ - utils.MetaEventType: utils.AccountUpdate, - }, + tEv2 := &utils.CGREvent{ + Tenant: "cgrates.org", + ID: "event1", + Event: map[string]interface{}{ + utils.EventType: utils.AccountUpdate, + utils.AccountField: "1002", + }, + APIOpts: map[string]interface{}{ + utils.MetaEventType: utils.AccountUpdate, }, } eIDs = []string{"TEST_PROFILE1"} @@ -408,17 +398,15 @@ func testV1FIdxCaUpdateThresholdProfileFromTP(t *testing.T) { } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - tEv := &engine.ThresholdsArgsProcessEvent{ - CGREvent: &utils.CGREvent{ - Tenant: "cgrates.org", - ID: "event1", - Event: map[string]interface{}{ - utils.AccountField: "1002", - utils.EventType: utils.BalanceUpdate, - }, - APIOpts: map[string]interface{}{ - utils.MetaEventType: utils.BalanceUpdate, - }, + tEv := &utils.CGREvent{ + Tenant: "cgrates.org", + ID: "event1", + Event: map[string]interface{}{ + utils.AccountField: "1002", + utils.EventType: utils.BalanceUpdate, + }, + APIOpts: map[string]interface{}{ + utils.MetaEventType: utils.BalanceUpdate, }, } var thIDs []string @@ -427,17 +415,15 @@ func testV1FIdxCaUpdateThresholdProfileFromTP(t *testing.T) { err.Error() != utils.ErrNotFound.Error() { t.Error(err) } - tEv2 := &engine.ThresholdsArgsProcessEvent{ - CGREvent: &utils.CGREvent{ - Tenant: "cgrates.org", - ID: "event3", - Event: map[string]interface{}{ - utils.AccountField: "1003", - utils.EventType: utils.BalanceUpdate, - }, - APIOpts: map[string]interface{}{ - utils.MetaEventType: utils.BalanceUpdate, - }, + tEv2 := &utils.CGREvent{ + Tenant: "cgrates.org", + ID: "event3", + Event: map[string]interface{}{ + utils.AccountField: "1003", + utils.EventType: utils.BalanceUpdate, + }, + APIOpts: map[string]interface{}{ + utils.MetaEventType: utils.BalanceUpdate, }, } eIDs := []string{"THD_ACNT_BALANCE_1"} @@ -451,17 +437,15 @@ func testV1FIdxCaUpdateThresholdProfileFromTP(t *testing.T) { func testV1FIdxCaRemoveThresholdProfile(t *testing.T) { var resp string - tEv := &engine.ThresholdsArgsProcessEvent{ - CGREvent: &utils.CGREvent{ - Tenant: "cgrates.org", - ID: "event8", - Event: map[string]interface{}{ - utils.AccountField: "1002", - utils.EventType: utils.AccountUpdate, - }, - APIOpts: map[string]interface{}{ - utils.MetaEventType: utils.AccountUpdate, - }, + tEv := &utils.CGREvent{ + Tenant: "cgrates.org", + ID: "event8", + Event: map[string]interface{}{ + utils.AccountField: "1002", + utils.EventType: utils.AccountUpdate, + }, + APIOpts: map[string]interface{}{ + utils.MetaEventType: utils.AccountUpdate, }, } var thIDs []string @@ -472,17 +456,15 @@ func testV1FIdxCaRemoveThresholdProfile(t *testing.T) { t.Errorf("Expecting : %s, received: %s", eIDs, thIDs) } - tEv2 := &engine.ThresholdsArgsProcessEvent{ - CGREvent: &utils.CGREvent{ - Tenant: "cgrates.org", - ID: "event9", - Event: map[string]interface{}{ - utils.AccountField: "1003", - utils.EventType: utils.BalanceUpdate, - }, - APIOpts: map[string]interface{}{ - utils.MetaEventType: utils.BalanceUpdate, - }, + tEv2 := &utils.CGREvent{ + Tenant: "cgrates.org", + ID: "event9", + Event: map[string]interface{}{ + utils.AccountField: "1003", + utils.EventType: utils.BalanceUpdate, + }, + APIOpts: map[string]interface{}{ + utils.MetaEventType: utils.BalanceUpdate, }, } eIDs = []string{"THD_ACNT_BALANCE_1"} diff --git a/apier/v1/remote_it_test.go b/apier/v1/remote_it_test.go index 6aaac6124..221ebb4ba 100644 --- a/apier/v1/remote_it_test.go +++ b/apier/v1/remote_it_test.go @@ -802,13 +802,11 @@ func testInternalReplicationSetThreshold(t *testing.T) { } func testInternalMatchThreshold(t *testing.T) { - ev := &engine.ThresholdsArgsProcessEvent{ - CGREvent: &utils.CGREvent{ - Tenant: "cgrates.org", - ID: "event2", - Event: map[string]interface{}{ - utils.AccountField: "1002", - }, + ev := &utils.CGREvent{ + Tenant: "cgrates.org", + ID: "event2", + Event: map[string]interface{}{ + utils.AccountField: "1002", }, } var ids []string @@ -818,13 +816,11 @@ func testInternalMatchThreshold(t *testing.T) { } else if !reflect.DeepEqual(ids, eIDs) { t.Errorf("Expecting ids: %s, received: %s", eIDs, ids) } - ev = &engine.ThresholdsArgsProcessEvent{ - CGREvent: &utils.CGREvent{ - Tenant: "cgrates.org", - ID: "event2", - Event: map[string]interface{}{ - utils.AccountField: "1001", - }, + ev = &utils.CGREvent{ + Tenant: "cgrates.org", + ID: "event2", + Event: map[string]interface{}{ + utils.AccountField: "1001", }, } eIDs = []string{"THD_ACNT_1001"} @@ -833,13 +829,11 @@ func testInternalMatchThreshold(t *testing.T) { } else if !reflect.DeepEqual(ids, eIDs) { t.Errorf("Expecting ids: %s, received: %s", eIDs, ids) } - ev2 := &engine.ThresholdsArgsProcessEvent{ - CGREvent: &utils.CGREvent{ - Tenant: "cgrates.org", - ID: "event3", - Event: map[string]interface{}{ - utils.AccountField: "1001", - }, + ev2 := &utils.CGREvent{ + Tenant: "cgrates.org", + ID: "event3", + Event: map[string]interface{}{ + utils.AccountField: "1001", }, } if err := internalRPC.Call(utils.ThresholdSv1ProcessEvent, ev2, &ids); err == nil || err.Error() != utils.ErrNotFound.Error() { diff --git a/apier/v1/replicate_it_test.go b/apier/v1/replicate_it_test.go index c3fbb5d36..f5b7a8f7c 100644 --- a/apier/v1/replicate_it_test.go +++ b/apier/v1/replicate_it_test.go @@ -1207,19 +1207,17 @@ func testInternalReplicateITThreshold(t *testing.T) { err.Error() != utils.ErrNotFound.Error() { t.Error(err) } - tEvs := engine.ThresholdsArgsProcessEvent{ - CGREvent: &utils.CGREvent{ - Tenant: "cgrates.org", - ID: "event1", - Event: map[string]interface{}{ - utils.EventType: utils.AccountUpdate, - utils.AccountField: "1005", - utils.AllowNegative: true, - utils.Disabled: false, - utils.Units: 12.3}, - APIOpts: map[string]interface{}{ - utils.MetaEventType: utils.AccountUpdate, - }, + tEvs := &utils.CGREvent{ + Tenant: "cgrates.org", + ID: "event1", + Event: map[string]interface{}{ + utils.EventType: utils.AccountUpdate, + utils.AccountField: "1005", + utils.AllowNegative: true, + utils.Disabled: false, + utils.Units: 12.3}, + APIOpts: map[string]interface{}{ + utils.MetaEventType: utils.AccountUpdate, }, } //set Actions diff --git a/apier/v1/thresholds.go b/apier/v1/thresholds.go index 640700112..1376a67d4 100644 --- a/apier/v1/thresholds.go +++ b/apier/v1/thresholds.go @@ -46,7 +46,7 @@ func (tSv1 *ThresholdSv1) GetThresholdIDs(tenant *utils.TenantWithAPIOpts, tIDs } // GetThresholdsForEvent returns a list of thresholds matching an event -func (tSv1 *ThresholdSv1) GetThresholdsForEvent(args *engine.ThresholdsArgsProcessEvent, reply *engine.Thresholds) error { +func (tSv1 *ThresholdSv1) GetThresholdsForEvent(args *utils.CGREvent, reply *engine.Thresholds) error { return tSv1.tS.V1GetThresholdsForEvent(args, reply) } @@ -56,7 +56,7 @@ func (tSv1 *ThresholdSv1) GetThreshold(tntID *utils.TenantIDWithAPIOpts, t *engi } // ProcessEvent will process an Event -func (tSv1 *ThresholdSv1) ProcessEvent(args *engine.ThresholdsArgsProcessEvent, tIDs *[]string) error { +func (tSv1 *ThresholdSv1) ProcessEvent(args *utils.CGREvent, tIDs *[]string) error { return tSv1.tS.V1ProcessEvent(args, tIDs) } diff --git a/apier/v1/thresholds_it_test.go b/apier/v1/thresholds_it_test.go index ec5035ba5..6057555b4 100644 --- a/apier/v1/thresholds_it_test.go +++ b/apier/v1/thresholds_it_test.go @@ -41,166 +41,148 @@ var ( tPrfl *engine.ThresholdProfileWithAPIOpts tSv1ConfDIR string //run tests for specific configuration - tEvs = []*engine.ThresholdsArgsProcessEvent{ - { - CGREvent: &utils.CGREvent{ // hitting THD_ACNT_BALANCE_1 - Tenant: "cgrates.org", - ID: "event1", - Event: map[string]interface{}{ - utils.EventType: utils.AccountUpdate, - utils.AccountField: "1002", - utils.AllowNegative: true, - utils.Disabled: false, - utils.Units: 12.3}, - APIOpts: map[string]interface{}{ - utils.MetaEventType: utils.AccountUpdate, - }, + tEvs = []*utils.CGREvent{ + { // hitting THD_ACNT_BALANCE_1 + Tenant: "cgrates.org", + ID: "event1", + Event: map[string]interface{}{ + utils.EventType: utils.AccountUpdate, + utils.AccountField: "1002", + utils.AllowNegative: true, + utils.Disabled: false, + utils.Units: 12.3}, + APIOpts: map[string]interface{}{ + utils.MetaEventType: utils.AccountUpdate, }, }, - { - CGREvent: &utils.CGREvent{ // hitting THD_ACNT_BALANCE_1 - Tenant: "cgrates.org", - ID: "event2", - Event: map[string]interface{}{ - utils.EventType: utils.BalanceUpdate, - utils.AccountField: "1002", - utils.BalanceID: utils.MetaDefault, - utils.Units: 12.3, - utils.ExpiryTime: time.Date(2009, 11, 10, 23, 00, 0, 0, time.UTC), - }, - APIOpts: map[string]interface{}{ - utils.MetaEventType: utils.BalanceUpdate, - }, + { // hitting THD_ACNT_BALANCE_1 + Tenant: "cgrates.org", + ID: "event2", + Event: map[string]interface{}{ + utils.EventType: utils.BalanceUpdate, + utils.AccountField: "1002", + utils.BalanceID: utils.MetaDefault, + utils.Units: 12.3, + utils.ExpiryTime: time.Date(2009, 11, 10, 23, 00, 0, 0, time.UTC), + }, + APIOpts: map[string]interface{}{ + utils.MetaEventType: utils.BalanceUpdate, }, }, - { - CGREvent: &utils.CGREvent{ // hitting THD_STATS_1 - Tenant: "cgrates.org", - ID: "event3", - Event: map[string]interface{}{ - utils.EventType: utils.StatUpdate, - utils.StatID: "Stats1", - utils.AccountField: "1002", - "ASR": 35.0, - "ACD": "2m45s", - "TCC": 12.7, - "TCD": "12m15s", - "ACC": 0.75, - "PDD": "2s", - }, - APIOpts: map[string]interface{}{ - utils.MetaEventType: utils.StatUpdate, - }, + { // hitting THD_STATS_1 + Tenant: "cgrates.org", + ID: "event3", + Event: map[string]interface{}{ + utils.EventType: utils.StatUpdate, + utils.StatID: "Stats1", + utils.AccountField: "1002", + "ASR": 35.0, + "ACD": "2m45s", + "TCC": 12.7, + "TCD": "12m15s", + "ACC": 0.75, + "PDD": "2s", + }, + APIOpts: map[string]interface{}{ + utils.MetaEventType: utils.StatUpdate, }, }, - { - CGREvent: &utils.CGREvent{ // hitting THD_STATS_1 and THD_STATS_2 - Tenant: "cgrates.org", - ID: "event4", - Event: map[string]interface{}{ - utils.EventType: utils.StatUpdate, - utils.StatID: "STATS_HOURLY_DE", - utils.AccountField: "1002", - "ASR": 35.0, - "ACD": "2m45s", - "TCD": "1h", - }, - APIOpts: map[string]interface{}{ - utils.MetaEventType: utils.StatUpdate, - }, + { // hitting THD_STATS_1 and THD_STATS_2 + Tenant: "cgrates.org", + ID: "event4", + Event: map[string]interface{}{ + utils.EventType: utils.StatUpdate, + utils.StatID: "STATS_HOURLY_DE", + utils.AccountField: "1002", + "ASR": 35.0, + "ACD": "2m45s", + "TCD": "1h", + }, + APIOpts: map[string]interface{}{ + utils.MetaEventType: utils.StatUpdate, }, }, - { - CGREvent: &utils.CGREvent{ // hitting THD_STATS_3 - Tenant: "cgrates.org", - ID: "event5", - Event: map[string]interface{}{ - utils.EventType: utils.StatUpdate, - utils.StatID: "STATS_DAILY_DE", - utils.AccountField: "1002", - "ACD": "2m45s", - "TCD": "3h1s", - }, - APIOpts: map[string]interface{}{ - utils.MetaEventType: utils.StatUpdate, - }, + { // hitting THD_STATS_3 + Tenant: "cgrates.org", + ID: "event5", + Event: map[string]interface{}{ + utils.EventType: utils.StatUpdate, + utils.StatID: "STATS_DAILY_DE", + utils.AccountField: "1002", + "ACD": "2m45s", + "TCD": "3h1s", + }, + APIOpts: map[string]interface{}{ + utils.MetaEventType: utils.StatUpdate, }, }, - { - CGREvent: &utils.CGREvent{ // hitting THD_RES_1 - Tenant: "cgrates.org", - ID: "event6", - Event: map[string]interface{}{ - utils.EventType: utils.ResourceUpdate, - utils.AccountField: "1002", - utils.ResourceID: "RES_GRP_1", - utils.Usage: 10.0, - }, - APIOpts: map[string]interface{}{ - utils.MetaEventType: utils.ResourceUpdate, - }, + { // hitting THD_RES_1 + Tenant: "cgrates.org", + ID: "event6", + Event: map[string]interface{}{ + utils.EventType: utils.ResourceUpdate, + utils.AccountField: "1002", + utils.ResourceID: "RES_GRP_1", + utils.Usage: 10.0, + }, + APIOpts: map[string]interface{}{ + utils.MetaEventType: utils.ResourceUpdate, }, }, - { - CGREvent: &utils.CGREvent{ // hitting THD_RES_1 - Tenant: "cgrates.org", - ID: "event6", - Event: map[string]interface{}{ - utils.EventType: utils.ResourceUpdate, - utils.AccountField: "1002", - utils.ResourceID: "RES_GRP_1", - utils.Usage: 10.0, - }, - APIOpts: map[string]interface{}{ - utils.MetaEventType: utils.ResourceUpdate, - }, + { // hitting THD_RES_1 + Tenant: "cgrates.org", + ID: "event6", + Event: map[string]interface{}{ + utils.EventType: utils.ResourceUpdate, + utils.AccountField: "1002", + utils.ResourceID: "RES_GRP_1", + utils.Usage: 10.0, + }, + APIOpts: map[string]interface{}{ + utils.MetaEventType: utils.ResourceUpdate, }, }, - { - CGREvent: &utils.CGREvent{ // hitting THD_RES_1 - Tenant: "cgrates.org", - ID: "event6", - Event: map[string]interface{}{ - utils.EventType: utils.ResourceUpdate, - utils.AccountField: "1002", - utils.ResourceID: "RES_GRP_1", - utils.Usage: 10.0, - }, - APIOpts: map[string]interface{}{ - utils.MetaEventType: utils.ResourceUpdate, - }, + { // hitting THD_RES_1 + Tenant: "cgrates.org", + ID: "event6", + Event: map[string]interface{}{ + utils.EventType: utils.ResourceUpdate, + utils.AccountField: "1002", + utils.ResourceID: "RES_GRP_1", + utils.Usage: 10.0, + }, + APIOpts: map[string]interface{}{ + utils.MetaEventType: utils.ResourceUpdate, }, }, - { - CGREvent: &utils.CGREvent{ // hitting THD_CDRS_1 - Tenant: "cgrates.org", - ID: "cdrev1", - Event: map[string]interface{}{ - "field_extr1": "val_extr1", - "fieldextr2": "valextr2", - utils.CGRID: utils.Sha1("dsafdsaf", time.Date(2013, 11, 7, 8, 42, 26, 0, time.UTC).String()), - utils.RunID: utils.MetaRaw, - utils.OrderID: 123, - utils.OriginHost: "192.168.1.1", - utils.Source: utils.UnitTest, - utils.OriginID: "dsafdsaf", - utils.ToR: utils.MetaVoice, - utils.RequestType: utils.MetaRated, - utils.Tenant: "cgrates.org", - utils.Category: "call", - utils.AccountField: "1007", - utils.Subject: "1007", - utils.Destination: "+4986517174963", - utils.SetupTime: time.Date(2013, 11, 7, 8, 42, 20, 0, time.UTC), - utils.PDD: 0 * time.Second, - utils.AnswerTime: time.Date(2013, 11, 7, 8, 42, 26, 0, time.UTC), - utils.Usage: 10 * time.Second, - utils.Route: "SUPPL1", - utils.Cost: -1.0, - }, - APIOpts: map[string]interface{}{ - utils.MetaEventType: utils.CDR, - }, + { // hitting THD_CDRS_1 + Tenant: "cgrates.org", + ID: "cdrev1", + Event: map[string]interface{}{ + "field_extr1": "val_extr1", + "fieldextr2": "valextr2", + utils.CGRID: utils.Sha1("dsafdsaf", time.Date(2013, 11, 7, 8, 42, 26, 0, time.UTC).String()), + utils.RunID: utils.MetaRaw, + utils.OrderID: 123, + utils.OriginHost: "192.168.1.1", + utils.Source: utils.UnitTest, + utils.OriginID: "dsafdsaf", + utils.ToR: utils.MetaVoice, + utils.RequestType: utils.MetaRated, + utils.Tenant: "cgrates.org", + utils.Category: "call", + utils.AccountField: "1007", + utils.Subject: "1007", + utils.Destination: "+4986517174963", + utils.SetupTime: time.Date(2013, 11, 7, 8, 42, 20, 0, time.UTC), + utils.PDD: 0 * time.Second, + utils.AnswerTime: time.Date(2013, 11, 7, 8, 42, 26, 0, time.UTC), + utils.Usage: 10 * time.Second, + utils.Route: "SUPPL1", + utils.Cost: -1.0, + }, + APIOpts: map[string]interface{}{ + utils.MetaEventType: utils.CDR, }, }, } @@ -617,13 +599,11 @@ func testV1TSMaxHits(t *testing.T) { var ids []string eIDs := []string{"TH3"} - thEvent := &engine.ThresholdsArgsProcessEvent{ - CGREvent: &utils.CGREvent{ // hitting TH3 - Tenant: "cgrates.org", - ID: "event1", - Event: map[string]interface{}{ - utils.AccountField: "1002", - }, + thEvent := &utils.CGREvent{ // hitting TH3 + Tenant: "cgrates.org", + ID: "event1", + Event: map[string]interface{}{ + utils.AccountField: "1002", }, } //process event @@ -724,14 +704,14 @@ func testV1TSUpdateSnooze(t *testing.T) { var ids []string eIDs := []string{"TH4"} - thEvent := &engine.ThresholdsArgsProcessEvent{ - ThresholdIDs: []string{"TH4"}, - CGREvent: &utils.CGREvent{ // hitting TH4 - Tenant: "cgrates.org", - ID: "event1", - Event: map[string]interface{}{ - "CustomEv": "SnoozeEv", - }, + thEvent := &utils.CGREvent{ // hitting TH4 + Tenant: "cgrates.org", + ID: "event1", + Event: map[string]interface{}{ + "CustomEv": "SnoozeEv", + }, + APIOpts: map[string]interface{}{ + utils.OptsThresholdsProfileIDs: []string{"TH4"}, }, } tNow := time.Now() @@ -857,13 +837,13 @@ func testv1TSGetThresholdProfileIDsCount(t *testing.T) { func testV1TSProcessEventWithoutTenant(t *testing.T) { var ids []string eIDs := []string{"TH4"} - thEvent := &engine.ThresholdsArgsProcessEvent{ - ThresholdIDs: []string{"TH4"}, - CGREvent: &utils.CGREvent{ // hitting TH4 - ID: "event1", - Event: map[string]interface{}{ - "CustomEv": "SnoozeEv", - }, + thEvent := &utils.CGREvent{ // hitting TH4 + ID: "event1", + Event: map[string]interface{}{ + "CustomEv": "SnoozeEv", + }, + APIOpts: map[string]interface{}{ + utils.OptsThresholdsProfileIDs: []string{"TH4"}, }, } if err := tSv1Rpc.Call(utils.ThresholdSv1ProcessEvent, thEvent, &ids); err != nil { @@ -948,14 +928,12 @@ func testV1TSProcessAccountUpdateEvent(t *testing.T) { t.Error(err) } - acntUpdateEv := &engine.ThresholdsArgsProcessEvent{ - CGREvent: &utils.CGREvent{ // hitting TH_ACNT_UPDATE_EV - Tenant: "cgrates.org", - ID: "SIMULATE_ACNT_UPDATE_EV", - Event: acnt.AsAccountSummary().AsMapInterface(), - APIOpts: map[string]interface{}{ - utils.MetaEventType: utils.AccountUpdate, - }, + acntUpdateEv := &utils.CGREvent{ // hitting TH_ACNT_UPDATE_EV + Tenant: "cgrates.org", + ID: "SIMULATE_ACNT_UPDATE_EV", + Event: acnt.AsAccountSummary().AsMapInterface(), + APIOpts: map[string]interface{}{ + utils.MetaEventType: utils.AccountUpdate, }, } @@ -1034,14 +1012,14 @@ func testV1ThresholdStopCPUProfiling(t *testing.T) { func testThresholdSCacheProcessEventNotFound(t *testing.T) { var ids []string - thEvent := &engine.ThresholdsArgsProcessEvent{ - ThresholdIDs: []string{"THRESHOLD_CACHE"}, - CGREvent: &utils.CGREvent{ - Tenant: "cgrates.org", - ID: "THRESHOLD_CACHE", - Event: map[string]interface{}{ - "CustomEv": "SnoozeEv", - }, + thEvent := &utils.CGREvent{ + Tenant: "cgrates.org", + ID: "THRESHOLD_CACHE", + Event: map[string]interface{}{ + "CustomEv": "SnoozeEv", + }, + APIOpts: map[string]interface{}{ + utils.OptsThresholdsProfileIDs: []string{"THRESHOLD_CACHE"}, }, } if err := tSv1Rpc.Call(utils.ThresholdSv1ProcessEvent, thEvent, &ids); err == nil || err.Error() != utils.ErrNotFound.Error() { @@ -1051,14 +1029,14 @@ func testThresholdSCacheProcessEventNotFound(t *testing.T) { func testThresholdSCacheProcessEventFound(t *testing.T) { var ids []string - thEvent := &engine.ThresholdsArgsProcessEvent{ - ThresholdIDs: []string{"THRESHOLD_CACHE"}, - CGREvent: &utils.CGREvent{ - Tenant: "cgrates.org", - ID: "THRESHOLD_CACHE", - Event: map[string]interface{}{ - "CustomEv": "SnoozeEv", - }, + thEvent := &utils.CGREvent{ + Tenant: "cgrates.org", + ID: "THRESHOLD_CACHE", + Event: map[string]interface{}{ + "CustomEv": "SnoozeEv", + }, + APIOpts: map[string]interface{}{ + utils.OptsThresholdsProfileIDs: []string{"THRESHOLD_CACHE"}, }, } if err := tSv1Rpc.Call(utils.ThresholdSv1ProcessEvent, thEvent, &ids); err != nil { diff --git a/config/config.go b/config/config.go index 8ad821cef..f3aaf4a6d 100644 --- a/config/config.go +++ b/config/config.go @@ -152,7 +152,7 @@ func newCGRConfig(config []byte) (cfg *CGRConfig, err error) { cfg.chargerSCfg = new(ChargerSCfg) cfg.resourceSCfg = new(ResourceSConfig) cfg.statsCfg = &StatSCfg{Opts: &StatsOpts{}} - cfg.thresholdSCfg = new(ThresholdSCfg) + cfg.thresholdSCfg = &ThresholdSCfg{Opts: &ThresholdsOpts{}} cfg.routeSCfg = new(RouteSCfg) cfg.sureTaxCfg = new(SureTaxCfg) cfg.dispatcherSCfg = new(DispatcherSCfg) diff --git a/config/config_defaults.go b/config/config_defaults.go index 0aeb87939..61939f987 100644 --- a/config/config_defaults.go +++ b/config/config_defaults.go @@ -764,6 +764,10 @@ const CGRATES_CFG_JSON = ` "prefix_indexed_fields": [], // query indexes based on these fields for faster processing "suffix_indexed_fields": [], // query indexes based on these fields for faster processing "nested_fields": false, // determines which field is checked when matching indexed filters(true: all; false: only the one on the first level) + "opts": { + "*profileIDs": [], + "*profileIgnoreFilters": false, + }, }, diff --git a/config/libconfig_json.go b/config/libconfig_json.go index 8c45a5940..3554c4025 100644 --- a/config/libconfig_json.go +++ b/config/libconfig_json.go @@ -462,6 +462,11 @@ type StatServJsonCfg struct { Opts *StatsOptsJson } +type ThresholdsOptsJson struct { + ProfileIDs *[]string `json:"*profileIDs"` + ProfileIgnoreFilters *bool `json:"*profileIgnoreFilters"` +} + // Threshold service config section type ThresholdSJsonCfg struct { Enabled *bool @@ -471,6 +476,7 @@ type ThresholdSJsonCfg struct { Prefix_indexed_fields *[]string Suffix_indexed_fields *[]string Nested_fields *bool // applies when indexed fields is not defined + Opts *ThresholdsOptsJson } // Route service config section diff --git a/config/thresholdscfg.go b/config/thresholdscfg.go index 15a46d978..7a32c4bfe 100644 --- a/config/thresholdscfg.go +++ b/config/thresholdscfg.go @@ -24,6 +24,11 @@ import ( "github.com/cgrates/cgrates/utils" ) +type ThresholdsOpts struct { + ProfileIDs []string + ProfileIgnoreFilters bool +} + // ThresholdSCfg the threshold config section type ThresholdSCfg struct { Enabled bool @@ -33,6 +38,19 @@ type ThresholdSCfg struct { PrefixIndexedFields *[]string SuffixIndexedFields *[]string NestedFields bool + Opts *ThresholdsOpts +} + +func (thdOpts *ThresholdsOpts) loadFromJSONCfg(jsnCfg *ThresholdsOptsJson) { + if jsnCfg == nil { + return + } + if jsnCfg.ProfileIDs != nil { + thdOpts.ProfileIDs = *jsnCfg.ProfileIDs + } + if jsnCfg.ProfileIgnoreFilters != nil { + thdOpts.ProfileIgnoreFilters = *jsnCfg.ProfileIgnoreFilters + } } func (t *ThresholdSCfg) loadFromJSONCfg(jsnCfg *ThresholdSJsonCfg) (err error) { @@ -74,16 +92,24 @@ func (t *ThresholdSCfg) loadFromJSONCfg(jsnCfg *ThresholdSJsonCfg) (err error) { if jsnCfg.Nested_fields != nil { t.NestedFields = *jsnCfg.Nested_fields } + if jsnCfg.Opts != nil { + t.Opts.loadFromJSONCfg(jsnCfg.Opts) + } return nil } // AsMapInterface returns the config as a map[string]interface{} func (t *ThresholdSCfg) AsMapInterface() (initialMP map[string]interface{}) { + opts := map[string]interface{}{ + utils.MetaProfileIDs: t.Opts.ProfileIDs, + utils.MetaProfileIgnoreFiltersCfg: t.Opts.ProfileIgnoreFilters, + } initialMP = map[string]interface{}{ utils.EnabledCfg: t.Enabled, utils.IndexedSelectsCfg: t.IndexedSelects, utils.NestedFieldsCfg: t.NestedFields, utils.StoreIntervalCfg: utils.EmptyString, + utils.OptsCfg: opts, } if t.StoreInterval != 0 { initialMP[utils.StoreIntervalCfg] = t.StoreInterval.String() @@ -113,6 +139,13 @@ func (t *ThresholdSCfg) AsMapInterface() (initialMP map[string]interface{}) { return } +func (thdOpts *ThresholdsOpts) Clone() *ThresholdsOpts { + return &ThresholdsOpts{ + ProfileIDs: utils.CloneStringSlice(thdOpts.ProfileIDs), + ProfileIgnoreFilters: thdOpts.ProfileIgnoreFilters, + } +} + // Clone returns a deep copy of ThresholdSCfg func (t ThresholdSCfg) Clone() (cln *ThresholdSCfg) { cln = &ThresholdSCfg{ @@ -120,6 +153,7 @@ func (t ThresholdSCfg) Clone() (cln *ThresholdSCfg) { IndexedSelects: t.IndexedSelects, StoreInterval: t.StoreInterval, NestedFields: t.NestedFields, + Opts: t.Opts.Clone(), } if t.StringIndexedFields != nil { diff --git a/console/thresholds_for_event.go b/console/thresholds_for_event.go index fb20cd583..9b97263d5 100644 --- a/console/thresholds_for_event.go +++ b/console/thresholds_for_event.go @@ -29,7 +29,7 @@ func init() { c := &CmdThresholdsForEvent{ name: "thresholds_for_event", rpcMethod: utils.ThresholdSv1GetThresholdsForEvent, - rpcParams: &engine.ThresholdsArgsProcessEvent{}, + rpcParams: &utils.CGREvent{}, } commands[c.Name()] = c c.CommandExecuter = &CommandExecuter{c} @@ -38,7 +38,7 @@ func init() { type CmdThresholdsForEvent struct { name string rpcMethod string - rpcParams *engine.ThresholdsArgsProcessEvent + rpcParams *utils.CGREvent *CommandExecuter } @@ -52,9 +52,7 @@ func (self *CmdThresholdsForEvent) RpcMethod() string { func (self *CmdThresholdsForEvent) RpcParams(reset bool) interface{} { if reset || self.rpcParams == nil { - self.rpcParams = &engine.ThresholdsArgsProcessEvent{ - CGREvent: new(utils.CGREvent), - } + self.rpcParams = new(utils.CGREvent) } return self.rpcParams } diff --git a/console/thresholds_process_event.go b/console/thresholds_process_event.go index fa4bec464..1a31fd720 100644 --- a/console/thresholds_process_event.go +++ b/console/thresholds_process_event.go @@ -21,7 +21,6 @@ package console import ( "time" - "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" ) @@ -29,7 +28,7 @@ func init() { c := &CmdThresholdProcessEvent{ name: "thresholds_process_event", rpcMethod: utils.ThresholdSv1ProcessEvent, - rpcParams: &engine.ThresholdsArgsProcessEvent{}, + rpcParams: &utils.CGREvent{}, } commands[c.Name()] = c c.CommandExecuter = &CommandExecuter{c} @@ -38,7 +37,7 @@ func init() { type CmdThresholdProcessEvent struct { name string rpcMethod string - rpcParams *engine.ThresholdsArgsProcessEvent + rpcParams *utils.CGREvent *CommandExecuter } @@ -52,17 +51,14 @@ func (self *CmdThresholdProcessEvent) RpcMethod() string { func (self *CmdThresholdProcessEvent) RpcParams(reset bool) interface{} { if reset || self.rpcParams == nil { - self.rpcParams = &engine.ThresholdsArgsProcessEvent{ - CGREvent: new(utils.CGREvent), - } + self.rpcParams = new(utils.CGREvent) } return self.rpcParams } func (self *CmdThresholdProcessEvent) PostprocessRpcParams() error { - if self.rpcParams != nil && self.rpcParams.CGREvent != nil && - self.rpcParams.CGREvent.Time == nil { - self.rpcParams.CGREvent.Time = utils.TimePointer(time.Now()) + if self.rpcParams != nil && self.rpcParams.Time == nil { + self.rpcParams.Time = utils.TimePointer(time.Now()) } return nil } diff --git a/dispatchers/thresholds.go b/dispatchers/thresholds.go index 8945dcb77..059c0d7b0 100644 --- a/dispatchers/thresholds.go +++ b/dispatchers/thresholds.go @@ -39,30 +39,30 @@ func (dS *DispatcherService) ThresholdSv1Ping(args *utils.CGREvent, reply *strin return dS.Dispatch(args, utils.MetaThresholds, utils.ThresholdSv1Ping, args, reply) } -func (dS *DispatcherService) ThresholdSv1GetThresholdsForEvent(args *engine.ThresholdsArgsProcessEvent, +func (dS *DispatcherService) ThresholdSv1GetThresholdsForEvent(args *utils.CGREvent, t *engine.Thresholds) (err error) { - args.CGREvent.Tenant = utils.FirstNonEmpty(args.CGREvent.Tenant, dS.cfg.GeneralCfg().DefaultTenant) + args.Tenant = utils.FirstNonEmpty(args.Tenant, dS.cfg.GeneralCfg().DefaultTenant) if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 { if err = dS.authorize(utils.ThresholdSv1GetThresholdsForEvent, - args.CGREvent.Tenant, - utils.IfaceAsString(args.APIOpts[utils.OptsAPIKey]), args.CGREvent.Time); err != nil { + args.Tenant, + utils.IfaceAsString(args.APIOpts[utils.OptsAPIKey]), args.Time); err != nil { return } } - return dS.Dispatch(args.CGREvent, utils.MetaThresholds, utils.ThresholdSv1GetThresholdsForEvent, args, t) + return dS.Dispatch(args, utils.MetaThresholds, utils.ThresholdSv1GetThresholdsForEvent, args, t) } -func (dS *DispatcherService) ThresholdSv1ProcessEvent(args *engine.ThresholdsArgsProcessEvent, +func (dS *DispatcherService) ThresholdSv1ProcessEvent(args *utils.CGREvent, tIDs *[]string) (err error) { - args.CGREvent.Tenant = utils.FirstNonEmpty(args.CGREvent.Tenant, dS.cfg.GeneralCfg().DefaultTenant) + args.Tenant = utils.FirstNonEmpty(args.Tenant, dS.cfg.GeneralCfg().DefaultTenant) if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 { if err = dS.authorize(utils.ThresholdSv1ProcessEvent, - args.CGREvent.Tenant, - utils.IfaceAsString(args.APIOpts[utils.OptsAPIKey]), args.CGREvent.Time); err != nil { + args.Tenant, + utils.IfaceAsString(args.APIOpts[utils.OptsAPIKey]), args.Time); err != nil { return } } - return dS.Dispatch(args.CGREvent, utils.MetaThresholds, utils.ThresholdSv1ProcessEvent, args, tIDs) + return dS.Dispatch(args, utils.MetaThresholds, utils.ThresholdSv1ProcessEvent, args, tIDs) } func (dS *DispatcherService) ThresholdSv1GetThresholdIDs(args *utils.TenantWithAPIOpts, tIDs *[]string) (err error) { diff --git a/dispatchers/thresholds_it_test.go b/dispatchers/thresholds_it_test.go index 9ac2f62d7..48c29f02c 100644 --- a/dispatchers/thresholds_it_test.go +++ b/dispatchers/thresholds_it_test.go @@ -105,18 +105,16 @@ func testDspThProcessEventFailover(t *testing.T) { var ids []string eIDs := []string{"THD_ACNT_1001"} nowTime := time.Now() - args := &engine.ThresholdsArgsProcessEvent{ - CGREvent: &utils.CGREvent{ - Tenant: "cgrates.org", - ID: utils.UUIDSha1Prefix(), - Time: &nowTime, - Event: map[string]interface{}{ - utils.EventName: "Event1", - utils.AccountField: "1001"}, + args := &utils.CGREvent{ + Tenant: "cgrates.org", + ID: utils.UUIDSha1Prefix(), + Time: &nowTime, + Event: map[string]interface{}{ + utils.EventName: "Event1", + utils.AccountField: "1001"}, - APIOpts: map[string]interface{}{ - utils.OptsAPIKey: "thr12345", - }, + APIOpts: map[string]interface{}{ + utils.OptsAPIKey: "thr12345", }, } diff --git a/dispatchers/thresholds_test.go b/dispatchers/thresholds_test.go index 19a3f049f..3051ed09d 100644 --- a/dispatchers/thresholds_test.go +++ b/dispatchers/thresholds_test.go @@ -67,10 +67,8 @@ func TestDspThresholdSv1PingErrorNil(t *testing.T) { func TestDspThresholdSv1GetThresholdsForEventNil(t *testing.T) { cgrCfg := config.NewDefaultCGRConfig() dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) - CGREvent := &engine.ThresholdsArgsProcessEvent{ - CGREvent: &utils.CGREvent{ - Tenant: "tenant", - }, + CGREvent := &utils.CGREvent{ + Tenant: "tenant", } var reply *engine.Thresholds result := dspSrv.ThresholdSv1GetThresholdsForEvent(CGREvent, reply) @@ -84,10 +82,8 @@ func TestDspThresholdSv1GetThresholdsEvnil(t *testing.T) { cgrCfg := config.NewDefaultCGRConfig() dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) cgrCfg.DispatcherSCfg().AttributeSConns = []string{"test"} - CGREvent := &engine.ThresholdsArgsProcessEvent{ - CGREvent: &utils.CGREvent{ - Tenant: "tenant", - }, + CGREvent := &utils.CGREvent{ + Tenant: "tenant", } var reply *engine.Thresholds result := dspSrv.ThresholdSv1GetThresholdsForEvent(CGREvent, reply) @@ -100,10 +96,8 @@ func TestDspThresholdSv1GetThresholdsEvnil(t *testing.T) { func TestDspThresholdSv1ProcessEventNil(t *testing.T) { cgrCfg := config.NewDefaultCGRConfig() dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) - CGREvent := &engine.ThresholdsArgsProcessEvent{ - CGREvent: &utils.CGREvent{ - Tenant: "tenant", - }, + CGREvent := &utils.CGREvent{ + Tenant: "tenant", } var reply *[]string result := dspSrv.ThresholdSv1ProcessEvent(CGREvent, reply) @@ -117,10 +111,8 @@ func TestDspThresholdSv1ProcessEventnNil(t *testing.T) { cgrCfg := config.NewDefaultCGRConfig() dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) cgrCfg.DispatcherSCfg().AttributeSConns = []string{"test"} - CGREvent := &engine.ThresholdsArgsProcessEvent{ - CGREvent: &utils.CGREvent{ - Tenant: "tenant", - }, + CGREvent := &utils.CGREvent{ + Tenant: "tenant", } var reply *[]string result := dspSrv.ThresholdSv1ProcessEvent(CGREvent, reply) diff --git a/engine/account.go b/engine/account.go index 9ffee9c40..f6798b89f 100644 --- a/engine/account.go +++ b/engine/account.go @@ -549,20 +549,18 @@ func (acc *Account) debitCreditBalance(cd *CallDescriptor, count bool, dryRun bo if len(config.CgrConfig().RalsCfg().ThresholdSConns) != 0 { defaultBalance := acc.GetDefaultMoneyBalance() acntTnt := utils.NewTenantID(acc.ID) - thEv := &ThresholdsArgsProcessEvent{ - CGREvent: &utils.CGREvent{ - Tenant: acntTnt.Tenant, - ID: utils.GenUUID(), - Event: map[string]interface{}{ - utils.EventType: utils.BalanceUpdate, - utils.EventSource: utils.AccountService, - utils.AccountField: acntTnt.ID, - utils.BalanceID: defaultBalance.ID, - utils.Units: defaultBalance.Value, - }, - APIOpts: map[string]interface{}{ - utils.MetaEventType: utils.BalanceUpdate, - }, + thEv := &utils.CGREvent{ + Tenant: acntTnt.Tenant, + ID: utils.GenUUID(), + Event: map[string]interface{}{ + utils.EventType: utils.BalanceUpdate, + utils.EventSource: utils.AccountService, + utils.AccountField: acntTnt.ID, + utils.BalanceID: defaultBalance.ID, + utils.Units: defaultBalance.Value, + }, + APIOpts: map[string]interface{}{ + utils.MetaEventType: utils.BalanceUpdate, }, } var tIDs []string @@ -1084,7 +1082,7 @@ func (acc *Account) Publish(initBal map[string]float64) { if len(config.CgrConfig().RalsCfg().ThresholdSConns) != 0 { var tIDs []string if err := connMgr.Call(config.CgrConfig().RalsCfg().ThresholdSConns, nil, - utils.ThresholdSv1ProcessEvent, &ThresholdsArgsProcessEvent{CGREvent: cgrEv}, &tIDs); err != nil && + utils.ThresholdSv1ProcessEvent, cgrEv, &tIDs); err != nil && err.Error() != utils.ErrNotFound.Error() { utils.Logger.Warning( fmt.Sprintf(" error: %s processing account event %+v with ThresholdS.", err.Error(), cgrEv)) diff --git a/engine/cdrs.go b/engine/cdrs.go index 30ffe5b1c..b98919c7b 100644 --- a/engine/cdrs.go +++ b/engine/cdrs.go @@ -392,9 +392,7 @@ func (cdrS *CDRServer) attrSProcessEvent(cgrEv *utils.CGREvent) (err error) { func (cdrS *CDRServer) thdSProcessEvent(cgrEv *utils.CGREvent) (err error) { var tIDs []string // we clone the CGREvent so we can add EventType without being propagated - thArgs := &ThresholdsArgsProcessEvent{ - CGREvent: cgrEv.Clone(), - } + thArgs := cgrEv.Clone() if thArgs.APIOpts == nil { thArgs.APIOpts = make(map[string]interface{}) } diff --git a/engine/resources.go b/engine/resources.go index 896c9389c..7c5305551 100644 --- a/engine/resources.go +++ b/engine/resources.go @@ -530,18 +530,16 @@ func (rS *ResourceService) processThresholds(rs Resources, opts map[string]inter } thIDs = r.rPrf.ThresholdIDs } - - thEv := &ThresholdsArgsProcessEvent{ThresholdIDs: thIDs, - CGREvent: &utils.CGREvent{ - Tenant: r.Tenant, - ID: utils.GenUUID(), - Event: map[string]interface{}{ - utils.EventType: utils.ResourceUpdate, - utils.ResourceID: r.ID, - utils.Usage: r.TotalUsage(), - }, - APIOpts: opts, + opts[utils.OptsThresholdsProfileIDs] = thIDs + thEv := &utils.CGREvent{ + Tenant: r.Tenant, + ID: utils.GenUUID(), + Event: map[string]interface{}{ + utils.EventType: utils.ResourceUpdate, + utils.ResourceID: r.ID, + utils.Usage: r.TotalUsage(), }, + APIOpts: opts, } var tIDs []string if err := rS.connMgr.Call(rS.cgrcfg.ResourceSCfg().ThresholdSConns, nil, diff --git a/engine/stats.go b/engine/stats.go index 984280901..f4278b939 100644 --- a/engine/stats.go +++ b/engine/stats.go @@ -291,17 +291,15 @@ func (sS *StatService) processThresholds(sQs StatQueues, opts map[string]interfa } thIDs = sq.sqPrfl.ThresholdIDs } - thEv := &ThresholdsArgsProcessEvent{ - ThresholdIDs: thIDs, - CGREvent: &utils.CGREvent{ - Tenant: sq.Tenant, - ID: utils.GenUUID(), - Event: map[string]interface{}{ - utils.EventType: utils.StatUpdate, - utils.StatID: sq.ID, - }, - APIOpts: opts, + opts[utils.OptsThresholdsProfileIDs] = thIDs + thEv := &utils.CGREvent{ + Tenant: sq.Tenant, + ID: utils.GenUUID(), + Event: map[string]interface{}{ + utils.EventType: utils.StatUpdate, + utils.StatID: sq.ID, }, + APIOpts: opts, } for metricID, metric := range sq.SQMetrics { thEv.Event[metricID] = metric.GetValue(sS.cgrcfg.GeneralCfg().RoundingDecimals) diff --git a/engine/stats_test.go b/engine/stats_test.go index 384aa06a1..80c8159bc 100644 --- a/engine/stats_test.go +++ b/engine/stats_test.go @@ -2337,19 +2337,17 @@ func TestStatQueueProcessThresholdsOK(t *testing.T) { ccM := &ccMock{ calls: map[string]func(args interface{}, reply interface{}) error{ utils.ThresholdSv1ProcessEvent: func(args, reply interface{}) error { - exp := &ThresholdsArgsProcessEvent{ - ThresholdIDs: []string{"TH1"}, - CGREvent: &utils.CGREvent{ - Tenant: "cgrates.org", - ID: args.(*ThresholdsArgsProcessEvent).CGREvent.ID, - Event: map[string]interface{}{ - utils.EventType: utils.StatUpdate, - utils.StatID: "SQ1", - "testMetricType": time.Duration(time.Hour), - }, - APIOpts: map[string]interface{}{ - utils.MetaEventType: utils.StatUpdate, - }, + exp := &utils.CGREvent{ + Tenant: "cgrates.org", + ID: args.(*utils.CGREvent).ID, + Event: map[string]interface{}{ + utils.EventType: utils.StatUpdate, + utils.StatID: "SQ1", + "testMetricType": time.Duration(time.Hour), + }, + APIOpts: map[string]interface{}{ + utils.MetaEventType: utils.StatUpdate, + utils.OptsThresholdsProfileIDs: []string{"TH1"}, }, } if !reflect.DeepEqual(exp, args) { diff --git a/engine/thresholds.go b/engine/thresholds.go index 948bf9b96..e9d19b3cf 100644 --- a/engine/thresholds.go +++ b/engine/thresholds.go @@ -143,7 +143,7 @@ func (t *Threshold) isLocked() bool { // ProcessEvent processes an ThresholdEvent // concurrentActions limits the number of simultaneous action sets executed -func (t *Threshold) ProcessEvent(args *ThresholdsArgsProcessEvent, dm *DataManager, fltrS *FilterS) (err error) { +func (t *Threshold) ProcessEvent(args *utils.CGREvent, dm *DataManager, fltrS *FilterS) (err error) { if t.Snooze.After(time.Now()) || // snoozed, not executing actions t.Hits < t.tPrfl.MinHits || // number of hits was not met, will not execute actions (t.tPrfl.MaxHits != -1 && @@ -165,7 +165,7 @@ func (t *Threshold) ProcessEvent(args *ThresholdsArgsProcessEvent, dm *DataManag at := &ActionTiming{ Uuid: utils.GenUUID(), ActionsID: actionSetID, - ExtraData: args.CGREvent, + ExtraData: args, } if tntAcnt != utils.EmptyString { at.accountIDs = utils.NewStringMap(tntAcnt) @@ -324,12 +324,18 @@ func (tS *ThresholdService) StoreThreshold(t *Threshold) (err error) { } // matchingThresholdsForEvent returns ordered list of matching thresholds which are active for an Event -func (tS *ThresholdService) matchingThresholdsForEvent(tnt string, args *ThresholdsArgsProcessEvent) (ts Thresholds, err error) { +func (tS *ThresholdService) matchingThresholdsForEvent(tnt string, args *utils.CGREvent) (ts Thresholds, err error) { evNm := utils.MapStorage{ utils.MetaReq: args.Event, utils.MetaOpts: args.APIOpts, } - tIDs := utils.NewStringSet(args.ThresholdIDs) + thdIDs := tS.cgrcfg.ThresholdSCfg().Opts.ProfileIDs + if opt, has := args.APIOpts[utils.OptsThresholdsProfileIDs]; has { + if thdIDs, err = utils.IfaceAsSliceString(opt); err != nil { + return + } + } + tIDs := utils.NewStringSet(thdIDs) if len(tIDs) == 0 { tIDs, err = MatchingItemIDsForEvent(evNm, tS.cgrcfg.ThresholdSCfg().StringIndexedFields, @@ -410,40 +416,8 @@ func (tS *ThresholdService) matchingThresholdsForEvent(tnt string, args *Thresho return } -// ThresholdsArgsProcessEvent are the arguments to proccess the event with thresholds -type ThresholdsArgsProcessEvent struct { - ThresholdIDs []string - *utils.CGREvent - clnb bool //rpcclonable -} - -// SetCloneable sets if the args should be clonned on internal connections -func (attr *ThresholdsArgsProcessEvent) SetCloneable(rpcCloneable bool) { - attr.clnb = rpcCloneable -} - -// RPCClone implements rpcclient.RPCCloner interface -func (attr *ThresholdsArgsProcessEvent) RPCClone() (interface{}, error) { - if !attr.clnb { - return attr, nil - } - return attr.Clone(), nil -} - -// Clone creates a clone of the object -func (attr *ThresholdsArgsProcessEvent) Clone() *ThresholdsArgsProcessEvent { - var thIDs []string - if attr.ThresholdIDs != nil { - thIDs = utils.CloneStringSlice(attr.ThresholdIDs) - } - return &ThresholdsArgsProcessEvent{ - ThresholdIDs: thIDs, - CGREvent: attr.CGREvent.Clone(), - } -} - // processEvent processes a new event, dispatching to matching thresholds -func (tS *ThresholdService) processEvent(tnt string, args *ThresholdsArgsProcessEvent) (thresholdsIDs []string, err error) { +func (tS *ThresholdService) processEvent(tnt string, args *utils.CGREvent) (thresholdsIDs []string, err error) { var matchTs Thresholds if matchTs, err = tS.matchingThresholdsForEvent(tnt, args); err != nil { return nil, err @@ -456,7 +430,7 @@ func (tS *ThresholdService) processEvent(tnt string, args *ThresholdsArgsProcess if err = t.ProcessEvent(args, tS.dm, tS.filterS); err != nil { utils.Logger.Warning( fmt.Sprintf(" threshold: %s, ignoring event: %s, error: %s", - t.TenantID(), utils.ConcatenatedKey(tnt, args.CGREvent.ID), err.Error())) + t.TenantID(), utils.ConcatenatedKey(tnt, args.ID), err.Error())) withErrors = true continue } @@ -498,13 +472,13 @@ func (tS *ThresholdService) processEvent(tnt string, args *ThresholdsArgsProcess } // V1ProcessEvent implements ThresholdService method for processing an Event -func (tS *ThresholdService) V1ProcessEvent(args *ThresholdsArgsProcessEvent, reply *[]string) (err error) { - if args.CGREvent == nil { +func (tS *ThresholdService) V1ProcessEvent(args *utils.CGREvent, reply *[]string) (err error) { + if args == nil { return utils.NewErrMandatoryIeMissing(utils.CGREventString) } if missing := utils.MissingStructFields(args, []string{utils.ID}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) - } else if args.CGREvent.Event == nil { + } else if args.Event == nil { return utils.NewErrMandatoryIeMissing(utils.Event) } tnt := args.Tenant @@ -520,13 +494,13 @@ func (tS *ThresholdService) V1ProcessEvent(args *ThresholdsArgsProcessEvent, rep } // V1GetThresholdsForEvent queries thresholds matching an Event -func (tS *ThresholdService) V1GetThresholdsForEvent(args *ThresholdsArgsProcessEvent, reply *Thresholds) (err error) { - if args.CGREvent == nil { +func (tS *ThresholdService) V1GetThresholdsForEvent(args *utils.CGREvent, reply *Thresholds) (err error) { + if args == nil { return utils.NewErrMandatoryIeMissing(utils.CGREventString) } if missing := utils.MissingStructFields(args, []string{utils.ID}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) - } else if args.CGREvent.Event == nil { + } else if args.Event == nil { return utils.NewErrMandatoryIeMissing(utils.Event) } tnt := args.Tenant diff --git a/engine/thresholds_test.go b/engine/thresholds_test.go index bfec960f3..c1e0c869f 100644 --- a/engine/thresholds_test.go +++ b/engine/thresholds_test.go @@ -85,34 +85,28 @@ var ( ID: "TH_3", }, } - testThresholdArgs = []*ThresholdsArgsProcessEvent{ + testThresholdArgs = []*utils.CGREvent{ { - CGREvent: &utils.CGREvent{ - Tenant: "cgrates.org", - ID: "Ev1", - Event: map[string]interface{}{ - "Threshold": "TH_1", - "Weight": "10.0", - }, + Tenant: "cgrates.org", + ID: "Ev1", + Event: map[string]interface{}{ + "Threshold": "TH_1", + "Weight": "10.0", }, }, { - CGREvent: &utils.CGREvent{ - Tenant: "cgrates.org", - ID: "Ev1", - Event: map[string]interface{}{ - "Threshold": "TH_2", - "Weight": "20.0", - }, + Tenant: "cgrates.org", + ID: "Ev1", + Event: map[string]interface{}{ + "Threshold": "TH_2", + "Weight": "20.0", }, }, { - CGREvent: &utils.CGREvent{ - Tenant: "cgrates.org", - ID: "Ev1", - Event: map[string]interface{}{ - "Threshold": "ThresholdPrefix123", - }, + Tenant: "cgrates.org", + ID: "Ev1", + Event: map[string]interface{}{ + "Threshold": "ThresholdPrefix123", }, }, } @@ -411,10 +405,8 @@ func TestThresholdsProcessEvent2(t *testing.T) { Tenant: "cgrates.org", ID: "TH_4", } - ev := &ThresholdsArgsProcessEvent{ - ThresholdIDs: []string{"TH_1", "TH_2", "TH_3", "TH_4"}, - CGREvent: testThresholdArgs[0].CGREvent, - } + testThresholdArgs[0].APIOpts[utils.OptsThresholdsProfileIDs] = []string{"TH_1", "TH_2", "TH_3", "TH_4"} + ev := testThresholdArgs[0] if err = dmTH.SetThresholdProfile(thPrf, true); err != nil { t.Fatal(err) } @@ -590,17 +582,15 @@ func TestThresholdsProcessEventAccountUpdateErrPartExec(t *testing.T) { tPrfl: thPrf, } - args := &ThresholdsArgsProcessEvent{ - ThresholdIDs: []string{"TH1"}, - CGREvent: &utils.CGREvent{ - Tenant: "cgrates.org", - ID: "ThresholdProcessEvent", - Event: map[string]interface{}{ - utils.AccountField: "1001", - }, - APIOpts: map[string]interface{}{ - utils.MetaEventType: utils.AccountUpdate, - }, + args := &utils.CGREvent{ + Tenant: "cgrates.org", + ID: "ThresholdProcessEvent", + Event: map[string]interface{}{ + utils.AccountField: "1001", + }, + APIOpts: map[string]interface{}{ + utils.MetaEventType: utils.AccountUpdate, + utils.OptsThresholdsProfileIDs: []string{"TH1"}, }, } expLog := `[WARNING] failed executing actions: actPrf, error: NOT_FOUND` @@ -642,14 +632,14 @@ func TestThresholdsProcessEventAsyncExecErr(t *testing.T) { tPrfl: thPrf, } - args := &ThresholdsArgsProcessEvent{ - ThresholdIDs: []string{"TH1"}, - CGREvent: &utils.CGREvent{ - Tenant: "cgrates.org", - ID: "ThresholdProcessEvent", - Event: map[string]interface{}{ - utils.AccountField: "1001", - }, + args := &utils.CGREvent{ + Tenant: "cgrates.org", + ID: "ThresholdProcessEvent", + Event: map[string]interface{}{ + utils.AccountField: "1001", + }, + APIOpts: map[string]interface{}{ + utils.OptsThresholdsProfileIDs: []string{"TH1"}, }, } expLog := `[WARNING] failed executing actions: actPrf, error: NOT_FOUND` @@ -681,17 +671,15 @@ func TestThresholdsProcessEvent3(t *testing.T) { tPrfl: thPrf, } - args := &ThresholdsArgsProcessEvent{ - ThresholdIDs: []string{"TH1"}, - CGREvent: &utils.CGREvent{ - Tenant: "cgrates.org", - ID: "ThresholdProcessEvent", - Event: map[string]interface{}{ - utils.AccountField: "1001", - }, - APIOpts: map[string]interface{}{ - utils.MetaEventType: utils.AccountUpdate, - }, + args := &utils.CGREvent{ + Tenant: "cgrates.org", + ID: "ThresholdProcessEvent", + Event: map[string]interface{}{ + utils.AccountField: "1001", + }, + APIOpts: map[string]interface{}{ + utils.MetaEventType: utils.AccountUpdate, + utils.OptsThresholdsProfileIDs: []string{"TH1"}, }, } if err := th.ProcessEvent(args, dm, nil); err != nil { @@ -850,63 +838,6 @@ func TestThresholdsStoreThresholdNilDirtyField(t *testing.T) { } } -func TestThresholdsSetCloneable(t *testing.T) { - args := &ThresholdsArgsProcessEvent{ - ThresholdIDs: []string{"THD_ID"}, - CGREvent: &utils.CGREvent{ - Tenant: "cgrates.org", - ID: "EventTest", - Event: map[string]interface{}{}, - }, - clnb: false, - } - - exp := &ThresholdsArgsProcessEvent{ - ThresholdIDs: []string{"THD_ID"}, - CGREvent: &utils.CGREvent{ - Tenant: "cgrates.org", - ID: "EventTest", - Event: map[string]interface{}{}, - }, - clnb: true, - } - args.SetCloneable(true) - - if !reflect.DeepEqual(args, exp) { - t.Errorf("expected: <%+v>, \nreceived: <%+v>", exp, args) - } -} - -func TestThresholdsRPCClone(t *testing.T) { - args := &ThresholdsArgsProcessEvent{ - ThresholdIDs: []string{"THD_ID"}, - CGREvent: &utils.CGREvent{ - Tenant: "cgrates.org", - ID: "EventTest", - Event: make(map[string]interface{}), - APIOpts: make(map[string]interface{}), - }, - clnb: true, - } - - exp := &ThresholdsArgsProcessEvent{ - ThresholdIDs: []string{"THD_ID"}, - CGREvent: &utils.CGREvent{ - Tenant: "cgrates.org", - ID: "EventTest", - Event: make(map[string]interface{}), - APIOpts: make(map[string]interface{}), - }, - } - - if out, err := args.RPCClone(); err != nil { - t.Error(err) - } else if !reflect.DeepEqual(out.(*ThresholdsArgsProcessEvent), exp) { - t.Errorf("expected: <%T>, \nreceived: <%T>", - args, exp) - } -} - func TestThresholdsProcessEventOK(t *testing.T) { cfg := config.NewDefaultCGRConfig() data := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) @@ -940,14 +871,14 @@ func TestThresholdsProcessEventOK(t *testing.T) { t.Error(err) } - args := &ThresholdsArgsProcessEvent{ - ThresholdIDs: []string{"TH1"}, - CGREvent: &utils.CGREvent{ - Tenant: "cgrates.org", - ID: "ThdProcessEvent", - Event: map[string]interface{}{ - utils.AccountField: "1001", - }, + args := &utils.CGREvent{ + Tenant: "cgrates.org", + ID: "ThdProcessEvent", + Event: map[string]interface{}{ + utils.AccountField: "1001", + }, + APIOpts: map[string]interface{}{ + utils.OptsThresholdsProfileIDs: []string{"TH1"}, }, } @@ -987,14 +918,14 @@ func TestThresholdsProcessEventStoreThOK(t *testing.T) { t.Error(err) } - args := &ThresholdsArgsProcessEvent{ - ThresholdIDs: []string{"TH2"}, - CGREvent: &utils.CGREvent{ - Tenant: "cgrates.org", - ID: "ThdProcessEvent", - Event: map[string]interface{}{ - utils.AccountField: "1001", - }, + args := &utils.CGREvent{ + Tenant: "cgrates.org", + ID: "ThdProcessEvent", + Event: map[string]interface{}{ + utils.AccountField: "1001", + }, + APIOpts: map[string]interface{}{ + utils.OptsThresholdsProfileIDs: []string{"TH2"}, }, } exp := &Threshold{ @@ -1078,14 +1009,14 @@ func TestThresholdsProcessEventMaxHitsDMErr(t *testing.T) { Cache.SetWithoutReplicate(utils.CacheThresholdProfiles, thPrf.TenantID(), thPrf, nil, true, utils.NonTransactional) Cache.SetWithoutReplicate(utils.CacheThresholds, thPrf.TenantID(), th, nil, true, utils.NonTransactional) - args := &ThresholdsArgsProcessEvent{ - ThresholdIDs: []string{"TH3"}, - CGREvent: &utils.CGREvent{ - Tenant: "cgrates.org", - ID: "ThdProcessEvent", - Event: map[string]interface{}{ - utils.AccountField: "1001", - }, + args := &utils.CGREvent{ + Tenant: "cgrates.org", + ID: "ThdProcessEvent", + Event: map[string]interface{}{ + utils.AccountField: "1001", + }, + APIOpts: map[string]interface{}{ + utils.OptsThresholdsProfileIDs: []string{"TH3"}, }, } @@ -1140,14 +1071,14 @@ func TestThresholdsProcessEventNotFound(t *testing.T) { t.Error(err) } - args := &ThresholdsArgsProcessEvent{ - ThresholdIDs: []string{"TH6"}, - CGREvent: &utils.CGREvent{ - Tenant: "cgrates.org", - ID: "ThdProcessEvent", - Event: map[string]interface{}{ - utils.AccountField: "1001", - }, + args := &utils.CGREvent{ + Tenant: "cgrates.org", + ID: "ThdProcessEvent", + Event: map[string]interface{}{ + utils.AccountField: "1001", + }, + APIOpts: map[string]interface{}{ + utils.OptsThresholdsProfileIDs: []string{"TH6"}, }, } @@ -1191,12 +1122,10 @@ func TestThresholdsV1ProcessEventOK(t *testing.T) { t.Error(err) } - args := &ThresholdsArgsProcessEvent{ - CGREvent: &utils.CGREvent{ - ID: "V1ProcessEventTest", - Event: map[string]interface{}{ - utils.AccountField: "1001", - }, + args := &utils.CGREvent{ + ID: "V1ProcessEventTest", + Event: map[string]interface{}{ + utils.AccountField: "1001", }, } var reply []string @@ -1254,12 +1183,10 @@ func TestThresholdsV1ProcessEventPartExecErr(t *testing.T) { t.Error(err) } - args := &ThresholdsArgsProcessEvent{ - CGREvent: &utils.CGREvent{ - ID: "V1ProcessEventTest", - Event: map[string]interface{}{ - utils.AccountField: "1001", - }, + args := &utils.CGREvent{ + ID: "V1ProcessEventTest", + Event: map[string]interface{}{ + utils.AccountField: "1001", }, } expLog1 := `[ERROR] Failed to get actions for ACT1: NOT_FOUND` @@ -1312,20 +1239,16 @@ func TestThresholdsV1ProcessEventMissingArgs(t *testing.T) { t.Error(err) } - args := &ThresholdsArgsProcessEvent{ - CGREvent: &utils.CGREvent{ - ID: "V1ProcessEventTest", - Event: map[string]interface{}{ - utils.AccountField: "1001", - }, + args := &utils.CGREvent{ + ID: "V1ProcessEventTest", + Event: map[string]interface{}{ + utils.AccountField: "1001", }, } - args = &ThresholdsArgsProcessEvent{ - CGREvent: &utils.CGREvent{ - Event: map[string]interface{}{ - utils.AccountField: "1001", - }, + args = &utils.CGREvent{ + Event: map[string]interface{}{ + utils.AccountField: "1001", }, } var reply []string @@ -1335,20 +1258,15 @@ func TestThresholdsV1ProcessEventMissingArgs(t *testing.T) { t.Errorf("expected: <%+v>, \nreceived: <%+v>", experr, err) } - args = &ThresholdsArgsProcessEvent{ - CGREvent: nil, - } experr = `MANDATORY_IE_MISSING: [CGREvent]` - if err := tS.V1ProcessEvent(args, &reply); err == nil || + if err := tS.V1ProcessEvent(nil, &reply); err == nil || err.Error() != experr { t.Errorf("expected: <%+v>, \nreceived: <%+v>", experr, err) } - args = &ThresholdsArgsProcessEvent{ - CGREvent: &utils.CGREvent{ - ID: "V1ProcessEventTest", - Event: nil, - }, + args = &utils.CGREvent{ + ID: "V1ProcessEventTest", + Event: nil, } experr = `MANDATORY_IE_MISSING: [Event]` if err := tS.V1ProcessEvent(args, &reply); err == nil || @@ -1454,9 +1372,10 @@ func TestThresholdMatchingThresholdForEventLocks(t *testing.T) { ids.Add(rPrf.ID) } dm.RemoveThreshold("cgrates.org", "TH1") - mth, err := rS.matchingThresholdsForEvent("cgrates.org", &ThresholdsArgsProcessEvent{ - ThresholdIDs: ids.AsSlice(), - CGREvent: new(utils.CGREvent), + mth, err := rS.matchingThresholdsForEvent("cgrates.org", &utils.CGREvent{ + APIOpts: map[string]interface{}{ + utils.OptsThresholdsProfileIDs: ids.AsSlice(), + }, }) if err != nil { t.Fatal(err) @@ -1518,9 +1437,10 @@ func TestThresholdMatchingThresholdForEventLocks2(t *testing.T) { } prfs = append(prfs, rPrf) ids.Add(rPrf.ID) - _, err := rS.matchingThresholdsForEvent("cgrates.org", &ThresholdsArgsProcessEvent{ - ThresholdIDs: ids.AsSlice(), - CGREvent: new(utils.CGREvent), + _, err := rS.matchingThresholdsForEvent("cgrates.org", &utils.CGREvent{ + APIOpts: map[string]interface{}{ + utils.OptsThresholdsProfileIDs: ids.AsSlice(), + }, }) expErr := utils.ErrPrefixNotFound(rPrf.FilterIDs[0]) if err == nil || err.Error() != expErr.Error() { @@ -1566,9 +1486,10 @@ func TestThresholdMatchingThresholdForEventLocksBlocker(t *testing.T) { prfs = append(prfs, rPrf) ids.Add(rPrf.ID) } - mres, err := rS.matchingThresholdsForEvent("cgrates.org", &ThresholdsArgsProcessEvent{ - ThresholdIDs: ids.AsSlice(), - CGREvent: new(utils.CGREvent), + mres, err := rS.matchingThresholdsForEvent("cgrates.org", &utils.CGREvent{ + APIOpts: map[string]interface{}{ + utils.OptsThresholdsProfileIDs: ids.AsSlice(), + }, }) if err != nil { t.Fatal(err) @@ -1632,9 +1553,11 @@ func TestThresholdMatchingThresholdForEventLocksActivationInterval(t *testing.T) } dm.SetThresholdProfile(rPrf, true) ids.Add(rPrf.ID) - mres, err := rS.matchingThresholdsForEvent("cgrates.org", &ThresholdsArgsProcessEvent{ - ThresholdIDs: ids.AsSlice(), - CGREvent: &utils.CGREvent{Time: utils.TimePointer(time.Now())}, + mres, err := rS.matchingThresholdsForEvent("cgrates.org", &utils.CGREvent{ + Time: utils.TimePointer(time.Now()), + APIOpts: map[string]interface{}{ + utils.OptsThresholdsProfileIDs: ids.AsSlice(), + }, }) if err != nil { t.Fatal(err) @@ -1684,9 +1607,10 @@ func TestThresholdMatchingThresholdForEventLocks3(t *testing.T) { for i := 0; i < 10; i++ { ids.Add(fmt.Sprintf("TH%d", i)) } - _, err := rS.matchingThresholdsForEvent("cgrates.org", &ThresholdsArgsProcessEvent{ - ThresholdIDs: ids.AsSlice(), - CGREvent: new(utils.CGREvent), + _, err := rS.matchingThresholdsForEvent("cgrates.org", &utils.CGREvent{ + APIOpts: map[string]interface{}{ + utils.OptsThresholdsProfileIDs: ids.AsSlice(), + }, }) if err != utils.ErrNotImplemented { t.Fatalf("Error: %+v", err) @@ -1724,9 +1648,10 @@ func TestThresholdMatchingThresholdForEventLocks4(t *testing.T) { ids.Add(rPrf.ID) } ids.Add("TH20") - mres, err := rS.matchingThresholdsForEvent("cgrates.org", &ThresholdsArgsProcessEvent{ - ThresholdIDs: ids.AsSlice(), - CGREvent: new(utils.CGREvent), + mres, err := rS.matchingThresholdsForEvent("cgrates.org", &utils.CGREvent{ + APIOpts: map[string]interface{}{ + utils.OptsThresholdsProfileIDs: ids.AsSlice(), + }, }) if err != nil { t.Fatal(err) @@ -1778,9 +1703,10 @@ func TestThresholdMatchingThresholdForEventLocks5(t *testing.T) { ids.Add(rPrf.ID) } dm.RemoveThreshold("cgrates.org", "TH1") - _, err := rS.matchingThresholdsForEvent("cgrates.org", &ThresholdsArgsProcessEvent{ - ThresholdIDs: ids.AsSlice(), - CGREvent: new(utils.CGREvent), + _, err := rS.matchingThresholdsForEvent("cgrates.org", &utils.CGREvent{ + APIOpts: map[string]interface{}{ + utils.OptsThresholdsProfileIDs: ids.AsSlice(), + }, }) if err != utils.ErrDisconnected { t.Fatal(err) @@ -1937,13 +1863,13 @@ func TestThresholdsV1GetThresholdsForEventOK(t *testing.T) { if err := dm.SetThresholdProfile(thPrf, true); err != nil { t.Error(err) } - args := &ThresholdsArgsProcessEvent{ - ThresholdIDs: []string{}, - CGREvent: &utils.CGREvent{ - ID: "TestGetThresholdsForEvent", - Event: map[string]interface{}{ - utils.AccountField: "1001", - }, + args := &utils.CGREvent{ + ID: "TestGetThresholdsForEvent", + Event: map[string]interface{}{ + utils.AccountField: "1001", + }, + APIOpts: map[string]interface{}{ + utils.OptsThresholdsProfileIDs: []string{}, }, } @@ -1988,25 +1914,20 @@ func TestThresholdsV1GetThresholdsForEventMissingArgs(t *testing.T) { if err := dm.SetThresholdProfile(thPrf, true); err != nil { t.Error(err) } - args := &ThresholdsArgsProcessEvent{ - ThresholdIDs: []string{}, - CGREvent: nil, - } - experr := `MANDATORY_IE_MISSING: [CGREvent]` var reply Thresholds - if err := tS.V1GetThresholdsForEvent(args, &reply); err == nil || + if err := tS.V1GetThresholdsForEvent(nil, &reply); err == nil || err.Error() != experr { t.Error(err) } - args = &ThresholdsArgsProcessEvent{ - ThresholdIDs: []string{}, - CGREvent: &utils.CGREvent{ - Tenant: "cgrates.org", - Event: map[string]interface{}{ - utils.AccountField: "1001", - }, + args := &utils.CGREvent{ + Tenant: "cgrates.org", + Event: map[string]interface{}{ + utils.AccountField: "1001", + }, + APIOpts: map[string]interface{}{ + utils.OptsThresholdsProfileIDs: []string{}, }, } @@ -2016,12 +1937,12 @@ func TestThresholdsV1GetThresholdsForEventMissingArgs(t *testing.T) { t.Error(err) } - args = &ThresholdsArgsProcessEvent{ - ThresholdIDs: []string{}, - CGREvent: &utils.CGREvent{ - Tenant: "cgrates.org", - ID: "TestGetThresholdsForEvent", - Event: nil, + args = &utils.CGREvent{ + Tenant: "cgrates.org", + ID: "TestGetThresholdsForEvent", + Event: nil, + APIOpts: map[string]interface{}{ + utils.OptsThresholdsProfileIDs: []string{}, }, } @@ -2382,12 +2303,10 @@ func TestThresholdsMatchingThresholdsForEventNotFoundErr(t *testing.T) { t.Error(err) } - args := &ThresholdsArgsProcessEvent{ - CGREvent: &utils.CGREvent{ - Tenant: "cgrates.org", - ID: "TestEvent", - Event: map[string]interface{}{}, - }, + args := &utils.CGREvent{ + Tenant: "cgrates.org", + ID: "TestEvent", + Event: map[string]interface{}{}, } if _, err := tS.matchingThresholdsForEvent("cgrates.org", args); err == nil || diff --git a/engine/z_actions_it_test.go b/engine/z_actions_it_test.go index d7bd388fd..c320af0cb 100644 --- a/engine/z_actions_it_test.go +++ b/engine/z_actions_it_test.go @@ -368,37 +368,35 @@ func testActionsitThresholdCDrLog(t *testing.T) { } else if !reflect.DeepEqual(tPrfl.ThresholdProfile, thReply) { t.Errorf("Expecting: %+v, received: %+v", tPrfl.ThresholdProfile, thReply) } - ev := &ThresholdsArgsProcessEvent{ - CGREvent: &utils.CGREvent{ - Tenant: "cgrates.org", - ID: "cdrev1", - Event: map[string]interface{}{ - utils.EventType: utils.CDR, - "field_extr1": "val_extr1", - "fieldextr2": "valextr2", - utils.CGRID: utils.Sha1("dsafdsaf", time.Date(2013, 11, 7, 8, 42, 26, 0, time.UTC).String()), - utils.RunID: utils.MetaRaw, - utils.OrderID: 123, - utils.OriginHost: "192.168.1.1", - utils.Source: utils.UnitTest, - utils.OriginID: "dsafdsaf", - utils.ToR: utils.MetaVoice, - utils.RequestType: utils.MetaRated, - utils.Tenant: "cgrates.org", - utils.Category: "call", - utils.AccountField: "th_acc", - utils.Subject: "th_acc", - utils.Destination: "+4986517174963", - utils.SetupTime: time.Date(2013, 11, 7, 8, 42, 20, 0, time.UTC), - utils.PDD: 0 * time.Second, - utils.AnswerTime: time.Date(2013, 11, 7, 8, 42, 26, 0, time.UTC), - utils.Usage: 10 * time.Second, - utils.Route: "SUPPL1", - utils.Cost: -1.0, - }, - APIOpts: map[string]interface{}{ - utils.MetaEventType: utils.CDR, - }, + ev := &utils.CGREvent{ + Tenant: "cgrates.org", + ID: "cdrev1", + Event: map[string]interface{}{ + utils.EventType: utils.CDR, + "field_extr1": "val_extr1", + "fieldextr2": "valextr2", + utils.CGRID: utils.Sha1("dsafdsaf", time.Date(2013, 11, 7, 8, 42, 26, 0, time.UTC).String()), + utils.RunID: utils.MetaRaw, + utils.OrderID: 123, + utils.OriginHost: "192.168.1.1", + utils.Source: utils.UnitTest, + utils.OriginID: "dsafdsaf", + utils.ToR: utils.MetaVoice, + utils.RequestType: utils.MetaRated, + utils.Tenant: "cgrates.org", + utils.Category: "call", + utils.AccountField: "th_acc", + utils.Subject: "th_acc", + utils.Destination: "+4986517174963", + utils.SetupTime: time.Date(2013, 11, 7, 8, 42, 20, 0, time.UTC), + utils.PDD: 0 * time.Second, + utils.AnswerTime: time.Date(2013, 11, 7, 8, 42, 26, 0, time.UTC), + utils.Usage: 10 * time.Second, + utils.Route: "SUPPL1", + utils.Cost: -1.0, + }, + APIOpts: map[string]interface{}{ + utils.MetaEventType: utils.CDR, }, } var ids []string @@ -595,8 +593,7 @@ func testActionsitThresholdCgrRpcAction(t *testing.T) { } var ids []string eIDs := []string{"TH_CGRRPC"} - if err := actsLclRpc.Call(utils.ThresholdSv1ProcessEvent, &ThresholdsArgsProcessEvent{ - CGREvent: ev}, &ids); err != nil { + if err := actsLclRpc.Call(utils.ThresholdSv1ProcessEvent, ev, &ids); err != nil { t.Error(err) } else if !reflect.DeepEqual(ids, eIDs) { t.Errorf("Expecting ids: %s, received: %s", eIDs, ids) @@ -678,8 +675,7 @@ func testActionsitThresholdPostEvent(t *testing.T) { } var ids []string eIDs := []string{"THD_PostEvent"} - if err := actsLclRpc.Call(utils.ThresholdSv1ProcessEvent, &ThresholdsArgsProcessEvent{ - CGREvent: ev}, &ids); err != nil { + if err := actsLclRpc.Call(utils.ThresholdSv1ProcessEvent, ev, &ids); err != nil { t.Error(err) } else if !reflect.DeepEqual(ids, eIDs) { t.Errorf("Expecting ids: %s, received: %s", eIDs, ids) diff --git a/engine/z_resources_test.go b/engine/z_resources_test.go index e90823671..fc4e54331 100644 --- a/engine/z_resources_test.go +++ b/engine/z_resources_test.go @@ -2895,19 +2895,17 @@ func TestResourcesProcessThresholdsOK(t *testing.T) { ccM := &ccMock{ calls: map[string]func(args interface{}, reply interface{}) error{ utils.ThresholdSv1ProcessEvent: func(args, reply interface{}) error { - exp := &ThresholdsArgsProcessEvent{ - ThresholdIDs: []string{"THD_1"}, - CGREvent: &utils.CGREvent{ - Tenant: "cgrates.org", - ID: args.(*ThresholdsArgsProcessEvent).CGREvent.ID, - Event: map[string]interface{}{ - utils.EventType: utils.ResourceUpdate, - utils.ResourceID: "RES_1", - utils.Usage: 0., - }, - APIOpts: map[string]interface{}{ - utils.MetaEventType: utils.ResourceUpdate, - }, + exp := &utils.CGREvent{ + Tenant: "cgrates.org", + ID: args.(*utils.CGREvent).ID, + Event: map[string]interface{}{ + utils.EventType: utils.ResourceUpdate, + utils.ResourceID: "RES_1", + utils.Usage: 0., + }, + APIOpts: map[string]interface{}{ + utils.MetaEventType: utils.ResourceUpdate, + utils.OptsThresholdsProfileIDs: []string{"THD_1"}, }, } if !reflect.DeepEqual(exp, args) { @@ -2964,19 +2962,17 @@ func TestResourcesProcessThresholdsCallErr(t *testing.T) { ccM := &ccMock{ calls: map[string]func(args interface{}, reply interface{}) error{ utils.ThresholdSv1ProcessEvent: func(args, reply interface{}) error { - exp := &ThresholdsArgsProcessEvent{ - ThresholdIDs: []string{"THD_1"}, - CGREvent: &utils.CGREvent{ - Tenant: "cgrates.org", - ID: args.(*ThresholdsArgsProcessEvent).CGREvent.ID, - Event: map[string]interface{}{ - utils.EventType: utils.ResourceUpdate, - utils.ResourceID: "RES_1", - utils.Usage: 0., - }, - APIOpts: map[string]interface{}{ - utils.MetaEventType: utils.ResourceUpdate, - }, + exp := &utils.CGREvent{ + Tenant: "cgrates.org", + ID: args.(*utils.CGREvent).ID, + Event: map[string]interface{}{ + utils.EventType: utils.ResourceUpdate, + utils.ResourceID: "RES_1", + utils.Usage: 0., + }, + APIOpts: map[string]interface{}{ + utils.MetaEventType: utils.ResourceUpdate, + utils.OptsThresholdsProfileIDs: []string{"THD_1"}, }, } if !reflect.DeepEqual(exp, args) { diff --git a/general_tests/filtered_replication_it_test.go b/general_tests/filtered_replication_it_test.go index 41861922d..13bd17dd2 100644 --- a/general_tests/filtered_replication_it_test.go +++ b/general_tests/filtered_replication_it_test.go @@ -492,13 +492,11 @@ func testFltrRplThresholdProfile(t *testing.T) { t.Fatalf("Unexpected error: %v", err) } - tEv := &engine.ThresholdsArgsProcessEvent{ - CGREvent: &utils.CGREvent{ - Tenant: "cgrates.org", - ID: "event1", - Event: map[string]interface{}{ - utils.AccountField: "dan", - }, + tEv := &utils.CGREvent{ + Tenant: "cgrates.org", + ID: "event1", + Event: map[string]interface{}{ + utils.AccountField: "dan", }, } var thIDs []string diff --git a/general_tests/filters_it_test.go b/general_tests/filters_it_test.go index 45cd4779a..8e9dad9f0 100644 --- a/general_tests/filters_it_test.go +++ b/general_tests/filters_it_test.go @@ -333,13 +333,11 @@ func testV1FltrPopulateThreshold(t *testing.T) { func testV1FltrGetThresholdForEvent(t *testing.T) { // check the event - tEv := &engine.ThresholdsArgsProcessEvent{ - CGREvent: &utils.CGREvent{ - Tenant: "cgrates.org", - ID: "event1", - Event: map[string]interface{}{ - utils.AccountField: "1010"}, - }, + tEv := &utils.CGREvent{ + Tenant: "cgrates.org", + ID: "event1", + Event: map[string]interface{}{ + utils.AccountField: "1010"}, } var ids []string eIDs := []string{"TH_Stats1"} @@ -396,13 +394,11 @@ func testV1FltrGetThresholdForEvent2(t *testing.T) { t.Error("Unexpected reply returned", result) } - tEv := &engine.ThresholdsArgsProcessEvent{ - CGREvent: &utils.CGREvent{ - Tenant: "cgrates.org", - ID: "event1", - Event: map[string]interface{}{ - utils.AccountField: "1010"}, - }, + tEv := &utils.CGREvent{ + Tenant: "cgrates.org", + ID: "event1", + Event: map[string]interface{}{ + utils.AccountField: "1010"}, } var ids []string if err := fltrRpc.Call(utils.ThresholdSv1ProcessEvent, tEv, &ids); err == nil || @@ -504,13 +500,11 @@ func testV1FltrPopulateResources(t *testing.T) { } // check the event - tEv := &engine.ThresholdsArgsProcessEvent{ - CGREvent: &utils.CGREvent{ - Tenant: "cgrates.org", - ID: "event1", - Event: map[string]interface{}{ - utils.AccountField: "2020"}, - }, + tEv := &utils.CGREvent{ + Tenant: "cgrates.org", + ID: "event1", + Event: map[string]interface{}{ + utils.AccountField: "2020"}, } var ids []string @@ -773,13 +767,11 @@ func testV1FltrAccounts(t *testing.T) { t.Errorf("Expecting: %+v, received: %+v", tPrfl.ThresholdProfile, rcvTh) } - tEv := &engine.ThresholdsArgsProcessEvent{ - CGREvent: &utils.CGREvent{ - Tenant: "cgrates.org", - ID: "event1", - Event: map[string]interface{}{ - utils.AccountField: "1001"}, - }, + tEv := &utils.CGREvent{ + Tenant: "cgrates.org", + ID: "event1", + Event: map[string]interface{}{ + utils.AccountField: "1001"}, } var ids []string if err := fltrRpc.Call(utils.ThresholdSv1ProcessEvent, tEv, &ids); err != nil { @@ -861,13 +853,11 @@ func testV1FltrAccountsExistsDynamicaly(t *testing.T) { t.Errorf("Expecting: %+v, received: %+v", tPrfl.ThresholdProfile, rcvTh) } - tEv := &engine.ThresholdsArgsProcessEvent{ - CGREvent: &utils.CGREvent{ - Tenant: "cgrates.org", - ID: "event1", - Event: map[string]interface{}{ - utils.AccountField: "1001"}, - }, + tEv := &utils.CGREvent{ + Tenant: "cgrates.org", + ID: "event1", + Event: map[string]interface{}{ + utils.AccountField: "1001"}, } var ids []string if err := fltrRpc.Call(utils.ThresholdSv1ProcessEvent, tEv, &ids); err != nil { @@ -876,13 +866,11 @@ func testV1FltrAccountsExistsDynamicaly(t *testing.T) { t.Error("Unexpected reply returned", ids) } - tEv = &engine.ThresholdsArgsProcessEvent{ - CGREvent: &utils.CGREvent{ - Tenant: "cgrates.org", - ID: "event2", - Event: map[string]interface{}{ - utils.AccountField: "non"}, - }, + tEv = &utils.CGREvent{ + Tenant: "cgrates.org", + ID: "event2", + Event: map[string]interface{}{ + utils.AccountField: "non"}, } ids = nil if err := fltrRpc.Call(utils.ThresholdSv1ProcessEvent, tEv, &ids); err == nil || err.Error() != utils.ErrNotFound.Error() { diff --git a/general_tests/rpccaching_it_test.go b/general_tests/rpccaching_it_test.go index f7b3c68ce..a8a6b626f 100644 --- a/general_tests/rpccaching_it_test.go +++ b/general_tests/rpccaching_it_test.go @@ -230,14 +230,12 @@ func testRPCMethodsAuthorizeSession(t *testing.T) { //disable the account var ids []string - thEvent := &engine.ThresholdsArgsProcessEvent{ - CGREvent: &utils.CGREvent{ - Tenant: "cgrates.org", - ID: "DisableAccount", - Event: map[string]interface{}{ - utils.AccountField: "1001", - "DisableAction": "DisableAction", - }, + thEvent := &utils.CGREvent{ + Tenant: "cgrates.org", + ID: "DisableAccount", + Event: map[string]interface{}{ + utils.AccountField: "1001", + "DisableAction": "DisableAction", }, } //process event @@ -277,7 +275,7 @@ func testRPCMethodsAuthorizeSession(t *testing.T) { } //enable the account - thEvent.CGREvent = &utils.CGREvent{ + thEvent = &utils.CGREvent{ Tenant: "cgrates.org", ID: "EnableAccount", Event: map[string]interface{}{ @@ -325,14 +323,12 @@ func testRPCMethodsInitSession(t *testing.T) { //disable the account var ids []string - thEvent := &engine.ThresholdsArgsProcessEvent{ - CGREvent: &utils.CGREvent{ - Tenant: "cgrates.org", - ID: "DisableAccount", - Event: map[string]interface{}{ - utils.AccountField: "1001", - "DisableAction": "DisableAction", - }, + thEvent := &utils.CGREvent{ + Tenant: "cgrates.org", + ID: "DisableAccount", + Event: map[string]interface{}{ + utils.AccountField: "1001", + "DisableAction": "DisableAction", }, } //process event @@ -373,7 +369,7 @@ func testRPCMethodsInitSession(t *testing.T) { } //enable the account - thEvent.CGREvent = &utils.CGREvent{ + thEvent = &utils.CGREvent{ Tenant: "cgrates.org", ID: "EnableAccount", Event: map[string]interface{}{ @@ -421,14 +417,12 @@ func testRPCMethodsUpdateSession(t *testing.T) { //disable the account var ids []string - thEvent := &engine.ThresholdsArgsProcessEvent{ - CGREvent: &utils.CGREvent{ - Tenant: "cgrates.org", - ID: "DisableAccount", - Event: map[string]interface{}{ - utils.AccountField: "1001", - "DisableAction": "DisableAction", - }, + thEvent := &utils.CGREvent{ + Tenant: "cgrates.org", + ID: "DisableAccount", + Event: map[string]interface{}{ + utils.AccountField: "1001", + "DisableAction": "DisableAction", }, } //process event @@ -468,7 +462,7 @@ func testRPCMethodsUpdateSession(t *testing.T) { } //enable the account - thEvent.CGREvent = &utils.CGREvent{ + thEvent = &utils.CGREvent{ Tenant: "cgrates.org", ID: "EnableAccount", Event: map[string]interface{}{ @@ -633,14 +627,12 @@ func testRPCMethodsProcessEvent(t *testing.T) { //disable the account var ids []string - thEvent := &engine.ThresholdsArgsProcessEvent{ - CGREvent: &utils.CGREvent{ - Tenant: "cgrates.org", - ID: "DisableAccount", - Event: map[string]interface{}{ - utils.AccountField: "1001", - "DisableAction": "DisableAction", - }, + thEvent := &utils.CGREvent{ + Tenant: "cgrates.org", + ID: "DisableAccount", + Event: map[string]interface{}{ + utils.AccountField: "1001", + "DisableAction": "DisableAction", }, } //process event @@ -681,7 +673,7 @@ func testRPCMethodsProcessEvent(t *testing.T) { } //enable the account - thEvent.CGREvent = &utils.CGREvent{ + thEvent = &utils.CGREvent{ Tenant: "cgrates.org", ID: "EnableAccount", Event: map[string]interface{}{ diff --git a/general_tests/sessions_race_test.go b/general_tests/sessions_race_test.go index 9b5f1bfae..f426b475b 100644 --- a/general_tests/sessions_race_test.go +++ b/general_tests/sessions_race_test.go @@ -49,10 +49,10 @@ var ( type raceConn struct{} func (_ raceConn) Call(serviceMethod string, args interface{}, reply interface{}) (err error) { - cgrev := args.(*engine.ThresholdsArgsProcessEvent) + cgrev := args.(*utils.CGREvent) for { - for k := range cgrev.CGREvent.Event { - if _, has := cgrev.CGREvent.Event[k]; !has { + for k := range cgrev.Event { + if _, has := cgrev.Event[k]; !has { fmt.Println(1) } } diff --git a/sessions/sessions.go b/sessions/sessions.go index 515687b49..bc0f50c82 100644 --- a/sessions/sessions.go +++ b/sessions/sessions.go @@ -3810,16 +3810,13 @@ func (sS *SessionS) processThreshold(cgrEv *utils.CGREvent, thIDs []string, clnb if len(sS.cgrCfg.SessionSCfg().ThreshSConns) == 0 { return tIDs, utils.NewErrNotConnected(utils.ThresholdS) } - thEv := &engine.ThresholdsArgsProcessEvent{ - CGREvent: cgrEv, - } // check if we have thresholdIDs if len(thIDs) != 0 { - thEv.ThresholdIDs = thIDs + cgrEv.APIOpts[utils.OptsThresholdsProfileIDs] = thIDs } - thEv.SetCloneable(clnb) + cgrEv.SetCloneable(clnb) //initialize the returned variable - err = sS.connMgr.Call(sS.cgrCfg.SessionSCfg().ThreshSConns, nil, utils.ThresholdSv1ProcessEvent, thEv, &tIDs) + err = sS.connMgr.Call(sS.cgrCfg.SessionSCfg().ThreshSConns, nil, utils.ThresholdSv1ProcessEvent, cgrEv, &tIDs) return } diff --git a/utils/consts.go b/utils/consts.go index 800da8198..2cc7c0561 100644 --- a/utils/consts.go +++ b/utils/consts.go @@ -2399,7 +2399,7 @@ var CGROptionsSet = NewStringSet([]string{OptsSessionsTTL, OptsAttributesProcessRuns, OptsAttributesProfileIDs, OptsRoutesLimit, OptsRoutesOffset, OptsChargeable, RemoteHostOpt, CacheOpt, OptsRoutesProfilesCount, OptsDispatchersProfilesCount, OptsAttributesProfileRuns, OptsAttributesProfileIgnoreFilters, OptsStatsProfileIDs, - OptsStatsProfileIgnoreFilters}) + OptsStatsProfileIgnoreFilters, OptsThresholdsProfileIDs, OptsThresholdsProfileIgnoreFilters}) // EventExporter metrics const ( @@ -2450,6 +2450,9 @@ const ( // Stats OptsStatsProfileIDs = "*stsProfileIDs" OptsStatsProfileIgnoreFilters = "*stsProfileIgnoreFilters" + // Thresholds + OptsThresholdsProfileIDs = "*thdProfileIDs" + OptsThresholdsProfileIgnoreFilters = "*thdProfileIgnoreFilters" // Others OptsContext = "*context" Subsys = "*subsys"