Skip to content

Commit

Permalink
fix: better error handling for multiple election failed
Browse files Browse the repository at this point in the history
  • Loading branch information
achoimet committed Nov 21, 2024
1 parent 4632685 commit e7a6085
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion extkafka/partition_attack_elect_new_leader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -123,14 +124,15 @@ 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 {
messages = append(messages, action_kit_api.Message{
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),
Expand All @@ -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,
Expand Down

0 comments on commit e7a6085

Please sign in to comment.