-
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
x-pack/filebeat/input/http_endpoint: make input GA #39410
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
338227a
x-pack/filebeat/input/http_endpoint: make input GA
efd6 3d87bdf
x-pack/filebeat/input/http_endpoint: add acking
efd6 8972f9e
address pr comments
efd6 f2748c1
x-pack/filebeat/input/http_endpoint: add e2e acking
efd6 9bbcac2
x-pack/filebeat/input/http_endpoint: add debug URL logging
efd6 4e9325e
x-pack/filebeat/docs/inputs: add timeout documentation
efd6 d08dad2
address pr comment
efd6 310ce79
validate queries
efd6 db44a7b
add system test for acking
efd6 e901753
x-pack/filebeat/input/http_endpoint: allow user to place events at do…
efd6 b7d7f50
address pr comment
efd6 19ce29d
address pr comments
efd6 0d7f581
x-pack/filebeat/input/http_endpoint: fix request trace filename handling
efd6 File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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,77 @@ | ||||||||||||||||||
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||||||||||||||||||
// or more contributor license agreements. Licensed under the Elastic License; | ||||||||||||||||||
// you may not use this file except in compliance with the Elastic License. | ||||||||||||||||||
|
||||||||||||||||||
package http_endpoint | ||||||||||||||||||
|
||||||||||||||||||
import ( | ||||||||||||||||||
"sync" | ||||||||||||||||||
|
||||||||||||||||||
"github.com/elastic/beats/v7/libbeat/beat" | ||||||||||||||||||
"github.com/elastic/beats/v7/libbeat/common/acker" | ||||||||||||||||||
) | ||||||||||||||||||
|
||||||||||||||||||
// newEventACKHandler returns a beat ACKer that can receive callbacks when | ||||||||||||||||||
// an event has been ACKed an output. If the event contains a private metadata | ||||||||||||||||||
// pointing to a batchACKTracker then it will invoke the tracker's ACK() method | ||||||||||||||||||
// to decrement the number of pending ACKs. | ||||||||||||||||||
Comment on lines
+14
to
+17
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. Typo
Suggested change
|
||||||||||||||||||
func newEventACKHandler() beat.EventListener { | ||||||||||||||||||
return acker.ConnectionOnly( | ||||||||||||||||||
acker.EventPrivateReporter(func(_ int, privates []interface{}) { | ||||||||||||||||||
for _, private := range privates { | ||||||||||||||||||
if ack, ok := private.(*batchACKTracker); ok { | ||||||||||||||||||
ack.ACK() | ||||||||||||||||||
} | ||||||||||||||||||
} | ||||||||||||||||||
}), | ||||||||||||||||||
) | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
// batchACKTracker invokes batchACK when all events associated to the batch | ||||||||||||||||||
// have been published and acknowledged by an output. | ||||||||||||||||||
type batchACKTracker struct { | ||||||||||||||||||
batchACK func() | ||||||||||||||||||
|
||||||||||||||||||
mu sync.Mutex | ||||||||||||||||||
pending int64 | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
// newBatchACKTracker returns a new batchACKTracker. The provided batchACK function | ||||||||||||||||||
// is invoked after the full batch has been acknowledged. Ready() must be invoked | ||||||||||||||||||
// after all events in the batch are published. | ||||||||||||||||||
func newBatchACKTracker(fn func()) *batchACKTracker { | ||||||||||||||||||
return &batchACKTracker{ | ||||||||||||||||||
batchACK: fn, | ||||||||||||||||||
pending: 1, // Ready() must be called to consume this "1". | ||||||||||||||||||
} | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
// Ready signals that the batch has been fully consumed. Only | ||||||||||||||||||
// after the batch is marked as "ready" can the batch be ACKed. | ||||||||||||||||||
// This prevents the batch from being ACKed prematurely. | ||||||||||||||||||
func (t *batchACKTracker) Ready() { | ||||||||||||||||||
t.ACK() | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
// Add increments the number of pending ACKs. | ||||||||||||||||||
func (t *batchACKTracker) Add() { | ||||||||||||||||||
t.mu.Lock() | ||||||||||||||||||
t.pending++ | ||||||||||||||||||
t.mu.Unlock() | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
// ACK decrements the number of pending event ACKs. When all pending ACKs are | ||||||||||||||||||
// received then the event batch is ACKed. | ||||||||||||||||||
func (t *batchACKTracker) ACK() { | ||||||||||||||||||
t.mu.Lock() | ||||||||||||||||||
defer t.mu.Unlock() | ||||||||||||||||||
|
||||||||||||||||||
if t.pending <= 0 { | ||||||||||||||||||
panic("misuse detected: negative ACK counter") | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
t.pending-- | ||||||||||||||||||
if t.pending == 0 { | ||||||||||||||||||
t.batchACK() | ||||||||||||||||||
} | ||||||||||||||||||
} |
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,50 @@ | ||
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
// or more contributor license agreements. Licensed under the Elastic License; | ||
// you may not use this file except in compliance with the Elastic License. | ||
|
||
package http_endpoint | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestBatchACKTracker(t *testing.T) { | ||
t.Run("empty", func(t *testing.T) { | ||
tracker := make(ack) | ||
|
||
acker := newBatchACKTracker(tracker.ACK) | ||
require.False(t, tracker.wasACKed()) | ||
|
||
acker.Ready() | ||
require.True(t, tracker.wasACKed()) | ||
}) | ||
|
||
t.Run("single_event", func(t *testing.T) { | ||
tracker := make(ack) | ||
|
||
acker := newBatchACKTracker(tracker.ACK) | ||
acker.Add() | ||
acker.ACK() | ||
require.False(t, tracker.wasACKed()) | ||
|
||
acker.Ready() | ||
require.True(t, tracker.wasACKed()) | ||
}) | ||
} | ||
|
||
type ack chan struct{} | ||
|
||
func (a ack) ACK() { | ||
close(a) | ||
} | ||
|
||
func (a ack) wasACKed() bool { | ||
select { | ||
case <-a: | ||
return true | ||
default: | ||
return false | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
[Suggestion]
Use the loopback IP address so people can copy/paste the config as is for testing/experimenting.
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.
I think in this case documentational consistency and clarity trumps copy/paste convenience; the other examples all use 192.168.1.1 and that address is an address that is not special. Changing either of those things I think harms clarity.