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

Added general file descriptor logic and implemented for linux #30

Merged
merged 1 commit into from
Jun 3, 2016

Conversation

kinghrothgar
Copy link

Add support for #29.

I have implemented the initial logic for Linux and just wanted to get some input to make sure I'm on the right track before I move on to attempting some of the other OSes. A few things of note / questions:

  1. Also, I'm not sure what to do what to do when reading /proc/{PID}/fd fails which is will for root processes if run as not root. Currently, it just returns 0 for the open count. I think this maybe the best route, but I am not sure.
  2. I assume I should also add tests for the new logic?
  3. Since we don't want the FD metrics reported by the beat if it's not implemented for the OS, I think instead of returning nil I should through an error in the unimplemented functions?

@kinghrothgar kinghrothgar changed the title Added general file descriptor logic and implemented for linux NO MERGE: Added general file descriptor logic and implemented for linux May 27, 2016
@codecov-io
Copy link

codecov-io commented May 27, 2016

Current coverage is 56.95%

Merging #30 into master will decrease coverage by 14.56%

@@             master        #30   diff @@
==========================================
  Files             9          6     -3   
  Lines          1025        525   -500   
  Methods           0          0          
  Messages          0          0          
  Branches          0          0          
==========================================
- Hits            733        299   -434   
+ Misses          238        205    -33   
+ Partials         54         21    -33   

Powered by Codecov. Last updated by e9bc408...04e10c4

if len(fields) == 6 {
self.SoftLimit, _ = strconv.ParseUint(fields[3], 10, 64)
self.HardLimit, _ = strconv.ParseUint(fields[4], 10, 64)
return false
Copy link
Member

Choose a reason for hiding this comment

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

I think this return false should be moved outside and after this if block. After finding Max open files you want to stop reading the file regardless of success/failure in parsing this line.

@andrewkroh
Copy link
Member

The changes look good, they just need some tests.

For your questions:

  1. I thinking returning 0 is a good trade-off.
  2. Yes, please add tests.
  3. Yes, I think the package needs a public (exported) error type like ErrNotImplemented that can be returned from functions when the feature is not implemented. Users like Metricbeat can then test if the feature is implemented by calling the function once to see if ErrNotImplemented is returned.

@kinghrothgar kinghrothgar force-pushed the addFileDescriptorUsage branch 3 times, most recently from 73318fd to 70932cd Compare May 31, 2016 22:35
@kinghrothgar kinghrothgar changed the title NO MERGE: Added general file descriptor logic and implemented for linux Added general file descriptor logic and implemented for linux May 31, 2016
@kinghrothgar
Copy link
Author

Alright, I believe I did everything needed for merge. Two things I'm a little unsure of:

  1. Where to put the def of ErrNotImplemented. I put it in sigar_interface.go for now but maybe it would go better in sigar_util.go
  2. I didn't make any of the existing unimplemented methods start returning an ErrNotImplemented as I believe that would be an unexpected change for somethings that use gosigar?

fdUsage, err := concreteSigar.GetFDUsage()
// if it's not implemented, don't test
if _, ok := err.(*sigar.ErrNotImplemented); ok {
println("Skipping *ConcreteSigar.GetFDUsage test because it is no implemented for " + runtime.GOOS)
Copy link
Member

Choose a reason for hiding this comment

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

"no implemented" -> "not implemented"

Copy link
Member

Choose a reason for hiding this comment

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

Instead of println, you can you testing.Skipf().

@andrewkroh
Copy link
Member

andrewkroh commented Jun 2, 2016

The new changes look good. I just left some cosmetic comments. I think the location of new error is good. And the refactoring (#31) of the existing methods to use the new error is a larger task that someone (probably myself) can tackle in the future. Thanks!

@kinghrothgar kinghrothgar force-pushed the addFileDescriptorUsage branch from 70932cd to 6654280 Compare June 3, 2016 18:50
@kinghrothgar
Copy link
Author

All commented items fixed.

@andrewkroh andrewkroh merged commit f932de4 into elastic:master Jun 3, 2016
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.

3 participants