-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Update for "multiline processing for tail input plugin" #7309
Conversation
@ssoroka Hello, would really like to see this PR merged and released. Any idea on when that may be ? |
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.
Thanks for picking up this PR and running with it!
I'm mainly concerned about the new code branch with a second receiver function. I know this wasn't your design, but maybe we can improve it. See notes below.
FYI if you want help getting this over the line, just say the word and we will jump in where/when possible.
plugins/inputs/tail/multiline.go
Outdated
return nil, err | ||
} | ||
if m.Timeout == nil || m.Timeout.Duration.Nanoseconds() == int64(0) { | ||
duration, _ := time.ParseDuration("5s") |
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.
something like 5 * time.Second
will give you type safety here.
plugins/inputs/tail/README.md
Outdated
## The pattern should be a regexp which matches what you believe to be an indicator that the field is part of an event consisting of multiple lines of log data. | ||
#pattern = "^\s" | ||
|
||
## The what must be previous or next and indicates the relation to the multi-line event. |
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.
This could be clearer. "what" is already not a great name (I understand it was borrowed from elastic; something like "MatchWhichLine" would be better). You could add some context and examples; eg "previous means any line matching the pattern belongs to the previous line"
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 agree on the unclear naming. I renamed the config element and added more detailed description for the two possible values.
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.
Can you update the docs to match? It looks like they still say "what" in multiple places. Need to keep the docs in sync with the sample config
plugins/inputs/tail/tail.go
Outdated
|
||
acc telegraf.TrackingAccumulator | ||
|
||
sync.Mutex |
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.
Looks like this was removed in another commit and came back from the merge (rebase is safer in this respect). We can remove this line.
plugins/inputs/tail/tail.go
Outdated
go func() { | ||
defer t.wg.Done() | ||
t.receiver(parser, tailer) | ||
if t.multiline.IsEnabled() { | ||
go t.receiverMultiline(parser, tailer) |
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 don't really like that the conditional around receiverMultiline forks the behavior here (I'm not talking about the go routine). It definitely adds a lot of code complexity and likely introduces bugs in how the two receivers process input. eg, search for "Block until plugin is stopping or room is available to add metrics" and you'll find that this other receiver code has already changed, and multiline isn't supporting coordination with downstream outputs to not overwhelm them. Now the multiline receiver is out of sync and won't respect this behavior. In the best case scenario, future updates will have to update two versions of the code.
How difficult do you think it'd be to merge the two receiver functions? Any concerns?
plugins/inputs/tail/tail.go
Outdated
var firstLine = true | ||
for { | ||
var line *tail.Line | ||
timer := time.NewTimer(t.MultilineConfig.Timeout.Duration) |
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.
can define this once and then do Reset(t.MultilineConfig.Timeout.Duration)
Merge receiver functions in the tail input plugin.
Hi @ssoroka, thanks for your detailed review. I have merged the two receiver functions into one, respecting the changes regarding downstream consumers. |
@@ -246,12 +247,12 @@ func TestGrokParseLogFilesWithMultilineTimeout(t *testing.T) { | |||
|
|||
acc := testutil.Accumulator{} | |||
assert.NoError(t, tt.Start(&acc)) | |||
time.Sleep(20) // will force timeout | |||
time.Sleep(5 * time.Second) // will force timeout |
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.
not sure I understand these sleeps in the tests. Are we really expecting this test to sleep for 5x2 seconds?
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.
Ok, I think we're good here from my view. I'd like to test it locally and get one more review before merging.
Thanks so much for the work you've put into this; this is one of our most popular plugins, and it is much appreciated!
When you plan to merge this PR? |
Waiting on a review from @danielnelson poke |
@danielnelson We‘d really appreciate if you could review the code. |
@ssoroka, @binchow-ai I've fixed the conflicts with the current master branch, this should be ready to be merged now. |
Any example of the syntax how to use this multiline feature ? |
@kemuning
|
@zibuyu1995 Thanks. |
@zibuyu1995 Strange ... I have this config :
but then I got an error I am using telegraf 1.15.2. Any idea ? |
@kemuning No, version 1.5.2 does not support multiline feature , you need to select https://github.com/semigroupoid/telegraf |
Is there any timeline when will this PR be merged ? |
_, err = tmpfile.WriteString(" ") | ||
require.NoError(t, err) | ||
require.NoError(t, tmpfile.Sync()) |
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'd like to understand more about why this is necessary.
plugins/inputs/tail/README.md
Outdated
## The pattern should be a regexp which matches what you believe to be an indicator that the field is part of an event consisting of multiple lines of log data. | ||
#pattern = "^\s" | ||
|
||
## The what must be previous or next and indicates the relation to the multi-line event. |
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.
Can you update the docs to match? It looks like they still say "what" in multiple places. Need to keep the docs in sync with the sample config
plugins/inputs/tail/multiline.go
Outdated
case `PREVIOUS`: | ||
fallthrough | ||
case `"PREVIOUS"`: | ||
fallthrough | ||
case `'PREVIOUS'`: |
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.
just fyi, you can do this:
case `PREVIOUS`: | |
fallthrough | |
case `"PREVIOUS"`: | |
fallthrough | |
case `'PREVIOUS'`: | |
case `PREVIOUS`, `"PREVIOUS"`, `'PREVIOUS'`: |
plugins/inputs/tail/tail.go
Outdated
case <-t.ctx.Done(): | ||
return |
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.
We can't remove this, or the plugin can hang and not shutdown properly.
plugins/inputs/tail/tail.go
Outdated
channelOpen := true | ||
|
||
for { | ||
var line *tail.Line |
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.
Not sure what the compiler does here, but it looks like this is being reallocated every iteration, where we could just be setting it to nil.
plugins/inputs/tail/tail.go
Outdated
## The negate field can be true or false (defaults to false). | ||
## If true, a message not matching the pattern will constitute a match of the multiline | ||
## filter and the what will be applied. (vice-versa is also true) | ||
#negate = false |
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.
How do you feel about changing this name to invert_match
?
Would like to see a few more things before this gets merged. Also if anyone is really interested in it, please check out this branch and build it, try it out locally and see how it works for you. |
Hello everybody interested in this feature. we are using this feature (build locally) in a production environment for more than one year by now. So please merge this PR soon. |
@lsitzmann I really appreciate hearing about your experience! Your vote of confidence means a lot. |
Is there any updates on this PR ? |
Hey @semigroupoid, would you like make the changes @ssoroka mentioned above. If anyone would like to check out this branch and complete the fixes that would be awesome too. We'd love to get this merged in before the next release. |
Look like this introduces some kind of race in TestGrokParseLogFilesWithMultilineTailerCloseFlushesMultilineBuffer test.
|
Ok, I have a fix for this failure. I've moved it into another PR to keep it clean. #8167 |
merged in #8190 |
This PR contains the content of the existing PR 5603 but rebased on top of the current master branch of this repository.
Required for all PRs: