-
Notifications
You must be signed in to change notification settings - Fork 51
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
Convert brw_stats sizes to bytes #86
Conversation
a897f78
to
bbdc997
Compare
I'd like this to be a conversation starter, rather than a sure-fire code change. I'm not sure that this makes the user's life any better, since now you see entries like: lustre_disk_io_total{operations="read", ost="XXX", size="1000"} 1 Which I don't think is meaningfully better than: lustre_disk_io_total{operations="read", ost="XXX", size="1K"} 1 Thoughts, @mjtrangoni or @knweiss? |
@joehandzik Using bytes will e.g. help Grafana to display a numerically sorted graph legend (i.e. sorted by Please use 1024 instead of 1000 as the base. |
@knweiss good tip on sorting based on numeric labels in Grafana, I haven't played around with that feature too much yet. I can see value in that feature. One concern I have is differentiating the sizes in Grafana. Does it auto-configure numeric labels similar to axis values? I just have concerns about these numbers taking up a lot of real-estate in Grafana. For example, just 1GB is Could be I'm off-base here since I haven't played around with this specific functionality in Grafana too much yet, so please correct me if I am wrong. |
sources/procfs.go
Outdated
new_s = strings.TrimSuffix(s, "G") | ||
multiplier = 1000000000 | ||
default: | ||
//this should only happen for integers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or if for some reason the file has another label... though we aren't there yet, imagine once we get into the terabyte range, we will have to parse for that. Though this should work for all current scenarios, just note that it could get some unexpected value and it would be tossed here. Not that that's bad, just that your comment might be misleading.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment clarified as suggested.
sources/procfs.go
Outdated
func convertToBytes(s string) string { | ||
new_s := "" | ||
multiplier := 1 | ||
switch finalChar := s[len(s)-1:]; finalChar { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, there shouldn't be an issue with this, but might be safe to force this to an uppercase value. Might add a bit of safety just in case these values get changed for some odd reason in future updates. Though I certainly don't feel very strongly about this, so take it or leave it as you desire.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Forced capitalization as suggested.
sources/procfs.go
Outdated
func convertToBytes(s string) string { | ||
new_s := "" | ||
multiplier := 1 | ||
switch finalChar := s[len(s)-1:]; finalChar { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another thought, are we sure the length of s
will always be at least 1? I'm pretty sure we can be confident it is at least 1 as we shouldn't make it to this function if it isn't, but might not hurt to double check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check added as suggested.
sources/procfs.go
Outdated
return s | ||
} | ||
byteVal = byteVal * multiplier | ||
return strconv.Itoa(byteVal) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably want to use the longer string/int parsing method we have used throughout this file as this breaks for sizes much greater than 1GB. For example, check out this sample code for 10GB. It returns an unexpected number. Playing around with smaller values works as expected though.
Sorry this didn't make it into the actual review!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was the most egregious mistake I made! The code was actually broken. Accounted for, though I'm not super crazy about a lot of the casting choices I made. I could force everything to float64 and minimize the casting, but that's the only simplification I see. Penny for your thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No worries my friend! Hmm... any reason for float64 as opposed to just int64 (or... uint64)? I like that idea though, just force it all to that value just to be safe. Heck, what if there's some bug where Lustre has the metrics as bytes in the code but it's actually in the GB size, then we will still run into this issue. It's a stretch... but I'd rather be safe. Regardless of that though, I like the idea of forcing float64(/int64/uint64) on everything.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I can force float64. It's float64 because that's what math.Pow() returns (I guess I could immediately cast to uint64, but that seems...limiting).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I can force float64. It's float64 because that's what math.Pow() returns (I guess I could immediately cast to uint64, but that seems...limiting).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sold! Works for me!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, after looking at this again and looking at some of the float-to-string and string-to-float methods, I'm not sure that's any better. I could convert the math.Pow() operations to uint64 immediately, but that just makes the code messier. Any serious opposition to leaving the PR as-is currently?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, I'm fine with how it is. Just thinking it might've been easier to keep it all int, but based on what you said, I think this makes a lot more sense this way.
bbdc997
to
24b86a0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking a lot better! Only thing that still stands out to me (and I'm open to discussion) is the float vs. int discussion.
Edit: Dismissing this particular review based on discussions above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good - ready to merge whenever you are.
Works for me @joehandzik |
sources/procfs.go
Outdated
} | ||
new_s := "" | ||
multiplier := float64(1) | ||
switch finalChar := strings.ToUpper(s[len(s)-1:]); finalChar { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@joehandzik just a question. Are they originally upper or lower case? Why do you have to force to the upper case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They are currently uppercase in every situation that we've seen. But...we've been down this road before with string parsing in another project that I help maintain. Any time you can eliminate case sensitivity bugs, you sleep just a little better. :)
Some thoughts:
FWIW (still uses an integer string representation):
|
Good point. An argument can be made about future-proofing this, though it does seem a little excessive if the Lustre source doesn't even handle it.
I was originally thinking about it the other way and asking @joehandzik if we could replace the float64 with a uint64 since that's what we use later, and he rightfully talked me out of it. Your thought is probably even more straightforward. So... can we replace the uint64 in
Agreed!
Good idea, though I might argue against the Thanks as always for the feedback @knweiss - much appreciated! Let me know if you have any questions on my thoughts. |
@roclark AFAICS the code handles single-character sizes correctly as it returns early if no unit character is present:
You'll only get the |
@knweiss ah, yes, you are correct! I think I looked right through those particular lines... |
@knweiss I'm hesitant to add any error catching at all beyond detecting that we don't know how to interpret something and pass it through. If we see bad output, I'd rather bail on the parsing instead of throwing an error that would halt the exporter. Agreed that a unit test is worthwhile. As for using float64...I'm fine with that, but it'll need to be a change that is part of a larger refactor. The rest of the code expects uint64 today, so I can't change this here without triggering a bunch of build warning about mismatched types. I'd rather translate to a uint64 in this code today, and schedule in a separate change to normalize everything to a float64 later on (probably sometime this week, just after this gets merged). |
3e3591c
to
42d8f9f
Compare
Unit tests look good to me. One might argue you could test a lower-case unit... but I'm not too worried about that considering Lustre doesn't currently (assuming they don't randomly change it later) use lower-case units. |
42d8f9f
to
d1abd88
Compare
@roclark That was totally worthwhile, actually. There was a bug in my logic for uppercasing. |
Glad I mentioned it then! Nothing else stands out to me at the moment. |
This will work through IO sizes of Gigabytes Fixes #50 Signed-Off-By: Joe Handzik <joseph.t.handzik@hpe.com>
d1abd88
to
26bafb8
Compare
26bafb8
to
0c76943
Compare
@roclark Rebase done, everything should build, check, and merge cleanly now. I moved the convertToBytes() method to proc_common.go, FYI. |
This will work through IO sizes of Gigabytes
Fixes #50
Signed-Off-By: Joe Handzik joseph.t.handzik@hpe.com