-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Add support for raid0 devices in mdadm_linux collector. #253
Conversation
dc3d7f8
to
3711be7
Compare
Hmmm, I think I need to make an example of failed raid0. |
2c950e1
to
60e134f
Compare
active, total, size, err := evalStatusline(lines[i+1]) // parse statusline, always present | ||
switch personality { | ||
case "raid0": | ||
active := len(mainLine) - 4 // Get the number of devices from the main line |
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.
End comments with periods everywhere.
Looks good in general, would be good to get a second opinion from someone with mdadm / RAID experience, like probably @brian-brazil. |
493b1b6
to
5516297
Compare
Ok, fixed my go newbie bugs, and end-to-end tests. 💚 |
@@ -138,12 +163,20 @@ func parseMdstat(mdStatusFilePath string) ([]mdStatus, error) { | |||
} | |||
currentMD = mainLine[0] // name of md-device | |||
isActive := (mainLine[2] == "active") // activity status of said md-device | |||
personality = mainLine[3] // Personality type of md-device. |
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.
In the check above we only ensure that the line has at least 3 parts. While I assume a line with less than 4 parts to be invalid, it's possible to run into an out-of-bound panic with this change, no?
Bonus points for adding a test for such invalid short lines.
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.
Ahh, yea, mainLine should always have atleast 4 parts anyway. I'll update the test.
9ebcf4c
to
ce739bf
Compare
@@ -133,17 +158,25 @@ func parseMdstat(mdStatusFilePath string) ([]mdStatus, error) { | |||
} | |||
|
|||
mainLine := strings.Split(l, " ") | |||
if len(mainLine) < 3 { | |||
if len(mainLine) < 4 { | |||
return mdStates, fmt.Errorf("error parsing mdline: %s", l) | |||
} | |||
currentMD = mainLine[0] // name of md-device |
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.
Comments here should be full sentences.
👍 |
// +1 to make it more obvious that the whole string containing the info is also returned as matches[0]. | ||
if len(matches) < 1+1 { | ||
return 0, fmt.Errorf("too few matches found in statusline: %s", statusline) | ||
} else { |
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.
Reduce the indentation level in go if possible. This else branch is not necessary.
Ok, addressed all comments. |
👍 |
/proc/[pid]/maps parser
Fix for #219