diff --git a/analyzers/analyzers.go b/analyzers/analyzers.go index 2a2fd4bb9..784c9f79a 100644 --- a/analyzers/analyzers.go +++ b/analyzers/analyzers.go @@ -59,7 +59,7 @@ func (aS *AnalyzerService) SetFilterS(fS *engine.FilterS) { } func (aS *AnalyzerService) initDB() (err error) { - if aS.cfg.AnalyzerSCfg().DBPath == utils.EmptyString { + if aS.cfg.AnalyzerSCfg().IndexType == utils.MetaInternal { aS.db, err = bleve.NewMemOnly(bleve.NewIndexMapping()) return } diff --git a/analyzers/analyzers_test.go b/analyzers/analyzers_test.go index 193062a62..370f994b2 100644 --- a/analyzers/analyzers_test.go +++ b/analyzers/analyzers_test.go @@ -169,7 +169,7 @@ func TestAnalyzersListenAndServe(t *testing.T) { t.Fatal(err) } go func() { - time.Sleep(1) + time.Sleep(time.Nanosecond) runtime.Gosched() anz.db.Close() }() @@ -445,6 +445,7 @@ func TestAnalyzerSLogTrafficInternalDB(t *testing.T) { cfg := config.NewDefaultCGRConfig() cfg.AnalyzerSCfg().DBPath = utils.EmptyString + cfg.AnalyzerSCfg().IndexType = utils.MetaInternal cfg.AnalyzerSCfg().TTL = 30 * time.Minute anz, err := NewAnalyzerService(cfg) if err != nil { diff --git a/config/configsanity.go b/config/configsanity.go index 8e173051b..5601d695e 100644 --- a/config/configsanity.go +++ b/config/configsanity.go @@ -1078,7 +1078,12 @@ func (cfg *CGRConfig) checkConfigSanity() error { if !utils.AnzIndexType.Has(cfg.analyzerSCfg.IndexType) { return fmt.Errorf("<%s> unsuported index type: %q", utils.AnalyzerS, cfg.analyzerSCfg.IndexType) } - // TTL and CleanupInterval should always be bigger than zero in order to not keep unnecessary logs in index + if cfg.analyzerSCfg.IndexType != utils.MetaInternal { + 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) + } + } + // TTL and CleanupInterval should always be biger than zero in order to not keep unecesary logs in index if cfg.analyzerSCfg.TTL <= 0 { return fmt.Errorf("<%s> the TTL needs to be bigger than 0", utils.AnalyzerS) } diff --git a/config/configsanity_test.go b/config/configsanity_test.go index 4402317ef..2acbe1314 100644 --- a/config/configsanity_test.go +++ b/config/configsanity_test.go @@ -1692,9 +1692,14 @@ func TestConfigSanityAnalyzer(t *testing.T) { t.Errorf("Expecting: %+q received: %+q", expected, err) } + cfg.analyzerSCfg.IndexType = utils.MetaScorch + cfg.analyzerSCfg.DBPath = "/inexistent/Path" + expected = " 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 expected = " the TTL needs to be bigger than 0" if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected { t.Errorf("Expecting: %+q received: %+q", expected, err) diff --git a/utils/consts.go b/utils/consts.go index 09600095a..493d0282d 100644 --- a/utils/consts.go +++ b/utils/consts.go @@ -2604,15 +2604,13 @@ const ( ExecCgr = "exec" ) -var ( - // AnzIndexType are the analyzers possible index types - AnzIndexType = StringSet{ - MetaScorch: {}, - MetaBoltdb: {}, - MetaLeveldb: {}, - MetaMoss: {}, - } -) +var AnzIndexType = StringSet{ // AnzIndexType are the analyzers possible index types + MetaScorch: {}, + MetaBoltdb: {}, + MetaLeveldb: {}, + MetaMoss: {}, + MetaInternal: {}, +} // StringTmplType a string set used, by agentRequest and eventRequest to determine if the returned template type is string var StringTmplType = StringSet{