Skip to content

Commit

Permalink
Do not treat missing num values as parse errors (#228)
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-helmich authored Nov 26, 2021
1 parent 248631e commit f09c9dc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
12 changes: 11 additions & 1 deletion features/issues.feature
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,14 @@ Feature: Various issues reported in the bug tracker remain solved
www.example.com 10.0.0.2 - - [27/Oct/2021:06:00:15 +0200] "GET /websocket HTTP/1.1" 200 552 "-" "AnotherUserAgent" 0.000 "1.000, 0.250, 2.000, 0.750" . TLSv1.3/TLS_AES_256_GCM_SHA384 1234567890 www.example.com
www.example.com 10.0.0.3 - - [27/Oct/2021:06:00:15 +0200] "GET /websocket HTTP/1.1" 200 150 "-" "SomeUserAgentString" 0.001 "1.000, 0.250, 2.000, 0.750" . TLSv1.3/TLS_AES_256_GCM_SHA384 1234567890 www.example.com
"""
Then the exporter should report value 12 for metric test_http_upstream_time_seconds_sum{method="GET",status="200"}
Then the exporter should report value 12 for metric test_http_upstream_time_seconds_sum{method="GET",status="200"}

Scenario: Issue 224: Missing float values
Given a running exporter listening with configuration file "test-config-issue217.yaml"
When the following HTTP request is logged to "access.log"
"""
www.example.com 10.0.0.1 - - [27/Oct/2021:06:00:14 +0200] "GET /websocket HTTP/1.1" 200 552 "-" "SomeUserAgentString" 0.000 "1.000, -, 2.000" . TLSv1.3/TLS_AES_256_GCM_SHA384 1234567890 www.example.com
www.example.com 10.0.0.2 - - [27/Oct/2021:06:00:15 +0200] "GET /websocket HTTP/1.1" 200 552 "-" "AnotherUserAgent" - "1.000" . TLSv1.3/TLS_AES_256_GCM_SHA384 1234567890 www.example.com
"""
Then the exporter should report value 0 for metric test_parse_errors_total
Then the exporter should report value 4 for metric test_http_upstream_time_seconds_sum{method="GET",status="200"}
8 changes: 8 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,10 @@ func floatFromFieldsMulti(fields map[string]string, name string) (float64, bool,
for _, v := range strings.Split(val, ",") {
v = strings.TrimSpace(v)

if v == "-" {
continue
}

f, err := strconv.ParseFloat(v, 64)
if err != nil {
return 0, false, fmt.Errorf("value '%s' could not be parsed into float", val)
Expand All @@ -463,6 +467,10 @@ func floatFromFields(fields map[string]string, name string) (float64, bool, erro
return 0, false, nil
}

if val == "-" {
return 0, false, nil
}

f, err := strconv.ParseFloat(val, 64)
if err != nil {
return 0, false, fmt.Errorf("value '%s' could not be parsed into float", val)
Expand Down

0 comments on commit f09c9dc

Please sign in to comment.