Make sure we only return one metric per mounted fs#399
Make sure we only return one metric per mounted fs#399discordianfish merged 1 commit intoprometheus:masterfrom
Conversation
collector/filesystem_common.go
Outdated
There was a problem hiding this comment.
Not sure if that's the way to go. Could also just iterate over stats to check if something was printed already. Thoughts?
There was a problem hiding this comment.
First of all, %q is the printf verb for strings, what you want here is %v or %+v. Go vet should complain about this actually.
Creating a string key for every stats will require additional allocations. Ideally we would just use the struct itself as key. Looking at filesystemStats the only field preventing this is labelValues as structs can only be used as keys if their fields are basic types. Looking at labelValues it appears that using a string slice is a weak data type anyway, as there is strong assumption about the order, length and value. I'd suggest to make the assumption explicit and replace labelValues with three explicit string fields "device", "mountpoint", "fstype".
This will ensure that OS specific implementations can't pass the values in a wrong order and allow you to use the struct as key, avoiding any further allocations by this addition.
There was a problem hiding this comment.
as structs can only be used as keys if their fields are basic types
Ah! Good to know, using the struct as key was what I tried first. Will convert it.
There was a problem hiding this comment.
Here is the the more accurate description of what types can be compared and used as map keys: https://golang.org/ref/spec#Comparison_operators
collector/filesystem_common.go
Outdated
6495b30 to
9194943
Compare
|
@grobie Changed as discussed |
collector/filesystem_common.go
Outdated
There was a problem hiding this comment.
While I believe the change to filesystemsStats was worthwhile anyway, it's actually still possible that we export multiple metrics for the same label set. Unless it's impossible in all os implementations to create structs with different metric values but same label values, we should maybe afterall create a key only based on the label values.
There was a problem hiding this comment.
Oh good catch.. Right, value could be different.. While that should be the case, I came up with a better way. What do you think about this?
9194943 to
6a3d1e6
Compare
grobie
left a comment
There was a problem hiding this comment.
I'm fine with the approach. Just a few nits.
collector/filesystem_freebsd.go
Outdated
There was a problem hiding this comment.
Yes, I just realize that we don't run circleci for the pull requests which would have catched this (and me breaking master with my meminfo changes). Opened #401 for that.
collector/filesystem_linux.go
Outdated
There was a problem hiding this comment.
Why do we need to build filesystemLabels again?
There was a problem hiding this comment.
Missed that when changing. Fixed, also renamed 'mpd' to labels to make it more readable.
collector/filesystem_common.go
Outdated
There was a problem hiding this comment.
Did you run go fmt? I believe that will enforce a newline between type definitions.
There was a problem hiding this comment.
Nope, but added newline manually.
There was a problem hiding this comment.
(Nope it doesn't force, I ran go fmt)
6a3d1e6 to
285a701
Compare
grobie
left a comment
There was a problem hiding this comment.
Thanks! Looks good, feel free to merge.
collector/filesystem_freebsd.go
Outdated
There was a problem hiding this comment.
Did you add this newline on purpose?
There was a problem hiding this comment.
Nope, fixed and going to merge now.
285a701 to
4c9131b
Compare
Closes #377
--
Now we should also have tests for that. I've tried enabling the filesystem collector in the end to end tests but failed. Somehow it always showed a difference for my root filesystem. Anyone know why the collector isn't included in the tests?
Either way, we should have end-to-end tests for that, but I don't think it should block this bugfix here either.