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

Improve parsing of boolean strings #548

Merged
merged 1 commit into from
Apr 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ workflows:
parameters:
mysql_image:
- mysql/mysql-server:5.6
- mysql/mysql-server:5.7
- mysql/mysql-server:5.7.33
- mysql/mysql-server:8.0
- mariadb:10.2
- mariadb:10.3
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
* [ENHANCEMENT]
* [BUGFIX]

* [ENHANCEMENT] Improve parsing of boolean strings

## 0.13.0-rc.0 / 2021-04-26

BREAKING CHANGES:
Expand Down
16 changes: 7 additions & 9 deletions collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,19 @@ func newDesc(subsystem, name, help string) *prometheus.Desc {
}

func parseStatus(data sql.RawBytes) (float64, bool) {
if bytes.Equal(data, []byte("Yes")) || bytes.Equal(data, []byte("ON")) {
dataString := strings.ToLower(string(data))
switch dataString {
case "yes", "on":
return 1, true
}
if bytes.Equal(data, []byte("No")) || bytes.Equal(data, []byte("OFF")) {
case "no", "off", "disabled":
return 0, true
}
// SHOW SLAVE STATUS Slave_IO_Running can return "Connecting" which is a non-running state.
if bytes.Equal(data, []byte("Connecting")) {
case "connecting":
return 0, true
}
// SHOW GLOBAL STATUS like 'wsrep_cluster_status' can return "Primary" or "non-Primary"/"Disconnected"
if bytes.Equal(data, []byte("Primary")) {
case "primary":
return 1, true
}
if strings.EqualFold(string(data), "non-Primary") || bytes.Equal(data, []byte("Disconnected")) {
case "non-primary", "disconnected":
return 0, true
}
if logNum := logRE.Find(data); logNum != nil {
Expand Down