mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Added support for in memory db for analyzers
This commit is contained in:
committed by
Dan Christian Bogos
parent
2f0fb3b820
commit
6476c036b1
@@ -59,6 +59,10 @@ func (aS *AnalyzerService) SetFilterS(fS *engine.FilterS) {
|
||||
}
|
||||
|
||||
func (aS *AnalyzerService) initDB() (err error) {
|
||||
if aS.cfg.AnalyzerSCfg().DBPath == utils.EmptyString {
|
||||
aS.db, err = bleve.NewMemOnly(bleve.NewIndexMapping())
|
||||
return
|
||||
}
|
||||
dbPath := path.Join(aS.cfg.AnalyzerSCfg().DBPath, utils.AnzDBDir)
|
||||
if _, err = os.Stat(dbPath); err == nil {
|
||||
aS.db, err = bleve.Open(dbPath)
|
||||
|
||||
@@ -440,3 +440,48 @@ func TestAnalyzersV1Search(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAnalyzerSLogTrafficInternalDB(t *testing.T) {
|
||||
cfg := config.NewDefaultCGRConfig()
|
||||
|
||||
cfg.AnalyzerSCfg().DBPath = utils.EmptyString
|
||||
cfg.AnalyzerSCfg().TTL = 30 * time.Minute
|
||||
anz, err := NewAnalyzerService(cfg)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t1 := time.Now().Add(-time.Hour)
|
||||
if err = anz.logTrafic(0, utils.AnalyzerSv1Ping, "status", "result", "error",
|
||||
utils.MetaJSON, "127.0.0.1:5565", "127.0.0.1:2012", t1, t1.Add(time.Second)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = anz.logTrafic(0, utils.CoreSv1Status, "status", "result", "error",
|
||||
utils.MetaJSON, "127.0.0.1:5565", "127.0.0.1:2012", t1, t1.Add(time.Second)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t1 = time.Now().Add(-10 * time.Minute)
|
||||
if err = anz.logTrafic(0, utils.CoreSv1Status, "status", "result", "error",
|
||||
utils.MetaJSON, "127.0.0.1:5565", "127.0.0.1:2012", t1, t1.Add(time.Second)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if cnt, err := anz.db.DocCount(); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if cnt != 2 {
|
||||
t.Errorf("Expected only 2 documents received:%v", cnt)
|
||||
}
|
||||
if err = anz.clenaUp(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if cnt, err := anz.db.DocCount(); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if cnt != 1 {
|
||||
t.Errorf("Expected only one document received:%v", cnt)
|
||||
}
|
||||
|
||||
if err = anz.db.Close(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = anz.clenaUp(); err != bleve.ErrorIndexClosed {
|
||||
t.Errorf("Expected error: %v,received: %+v", bleve.ErrorIndexClosed, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1075,9 +1075,6 @@ func (cfg *CGRConfig) checkConfigSanity() error {
|
||||
}
|
||||
|
||||
if cfg.analyzerSCfg.Enabled {
|
||||
if _, err := os.Stat(cfg.analyzerSCfg.DBPath); err != nil && os.IsNotExist(err) {
|
||||
return fmt.Errorf("<%s> nonexistent DB folder: %q", utils.AnalyzerS, cfg.analyzerSCfg.DBPath)
|
||||
}
|
||||
if !utils.AnzIndexType.Has(cfg.analyzerSCfg.IndexType) {
|
||||
return fmt.Errorf("<%s> unsuported index type: %q", utils.AnalyzerS, cfg.analyzerSCfg.IndexType)
|
||||
}
|
||||
|
||||
@@ -1692,11 +1692,6 @@ func TestConfigSanityAnalyzer(t *testing.T) {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
|
||||
cfg.analyzerSCfg.DBPath = "/inexistent/Path"
|
||||
expected = "<AnalyzerS> nonexistent DB folder: \"/inexistent/Path\""
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
cfg.analyzerSCfg.DBPath = "/"
|
||||
|
||||
cfg.analyzerSCfg.IndexType = utils.MetaScorch
|
||||
|
||||
Reference in New Issue
Block a user