cfg: move failed_posts to ees, add static_ttl

This commit is contained in:
ionutboangiu
2025-10-24 17:41:53 +03:00
committed by Dan Christian Bogos
parent 082c412159
commit 295ddec792
45 changed files with 324 additions and 208 deletions

View File

@@ -53,14 +53,14 @@ func callURL(ub *engine.Account, a *engine.Action, _ engine.Actions, _ *engine.F
if err != nil {
return err
}
eeCfg := config.NewEventExporterCfg(a.Id, "", a.ExtraParameters, config.CgrConfig().GeneralCfg().FailedPostsDir,
eeCfg := config.NewEventExporterCfg(a.Id, "", a.ExtraParameters, config.CgrConfig().EEsCfg().FailedPosts.Dir,
config.CgrConfig().GeneralCfg().PosterAttempts, nil)
pstr, err := NewHTTPjsonMapEE(eeCfg, config.CgrConfig(), nil, nil)
if err != nil {
return err
}
err = ExportWithAttempts(pstr, &HTTPPosterRequest{Body: body, Header: make(http.Header)}, "")
if config.CgrConfig().GeneralCfg().FailedPostsDir != utils.MetaNone {
if config.CgrConfig().EEsCfg().FailedPosts.Dir != utils.MetaNone {
err = nil
}
return err
@@ -73,7 +73,7 @@ func callURLAsync(ub *engine.Account, a *engine.Action, _ engine.Actions, _ *eng
if err != nil {
return err
}
eeCfg := config.NewEventExporterCfg(a.Id, "", a.ExtraParameters, config.CgrConfig().GeneralCfg().FailedPostsDir,
eeCfg := config.NewEventExporterCfg(a.Id, "", a.ExtraParameters, config.CgrConfig().EEsCfg().FailedPosts.Dir,
config.CgrConfig().GeneralCfg().PosterAttempts, nil)
pstr, err := NewHTTPjsonMapEE(eeCfg, config.CgrConfig(), nil, nil)
if err != nil {
@@ -89,14 +89,14 @@ func postEvent(_ *engine.Account, a *engine.Action, _ engine.Actions, _ *engine.
if err != nil {
return err
}
eeCfg := config.NewEventExporterCfg(a.Id, "", a.ExtraParameters, config.CgrConfig().GeneralCfg().FailedPostsDir,
eeCfg := config.NewEventExporterCfg(a.Id, "", a.ExtraParameters, config.CgrConfig().EEsCfg().FailedPosts.Dir,
config.CgrConfig().GeneralCfg().PosterAttempts, nil)
pstr, err := NewHTTPjsonMapEE(eeCfg, config.CgrConfig(), nil, nil)
if err != nil {
return err
}
err = ExportWithAttempts(pstr, &HTTPPosterRequest{Body: body, Header: make(http.Header)}, "")
if config.CgrConfig().GeneralCfg().FailedPostsDir != utils.MetaNone {
if config.CgrConfig().EEsCfg().FailedPosts.Dir != utils.MetaNone {
err = nil
}
return err

View File

@@ -40,8 +40,8 @@ func init() {
}
// SetFailedPostCacheTTL recreates the failed cache
func SetFailedPostCacheTTL(ttl time.Duration) {
failedPostCache = ltcache.NewCache(-1, ttl, false, false, []func(itmID string, value any){writeFailedPosts})
func SetFailedPostCacheTTL(ttl time.Duration, static bool) {
failedPostCache = ltcache.NewCache(-1, ttl, static, false, []func(itmID string, value any){writeFailedPosts})
}
func writeFailedPosts(_ string, value any) {

View File

@@ -46,7 +46,7 @@ func TestWriteFldPosts(t *testing.T) {
if err := os.MkdirAll(dir, 0755); err != nil {
t.Fatal("Error creating folder: ", dir, err)
}
config.CgrConfig().GeneralCfg().FailedPostsDir = dir
config.CgrConfig().EEsCfg().FailedPosts.Dir = dir
writeFailedPosts("itmID", exportEvent)
if filename, err := filepath.Glob(filepath.Join(dir, "EEs|*.gob")); err != nil {

View File

@@ -30,7 +30,7 @@ import (
func TestSetFldPostCacheTTL(t *testing.T) {
var1 := failedPostCache
SetFailedPostCacheTTL(50 * time.Millisecond)
SetFailedPostCacheTTL(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)
SetFailedPostCacheTTL(5*time.Second, false)
AddFailedPost("", "path1", "format1", "1", &config.EventExporterOpts{
AMQP: &config.AMQPOpts{},
Els: &config.ElsOpts{},

View File

@@ -66,7 +66,7 @@ type TestContent struct {
}
func TestHttpJsonPoster(t *testing.T) {
SetFailedPostCacheTTL(time.Millisecond)
SetFailedPostCacheTTL(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)
SetFailedPostCacheTTL(time.Millisecond, false)
content := []byte(`Test
Test2
`)