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

MINOR: kern_procargs more robust on darwin #78

Merged
merged 1 commit into from
Oct 11, 2017

Conversation

ph
Copy link

@ph ph commented Oct 10, 2017

Under some circonstance the code can fail, the root cause is not clear
at the moment, but we should still make the code more robust when
retrieving information for a specific process.

The problem is the bytes.SplitN can return an array of one element
making the process panic when we access the other element.

This commit make the code a bit more robust and check to make sure we
successfully retrieved 2 elements instead of one and return an error
if it failed.

Reference: elastic/beats#5337

@ph
Copy link
Author

ph commented Oct 10, 2017

Error Trace: sigar_interface_test.go:137
Error: Not equal:
expected: "${debian_chroot:+($debian_chroot)}\u@\h:\w\$ "
actual: "${debian_chroot:+($debian_chroot)}\u@\h:\w\$"

This failure should not be related to changes.

ph added a commit to ph/gosigar that referenced this pull request Oct 10, 2017
When working on elastic#78, I was hit by a test failing on linux (debian host)
Our code is triming values so we need to adjust the test code to make
sure we also trim values before doing the comparison.

Example:
```
	expected: "${debian_chroot:+($debian_chroot)}\\u@\\h:\\w\\$ "
	            	actual: "${debian_chroot:+($debian_chroot)}\\u@\\h:\\w\\$"
```
ph added a commit to ph/gosigar that referenced this pull request Oct 10, 2017
When working on elastic#78, I was hit by a test failing on linux (debian host)
Our code is triming values so we need to adjust the test code to make
sure we also trim values before doing the comparison.

Example:
```
	expected: "${debian_chroot:+($debian_chroot)}\\u@\\h:\\w\\$ "
	            	actual: "${debian_chroot:+($debian_chroot)}\\u@\\h:\\w\\$"
```
ph added a commit to ph/gosigar that referenced this pull request Oct 11, 2017
When working on elastic#78, I was hit by a test failing on linux (debian host)
Our code is triming values so we need to adjust the test code to make
sure we also trim values before doing the comparison.

Example:
```
	expected: "${debian_chroot:+($debian_chroot)}\\u@\\h:\\w\\$ "
	            	actual: "${debian_chroot:+($debian_chroot)}\\u@\\h:\\w\\$"
```
@ph ph force-pushed the fix/make-darwin-pid-check-more-robust branch from 4ccc5c9 to 876f407 Compare October 11, 2017 13:15
@ph ph added the review label Oct 11, 2017
@ph
Copy link
Author

ph commented Oct 11, 2017

Require #79 to make the test green under linux.

sigar_darwin.go Outdated
@@ -420,7 +420,12 @@ func kern_procargs(pid int,
return fmt.Errorf("Error reading args: %v", err)
}
pair := bytes.SplitN(chop(line), delim, 2)
env(string(pair[0]), string(pair[1]))

if len(pair) == 2 {
Copy link
Member

Choose a reason for hiding this comment

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

It seems more common in Go to check for the error case and omit the else (i.e. if len != 2 { return error }).

Copy link
Author

Choose a reason for hiding this comment

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

+1 will make the changes

andrewkroh pushed a commit that referenced this pull request Oct 11, 2017
When working on #78, I was hit by a test failing on linux (debian host)
Our code is triming values so we need to adjust the test code to make
sure we also trim values before doing the comparison.

Example:
```
	expected: "${debian_chroot:+($debian_chroot)}\\u@\\h:\\w\\$ "
	            	actual: "${debian_chroot:+($debian_chroot)}\\u@\\h:\\w\\$"
```
@ph
Copy link
Author

ph commented Oct 11, 2017

@andrewkroh updated with comments from the review.

@ph ph force-pushed the fix/make-darwin-pid-check-more-robust branch from 82cfe9e to b9dbf3b Compare October 11, 2017 20:25
Under some circonstance the code can fail, the root cause is not clear
at the moment, but we should still make the code more robust when
retrieving information for a specific process.

The problem is the `bytes.SplitN` can return an array of one element
making the process panic when we access the other element.

This commit make the code a bit more robust and check to make sure we
successfully retrieved 2 elements instead of one and return an error
if it failed.

Reference: elastic/beats#5337
@ph ph force-pushed the fix/make-darwin-pid-check-more-robust branch from b9dbf3b to d81aa9d Compare October 11, 2017 20:26
@andrewkroh andrewkroh merged commit eb462da into elastic:master Oct 11, 2017
@andrewkroh
Copy link
Member

@ph Would you like to make a release and update the vendored copy in beats? (or I can do it)

@ph
Copy link
Author

ph commented Oct 12, 2017

@andrewkroh I can do it, its only a matter of doing the following?

  • Updating the changelog (0.5.0)
  • Create a v0.5.0 tag
  • Create a PR with the updated vendored in beats?

@andrewkroh
Copy link
Member

@ph Exactly. Plus add back the "Unreleased" placeholder to the changelog after tagging. That's not really required but it's nice touch for the next person that makes a change.

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.

2 participants