Skip to content

Commit

Permalink
fix: check lag failed if acceptable lag crossed
Browse files Browse the repository at this point in the history
  • Loading branch information
achoimet committed Nov 20, 2024
1 parent d1ff614 commit 4e2bf11
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions extkafka/check_topic_lag_for_consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type ConsumerGroupLagCheckState struct {
End time.Time
AcceptableLag int64
StateCheckSuccess bool
StateCheckFailed bool
}

// Make sure action implements all required interfaces
Expand Down Expand Up @@ -157,6 +158,7 @@ func (m *ConsumerGroupLagCheckAction) Prepare(_ context.Context, state *Consumer
}
state.Topic = extutil.ToString(request.Config["topic"])
state.AcceptableLag = extutil.ToInt64(request.Config["acceptableLag"])
state.StateCheckFailed = false

duration := request.Config["duration"].(float64)
end := time.Now().Add(time.Millisecond * time.Duration(duration))
Expand Down Expand Up @@ -211,10 +213,12 @@ func ConsumerGroupLagCheckStatus(ctx context.Context, state *ConsumerGroupLagChe
var checkError *action_kit_api.ActionKitError
if topicLag < state.AcceptableLag {
state.StateCheckSuccess = true
} else {
state.StateCheckFailed = true
}
if completed && !state.StateCheckSuccess {
if completed && state.StateCheckFailed {
checkError = extutil.Ptr(action_kit_api.ActionKitError{
Title: fmt.Sprintf("Consumer Group Lag was higher once than acceptable threshold '%d'.",
Title: fmt.Sprintf("Consumer Group Lag was higher at least once than acceptable threshold '%d'.",
state.AcceptableLag),
Status: extutil.Ptr(action_kit_api.Failed),
})
Expand Down

0 comments on commit 4e2bf11

Please sign in to comment.