From 4c30ec4e4c0a3079a694d47d3ddee984beba7d01 Mon Sep 17 00:00:00 2001 From: ionutboangiu Date: Fri, 24 Oct 2025 18:08:47 +0300 Subject: [PATCH] ees: remove init from libcdre, rename to failedposts --- ees/ees_test.go | 1 + ees/{libcdre.go => failedposts.go} | 8 ++------ ees/{libcdre_it_test.go => failedposts_it_test.go} | 0 ees/{libcdre_test.go => failedposts_test.go} | 4 ++-- ees/poster_it_test.go | 4 ++-- services/globalvars.go | 2 +- 6 files changed, 8 insertions(+), 11 deletions(-) rename ees/{libcdre.go => failedposts.go} (95%) rename ees/{libcdre_it_test.go => failedposts_it_test.go} (100%) rename ees/{libcdre_test.go => failedposts_test.go} (98%) diff --git a/ees/ees_test.go b/ees/ees_test.go index e3198bdd4..b70ec3bba 100644 --- a/ees/ees_test.go +++ b/ees/ees_test.go @@ -269,6 +269,7 @@ func TestV1ProcessEvent4(t *testing.T) { cfg.EEsCfg().Exporters[0].Type = utils.MetaHTTPPost cfg.EEsCfg().Exporters[0].ID = "SQLExporterFull" cfg.EEsCfg().Exporters[0].Synchronous = true + InitFailedPostCache(cfg.EEsCfg().FailedPosts.TTL, cfg.EEsCfg().FailedPosts.StaticTTL) newIDb, err := engine.NewInternalDB(nil, nil, true, nil, cfg.DataDbCfg().Items) if err != nil { t.Error(err) diff --git a/ees/libcdre.go b/ees/failedposts.go similarity index 95% rename from ees/libcdre.go rename to ees/failedposts.go index f61a3e9a6..7c0d5a001 100644 --- a/ees/libcdre.go +++ b/ees/failedposts.go @@ -35,12 +35,8 @@ import ( var failedPostCache *ltcache.Cache -func init() { - failedPostCache = ltcache.NewCache(-1, 5*time.Second, false, false, []func(itmID string, value any){writeFailedPosts}) // configurable general -} - -// SetFailedPostCacheTTL recreates the failed cache -func SetFailedPostCacheTTL(ttl time.Duration, static bool) { +// InitFailedPostCache initializes the failed posts cache. +func InitFailedPostCache(ttl time.Duration, static bool) { failedPostCache = ltcache.NewCache(-1, ttl, static, false, []func(itmID string, value any){writeFailedPosts}) } diff --git a/ees/libcdre_it_test.go b/ees/failedposts_it_test.go similarity index 100% rename from ees/libcdre_it_test.go rename to ees/failedposts_it_test.go diff --git a/ees/libcdre_test.go b/ees/failedposts_test.go similarity index 98% rename from ees/libcdre_test.go rename to ees/failedposts_test.go index 1d0edfb95..c34a0069e 100644 --- a/ees/libcdre_test.go +++ b/ees/failedposts_test.go @@ -30,7 +30,7 @@ import ( func TestSetFldPostCacheTTL(t *testing.T) { var1 := failedPostCache - SetFailedPostCacheTTL(50*time.Millisecond, false) + InitFailedPostCache(50*time.Millisecond, false) var2 := failedPostCache if reflect.DeepEqual(var1, var2) { t.Error("Expecting to be different") @@ -38,7 +38,7 @@ func TestSetFldPostCacheTTL(t *testing.T) { } func TestAddFldPost(t *testing.T) { - SetFailedPostCacheTTL(5*time.Second, false) + InitFailedPostCache(5*time.Second, false) AddFailedPost("", "path1", "format1", "1", &config.EventExporterOpts{ AMQP: &config.AMQPOpts{}, Els: &config.ElsOpts{}, diff --git a/ees/poster_it_test.go b/ees/poster_it_test.go index 83791b16a..7d146327f 100644 --- a/ees/poster_it_test.go +++ b/ees/poster_it_test.go @@ -66,7 +66,7 @@ type TestContent struct { } func TestHttpJsonPoster(t *testing.T) { - SetFailedPostCacheTTL(time.Millisecond, false) + InitFailedPostCache(time.Millisecond, false) content := &TestContent{Var1: "Val1", Var2: "Val2"} jsn, _ := json.Marshal(content) pstr, err := NewHTTPjsonMapEE(&config.EventExporterCfg{ @@ -123,7 +123,7 @@ func TestHttpJsonPoster(t *testing.T) { } func TestHttpBytesPoster(t *testing.T) { - SetFailedPostCacheTTL(time.Millisecond, false) + InitFailedPostCache(time.Millisecond, false) content := []byte(`Test Test2 `) diff --git a/services/globalvars.go b/services/globalvars.go index 4ce93eaa9..1fa6c0ad5 100644 --- a/services/globalvars.go +++ b/services/globalvars.go @@ -47,7 +47,7 @@ type GlobalVarS struct { // Start should handle the sercive start func (gv *GlobalVarS) Start() (err error) { engine.SetRoundingDecimals(gv.cfg.GeneralCfg().RoundingDecimals) - ees.SetFailedPostCacheTTL(gv.cfg.EEsCfg().FailedPosts.TTL, gv.cfg.EEsCfg().FailedPosts.StaticTTL) + ees.InitFailedPostCache(gv.cfg.EEsCfg().FailedPosts.TTL, gv.cfg.EEsCfg().FailedPosts.StaticTTL) engine.SetHTTPPstrTransport(gv.cfg.HTTPCfg().ClientOpts) return nil }