diff --git a/features/issues.feature b/features/issues.feature index 47f3b52..4e0a7d0 100644 --- a/features/issues.feature +++ b/features/issues.feature @@ -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"} \ No newline at end of file + 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"} \ No newline at end of file diff --git a/main.go b/main.go index 2def9e5..1380b9b 100644 --- a/main.go +++ b/main.go @@ -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) @@ -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)