-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
[libbeat] Document / clean up parts of the publisher queue interface #16858
Changes from 1 commit
ac9d308
4306c3f
a91943b
d0a7d4e
0d08201
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,23 +80,34 @@ type ProducerConfig struct { | |
DropOnCancel bool | ||
} | ||
|
||
// Producer interface to be used by the pipelines client to forward events to be | ||
// published to the queue. | ||
// When a producer calls `Cancel`, it's up to the queue to send or remove | ||
// events not yet ACKed. | ||
// Note: A queue is still allowed to send the ACK signal after Cancel. The | ||
// pipeline client must filter out ACKs after cancel. | ||
// Producer is an interface to be used by the pipelines client to forward | ||
// events to a queue. | ||
type Producer interface { | ||
// Publish adds an event to the queue, blocking if necessary, and returns | ||
// true on success. | ||
Publish(event publisher.Event) bool | ||
|
||
// TryPublish adds an event to the queue, returning immediately if the queue | ||
// is full, and returns true on success. | ||
TryPublish(event publisher.Event) bool | ||
|
||
// Cancel closes this Producer endpoint. If the producer is configured to | ||
// drop its events on Cancel, the number of dropped events is returned. | ||
// Note: A queue may still send ACK signals even after Cancel is called on | ||
// the originating Producer. The pipeline client must accept and | ||
// discard these ACKs. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I recall correctly the client based cancellers are closed as well. communication is async, which means that 'during' cancel we still get ACKs, but once close has finished no ACKs might be received anymore. The pipeline also has a 'global' ACK queue, which will still receive the ACKs. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you clarify? I'm not sure what "client based cancellers" are in this context. This comment was based on the code in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see. Yeah, you are right here. The behavior about ACKs is in the beat.Client interface, not the Producer interface. |
||
Cancel() int | ||
} | ||
|
||
// Consumer interface to be used by the pipeline output workers. | ||
// The `Get` method retrieves a batch of events up to size `sz`. If sz <= 0, | ||
// the batch size is up to the queue. | ||
// Consumer is an interface to be used by the pipeline output workers, | ||
// used to read events from the head of the queue. | ||
type Consumer interface { | ||
Get(sz int) (Batch, error) | ||
// Get retrieves a batch of up to eventCount events. If eventCount <= 0, | ||
// there is no bound on the number of returned events. | ||
Get(eventCount int) (Batch, error) | ||
|
||
// Close closes this Consumer. Returns an error if the Consumer is | ||
// already closed. | ||
Close() error | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
more correct might be: 'if the event can not be processed by the queue'.
e.g. memqueue broker also does some cleanup. During this phase it is possible that we can't accept events, although there is some space left.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, if possible I'd like somethng more precise than "can not be processed," I'm trying to articulate the specific contract for this interface. Can be we be more specific about the possible reasons for failure? Whether to call
Publish
orTryPublish
is decided by whether the client config for the pipeline setsPublishMode
toDropIfFull
. If that setting is actually dropping events for reasons other than a full queue, I'd like to make it more explicit in the description.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It depends per queue implementation. Important is to not block the caller at all if the event can not be processed right now.
DropIfFull
is maybe not a good name to transfer this message.One use-case is packetbeat. In packetbeat we must not block if the event can not be consumed right now. Packetbeat would rather drop the event and continue processing the next network packet, then drop a a multiple network packet . This is required due to packetbeat accumulating quite some internal state and packet loss can be much more severe.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the abstract it depends on queue implementation, but more pragmatically we only have one non-beta implementation of
queue.Queue
in the entire codebase, so it seems desirable to be as specific as we can about whyTryPublish
might fail. (The behavior of the whole publisher pipeline depends on the contract forPublish
andTryPublish
, which is currently entirely implicit, making it hard to safely reason about new queue implementations.)If the current design doesn't allow for something more specific, how about we explicitly call out that behavior dependency:
TryPublish adds an event to the queue if doing so will not block the caller, otherwise it immediately returns. The reasons a publish attempt might block are defined by the specific queue implementation and its configuration. Returns true if the event was successfully added, false otherwise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SGTM