Skip to content

Commit f09c9dc

Browse files
Do not treat missing num values as parse errors (#228)
1 parent 248631e commit f09c9dc

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

features/issues.feature

+11-1
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,14 @@ Feature: Various issues reported in the bug tracker remain solved
3434
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
3535
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
3636
"""
37-
Then the exporter should report value 12 for metric test_http_upstream_time_seconds_sum{method="GET",status="200"}
37+
Then the exporter should report value 12 for metric test_http_upstream_time_seconds_sum{method="GET",status="200"}
38+
39+
Scenario: Issue 224: Missing float values
40+
Given a running exporter listening with configuration file "test-config-issue217.yaml"
41+
When the following HTTP request is logged to "access.log"
42+
"""
43+
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
44+
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
45+
"""
46+
Then the exporter should report value 0 for metric test_parse_errors_total
47+
Then the exporter should report value 4 for metric test_http_upstream_time_seconds_sum{method="GET",status="200"}

main.go

+8
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,10 @@ func floatFromFieldsMulti(fields map[string]string, name string) (float64, bool,
446446
for _, v := range strings.Split(val, ",") {
447447
v = strings.TrimSpace(v)
448448

449+
if v == "-" {
450+
continue
451+
}
452+
449453
f, err := strconv.ParseFloat(v, 64)
450454
if err != nil {
451455
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
463467
return 0, false, nil
464468
}
465469

470+
if val == "-" {
471+
return 0, false, nil
472+
}
473+
466474
f, err := strconv.ParseFloat(val, 64)
467475
if err != nil {
468476
return 0, false, fmt.Errorf("value '%s' could not be parsed into float", val)

0 commit comments

Comments
 (0)