Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make event acknowledgment asynchronous in shipper output #32785

Merged
merged 7 commits into from
Aug 31, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 43 additions & 7 deletions libbeat/outputs/shipper/api/shipper_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package api

import (
context "context"
"errors"
"time"

pb "github.com/elastic/elastic-agent-shipper-client/pkg/proto"
"github.com/elastic/elastic-agent-shipper-client/pkg/proto/messages"
Expand All @@ -29,23 +31,29 @@ import (
func NewProducerMock(cap int) *ProducerMock {
id, _ := uuid.NewV4()
return &ProducerMock{
UUID: id.String(),
uuid: id.String(),
Q: make([]*messages.Event, 0, cap),
}
}

type ProducerMock struct {
pb.UnimplementedProducerServer
Q []*messages.Event
UUID string
Error error
Q []*messages.Event
uuid string
AcceptedCount uint32
persistedIndex uint64
Error error
}

func (p *ProducerMock) PublishEvents(ctx context.Context, r *messages.PublishRequest) (*messages.PublishReply, error) {
if p.Error != nil {
return nil, p.Error
}

if r.Uuid != p.uuid {
return nil, errors.New("UUID does not match")
}

resp := &messages.PublishReply{}

for _, e := range r.Events {
Expand All @@ -55,16 +63,44 @@ func (p *ProducerMock) PublishEvents(ctx context.Context, r *messages.PublishReq

p.Q = append(p.Q, e)
resp.AcceptedCount++
if resp.AcceptedCount == p.AcceptedCount {
break
}
rdner marked this conversation as resolved.
Show resolved Hide resolved
}

resp.AcceptedIndex = uint64(len(p.Q))

return resp, nil
}

func (p *ProducerMock) Persist(count uint64) {
p.persistedIndex = count
}
rdner marked this conversation as resolved.
Show resolved Hide resolved

func (p *ProducerMock) PersistedIndex(req *messages.PersistedIndexRequest, producer pb.Producer_PersistedIndexServer) error {
return producer.Send(&messages.PersistedIndexReply{
Uuid: p.UUID,
PersistedIndex: uint64(len(p.Q)),
err := producer.Send(&messages.PersistedIndexReply{
Uuid: p.uuid,
PersistedIndex: p.persistedIndex,
})
if err != nil {
return err
}

if !req.PollingInterval.IsValid() || req.PollingInterval.AsDuration() == 0 {
return nil
}

ticker := time.NewTicker(req.PollingInterval.AsDuration())
defer ticker.Stop()

for range ticker.C {
err = producer.Send(&messages.PersistedIndexReply{
Uuid: p.uuid,
PersistedIndex: p.persistedIndex,
})
if err != nil {
return err
}
}
return nil
}
Loading