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

Make beats properly exit #736

Merged
merged 1 commit into from Jan 18, 2016

Conversation

Projects
None yet
4 participants
@ruflin
Copy link
Collaborator

commented Jan 15, 2016

Parts of libbeat were exiting the application directly by using os.Exit(). This makes it impossible always clean up the application before cleanup. In addition, a manager which is part of a beat gets also exited in case the beat exits, which is not inteded.

  • os.Exit() was removed from all places
  • Additional tests were added to test exit behaviour
  • Test for version check was added

@ruflin ruflin force-pushed the ruflin:no-exit branch from 9887086 to 82b59cc Jan 15, 2016

@ruflin ruflin force-pushed the ruflin:no-exit branch 2 times, most recently from c912e2a to d610f04 Jan 15, 2016

err := b.Start()

if err != nil {
// TODO: detect if logging was already fully setup or not

This comment has been minimized.

Copy link
@andrewkroh

andrewkroh Jan 15, 2016

Member

Maybe that should be logic that gets embedded into logp.

This comment has been minimized.

Copy link
@ruflin

ruflin Jan 15, 2016

Author Collaborator

That would actually be nice. So we could use logp.* in all cases and it would decide if it needs fmt.* or not.

This comment has been minimized.

Copy link
@ruflin

ruflin Jan 18, 2016

Author Collaborator

I opened an issue here to solve this later: #746


assert True == self.log_contains("Loading config file error")
assert True == self.log_contains("Failed to read")

This comment has been minimized.

Copy link
@andrewkroh

andrewkroh Jan 15, 2016

Member

These tests should all validate the exit code (0 vs 1).

This comment has been minimized.

Copy link
@ruflin

ruflin Jan 15, 2016

Author Collaborator

👍 will change it.

This comment has been minimized.

Copy link
@ruflin

ruflin Jan 18, 2016

Author Collaborator

changed

@@ -120,18 +127,29 @@ func Run(name string, version string, bt Beater) {
}
}

// Starts the beat

This comment has been minimized.

Copy link
@andrewkroh

andrewkroh Jan 15, 2016

Member

This method doc doesn't start with the method name. Here's my suggestion.

// Start starts the Beat by parsing and interpreting the command line flags,
// loading and parsing the configuration file, and running the Beat. This
// method blocks until the Beat exits. If an error occurs while initializing
// or running the Beat it will be returned.

This comment has been minimized.

Copy link
@ruflin

ruflin Jan 18, 2016

Author Collaborator

Added

@andrewkroh

This comment has been minimized.

Copy link
Member

commented Jan 15, 2016

LGTM other than a few minor suggestions.

@ruflin ruflin force-pushed the ruflin:no-exit branch from 8ab3718 to 10349eb Jan 18, 2016

@ruflin

This comment has been minimized.

Copy link
Collaborator Author

commented Jan 18, 2016

@andrewkroh Inputs fixed and rebased again.

assert True == self.log_contains("Failed to read")


def test_invalid_config(self):

This comment has been minimized.

Copy link
@tsg

tsg Jan 18, 2016

Collaborator

I suggest also a test for the -testconfig option with a valid configuration file.

This comment has been minimized.

Copy link
@ruflin

ruflin Jan 18, 2016

Author Collaborator

Added

@ruflin ruflin force-pushed the ruflin:no-exit branch from 10349eb to 5d844a5 Jan 18, 2016

// logging not yet initialized, so using fmt.Printf
fmt.Printf("Loading config file error: %v\n", err)
os.Exit(1)
return fmt.Errorf("Loading config file error: %v\n", err)

This comment has been minimized.

Copy link
@urso

urso Jan 18, 2016

Collaborator

by convention error strings should start with lowercase, as these are often embedded in some other message.

This comment has been minimized.

Copy link
@ruflin

ruflin Jan 18, 2016

Author Collaborator

Interesting. Looks like we don't follow this rule so far in beats.

This comment has been minimized.

Copy link
@ruflin

ruflin Jan 18, 2016

Author Collaborator

I made all error messages lower case as discussed.

Make beats properly exit
Parts of libbeat were exiting the application directly by using os.Exit(). This makes it impossible always clean up the application before cleanup. In addition, a manager which is part of a beat gets also exited in case the beat exits, which is not inteded.

* os.Exit() was removed from all places
* Additional tests were added to test exit behaviour
* Test for version check was added
* Add test for -configtest flag
* Make error log messages starting lowercase

@ruflin ruflin force-pushed the ruflin:no-exit branch from 5d844a5 to 7a36fd6 Jan 18, 2016

tsg added a commit that referenced this pull request Jan 18, 2016

Merge pull request #736 from ruflin/no-exit
Make beats properly exit

@tsg tsg merged commit 02a5f48 into elastic:master Jan 18, 2016

4 checks passed

CLA Commit author has signed the CLA
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
default Merged build finished.
Details

@ruflin ruflin deleted the ruflin:no-exit branch Jan 18, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.