New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a way to test if a capture group has been defined in current scope #267
Comments
I struggle to use that variable... all my attempts fails (I tried to use As a workaround, I had to use an extra regex instead of checking the variable value
|
It didn't match so the value is empty. Put the variable definition outside
the | condition, and it will be either a number or a -.
In this case the capture group should be comparable to "" to know if it
matched.
…On Thu, 5 Sep 2019, 07:36 Frank lin Piat, ***@***.***> wrote:
I struggle to use that variable... all my attempts fails (I tried to use
len(), or string()... but all fails.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#267?email_source=notifications&email_token=AAXFX66BSNCMSVB44PV3XDDQIAS7RA5CNFSM4ITWPSFKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD55CANI#issuecomment-528097333>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAXFX644CI3LGW7Y754T7ALQIAS7RANCNFSM4ITWPSFA>
.
|
In this particular case it would work... But there are some other case where it is not possible. We need to be able to test a variable no matter if it match or not. |
mtail 3.0.0-rc35 does variable type detection during the program parsing phase. in kind, $maxage is being typed as an integer. at runtime, encountering a log entry with no maxage match makes $maxage an empty string and errors attempting to coerce it into an int (using strconv.ParseInt) and ultimately drops it. this is a known bug: google/mtail#267 this cs mangles the match a bit so that mtail will not treat it like an integer, but a string Bug: T251466 Change-Id: Ia764570b2d81c861e9fc7b5d52f56354006be6ec
The answer you came up with in #267 (comment) is the correct way to do this. You've matched a field which is either a number or not a number. |
I can add this pattern to the documentation, possibly even make the error easier to understand; is there anything else you think |
OK I think the feature to add is that we need a way to test if a capture group is defined. The current programme that works is to test the surrounding capture group content, but I admit tis does not make the pgramme very readable. |
Hi
When using a syntax like
((?P<response_size>\d+)|-)
on a line containing a-
instead of a digit, the variableresponse_time
is undefined. When attempting to use that variable, mtail throws an error.This error can be reproduced using apache_common.mtail and testdata/apache-common.log
...or this simplified test
Program
input log
mtail output log
I'am using mtail v3.0.0-rc33 (I tested rc16 and rc25 which have a similar behaviur)
The text was updated successfully, but these errors were encountered: