ees: preserve exporter attempts in failed posts

This commit is contained in:
ionutboangiu
2025-10-29 09:25:39 +02:00
committed by Dan Christian Bogos
parent 8443af3a89
commit c185e46455
6 changed files with 36 additions and 27 deletions

View File

@@ -351,7 +351,7 @@ func ExportWithAttempts(exp EventExporter, eEv any, key string) (err error) {
defer func() {
if err != nil {
AddFailedPost(exp.Cfg().FailedPostsDir, exp.Cfg().ExportPath,
exp.Cfg().Type, eEv, exp.Cfg().Opts)
exp.Cfg().Type, exp.Cfg().Attempts, eEv, exp.Cfg().Opts)
}
}()
}

View File

@@ -52,7 +52,8 @@ func writeFailedPosts(_ string, value any) {
}
}
func AddFailedPost(failedPostsDir, expPath, format string, ev any, opts *config.EventExporterOpts) {
func AddFailedPost(failedPostsDir, expPath, format string, attempts int, ev any,
opts *config.EventExporterOpts) {
key := utils.ConcatenatedKey(failedPostsDir, expPath, format)
// also in case of amqp,amqpv1,s3,sqs and kafka also separe them after queue id
var amqpQueueID string
@@ -93,6 +94,7 @@ func AddFailedPost(failedPostsDir, expPath, format string, ev any, opts *config.
failedPost = &ExportEvents{
Path: expPath,
Type: format,
Attempts: attempts,
Opts: opts,
failedPostsDir: failedPostsDir,
}
@@ -126,6 +128,7 @@ type ExportEvents struct {
Path string
Opts *config.EventExporterOpts
Type string
Attempts int
Events []any
failedPostsDir string
}
@@ -157,9 +160,9 @@ func (expEv *ExportEvents) AddEvent(ev any) {
}
// ReplayFailedPosts tryies to post cdrs again
func (expEv *ExportEvents) ReplayFailedPosts(attempts int) (failedEvents *ExportEvents, err error) {
func (expEv *ExportEvents) ReplayFailedPosts() (failedEvents *ExportEvents, err error) {
eeCfg := config.NewEventExporterCfg("ReplayFailedPosts", expEv.Type, expEv.Path, utils.MetaNone,
attempts, expEv.Opts)
expEv.Attempts, expEv.Opts)
var ee EventExporter
if ee, err = NewEventExporter(eeCfg, config.CgrConfig(), nil, nil); err != nil {
return
@@ -169,9 +172,10 @@ func (expEv *ExportEvents) ReplayFailedPosts(attempts int) (failedEvents *Export
keyFunc = utils.UUIDSha1Prefix
}
failedEvents = &ExportEvents{
Path: expEv.Path,
Opts: expEv.Opts,
Type: expEv.Type,
Path: expEv.Path,
Opts: expEv.Opts,
Type: expEv.Type,
Attempts: expEv.Attempts,
}
for _, ev := range expEv.Events {
if err = ExportWithAttempts(ee, ev, keyFunc()); err != nil {

View File

@@ -39,7 +39,7 @@ func TestSetFldPostCacheTTL(t *testing.T) {
func TestAddFldPost(t *testing.T) {
InitFailedPostCache(5*time.Second, false)
AddFailedPost("", "path1", "format1", "1", &config.EventExporterOpts{
AddFailedPost("", "path1", "format1", 1, "1", &config.EventExporterOpts{
AMQP: &config.AMQPOpts{},
Els: &config.ElsOpts{},
AWS: &config.AWSOpts{},
@@ -61,9 +61,10 @@ func TestAddFldPost(t *testing.T) {
t.Error("Error when casting")
}
eOut := &ExportEvents{
Path: "path1",
Type: "format1",
Events: []any{"1"},
Path: "path1",
Type: "format1",
Attempts: 1,
Events: []any{"1"},
Opts: &config.EventExporterOpts{
AMQP: &config.AMQPOpts{},
Els: &config.ElsOpts{},
@@ -77,7 +78,7 @@ func TestAddFldPost(t *testing.T) {
if !reflect.DeepEqual(eOut, failedPost) {
t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(eOut), utils.ToJSON(failedPost))
}
AddFailedPost("", "path1", "format1", "2", &config.EventExporterOpts{
AddFailedPost("", "path1", "format1", 1, "2", &config.EventExporterOpts{
AMQP: &config.AMQPOpts{},
Els: &config.ElsOpts{},
AWS: &config.AWSOpts{},
@@ -86,7 +87,7 @@ func TestAddFldPost(t *testing.T) {
RPC: &config.RPCOpts{},
SQL: &config.SQLOpts{},
})
AddFailedPost("", "path2", "format2", "3", &config.EventExporterOpts{
AddFailedPost("", "path2", "format2", 1, "3", &config.EventExporterOpts{
AWS: &config.AWSOpts{
SQSQueueID: utils.StringPointer("qID"),
},
@@ -109,9 +110,10 @@ func TestAddFldPost(t *testing.T) {
t.Error("Error when casting")
}
eOut = &ExportEvents{
Path: "path1",
Type: "format1",
Events: []any{"1", "2"},
Path: "path1",
Type: "format1",
Attempts: 1,
Events: []any{"1", "2"},
Opts: &config.EventExporterOpts{
AMQP: &config.AMQPOpts{},
Els: &config.ElsOpts{},
@@ -137,9 +139,10 @@ func TestAddFldPost(t *testing.T) {
t.Error("Error when casting")
}
eOut = &ExportEvents{
Path: "path2",
Type: "format2",
Events: []any{"3"},
Path: "path2",
Type: "format2",
Attempts: 1,
Events: []any{"3"},
Opts: &config.EventExporterOpts{
Els: &config.ElsOpts{},
NATS: &config.NATSOpts{},

View File

@@ -88,7 +88,7 @@ func TestHttpJsonPoster(t *testing.T) {
if err = ExportWithAttempts(pstr, &HTTPPosterRequest{Body: jsn, Header: make(http.Header)}, ""); err == nil {
t.Error("Expected error")
}
AddFailedPost("/tmp", "http://localhost:8080/invalid", utils.MetaHTTPjsonMap, jsn, &config.EventExporterOpts{
AddFailedPost("/tmp", "http://localhost:8080/invalid", utils.MetaHTTPjsonMap, 1, jsn, &config.EventExporterOpts{
AMQP: &config.AMQPOpts{},
Els: &config.ElsOpts{},
AWS: &config.AWSOpts{},
@@ -146,7 +146,7 @@ func TestHttpBytesPoster(t *testing.T) {
if err = ExportWithAttempts(pstr, &HTTPPosterRequest{Body: content, Header: make(http.Header)}, ""); err == nil {
t.Error("Expected error")
}
AddFailedPost("/tmp", "http://localhost:8080/invalid", utils.ContentJSON, content, &config.EventExporterOpts{
AddFailedPost("/tmp", "http://localhost:8080/invalid", utils.ContentJSON, 1, content, &config.EventExporterOpts{
AMQP: &config.AMQPOpts{},
Els: &config.ElsOpts{},
AWS: &config.AWSOpts{},