Not indexing for *asm + tests

This commit is contained in:
porosnicuadrian
2021-07-27 10:37:31 +03:00
committed by Dan Christian Bogos
parent a16f6106dc
commit 4b9d28b80a
3 changed files with 86 additions and 13 deletions

View File

@@ -30,10 +30,13 @@ import (
var (
FilterIndexTypes = utils.NewStringSet([]string{utils.MetaPrefix, utils.MetaString, utils.MetaSuffix})
// Element or values of a filter that starts with one of this should not be indexed
ToNotBeIndexed = []string{utils.DynamicDataPrefix + utils.MetaAccounts,
ToNotBeIndexed = []string{
utils.DynamicDataPrefix + utils.MetaAccounts,
utils.DynamicDataPrefix + utils.MetaStats,
utils.DynamicDataPrefix + utils.MetaResources,
utils.DynamicDataPrefix + utils.MetaLibPhoneNumber}
utils.DynamicDataPrefix + utils.MetaLibPhoneNumber,
utils.DynamicDataPrefix + utils.MetaAsm,
}
)
// newFilterIndex will get the index from DataManager if is not found it will create it

View File

@@ -15,11 +15,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
package engine
import (
"reflect"
"testing"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/utils"
"reflect"
"testing"
)
func TestFilterIndexesCheckingDynamicPathToNotIndex(t *testing.T) {
@@ -130,3 +129,77 @@ func TestFilterIndexesCheckingDynamicPathToNotIndex(t *testing.T) {
t.Errorf("Expected %+v, received %+v", utils.ToJSON(expIDx), utils.ToJSON(fltrIDx))
}
}
func TestFilterIndexesCheckingDynamicPathToNotIndexAsm(t *testing.T) {
Cache.Clear(nil)
cfg := config.NewDefaultCGRConfig()
db := NewInternalDB(nil, nil, true)
dm := NewDataManager(db, cfg.CacheCfg(), nil)
// set 1 charger profile with different *asm filter to index
cghPfr := &ChargerProfile{
Tenant: "cgrates.org",
ID: "CHARGER_1",
FilterIDs: []string{
"*prefix:~*req.DestinationNr:+10227",
"*string:~*accounts.RS_ALOC.Available:2",
"*string:~*asm.Cost:122.03",
},
RunID: "CustomRunID",
AttributeIDs: []string{"*none"},
Weight: 20,
}
if err := dm.SetChargerProfile(cghPfr, true); err != nil {
t.Error(err)
}
expIDx := map[string]utils.StringSet{
"*prefix:*req.DestinationNr:+10227": {
"CHARGER_1": {},
},
}
if fltrIDx, err := dm.GetIndexes(utils.CacheChargerFilterIndexes,
"cgrates.org", utils.EmptyString, true, true); err != nil {
t.Error(err)
} else if !reflect.DeepEqual(expIDx, fltrIDx) {
t.Errorf("Expected %+v, received %+v", utils.ToJSON(expIDx), utils.ToJSON(fltrIDx))
}
}
func TestFilterIndexesCheckingDynamicPathToNotIndexLibphNmbr(t *testing.T) {
Cache.Clear(nil)
cfg := config.NewDefaultCGRConfig()
db := NewInternalDB(nil, nil, true)
dm := NewDataManager(db, cfg.CacheCfg(), nil)
// set 1 charger profile with different *libphonenumber filter to index
cghPfr := &ChargerProfile{
Tenant: "cgrates.org",
ID: "CHARGER_2",
FilterIDs: []string{
"*prefix:~*req.CGRID:TEST_ID",
"*string:~*opts.TotalCost:~*stats.STS_PRF1.*tcc",
"*string:~*libphonenumber.<~*req.Destination:1233",
},
RunID: "RAW",
AttributeIDs: []string{"attr_1"},
Weight: 10,
}
if err := dm.SetChargerProfile(cghPfr, true); err != nil {
t.Error(err)
}
expIDx := map[string]utils.StringSet{
"*prefix:*req.CGRID:TEST_ID": {
"CHARGER_2": {},
},
}
if fltrIDx, err := dm.GetIndexes(utils.CacheChargerFilterIndexes,
"cgrates.org", utils.EmptyString, true, true); err != nil {
t.Error(err)
} else if !reflect.DeepEqual(expIDx, fltrIDx) {
t.Errorf("Expected %+v, received %+v", utils.ToJSON(expIDx), utils.ToJSON(fltrIDx))
}
}

View File

@@ -401,8 +401,8 @@ func TestHealthIndexThreshold(t *testing.T) {
Tenant: "cgrates.org",
ID: "TestHealthIndexThreshold",
FilterIDs: []string{"*string:~*opts.*eventType:AccountUpdate",
"*string:~*asm.ID:1002",
"*suffix:BrokenFilter:Invalid"},
"*string:~*asm.ID:1002", // *asm will not be indexing
"*suffix:BrokenFilter:Invalid"}, // static value, won't index
MaxHits: 1,
},
}
@@ -413,7 +413,6 @@ func TestHealthIndexThreshold(t *testing.T) {
args := &IndexHealthArgsWith3Ch{}
exp := &FilterIHReply{
MissingIndexes: map[string][]string{
"cgrates.org:*string:*asm.ID:1002": {"TestHealthIndexThreshold"},
"cgrates.org:*string:*opts.*eventType:AccountUpdate": {"TestHealthIndexThreshold"},
},
BrokenIndexes: map[string][]string{},
@@ -436,7 +435,7 @@ func TestHealthIndexThreshold(t *testing.T) {
"*string:*req.Destination:123": { // index is valid but the obj does not exist
"InexistingThreshold": {},
},
}
}
// we will set manually some indexes that points to an nil object or index is valid but the obj is missing
if err := dm.SetIndexes(utils.CacheThresholdFilterIndexes, "cgrates.org",
@@ -446,10 +445,9 @@ func TestHealthIndexThreshold(t *testing.T) {
exp = &FilterIHReply{
MissingObjects: []string{"cgrates.org:InexistingThreshold"},
MissingIndexes: map[string][]string{
"cgrates.org:*string:*asm.ID:1002": {"TestHealthIndexThreshold"},
"cgrates.org:*string:*opts.*eventType:AccountUpdate": {"TestHealthIndexThreshold"},
},
BrokenIndexes: map[string][]string{
BrokenIndexes: map[string][]string{
"cgrates.org:*prefix:req.InvalidIdx:10": {"TestHealthIndexThreshold"},
},
MissingFilters: map[string][]string{},
@@ -481,10 +479,9 @@ func TestHealthIndexThreshold(t *testing.T) {
exp = &FilterIHReply{
MissingObjects: []string{"cgrates.org:InexistingThreshold"},
MissingIndexes: map[string][]string{
"cgrates.org:*string:*asm.ID:1002": {"TestHealthIndexThreshold"},
"cgrates.org:*string:*opts.*eventType:AccountUpdate": {"TestHealthIndexThreshold"},
},
BrokenIndexes: map[string][]string{
BrokenIndexes: map[string][]string{
"cgrates.org:*prefix:req.InvalidIdx:10": {"TestHealthIndexThreshold"},
},
MissingFilters: map[string][]string{