From e7a608568fce6bb230d27c7332f7012e79f170ea Mon Sep 17 00:00:00 2001 From: "antoine.choimet" Date: Thu, 21 Nov 2024 14:46:16 +0100 Subject: [PATCH] fix: better error handling for multiple election failed --- extkafka/partition_attack_elect_new_leader.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/extkafka/partition_attack_elect_new_leader.go b/extkafka/partition_attack_elect_new_leader.go index 999c320..976e712 100644 --- a/extkafka/partition_attack_elect_new_leader.go +++ b/extkafka/partition_attack_elect_new_leader.go @@ -5,6 +5,7 @@ package extkafka import ( "context" + "errors" "fmt" "github.com/steadybit/action-kit/go/action_kit_api/v2" "github.com/steadybit/action-kit/go/action_kit_sdk" @@ -123,6 +124,7 @@ func (f kafkaBrokerElectNewLeaderAttack) Start(ctx context.Context, state *Kafka return nil, fmt.Errorf("failed to elect new leader for topic %s and partitions %s: %s", state.Topic, state.Partitions, err) } var errorElectLeader action_kit_api.ActionKitError + var errs []error for t, parts := range results { for partition, result := range parts { if result.Err != nil { @@ -130,7 +132,7 @@ func (f kafkaBrokerElectNewLeaderAttack) Start(ctx context.Context, state *Kafka Level: extutil.Ptr(action_kit_api.Warn), Message: fmt.Sprintf("Error while electing leader for topic '%s', partition %d, error is: %s", t, partition, result.Err.Error()), }) - errorElectLeader = action_kit_api.ActionKitError{Title: fmt.Sprintf("Election failed for partition %d", partition), Detail: extutil.Ptr(result.Err.Error())} + errs = append(errs, result.Err) } else { messages = append(messages, action_kit_api.Message{ Level: extutil.Ptr(action_kit_api.Info), @@ -139,6 +141,9 @@ func (f kafkaBrokerElectNewLeaderAttack) Start(ctx context.Context, state *Kafka } } } + if len(errs) > 0 { + errorElectLeader = action_kit_api.ActionKitError{Title: "Election failed for partition(s)", Detail: extutil.Ptr(errors.Join(errs...).Error())} + } return &action_kit_api.StartResult{ Messages: &messages,