From 29512865636e82e2e38a2f57edec9fd21a3ff1ec Mon Sep 17 00:00:00 2001 From: TeoV Date: Fri, 29 Sep 2017 08:46:20 +0300 Subject: [PATCH 1/2] Add methods for Threshold (get/set/remove) in Mongo Redis and StorageMap (DataDB) + test for them (onstor_it_test.go) --- engine/onstor_it_test.go | 32 ++++++++++++++++++++ engine/storage_interface.go | 3 ++ engine/storage_map.go | 45 +++++++++++++++++++++++++++++ engine/storage_mongo_datadb.go | 53 ++++++++++++++++++++++++++++++++-- engine/storage_redis.go | 42 +++++++++++++++++++++++++++ 5 files changed, 172 insertions(+), 3 deletions(-) diff --git a/engine/onstor_it_test.go b/engine/onstor_it_test.go index 3d6c3c6ea..4a69c302b 100644 --- a/engine/onstor_it_test.go +++ b/engine/onstor_it_test.go @@ -93,6 +93,7 @@ var sTestsOnStorIT = []func(t *testing.T){ testOnStorITCRUDStatQueueProfile, testOnStorITCRUDStoredStatQueue, testOnStorITCRUDThresholdProfile, + testOnStorITCRUDThreshold, } func TestOnStorITRedisConnect(t *testing.T) { @@ -2088,3 +2089,34 @@ func testOnStorITCRUDThresholdProfile(t *testing.T) { t.Error(rcvErr) } } + +func testOnStorITCRUDThreshold(t *testing.T) { + res := &Threshold{ + Tenant: "cgrates.org", + ID: "TH1", + LastExecuted: time.Date(2016, 10, 1, 0, 0, 0, 0, time.UTC).Local(), + WakeupTime: time.Date(2016, 10, 1, 0, 0, 0, 0, time.UTC).Local(), + } + if _, rcvErr := onStor.GetThreshold("cgrates.org", "TH1", true, utils.NonTransactional); rcvErr != nil && rcvErr != utils.ErrNotFound { + t.Error(rcvErr) + } + if err := onStor.SetThreshold(res); err != nil { + t.Error(err) + } + if rcv, err := onStor.GetThreshold("cgrates.org", "TH1", true, utils.NonTransactional); err != nil { + t.Error(err) + } else if !(reflect.DeepEqual(res, rcv)) { + t.Errorf("Expecting: %v, received: %v", res, rcv) + } + if rcv, err := onStor.GetThreshold("cgrates.org", "TH1", false, utils.NonTransactional); err != nil { + t.Error(err) + } else if !reflect.DeepEqual(res, rcv) { + t.Errorf("Expecting: %v, received: %v", res, rcv) + } + if err := onStor.RemoveThreshold(res.Tenant, res.ID, utils.NonTransactional); err != nil { + t.Error(err) + } + if _, rcvErr := onStor.GetThreshold(res.Tenant, res.ID, true, utils.NonTransactional); rcvErr != utils.ErrNotFound { + t.Error(rcvErr) + } +} diff --git a/engine/storage_interface.go b/engine/storage_interface.go index 4c4fc8028..4dc6ed658 100755 --- a/engine/storage_interface.go +++ b/engine/storage_interface.go @@ -123,6 +123,9 @@ type DataDB interface { GetThresholdProfile(tenant string, ID string, skipCache bool, transID string) (tp *ThresholdProfile, err error) SetThresholdProfile(tp *ThresholdProfile) (err error) RemThresholdProfile(tenant, id, transactionID string) (err error) + GetThreshold(string, string, bool, string) (*Threshold, error) + SetThreshold(*Threshold) error + RemoveThreshold(string, string, string) error // CacheDataFromDB loads data to cache, prefix represents the cache prefix, IDs should be nil if all available data should be loaded CacheDataFromDB(prefix string, IDs []string, mustBeCached bool) error // ToDo: Move this to dataManager } diff --git a/engine/storage_map.go b/engine/storage_map.go index 92e30e05e..a97a70357 100755 --- a/engine/storage_map.go +++ b/engine/storage_map.go @@ -1624,6 +1624,51 @@ func (ms *MapStorage) RemThresholdProfile(tenant, id, transactionID string) (err return } +func (ms *MapStorage) GetThreshold(tenant, id string, skipCache bool, transactionID string) (r *Threshold, err error) { + ms.mu.RLock() + defer ms.mu.RUnlock() + key := utils.ThresholdsPrefix + utils.ConcatenatedKey(tenant, id) + if !skipCache { + if x, ok := cache.Get(key); ok { + if x != nil { + return x.(*Threshold), nil + } + return nil, utils.ErrNotFound + } + } + values, ok := ms.dict[key] + if !ok { + cache.Set(key, nil, cacheCommit(transactionID), transactionID) + return nil, utils.ErrNotFound + } + err = ms.ms.Unmarshal(values, r) + if err != nil { + return nil, err + } + cache.Set(key, r, cacheCommit(transactionID), transactionID) + return +} + +func (ms *MapStorage) SetThreshold(r *Threshold) (err error) { + ms.mu.Lock() + defer ms.mu.Unlock() + result, err := ms.ms.Marshal(r) + if err != nil { + return err + } + ms.dict[utils.ThresholdsPrefix+utils.ConcatenatedKey(r.Tenant, r.ID)] = result + return +} + +func (ms *MapStorage) RemoveThreshold(tenant, id string, transactionID string) (err error) { + ms.mu.Lock() + defer ms.mu.Unlock() + key := utils.ThresholdsPrefix + utils.ConcatenatedKey(tenant, id) + delete(ms.dict, key) + cache.RemKey(key, cacheCommit(transactionID), transactionID) + return +} + func (ms *MapStorage) GetVersions(itm string) (vrs Versions, err error) { ms.mu.Lock() defer ms.mu.Unlock() diff --git a/engine/storage_mongo_datadb.go b/engine/storage_mongo_datadb.go index bcdca5bcc..2bc2a1ed4 100755 --- a/engine/storage_mongo_datadb.go +++ b/engine/storage_mongo_datadb.go @@ -61,7 +61,8 @@ const ( colRes = "resources" colSqs = "statqueues" colSqp = "statqueue_profiles" - colTlds = "thresholds" + colTlds = "threshold_profiles" + colThs = "thresholds" ) var ( @@ -330,6 +331,7 @@ func (ms *MongoStorage) getColNameForPrefix(prefix string) (name string, ok bool utils.ResourcesPrefix: colRes, utils.ResourceProfilesPrefix: colRsP, utils.ThresholdProfilePrefix: colTlds, + utils.ThresholdsPrefix: colThs, } name, ok = colMap[prefix] return @@ -537,6 +539,9 @@ func (ms *MongoStorage) CacheDataFromDB(prfx string, ids []string, mustBeCached case utils.ThresholdProfilePrefix: tntID := utils.NewTenantID(dataID) _, err = ms.GetThresholdProfile(tntID.Tenant, tntID.ID, true, utils.NonTransactional) + case utils.ThresholdsPrefix: + tntID := utils.NewTenantID(dataID) + _, err = ms.GetThreshold(tntID.Tenant, tntID.ID, true, utils.NonTransactional) } if err != nil { return utils.NewCGRError(utils.MONGO, @@ -713,8 +718,8 @@ func (ms *MongoStorage) HasData(category, subject string) (has bool, err error) case utils.StatQueuePrefix: count, err = db.C(colRes).Find(bson.M{"id": subject}).Count() has = count > 0 - case utils.ThresholdProfilePrefix: - count, err = db.C(colTlds).Find(bson.M{"id": subject}).Count() + case utils.ThresholdsPrefix: + count, err = db.C(colThs).Find(bson.M{"id": subject}).Count() has = count > 0 default: err = fmt.Errorf("unsupported category in HasData: %s", category) @@ -2181,3 +2186,45 @@ func (ms *MongoStorage) RemThresholdProfile(tenant, id, transactionID string) (e cacheCommit(transactionID), transactionID) return } + +func (ms *MongoStorage) GetThreshold(tenant, id string, skipCache bool, transactionID string) (r *Threshold, err error) { + key := utils.ThresholdsPrefix + utils.ConcatenatedKey(tenant, id) + if !skipCache { + if x, ok := cache.Get(key); ok { + if x == nil { + return nil, utils.ErrNotFound + } + return x.(*Threshold), nil + } + } + session, col := ms.conn(colThs) + defer session.Close() + r = new(Threshold) + if err = col.Find(bson.M{"tenant": tenant, "id": id}).One(r); err != nil { + if err == mgo.ErrNotFound { + err = utils.ErrNotFound + cache.Set(key, nil, cacheCommit(transactionID), transactionID) + } + return nil, err + } + cache.Set(key, r, cacheCommit(transactionID), transactionID) + return +} + +func (ms *MongoStorage) SetThreshold(r *Threshold) (err error) { + session, col := ms.conn(colThs) + defer session.Close() + _, err = col.Upsert(bson.M{"tenant": r.Tenant, "id": r.ID}, r) + return +} + +func (ms *MongoStorage) RemoveThreshold(tenant, id string, transactionID string) (err error) { + session, col := ms.conn(colThs) + defer session.Close() + if err = col.Remove(bson.M{"tenant": tenant, "id": id}); err != nil { + return + } + cache.RemKey(utils.ThresholdsPrefix+utils.ConcatenatedKey(tenant, id), + cacheCommit(transactionID), transactionID) + return nil +} diff --git a/engine/storage_redis.go b/engine/storage_redis.go index 450d6f940..710fe5442 100755 --- a/engine/storage_redis.go +++ b/engine/storage_redis.go @@ -1734,6 +1734,48 @@ func (rs *RedisStorage) RemThresholdProfile(tenant, id, transactionID string) (e return } +func (rs *RedisStorage) GetThreshold(tenant, id string, skipCache bool, transactionID string) (r *Threshold, err error) { + key := utils.ThresholdsPrefix + utils.ConcatenatedKey(tenant, id) + if !skipCache { + if x, ok := cache.Get(key); ok { + if x == nil { + return nil, utils.ErrNotFound + } + return x.(*Threshold), nil + } + } + var values []byte + if values, err = rs.Cmd("GET", key).Bytes(); err != nil { + if err == redis.ErrRespNil { // did not find the destination + cache.Set(key, nil, cacheCommit(transactionID), transactionID) + err = utils.ErrNotFound + } + return + } + if err = rs.ms.Unmarshal(values, &r); err != nil { + return + } + cache.Set(key, r, cacheCommit(transactionID), transactionID) + return +} + +func (rs *RedisStorage) SetThreshold(r *Threshold) (err error) { + result, err := rs.ms.Marshal(r) + if err != nil { + return err + } + return rs.Cmd("SET", utils.ThresholdsPrefix+utils.ConcatenatedKey(r.Tenant, r.ID), result).Err +} + +func (rs *RedisStorage) RemoveThreshold(tenant, id string, transactionID string) (err error) { + key := utils.ThresholdsPrefix + utils.ConcatenatedKey(tenant, id) + if err = rs.Cmd("DEL", key).Err; err != nil { + return + } + cache.RemKey(key, cacheCommit(transactionID), transactionID) + return +} + func (rs *RedisStorage) GetStorageType() string { return utils.REDIS } From 44fb51839b1a3806b8b3eb9e2f3136cec0ac3e5a Mon Sep 17 00:00:00 2001 From: TeoV Date: Fri, 29 Sep 2017 09:32:27 +0300 Subject: [PATCH 2/2] Remove MinItems from ThresholdProfiles and add/remote time.Sleep from resourcesv1_it_test.go and tp_it_test.go --- apier/v1/resourcesv1_it_test.go | 2 +- apier/v1/tp_it_test.go | 3 ++- data/storage/mysql/create_tariffplan_tables.sql | 5 +---- data/storage/postgres/create_tariffplan_tables.sql | 5 +---- data/tariffplans/testtp/Thresholds.csv | 4 ++-- data/tariffplans/tutorial/Thresholds.csv | 4 ++-- engine/loader_csv_test.go | 5 ++--- engine/model_helpers.go | 5 ----- engine/model_helpers_test.go | 4 ---- engine/models.go | 11 +++++------ engine/onstor_it_test.go | 1 - engine/storage_mongo_datadb.go | 2 +- engine/thresholds.go | 1 - utils/apitpdata.go | 1 - 14 files changed, 17 insertions(+), 36 deletions(-) diff --git a/apier/v1/resourcesv1_it_test.go b/apier/v1/resourcesv1_it_test.go index 42a6b03ad..96860e325 100644 --- a/apier/v1/resourcesv1_it_test.go +++ b/apier/v1/resourcesv1_it_test.go @@ -122,7 +122,6 @@ func testV1RsRpcConn(t *testing.T) { func testV1RsFromFolder(t *testing.T) { var reply string - time.Sleep(time.Duration(2000) * time.Millisecond) attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "tutorial")} if err := rlsV1Rpc.Call("ApierV1.LoadTariffPlanFromFolder", attrs, &reply); err != nil { t.Error(err) @@ -132,6 +131,7 @@ func testV1RsFromFolder(t *testing.T) { } func testV1RsGetResourcesForEvent(t *testing.T) { + time.Sleep(time.Duration(1000) * time.Millisecond) var reply *[]*engine.ResourceProfile args := &utils.ArgRSv1ResourceUsage{ Tenant: "cgrates.org", diff --git a/apier/v1/tp_it_test.go b/apier/v1/tp_it_test.go index a5d7c4f7e..b4c5c628e 100644 --- a/apier/v1/tp_it_test.go +++ b/apier/v1/tp_it_test.go @@ -84,7 +84,7 @@ func testTPInitCfg(t *testing.T) { config.SetCgrConfig(tpCfg) switch tpConfigDIR { case "tutmongo": // Mongo needs more time to reset db, need to investigate - tpDelay = 2000 + tpDelay = 4000 default: tpDelay = 2000 } @@ -114,6 +114,7 @@ func testTPRpcConn(t *testing.T) { } func testTPImportTPFromFolderPath(t *testing.T) { + time.Sleep(time.Duration(1 * time.Second)) var reply string if err := tpRPC.Call("ApierV1.ImportTariffPlanFromFolder", utils.AttrImportTPFromFolder{TPid: "TEST_TPID2", FolderPath: path.Join(tpDataDir, "tariffplans", "tutorial")}, &reply); err != nil { t.Error("Got error on ApierV1.ImportTarrifPlanFromFolder: ", err.Error()) diff --git a/data/storage/mysql/create_tariffplan_tables.sql b/data/storage/mysql/create_tariffplan_tables.sql index 8bd959e31..777109c9d 100644 --- a/data/storage/mysql/create_tariffplan_tables.sql +++ b/data/storage/mysql/create_tariffplan_tables.sql @@ -453,18 +453,15 @@ DROP TABLE IF EXISTS tp_thresholds; CREATE TABLE tp_thresholds ( `id` int(11) NOT NULL AUTO_INCREMENT, `tpid` varchar(64) NOT NULL, + `tenant` varchar(64) NOT NULL, `tag` varchar(64) NOT NULL, `filter_type` varchar(16) NOT NULL, `filter_field_name` varchar(64) NOT NULL, `filter_field_values` varchar(256) NOT NULL, `activation_interval` varchar(64) NOT NULL, - `threshold_type` char(64) NOT NULL, - `threshold_value` DECIMAL(20,4) NOT NULL, - `min_items` int(11) NOT NULL, `recurrent` BOOLEAN NOT NULL, `min_sleep` varchar(16) NOT NULL, `blocker` BOOLEAN NOT NULL, - `stored` BOOLEAN NOT NULL, `weight` decimal(8,2) NOT NULL, `action_ids` varchar(64) NOT NULL, `created_at` TIMESTAMP, diff --git a/data/storage/postgres/create_tariffplan_tables.sql b/data/storage/postgres/create_tariffplan_tables.sql index c2e9ef515..b9dbd986d 100644 --- a/data/storage/postgres/create_tariffplan_tables.sql +++ b/data/storage/postgres/create_tariffplan_tables.sql @@ -448,18 +448,15 @@ DROP TABLE IF EXISTS tp_thresholds; CREATE TABLE tp_thresholds ( "id" SERIAL PRIMARY KEY, "tpid" varchar(64) NOT NULL, + "tenant"varchar(64) NOT NULL, "tag" varchar(64) NOT NULL, "filter_type" varchar(16) NOT NULL, "filter_field_name" varchar(64) NOT NULL, "filter_field_values" varchar(256) NOT NULL, "activation_interval" varchar(64) NOT NULL, - "threshold_type" VARCHAR(64) NOT NULL, - "threshold_value" NUMERIC(20,4) NOT NULL, - "min_items" INTEGER NOT NULL, "recurrent" BOOLEAN NOT NULL, "min_sleep" varchar(16) NOT NULL, "blocker" BOOLEAN NOT NULL, - "stored" BOOLEAN NOT NULL, "weight" decimal(8,2) NOT NULL, "action_ids" varchar(64) NOT NULL, "created_at" TIMESTAMP WITH TIME ZONE diff --git a/data/tariffplans/testtp/Thresholds.csv b/data/tariffplans/testtp/Thresholds.csv index 9e629d669..a422ddaa6 100644 --- a/data/tariffplans/testtp/Thresholds.csv +++ b/data/tariffplans/testtp/Thresholds.csv @@ -1,2 +1,2 @@ -#Tenant[0],Id[1],FilterType[2],FilterFieldName[3],FilterFieldValues[4],ActivationInterval[5],MinItems[6],Recurrent[7],MinSleep[8],Blocker[9],Weight[10],ActionIDs[11] -cgrates.org,Threshold1,*string,Account,1001;1002,2014-07-29T15:00:00Z,10,true,1s,true,10,THRESH1;THRESH2 +#Tenant[0],Id[1],FilterType[2],FilterFieldName[3],FilterFieldValues[4],ActivationInterval[5],Recurrent[6],MinSleep[7],Blocker[8],Weight[9],ActionIDs[10] +cgrates.org,Threshold1,*string,Account,1001;1002,2014-07-29T15:00:00Z,true,1s,true,10,THRESH1;THRESH2 diff --git a/data/tariffplans/tutorial/Thresholds.csv b/data/tariffplans/tutorial/Thresholds.csv index 374a0342e..a422ddaa6 100644 --- a/data/tariffplans/tutorial/Thresholds.csv +++ b/data/tariffplans/tutorial/Thresholds.csv @@ -1,2 +1,2 @@ -#Tenant[0],Id[1],FilterType[2],FilterFieldName[3],FilterFieldValues[4],ActivationInterval[5],MinItems[6],Recurrent[7],MinSleep[8],Blocker[9],Weight[10],MinItems[11],ActionIDs[12] -cgrates.org,Threshold1,*string,Account,1001;1002,2014-07-29T15:00:00Z,10,true,1s,true,10,THRESH1;THRESH2 +#Tenant[0],Id[1],FilterType[2],FilterFieldName[3],FilterFieldValues[4],ActivationInterval[5],Recurrent[6],MinSleep[7],Blocker[8],Weight[9],ActionIDs[10] +cgrates.org,Threshold1,*string,Account,1001;1002,2014-07-29T15:00:00Z,true,1s,true,10,THRESH1;THRESH2 diff --git a/engine/loader_csv_test.go b/engine/loader_csv_test.go index 471030ccf..aedcc7624 100755 --- a/engine/loader_csv_test.go +++ b/engine/loader_csv_test.go @@ -278,8 +278,8 @@ cgrates.org,Stats1,*string,Account,1001;1002,2014-07-29T15:00:00Z,100,1s,*asr;*a ` thresholds = ` -#Tenant[0],Id[1],FilterType[2],FilterFieldName[3],FilterFieldValues[4],ActivationInterval[5],MinItems[6],Recurrent[7],MinSleep[8],Blocker[9],Weight[10],ActionIDs[11] -cgrates.org,Threshold1,*string,Account,1001;1002,2014-07-29T15:00:00Z,10,true,1s,true,10,THRESH1;THRESH2 +#Tenant[0],Id[1],FilterType[2],FilterFieldName[3],FilterFieldValues[4],ActivationInterval[5],Recurrent[6],MinSleep[7],Blocker[8],Weight[9],ActionIDs[10] +cgrates.org,Threshold1,*string,Account,1001;1002,2014-07-29T15:00:00Z,true,1s,true,10,THRESH1;THRESH2 ` ) @@ -1482,7 +1482,6 @@ func TestLoadThresholds(t *testing.T) { ActivationInterval: &utils.TPActivationInterval{ ActivationTime: "2014-07-29T15:00:00Z", }, - MinItems: 10, Recurrent: true, MinSleep: "1s", Blocker: true, diff --git a/engine/model_helpers.go b/engine/model_helpers.go index 235b98ea9..bc586d383 100755 --- a/engine/model_helpers.go +++ b/engine/model_helpers.go @@ -2137,9 +2137,6 @@ func (tps TpThresholdS) AsTPThreshold() (result []*utils.TPThreshold) { if tp.ActionIDs != "" { th.ActionIDs = append(th.ActionIDs, strings.Split(tp.ActionIDs, utils.INFIELD_SEP)...) } - if tp.MinItems != 0 { - th.MinItems = tp.MinItems - } if tp.Weight != 0 { th.Weight = tp.Weight } @@ -2182,7 +2179,6 @@ func APItoModelTPThreshold(th *utils.TPThreshold) (mdls TpThresholdS) { if i == 0 { mdl.Blocker = th.Blocker mdl.Weight = th.Weight - mdl.MinItems = th.MinItems mdl.Recurrent = th.Recurrent mdl.MinSleep = th.MinSleep if th.ActivationInterval != nil { @@ -2220,7 +2216,6 @@ func APItoThresholdProfile(tpTH *utils.TPThreshold, timezone string) (th *Thresh th = &ThresholdProfile{ Tenant: tpTH.Tenant, ID: tpTH.ID, - MinItems: tpTH.MinItems, Recurrent: tpTH.Recurrent, Weight: tpTH.Weight, Blocker: tpTH.Blocker, diff --git a/engine/model_helpers_test.go b/engine/model_helpers_test.go index d126748b7..937f79f85 100755 --- a/engine/model_helpers_test.go +++ b/engine/model_helpers_test.go @@ -940,7 +940,6 @@ func TestAsTPThresholdAsAsTPThreshold(t *testing.T) { FilterFieldName: "Account", FilterFieldValues: "1001;1002", ActivationInterval: "2014-07-29T15:00:00Z", - MinItems: 100, Recurrent: false, MinSleep: "1s", Blocker: false, @@ -962,7 +961,6 @@ func TestAsTPThresholdAsAsTPThreshold(t *testing.T) { ActivationInterval: &utils.TPActivationInterval{ ActivationTime: tps[0].ActivationInterval, }, - MinItems: tps[0].MinItems, MinSleep: tps[0].MinSleep, Recurrent: tps[0].Recurrent, Blocker: tps[0].Blocker, @@ -984,7 +982,6 @@ func TestAPItoTPThreshold(t *testing.T) { &utils.TPRequestFilter{Type: MetaString, FieldName: "Account", Values: []string{"1001", "1002"}}, }, ActivationInterval: &utils.TPActivationInterval{ActivationTime: "2014-07-29T15:00:00Z"}, - MinItems: 100, Recurrent: false, MinSleep: "1s", Blocker: false, @@ -995,7 +992,6 @@ func TestAPItoTPThreshold(t *testing.T) { eTPs := &ThresholdProfile{ ID: tps.ID, Filters: make([]*RequestFilter, len(tps.Filters)), - MinItems: tps.MinItems, Recurrent: tps.Recurrent, Blocker: tps.Blocker, Weight: tps.Weight, diff --git a/engine/models.go b/engine/models.go index 78ed32857..dad305048 100755 --- a/engine/models.go +++ b/engine/models.go @@ -508,11 +508,10 @@ type TpThreshold struct { FilterFieldName string `index:"3" re:""` FilterFieldValues string `index:"4" re:""` ActivationInterval string `index:"5" re:""` - MinItems int `index:"6" re:""` - Recurrent bool `index:"7" re:""` - MinSleep string `index:"8" re:""` - Blocker bool `index:"9" re:""` - Weight float64 `index:"10" re:"\d+\.?\d*"` - ActionIDs string `index:"11" re:""` + Recurrent bool `index:"6" re:""` + MinSleep string `index:"7" re:""` + Blocker bool `index:"8" re:""` + Weight float64 `index:"9" re:"\d+\.?\d*"` + ActionIDs string `index:"10" re:""` CreatedAt time.Time } diff --git a/engine/onstor_it_test.go b/engine/onstor_it_test.go index 4a69c302b..1703fab4d 100644 --- a/engine/onstor_it_test.go +++ b/engine/onstor_it_test.go @@ -2055,7 +2055,6 @@ func testOnStorITCRUDThresholdProfile(t *testing.T) { ID: "test", ActivationInterval: &utils.ActivationInterval{}, Filters: []*RequestFilter{}, - MinItems: 10, Recurrent: true, MinSleep: timeMinSleep, Blocker: true, diff --git a/engine/storage_mongo_datadb.go b/engine/storage_mongo_datadb.go index 2bc2a1ed4..903899e3e 100755 --- a/engine/storage_mongo_datadb.go +++ b/engine/storage_mongo_datadb.go @@ -718,7 +718,7 @@ func (ms *MongoStorage) HasData(category, subject string) (has bool, err error) case utils.StatQueuePrefix: count, err = db.C(colRes).Find(bson.M{"id": subject}).Count() has = count > 0 - case utils.ThresholdsPrefix: + case utils.ThresholdProfilePrefix: count, err = db.C(colThs).Find(bson.M{"id": subject}).Count() has = count > 0 default: diff --git a/engine/thresholds.go b/engine/thresholds.go index 80469e372..176565119 100644 --- a/engine/thresholds.go +++ b/engine/thresholds.go @@ -37,7 +37,6 @@ type ThresholdProfile struct { ID string Filters []*RequestFilter // Filters for the request ActivationInterval *utils.ActivationInterval // Time when this limit becomes active and expires - MinItems int // number of items agregated for the threshold to match Recurrent bool MinSleep time.Duration Blocker bool // blocker flag to stop processing on filters matched diff --git a/utils/apitpdata.go b/utils/apitpdata.go index cf7e209a8..48d5894b2 100755 --- a/utils/apitpdata.go +++ b/utils/apitpdata.go @@ -1360,7 +1360,6 @@ type TPThreshold struct { ID string Filters []*TPRequestFilter // Filters for the request ActivationInterval *TPActivationInterval // Time when this limit becomes active and expires - MinItems int // number of items agregated for the threshold to match Recurrent bool MinSleep string Blocker bool // blocker flag to stop processing on filters matched