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

Parse fdinfo and inotify stats from /proc/[pid]/fdinfo/[fd] #115

Merged
merged 5 commits into from
Jun 26, 2019

Conversation

pirxthepilot
Copy link
Contributor

First attempt at adding functionality to support #107. Not quite sure if my approach here is correct - guidance/feedback would be very much appreciated. Also thought I'd let you guys review first before I write the tests.

Thanks!

Copy link
Collaborator

@pgier pgier left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution! I think this is a good start. To be more consistent with the rest of the package, the code should be in a file called proc_fdinfo.go, and it should parse the data read instead of returning strings and byte slice.

inotify.go Outdated
"regexp"
"strings"
)

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it would be good to create an additional struct here called FDInfo which contains pos, flags, and mnt_id since those fields appear to be consistently available. The FDInfo struct could contain a slice of InotifyStat containing the detailed information for inotify file descriptors.
And to be more consistent with the rest of the API, the file should be called proc_fdinfo.go.

inotify.go Outdated
// InotifyStat represents a file descriptor's inotify watch count.
type InotifyStat struct {
// File descriptor
FD string
Copy link
Collaborator

Choose a reason for hiding this comment

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

This could be moved into the FDInfo struct.

inotify.go Outdated
// File descriptor
FD string
// List of inotify lines in the fdinfo file
Lines []string
Copy link
Collaborator

Choose a reason for hiding this comment

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

Instead of just loading the line here, I think it would be better to parse the values into their expected fields/types. Or at least add the values to map for easy lookup.

proc.go Outdated
@@ -256,3 +256,18 @@ func (p Proc) fileDescriptors() ([]string, error) {
func (p Proc) path(pa ...string) string {
return p.fs.Path(append([]string{strconv.Itoa(p.PID)}, pa...)...)
}

func (p Proc) fileDescriptorInfo(fd string) ([]byte, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This needs to capitalized to be available from outside of the procfs package. Also, I think this should return a FDInfo with the data already parsed, to make it easier to use.

@discordianfish
Copy link
Member

Agree with pgier and don't have more to add. And sorry for not responding earlier!

@pirxthepilot
Copy link
Contributor Author

Hi folks, just pushed some updates based on your feedback. I replaced fileDescriptorInfo with FileDescriptorsInfo, which now returns a slice of FDInfo types. Also modified and moved InotifyWatchLen to proc.go as it felt more correct to me.

I'm sure this still needs some tweaks. Also, my go-foo isn't too good to begin with :) Hope it at least makes some sense!

@pirxthepilot pirxthepilot changed the title Parse inotify stats from /proc/[pid]/fdinfo/[fd] Parse fdinfo and inotify stats from /proc/[pid]/fdinfo/[fd] May 27, 2019
@pgier
Copy link
Collaborator

pgier commented May 29, 2019

@pirxthepilot Looks good, but would you mind rebasing on latest master? I think the staticcheck CI failures are related to an outdated Makefile or some other build config.

@pirxthepilot
Copy link
Contributor Author

@pgier whoops, sorry bout that! done!

Copy link
Collaborator

@pgier pgier left a comment

Choose a reason for hiding this comment

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

@pirxthepilot Would you mind adding some basic tests before we merge?

proc_fdinfo.go Outdated Show resolved Hide resolved
@pgier
Copy link
Collaborator

pgier commented Jun 18, 2019

@pirxthepilot I think this still needs unit tests before we merge.

@pirxthepilot pirxthepilot force-pushed the inotify branch 2 times, most recently from d97b4dd to 26c06f6 Compare June 19, 2019 09:15
@pirxthepilot
Copy link
Contributor Author

@pgier sorry for the delayed response. I pushed a new commit with the requested changes. Just want to run it by you as I start writing the tests.

As for the tests, how should I go about adding fixtures? Do I just append data by hand in fixtures.ttar?

Copy link
Collaborator

@pgier pgier left a comment

Choose a reason for hiding this comment

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

Looking at this again, I noticed a couple more minor things that might be improved.
For updating the fixtures there is some info in README.md. Just extract the fixtures, make the updates you want, then pack them up again.

proc_fdinfo.go Show resolved Hide resolved
proc.go Outdated Show resolved Hide resolved
proc_fdinfo.go Outdated Show resolved Hide resolved
@pirxthepilot pirxthepilot force-pushed the inotify branch 2 times, most recently from 37bb438 to 1b9a28b Compare June 23, 2019 04:36
@pirxthepilot
Copy link
Contributor Author

pirxthepilot commented Jun 23, 2019

Changes made and tests written. I think the test in proc_test.go should provide coverage for the types and functions in proc_fdinfo.go, except for InotifyWatchLen, which I wrote a separate test for in proc_fdinfo_test.go. Let me know if you need anything else.

Copy link
Collaborator

@pgier pgier left a comment

Choose a reason for hiding this comment

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

Thanks for the update, tests look good. It looks like you are using an out of date fixtures.ttar, you may need to rebase on latest master to avoid conflict in the fixtures.

proc.go Outdated Show resolved Hide resolved
fixtures.ttar Outdated Show resolved Hide resolved
proc_fdinfo.go Outdated Show resolved Hide resolved
@pgier
Copy link
Collaborator

pgier commented Jun 24, 2019

I think the fixtures issue is a separate issue and should be fixed by PR #185, so you can ignore that part.

Edit: if you temporarily change the base branch of the PR and then change it back to master, it should update the diff to remove the bad fixtures stuff.

Signed-off-by: Joon Guillen <joon@modulogeek.com>
Signed-off-by: Joon Guillen <joon@modulogeek.com>
Signed-off-by: Joon Guillen <joon@modulogeek.com>
Signed-off-by: Joon Guillen <joon@modulogeek.com>
@pirxthepilot pirxthepilot force-pushed the inotify branch 2 times, most recently from b0fbe08 to b6b6455 Compare June 26, 2019 07:09
- Use slices instead of arrays to get FileDescriptorsInfo
- Move regex declarations into global scope

Signed-off-by: Joon Guillen <joon@modulogeek.com>
@pirxthepilot
Copy link
Contributor Author

Updated!

Copy link
Collaborator

@pgier pgier left a comment

Choose a reason for hiding this comment

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

LGTM

@pgier pgier merged commit 7708988 into prometheus:master Jun 26, 2019
pgier pushed a commit to pgier/procfs that referenced this pull request Jun 26, 2019
@pgier
Copy link
Collaborator

pgier commented Jun 26, 2019

Ug, sorry, the commit message lost the signoff when I did a squash merge. I had to amend the commit and do a force push in #189.

remijouannet pushed a commit to remijouannet/procfs that referenced this pull request Oct 20, 2022
bobrik pushed a commit to bobrik/procfs that referenced this pull request Jan 14, 2023
Add support for a bunch of low hanging fruits
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants