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

prospector: cache resolved glob patterns during init #4269

Merged
merged 1 commit into from
May 19, 2017
Merged

prospector: cache resolved glob patterns during init #4269

merged 1 commit into from
May 19, 2017

Conversation

7AC
Copy link
Contributor

@7AC 7AC commented May 9, 2017

Before this change recursive glob patterns were resolved only at runtime, so everytime filebeat restarted it would try to recover its previous state without expanding the patterns first. With this change we expand the patterns once and for all during init, fixing both the start and the restart case.

Resolves #4182

@7AC 7AC added the review label May 9, 2017
@@ -42,12 +43,33 @@ func NewLog(p *Prospector) (*Log, error) {
return prospectorer, nil
}

func (l *Log) resolvePaths() error {
if l.paths != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would avoid making a distinction between non-nil and zero length slices. This can lead to subtle programming mistakes. I would check for len(l.paths) > 0

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, yeah I prefer that too

l.paths = l.config.Paths
return nil
}
l.paths = []string{}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unnecessary if you check the len() of the slice above, rather than for non-nil.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@ruflin
Copy link
Member

ruflin commented May 9, 2017

@7AC I didn't check the PR yet but I strongly recommend to add some system test to it to check if everything goes well during restart. I remember doing the first implementation without the "extra glob" was a bit tricky, especially on windows. We must make sure the right paths are picked up again.

@ruflin ruflin added Filebeat Filebeat in progress Pull request is currently in progress. labels May 10, 2017
@7AC 7AC removed the review label May 10, 2017

func (config *prospectorConfig) resolvePaths() error {
var paths []string
if !config.recursiveGlob {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason this is not working is that recursiveGlob is a private variable and golang can only extract values in global variables. You must set it to RecursiveGlob in prospectorConfig.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@7AC 7AC added review and removed in progress Pull request is currently in progress. labels May 11, 2017
Copy link
Member

@ruflin ruflin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change LGTM. Left some minor comments for the tests.

Could you add a CHANGELOG entry?

name="output contains 'entry1'")

# Wait a momemt to make sure registry is completely written
time.sleep(1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sleep is very flaky with these kind of things. We normally rely on the log_contains messages here. Check some other tests for it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's copy/paste from test_registrar.py (had the same observation btw :) I don't think I need it here anyways I'll remove it

@@ -1396,3 +1398,8 @@ def test_registrar_files_with_prospector_level_processors(self):
"inode": stat.st_ino,
"device": stat.st_dev,
}, file_state_os)


if __name__ == '__main__':
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this addition, can you directly "run" the file without prepending it with nosetests?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, just need to pip install a couple of things

@@ -350,6 +353,16 @@ def output_has(self, lines, output_file=None):
except IOError:
return False

def output_has_message(self, message, output_file=None):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That will become handy in other tests too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I tried working with the existing APIs but checking the length wasn't enough since when I restart I want to check for the different message to show up (length still 1)

lambda: self.output_has_message("entry2"),
max_timeout=10,
name="output contains 'entry2'")

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

filebeat must be stopped again here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -31,6 +31,7 @@ https://github.com/elastic/beats/compare/v6.0.0-alpha1...master[Check the HEAD d
- Fix importing the dashboards when the limit for max open files is too low. {issue}4244[4244]

*Filebeat*
- Make recursive glob resolution work across restarts. {pull}4269[4269]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be "make recursive glob working"? Not sure it was working before?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I rephrased it

Copy link
Member

@ruflin ruflin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Could you rebase on master? There is a conflict :-(

@ruflin ruflin merged commit 8fb1cf9 into elastic:master May 19, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Filebeat - Error in load states when enable the recursive glob
3 participants