Skip to content
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

Merged
merged 2 commits into from
Jun 14, 2016

Conversation

SuperQ
Copy link
Member

@SuperQ SuperQ commented Jun 6, 2016

Fix for #219

@SuperQ SuperQ force-pushed the superq/md_raid0 branch 2 times, most recently from dc3d7f8 to 3711be7 Compare June 6, 2016 21:20
@SuperQ
Copy link
Member Author

SuperQ commented Jun 6, 2016

Hmmm, I think I need to make an example of failed raid0.

@SuperQ SuperQ changed the title Add support for raid0 devices in mdadm_linux collector. [WIP] Add support for raid0 devices in mdadm_linux collector. Jun 6, 2016
@SuperQ SuperQ force-pushed the superq/md_raid0 branch 3 times, most recently from 2c950e1 to 60e134f Compare June 6, 2016 21:31
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
Copy link
Member

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.

@juliusv
Copy link
Member

juliusv commented Jun 6, 2016

Looks good in general, would be good to get a second opinion from someone with mdadm / RAID experience, like probably @brian-brazil.

@SuperQ SuperQ force-pushed the superq/md_raid0 branch 3 times, most recently from 493b1b6 to 5516297 Compare June 6, 2016 21:52
@SuperQ SuperQ changed the title [WIP] Add support for raid0 devices in mdadm_linux collector. Add support for raid0 devices in mdadm_linux collector. Jun 6, 2016
@SuperQ
Copy link
Member Author

SuperQ commented Jun 6, 2016

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

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.

Copy link
Member Author

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.

@SuperQ SuperQ force-pushed the superq/md_raid0 branch 2 times, most recently from 9ebcf4c to ce739bf Compare June 7, 2016 06:26
@@ -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
Copy link
Contributor

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.

@brian-brazil
Copy link
Contributor

👍

// +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 {
Copy link
Member

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.

@SuperQ SuperQ force-pushed the superq/md_raid0 branch from ce739bf to 3bea583 Compare June 11, 2016 06:26
@SuperQ SuperQ force-pushed the superq/md_raid0 branch from 3bea583 to 8c809cd Compare June 11, 2016 06:54
@SuperQ
Copy link
Member Author

SuperQ commented Jun 11, 2016

Ok, addressed all comments.

@matthiasr
Copy link
Contributor

👍

@matthiasr matthiasr merged commit 344fe2c into master Jun 14, 2016
@matthiasr matthiasr deleted the superq/md_raid0 branch June 14, 2016 10:14
@SuperQ SuperQ mentioned this pull request Nov 6, 2016
tamcore pushed a commit to gitgrave/node_exporter that referenced this pull request Oct 22, 2024
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.

6 participants