forked from elastic/beats
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Filebeat: Allow stateless and stateful ACKer on the global ack handler (
elastic#7214) (elastic#7258) * Filebeat: Allow stateless and stateful ACKer on the global ack handler This commit introduces a change in how filebat handle ACK by default, before the ACK was using the private field of the event to retrieve a state. The updated state was sent to the registrar, and the registrar was finalizing the ACK. But with the introduction of the TCP/UDP and the Redis input, the events don't have any state attached. So in that scenario, Filebeat was not correctly acking these events to some wait group. The ACKer was modified to handle both stateless (default) and stateful events, when stateful is required, the states are sent to the registry otherwise, the waiting groups are directly updated. Fixes: elastic#7202 * changelog (cherry picked from commit 31c46c9)
- Loading branch information
Showing
4 changed files
with
95 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package beater | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/elastic/beats/filebeat/input/file" | ||
) | ||
|
||
type mockStatefulLogger struct { | ||
states []file.State | ||
} | ||
|
||
func (sf *mockStatefulLogger) Published(states []file.State) { | ||
sf.states = states | ||
} | ||
|
||
type mockStatelessLogger struct { | ||
count int | ||
} | ||
|
||
func (sl *mockStatelessLogger) Published(count int) bool { | ||
sl.count = count | ||
return true | ||
} | ||
|
||
func TestACKer(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
data []interface{} | ||
stateless int | ||
stateful []file.State | ||
}{ | ||
{ | ||
name: "only stateless", | ||
data: []interface{}{nil, nil}, | ||
stateless: 2, | ||
}, | ||
{ | ||
name: "only stateful", | ||
data: []interface{}{file.State{Source: "-"}, file.State{Source: "-"}}, | ||
stateful: []file.State{file.State{Source: "-"}, file.State{Source: "-"}}, | ||
stateless: 0, | ||
}, | ||
{ | ||
name: "both", | ||
data: []interface{}{file.State{Source: "-"}, nil, file.State{Source: "-"}}, | ||
stateful: []file.State{file.State{Source: "-"}, file.State{Source: "-"}}, | ||
stateless: 1, | ||
}, | ||
{ | ||
name: "any other Private type", | ||
data: []interface{}{struct{}{}, nil}, | ||
stateless: 2, | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
sl := &mockStatelessLogger{} | ||
sf := &mockStatefulLogger{} | ||
|
||
h := newEventACKer(sl, sf) | ||
|
||
h.ackEvents(test.data) | ||
assert.Equal(t, test.stateless, sl.count) | ||
assert.Equal(t, test.stateful, sf.states) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters