Skip to content

Comments

Make sure we only return one metric per mounted fs#399

Merged
discordianfish merged 1 commit intoprometheus:masterfrom
discordianfish:fish-fs-uniq-metric
Jan 4, 2017
Merged

Make sure we only return one metric per mounted fs#399
discordianfish merged 1 commit intoprometheus:masterfrom
discordianfish:fish-fs-uniq-metric

Conversation

@discordianfish
Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure if that's the way to go. Could also just iterate over stats to check if something was printed already. Thoughts?

Copy link
Member

Choose a reason for hiding this comment

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

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

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.

Copy link
Member

Choose a reason for hiding this comment

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

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

Copy link
Member

Choose a reason for hiding this comment

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

Maybe seen is clearer?

@discordianfish
Copy link
Member Author

@grobie Changed as discussed

Copy link
Member

Choose a reason for hiding this comment

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

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

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?

Copy link
Member

@grobie grobie left a comment

Choose a reason for hiding this comment

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

I'm fine with the approach. Just a few nits.

Copy link
Member

Choose a reason for hiding this comment

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

This needs to be updated.

Copy link
Member Author

Choose a reason for hiding this comment

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

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.

Copy link
Member

Choose a reason for hiding this comment

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

Why do we need to build filesystemLabels again?

Copy link
Member Author

Choose a reason for hiding this comment

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

Missed that when changing. Fixed, also renamed 'mpd' to labels to make it more readable.

Copy link
Member

Choose a reason for hiding this comment

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

Did you run go fmt? I believe that will enforce a newline between type definitions.

Copy link
Member Author

Choose a reason for hiding this comment

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

Nope, but added newline manually.

Copy link
Member Author

Choose a reason for hiding this comment

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

(Nope it doesn't force, I ran go fmt)

Copy link
Member

@grobie grobie left a comment

Choose a reason for hiding this comment

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

Thanks! Looks good, feel free to merge.

Copy link
Member

Choose a reason for hiding this comment

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

Did you add this newline on purpose?

Copy link
Member Author

Choose a reason for hiding this comment

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

Nope, fixed and going to merge now.

@discordianfish discordianfish merged commit f9d3f83 into prometheus:master Jan 4, 2017
@discordianfish discordianfish deleted the fish-fs-uniq-metric branch January 4, 2017 15:48
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.

Issue collecting duplicate entries from /proc/mounts

2 participants