google / google/mtail

Add a way to test if a capture group has been defined in current scope

Open
#267 6 comments 4 reactions 0 assignees View on GitHub
enhancement mtail-Language/VM
Dominant language
Go
Stars
4k
Forks
392
PR merge metrics
No merged PRs in 30d

Description

Hi

When using a syntax like `((?P\d+)|-)` on a line containing a `-` instead of a digit, the variable `response_time` is undefined. When attempting to use that variable, mtail throws an error.

This error can be reproduced using [apache_common.mtail](https://github.com/google/mtail/blob/master/examples/apache_common.mtail) and [testdata/apache-common.log](https://github.com/google/mtail/blob/master/internal/mtail/testdata/apache-common.log)

...or this simplified test

### Program

counter total

/^[a-z]+ ((?P\d+)|-)$/ {

$response_size > 0 {
total = $response_size
}
}

### input log

test 99
test -

### mtail output log

vm.go:92] test.mtail: Runtime error: strconv.ParseInt: parsing "": invalid syntax
vm.go:93] Error occurred at instruction 5 {s2i, }, originating in test.mtail at line 5
vm.go:95] Full input text from "log" was "test -"

I'am using mtail v3.0.0-rc33 (I tested rc16 and rc25 which have a similar behaviur)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.