Skip to content
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

Expressions Gotchas and Need Better Examples #588

Open
Dylan-M opened this issue Feb 28, 2022 · 0 comments
Open

Expressions Gotchas and Need Better Examples #588

Dylan-M opened this issue Feb 28, 2022 · 0 comments
Assignees
Labels
documentation Improvements or additions to documentation

Comments

@Dylan-M
Copy link
Contributor

Dylan-M commented Feb 28, 2022

Currently the expressions language has some "gotchas" that aren't documented. Additionally, expected data types for the fields that expr can be used with are not declared.

Currently, expressions using matches (regex) cannot have named capture groups in them. This makes sense, but isn't documented, and can catch people trying to make a router by copy/pasting the regex from a regex_parser that the router will drive to.

Additionally, all escape characters (backslash by default), but be escaped. This is counterintuitive, as it does not match out regex_parser.

Non-working example (contains named capture groups, and does not escape the escape characters)

  - type: router
    routes:
      - expr: '$record matches "^\[(?P<datetime>\d{4}-\d{2}-\d{2}\s+\d{2}:\d{2}:\d{2}),\d+\]\s\d+\s(?P<severity>\w+)\s(?P<workflow>.*?):(?P<process>.*?):(?P<line_number>\d+)\s-\s\[(?P<type>.*?)\]\s(?P<message>.*)\sWorker\(id=(?P<worker_id>\d+),\sname=(?P<worker_name>.*?)\)"'
        output: formatA_parser
      - expr: '$labels["k8s-pod/app"] contains "worker-automation"'
        output: general_format_parser
    default: output

Working version of the above

  - type: router
    routes:
      - expr: '$record matches "^\\[\\d{4}-\\d{2}-\\d{2}\\s+\\d{2}\\:\\d{2}\\:\\d{2},\\d+\\]\\s\\d+\\s\\w+\\s.*?\\:.*?\\:\\d+\\s-\\s\\[.*?\\]\\s.*\\sWorker\\(id=\\d+,\\sname=.*?\\)"'
        output: formatA_parser
      - expr: '$labels["k8s-pod/app"] contains "worker-automation"'
        output: general_format_parser
    default: output

Data that matches the formatA

[2022-02-04 12:21:06,301] 1 DEBUG inmar_libs.workflows.process_hire:process_hire_worker:555 - [New Hire] Username will be hawoody. Worker(id=205298, name=Hannah Woody)
@Dylan-M Dylan-M added the documentation Improvements or additions to documentation label Feb 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants