Skip to content

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

Merged
pgier merged 5 commits into
prometheus:masterfrom
pirxthepilot:inotify
Jun 26, 2019
Merged

Parse fdinfo and inotify stats from /proc/[pid]/fdinfo/[fd]#115
pgier merged 5 commits into
prometheus:masterfrom
pirxthepilot:inotify

Conversation

@pirxthepilot

Copy link
Copy Markdown
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!

@pgier pgier left a comment

Copy link
Copy Markdown
Collaborator

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.

Comment thread inotify.go Outdated
"regexp"
"strings"
)

Copy link
Copy Markdown
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.

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

Copy link
Copy Markdown
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.

Comment thread inotify.go Outdated
// File descriptor
FD string
// List of inotify lines in the fdinfo file
Lines []string

Copy link
Copy Markdown
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.

Comment thread proc.go Outdated
return p.fs.Path(append([]string{strconv.Itoa(p.PID)}, pa...)...)
}

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

Copy link
Copy Markdown
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
Copy Markdown
Member

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

@pirxthepilot

Copy link
Copy Markdown
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

pgier commented May 29, 2019

Copy link
Copy Markdown
Collaborator

@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
Copy Markdown
Contributor Author

@pgier whoops, sorry bout that! done!

@pgier pgier left a comment

Copy link
Copy Markdown
Collaborator

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?

Comment thread proc_fdinfo.go Outdated
@pgier

pgier commented Jun 18, 2019

Copy link
Copy Markdown
Collaborator

@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
Copy Markdown
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?

@pgier pgier left a comment

Copy link
Copy Markdown
Collaborator

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.

Comment thread proc_fdinfo.go
Comment thread proc.go Outdated
Comment thread proc_fdinfo.go Outdated
@pirxthepilot
pirxthepilot force-pushed the inotify branch 2 times, most recently from 37bb438 to 1b9a28b Compare June 23, 2019 04:36
@pirxthepilot

pirxthepilot commented Jun 23, 2019

Copy link
Copy Markdown
Contributor Author

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.

@pgier pgier left a comment

Copy link
Copy Markdown
Collaborator

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.

Comment thread proc.go Outdated
Comment thread fixtures.ttar
Comment thread proc_fdinfo.go Outdated
@pgier

pgier commented Jun 24, 2019

Copy link
Copy Markdown
Collaborator

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
Copy Markdown
Contributor Author

Updated!

@pgier pgier left a comment

Copy link
Copy Markdown
Collaborator

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

pgier commented Jun 26, 2019

Copy link
Copy Markdown
Collaborator

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.

3 participants