From fead904f9bbb10adbc5f45a9a6148c342fa0cbf7 Mon Sep 17 00:00:00 2001 From: porosnicuadrian Date: Fri, 29 Apr 2022 15:31:59 +0300 Subject: [PATCH] Tested stats metrics blockers functionality --- apis/attributes_it_test.go | 8 +-- apis/stats_it_test.go | 99 ++++++++++++++++++++++++++++++++++++++ engine/stats.go | 3 +- 3 files changed, 104 insertions(+), 6 deletions(-) diff --git a/apis/attributes_it_test.go b/apis/attributes_it_test.go index 35af0004c..802a11374 100644 --- a/apis/attributes_it_test.go +++ b/apis/attributes_it_test.go @@ -46,7 +46,7 @@ var ( testAttributeSInitDataDb, testAttributeSStartEngine, testAttributeSRPCConn, - /* testGetAttributeProfileBeforeSet, + testGetAttributeProfileBeforeSet, testGetAttributeProfilesBeforeSet, testAttributeSetAttributeProfile, testAttributeGetAttributeIDs, @@ -74,13 +74,13 @@ var ( testAttributeGetAttributeProfileAllIDs, testAttributeGetAttributeProfileAllCount, testAttributeRemoveRemainAttributeProfiles, - testAttributeGetAttributeProfileAfterRemove, */ + testAttributeGetAttributeProfileAfterRemove, testAttributeSetAttributeProfileWithAttrBlockers, testAttributeSetAttributeProfileWithAttrBlockers2, testAttributeSetAttributeProfileBlockersBothProfilesProcessRuns, // Testing index behaviour - /* testAttributeSSetNonIndexedTypeFilter, + testAttributeSSetNonIndexedTypeFilter, testAttributeSSetIndexedTypeFilter, testAttributeSClearIndexes, testAttributeSCheckIndexesSetAttributeProfileWithoutFilters, @@ -88,7 +88,7 @@ var ( testAttributeSCheckIndexesAddIndexedFilters, testAttributeSCheckIndexesModifyIndexedFilter, testAttributeSCheckIndexesRemoveAnIndexedFilter, - testAttributeSCheckIndexesRemoveAttributeProfile, */ + testAttributeSCheckIndexesRemoveAttributeProfile, testAttributeSKillEngine, } diff --git a/apis/stats_it_test.go b/apis/stats_it_test.go index 0914721e8..e500a4336 100644 --- a/apis/stats_it_test.go +++ b/apis/stats_it_test.go @@ -62,6 +62,7 @@ var ( testStatsGetStatQueueProfilesCount, testStatsRemoveStatQueueProfiles, testStatsGetStatQueuesAfterRemove, + //testStatsProcessEventWithBlockersOnMetrics, // check if stats, thresholds and actions subsystems function properly together testStatsStartServer, testStatsSetActionProfileBeforeProcessEv, @@ -620,6 +621,104 @@ func testStatsGetStatQueuesAfterRemove(t *testing.T) { } } +func testStatsProcessEventWithBlockersOnMetrics(t *testing.T) { + sqPrf := &engine.StatQueueProfileWithAPIOpts{ + StatQueueProfile: &engine.StatQueueProfile{ + Tenant: "cgrates.org", + ID: "SQ_WithBlockers", + FilterIDs: []string{"*string:~*req.StatsMetrics:*exists"}, + QueueLength: 100, + TTL: time.Duration(1 * time.Minute), + MinItems: 0, + Metrics: []*engine.MetricWithFilters{ + { + MetricID: utils.MetaTCD, + }, + { + MetricID: utils.MetaTCC, + }, + { + MetricID: utils.MetaASR, + Blockers: utils.Blockers{ + { + FilterIDs: []string{"*prefix:~*req.CallerID:4433"}, + Blocker: true, + }, + }, + }, + { + MetricID: utils.MetaPDD, + }, + { + MetricID: utils.MetaACD, + Blockers: utils.Blockers{ + { + FilterIDs: []string{"*prefix:~*req.CallerID:44112"}, + Blocker: true, + }, + }, + }, + { + MetricID: utils.MetaDDC, + }, + }, + ThresholdIDs: []string{"*none"}, + }, + } + + var reply string + if err := sqRPC.Call(context.Background(), utils.AdminSv1SetStatQueueProfile, + sqPrf, &reply); err != nil { + t.Error(err) + } else if reply != utils.OK { + t.Error("Unexpected reply returned:", reply) + } + + args := &utils.CGREvent{ + Tenant: "cgrates.org", + ID: "SQ_WithBlockers_Event", + Event: map[string]interface{}{ + utils.AccountField: "1001", + "StatsMetrics": "*exists", + "CallerID": "443321", + }, + APIOpts: map[string]interface{}{ + utils.MetaUsage: 30 * time.Second, + utils.MetaCost: 102.1, + utils.MetaDestination: "332214", + utils.MetaStartTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC), + utils.MetaPDD: 5 * time.Second, + }, + } + expected := []string{"SQ_WithBlockers"} + var replyStats []string + if err := sqRPC.Call(context.Background(), utils.StatSv1ProcessEvent, + args, &replyStats); err != nil { + t.Error(err) + } else if !reflect.DeepEqual(replyStats, expected) { + t.Errorf("expected: <%+v>, \nreceived: <%+v>", expected, replyStats) + } + + /* + expFloat := map[string]float64{ + utils.MetaACD: 46400000000., + utils.MetaASR: 60., + } + var rplyDec map[string]float64 + if err := sqRPC.Call(context.Background(), utils.StatSv1GetQueueFloatMetrics, + &utils.TenantIDWithAPIOpts{ + TenantID: &utils.TenantID{ + Tenant: "cgrates.org", + ID: "SQ_WithBlockers", + }, + }, &rplyDec); err != nil { + t.Error(err) + } else if !reflect.DeepEqual(rplyDec, expFloat) { + t.Errorf("Expected %v, received %v", utils.ToJSON(expFloat), utils.ToJSON(rplyDec)) + } + */ +} + func testStatsStartServer(t *testing.T) { sqSrv = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { var err error diff --git a/engine/stats.go b/engine/stats.go index d005385c1..62d7ed316 100644 --- a/engine/stats.go +++ b/engine/stats.go @@ -227,7 +227,7 @@ func (sS *StatS) matchingStatQueuesForEvent(ctx *context.Context, tnt string, st return } // if we have blocker, ignore the rest of the metrics - if blocker { + if blocker && idx != len(sqPrfl.Metrics)-1 { // not the last metric sqPrfl.Metrics = sqPrfl.Metrics[:idx+1] break } @@ -256,7 +256,6 @@ func (sS *StatS) matchingStatQueuesForEvent(ctx *context.Context, tnt string, st break } } - return }