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

Regex fix #4

Merged
merged 2 commits into from
Feb 18, 2020
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
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,4 @@
build/

# test artifacts
build/cover.out
build/*.cover.out
build/cover.html
*.actual
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ build/mock-tools: FORCE
$(GO) install $(GO_BUILDFLAGS) -ldflags '$(GO_LDFLAGS)' '$(PKG)/test/cmd/mock-swift-recon-with-errors'

clean: FORCE
rm -rf -- build
rm -rf build/*

vendor: FORCE
$(GO) mod tidy
Expand Down
16 changes: 16 additions & 0 deletions collector/fixtures/recon_failed_collect.prom
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,22 @@ swift_cluster_drives_audit_errors{storage_ip="10.0.0.1"} 0
# HELP swift_cluster_drives_unmounted Unmounted drives reported by the swift-recon tool.
# TYPE swift_cluster_drives_unmounted gauge
swift_cluster_drives_unmounted{storage_ip="10.0.0.1"} 0
# HELP swift_cluster_md5_all Sum of matched-, not matched hosts, and errors encountered while check hosts for md5sum(s) as reported by the swift-recon tool.
# TYPE swift_cluster_md5_all gauge
swift_cluster_md5_all{kind="ring"} 5
swift_cluster_md5_all{kind="swiftconf"} 5
# HELP swift_cluster_md5_errors Errors encountered while checking hosts for md5sum(s) as reported by the swift-recon tool.
# TYPE swift_cluster_md5_errors gauge
swift_cluster_md5_errors{kind="ring"} 2
swift_cluster_md5_errors{kind="swiftconf"} 2
# HELP swift_cluster_md5_matched Matched hosts for md5sum(s) reported by the swift-recon tool.
# TYPE swift_cluster_md5_matched gauge
swift_cluster_md5_matched{kind="ring"} 1
swift_cluster_md5_matched{kind="swiftconf"} 1
# HELP swift_cluster_md5_not_matched Not matched hosts for md5sum(s) reported by the swift-recon tool.
# TYPE swift_cluster_md5_not_matched gauge
swift_cluster_md5_not_matched{kind="ring"} 2
swift_cluster_md5_not_matched{kind="swiftconf"} 2
# HELP swift_cluster_objects_quarantined Quarantined objects reported by the swift-recon tool.
# TYPE swift_cluster_objects_quarantined gauge
swift_cluster_objects_quarantined{storage_ip="10.0.0.1"} 0
Expand Down
13 changes: 9 additions & 4 deletions collector/recon.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,9 @@ func newReconMD5Task(pathToReconExecutable string) collectorTask {
return &reconMD5Task{
pathToReconExecutable: pathToReconExecutable,
md5OutputRx: regexp.MustCompile(
`(?m)^.* Checking ([\.a-zA-Z0-9_]+) md5sum(?:s)?\s*([0-9]+)/([0-9]+) hosts matched, ([0-9]+) error.*$`),
// Match group ref:
// <1: kind> <2: output in case of error> <3: matched hosts> <4: total hosts> <5: errors>
`(?m)^.* Checking ([\.a-zA-Z0-9_]+) md5sums?\s*((?:->\s\S*\s.*\s*)*)?([0-9]+)/([0-9]+) hosts matched, ([0-9]+) error.*$`),
all: typedDesc{
desc: prometheus.NewDesc("swift_cluster_md5_all",
"Sum of matched-, not matched hosts, and errors encountered while check hosts for md5sum(s) as reported by the swift-recon tool.",
Expand Down Expand Up @@ -274,12 +276,15 @@ func (t *reconMD5Task) collectMetrics(ch chan<- prometheus.Metric, exitCodeTyped
}

for _, match := range matchList {
if len(match[2]) > 0 {
exitCode = 1
}
var totalHosts, errsEncountered float64
matchedHosts, err := strconv.ParseFloat(string(match[2]), 64)
matchedHosts, err := strconv.ParseFloat(string(match[3]), 64)
if err == nil {
totalHosts, err = strconv.ParseFloat(string(match[3]), 64)
totalHosts, err = strconv.ParseFloat(string(match[4]), 64)
if err == nil {
errsEncountered, err = strconv.ParseFloat(string(match[4]), 64)
errsEncountered, err = strconv.ParseFloat(string(match[5]), 64)
if err == nil {
kind := strings.ReplaceAll(string(match[1]), ".", "")
notMatchedHosts := totalHosts - matchedHosts
Expand Down
8 changes: 5 additions & 3 deletions test/cmd/mock-swift-recon-with-errors/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,17 @@ Disk usage: lowest: 5.88%, highest: 6.45%, avg: 6.21618072487%
===============================================================================`)

var md5Data = []byte(`===============================================================================
--> Starting reconnaissance on 2 hosts (object)
--> Starting reconnaissance on 3 hosts (object)
===============================================================================
[2020-01-14 12:55:30] Checking ring md5sums
-> http://10.0.0.1:6000/recon/ringmd5: <urlopen error timed out>
-> http://10.0.0.2:6000/recon/ringmd5: <urlopen error timed out>
1/2 hosts matched, 1 error[s] while checking hosts.
1/3 hosts matched, 2 error[s] while checking hosts.
===============================================================================
[2020-01-14 12:55:35] Checking swift.conf md5sum
-> http://10.0.0.1:6000/recon/swiftconfmd5: <urlopen error timed out>
-> http://10.0.0.2:6000/recon/swiftconfmd5: <urlopen error timed out>
1/2 hosts matched, 1 error[s] while checking hosts.
1/3 hosts matched, 2 error[s] while checking hosts.
===============================================================================`)

var containerUpdaterVerboseData = []byte(`===============================================================================
Expand Down