diff --git a/lib/logstorage/block_result.go b/lib/logstorage/block_result.go index 97acfab74..033dcac48 100644 --- a/lib/logstorage/block_result.go +++ b/lib/logstorage/block_result.go @@ -4,6 +4,7 @@ import ( "math" "slices" "strconv" + "strings" "sync/atomic" "time" "unsafe" @@ -1933,7 +1934,7 @@ func tryParseNumber(s string) (float64, bool) { if ok { return float64(bytes), true } - if isNumberPrefix(s) { + if isLikelyNumber(s) { f, err := strconv.ParseFloat(s, 64) if err == nil { return f, true @@ -1946,5 +1947,20 @@ func tryParseNumber(s string) (float64, bool) { return 0, false } +func isLikelyNumber(s string) bool { + if !isNumberPrefix(s) { + return false + } + if strings.Count(s, ".") > 1 { + // This is likely IP address + return false + } + if strings.IndexByte(s, ':') >= 0 || strings.Count(s, "-") > 2 { + // This is likely a timestamp + return false + } + return true +} + var nan = math.NaN() var inf = math.Inf(1) diff --git a/lib/logstorage/parser_test.go b/lib/logstorage/parser_test.go index 9afddc17d..ff603be33 100644 --- a/lib/logstorage/parser_test.go +++ b/lib/logstorage/parser_test.go @@ -496,7 +496,7 @@ func TestParseRangeFilter(t *testing.T) { } fr, ok := q.f.(*filterRange) if !ok { - t.Fatalf("unexpected filter type; got %T; want *filterIPv4Range; filter: %s", q.f, q.f) + t.Fatalf("unexpected filter type; got %T; want *filterRange; filter: %s", q.f, q.f) } if fr.fieldName != fieldNameExpected { t.Fatalf("unexpected fieldName; got %q; want %q", fr.fieldName, fieldNameExpected)