-
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
Use server-side filtering when retrieving Cloud Foundry logs #33456
Merged
Merged
Changes from 6 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
971dd5d
Expose Cloud Foundry filtering into user configuration
jsoriano 20c7ddc
Fix changelog
jsoriano 7fc340d
Linting and fix on docs
jsoriano fae0b0a
Add both server and client side filtering
MichaelKatsoulis 1a1ff0f
Merge remote-tracking branch 'upstream/main' into cloudfoundry-config…
MichaelKatsoulis 989dfde
Edit changelog
MichaelKatsoulis 7b6afaf
Merge remote-tracking branch 'origin/main' into cloudfoundry-config-f…
jsoriano 17d262b
Remove all-logs option
jsoriano 3deb848
Remove option, simplify
jsoriano 07e002b
Merge remote-tracking branch 'upstream/main' into cloudfoundry-config…
MichaelKatsoulis f0ca944
Merge upstream
MichaelKatsoulis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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
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 |
---|---|---|
|
@@ -19,6 +19,7 @@ import ( | |
) | ||
|
||
type DopplerCallbacks struct { | ||
Filter string | ||
Log func(evt Event) | ||
Metric func(evt Event) | ||
Error func(evt EventError) | ||
|
@@ -80,23 +81,49 @@ func (c *DopplerConsumer) Run() { | |
} | ||
|
||
func (c *DopplerConsumer) logsFirehose() { | ||
c.firehose(c.callbacks.Log, consumer.LogMessages) | ||
filter := FirehoseFilterAllLogs | ||
if c.callbacks.Filter != "" { | ||
filter = c.callbacks.Filter | ||
} | ||
filterFn, envelopeFilter := selectFilter(filter) | ||
c.firehose(c.callbacks.Log, filterFn, envelopeFilter) | ||
} | ||
|
||
func (c *DopplerConsumer) metricsFirehose() { | ||
c.firehose(c.callbacks.Metric, consumer.Metrics) | ||
filter := FirehoseFilterMetrics | ||
if c.callbacks.Filter != "" { | ||
filter = c.callbacks.Filter | ||
} | ||
filterFn, envelopeFilter := selectFilter(filter) | ||
c.firehose(c.callbacks.Metric, filterFn, envelopeFilter) | ||
} | ||
|
||
func selectFilter(firehoseFilter string) (func(*events.Envelope) bool, consumer.EnvelopeFilter) { | ||
switch firehoseFilter { | ||
case FirehoseFilterAll: | ||
return filterNoFilter, -1 | ||
case FirehoseFilterAllLogs: | ||
// Requests all events, and selects log-like events. | ||
return filterLogs, -1 | ||
case FirehoseFilterLogs: | ||
// Uses filter-type=logs in requests to the firehose. | ||
return filterLogs, consumer.LogMessages | ||
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. LGTM to use both filters here. |
||
case FirehoseFilterMetrics: | ||
// Uses filter-type=metrics in requests to the firehose. | ||
return filterNoFilter, consumer.Metrics | ||
default: | ||
// TODO: Handle unknown filters. | ||
return filterNoFilter, -1 | ||
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. We should decide if we want some kind of error handling here, or if we just consider |
||
} | ||
} | ||
|
||
func (c *DopplerConsumer) firehose(cb func(evt Event), filter consumer.EnvelopeFilter) { | ||
func (c *DopplerConsumer) firehose(cb func(evt Event), filterFn func(*events.Envelope) bool, filter consumer.EnvelopeFilter) { | ||
var msgChan <-chan *events.Envelope | ||
var errChan <-chan error | ||
filterFn := filterNoFilter | ||
if filter == consumer.LogMessages { | ||
// We are interested in more envelopes than the ones obtained when filtering | ||
// by log messages, retrieve them all and filter later. | ||
// If this causes performance or other problems, we will have to investigate | ||
// if it is possible to pass different filters to the firehose url. | ||
filterFn = filterLogs | ||
if filterFn == nil { | ||
filterFn = filterNoFilter | ||
} | ||
if filter == consumer.LogMessages || filter == consumer.Metrics { | ||
msgChan, errChan = c.consumer.Firehose(c.subscriptionID, "") | ||
} else { | ||
msgChan, errChan = c.consumer.FilteredFirehose(c.subscriptionID, "", filter) | ||
|
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.
If we are sure that
FirehoseFilterAllLogs
andFirehoseFilterLogs
collect the same logs, butFirehoseFilterLogs
is much more efficient, wdyt about usingFirehoseFilterLogs
here and don't expose the option to the user?