diff --git a/apier/v1/stats_it_test.go b/apier/v1/stats_it_test.go index 00b207b39..4714e41ef 100644 --- a/apier/v1/stats_it_test.go +++ b/apier/v1/stats_it_test.go @@ -81,6 +81,7 @@ var ( testV1STSProcessMetricsWithFilter, testV1STSProcessStaticMetrics, testV1STSProcessStatWithThreshold, + testV1STSV1GetQueueIDs, testV1STSGetStatQueueProfileWithoutTenant, testV1STSRemStatQueueProfileWithoutTenant, //testV1STSProcessCDRStat, @@ -1244,3 +1245,22 @@ func testV1STSRemStatQueueProfileWithoutTenant(t *testing.T) { t.Error(err) } } + +func testV1STSV1GetQueueIDs(t *testing.T) { + expected := []string{"StatWithThreshold", "Stats1", "StaticStatQueue", "CustomStatProfile"} + var qIDs []string + if err := stsV1Rpc.Call(utils.StatSv1GetQueueIDs, + &utils.TenantWithOpts{}, + &qIDs); err != nil { + t.Error(err) + } else if !reflect.DeepEqual(qIDs, expected) { + t.Errorf("Expected %+v \n ,received %+v", expected, qIDs) + } + if err := stsV1Rpc.Call(utils.StatSv1GetQueueIDs, + &utils.TenantWithOpts{Tenant: "cgrates.org"}, + &qIDs); err != nil { + t.Error(err) + } else if !reflect.DeepEqual(qIDs, expected) { + t.Errorf("Expected %+v \n ,received %+v", expected, qIDs) + } +} diff --git a/apier/v1/thresholds_it_test.go b/apier/v1/thresholds_it_test.go index 169dc14db..9d0896f92 100644 --- a/apier/v1/thresholds_it_test.go +++ b/apier/v1/thresholds_it_test.go @@ -243,6 +243,7 @@ var ( testV1TSGetThresholdProfileWithoutTenant, testV1TSRemThresholdProfileWithoutTenant, testV1TSProcessEventWithoutTenant, + testV1TSGetThresholdsWithoutTenant, testV1TSStopEngine, } ) @@ -314,6 +315,12 @@ func testV1TSFromFolder(t *testing.T) { func testV1TSGetThresholds(t *testing.T) { var tIDs []string expectedIDs := []string{"THD_RES_1", "THD_STATS_2", "THD_STATS_1", "THD_ACNT_BALANCE_1", "THD_ACNT_EXPIRED", "THD_STATS_3", "THD_CDRS_1"} + if err := tSv1Rpc.Call(utils.ThresholdSv1GetThresholdIDs, + &utils.TenantWithOpts{}, &tIDs); err != nil { + t.Error(err) + } else if len(expectedIDs) != len(tIDs) { + t.Errorf("expecting: %+v, received reply: %s", expectedIDs, tIDs) + } if err := tSv1Rpc.Call(utils.ThresholdSv1GetThresholdIDs, &utils.TenantWithOpts{Tenant: "cgrates.org"}, &tIDs); err != nil { t.Error(err) @@ -838,3 +845,23 @@ func testV1TSProcessEventWithoutTenant(t *testing.T) { t.Errorf("Expecting ids: %s, received: %s", eIDs, ids) } } + +func testV1TSGetThresholdsWithoutTenant(t *testing.T) { + expectedThreshold := &engine.Threshold{ + Tenant: "cgrates.org", + ID: "THD_ACNT_BALANCE_1", + Hits: 1, + } + var reply *engine.Threshold + if err := tSv1Rpc.Call(utils.ThresholdSv1GetThreshold, + &utils.TenantIDWithOpts{TenantID: &utils.TenantID{ID: "THD_ACNT_BALANCE_1"}}, + &reply); err != nil { + t.Error(err) + } else if !reflect.DeepEqual(expectedThreshold.ID, reply.ID) { + t.Errorf("Expected %+v \n, received %+v", utils.ToJSON(expectedThreshold.ID), utils.ToJSON(reply.ID)) + } else if !reflect.DeepEqual(expectedThreshold.Tenant, reply.Tenant) { + t.Errorf("Expected %+v \n, received %+v", utils.ToJSON(expectedThreshold.Tenant), utils.ToJSON(reply.Tenant)) + } else if !reflect.DeepEqual(expectedThreshold.ID, reply.ID) { + t.Errorf("Expected %+v \n, received %+v", utils.ToJSON(expectedThreshold.Tenant), utils.ToJSON(reply.Tenant)) + } +} diff --git a/engine/stats.go b/engine/stats.go index 942ba5127..f4e4cb8a1 100644 --- a/engine/stats.go +++ b/engine/stats.go @@ -463,6 +463,9 @@ func (sS *StatService) V1GetQueueFloatMetrics(args *utils.TenantID, reply *map[s // V1GetQueueIDs returns list of queueIDs registered for a tenant func (sS *StatService) V1GetQueueIDs(tenant string, qIDs *[]string) (err error) { + if tenant == utils.EmptyString { + tenant = sS.cgrcfg.GeneralCfg().DefaultTenant + } prfx := utils.StatQueuePrefix + tenant + ":" keys, err := sS.dm.DataDB().GetKeysForPrefix(prfx) if err != nil { diff --git a/engine/thresholds.go b/engine/thresholds.go index bf3b34b99..9e4eeb516 100644 --- a/engine/thresholds.go +++ b/engine/thresholds.go @@ -430,6 +430,9 @@ func (tS *ThresholdService) V1GetThresholdsForEvent(args *ThresholdsArgsProcessE // V1GetThresholdIDs returns list of thresholdIDs configured for a tenant func (tS *ThresholdService) V1GetThresholdIDs(tenant string, tIDs *[]string) (err error) { + if tenant == utils.EmptyString { + tenant = tS.cgrcfg.GeneralCfg().DefaultTenant + } prfx := utils.ThresholdPrefix + tenant + ":" keys, err := tS.dm.DataDB().GetKeysForPrefix(prfx) if err != nil { @@ -446,7 +449,11 @@ func (tS *ThresholdService) V1GetThresholdIDs(tenant string, tIDs *[]string) (er // V1GetThreshold retrieves a Threshold func (tS *ThresholdService) V1GetThreshold(tntID *utils.TenantID, t *Threshold) (err error) { var thd *Threshold - if thd, err = tS.dm.GetThreshold(tntID.Tenant, tntID.ID, true, true, ""); err != nil { + tnt := tntID.Tenant + if tnt == utils.EmptyString { + tnt = tS.cgrcfg.GeneralCfg().DefaultTenant + } + if thd, err = tS.dm.GetThreshold(tnt, tntID.ID, true, true, ""); err != nil { return } *t = *thd diff --git a/utils/consts.go b/utils/consts.go index 20458adde..0efd9147c 100755 --- a/utils/consts.go +++ b/utils/consts.go @@ -1499,6 +1499,7 @@ const ( StatSv1Ping = "StatSv1.Ping" StatSv1GetStatQueuesForEvent = "StatSv1.GetStatQueuesForEvent" StatSv1GetStatQueue = "StatSv1.GetStatQueue" + StatSv1V1GetQueueIDs = "StatSv1.GetQueueIDs" APIerSv1GetStatQueueProfile = "APIerSv1.GetStatQueueProfile" APIerSv1RemoveStatQueueProfile = "APIerSv1.RemoveStatQueueProfile" APIerSv1SetStatQueueProfile = "APIerSv1.SetStatQueueProfile"