Skip to content

Cannot filter messages by a json format #520

Description

@ifat-afek

Describe the bug
I have a log file that contains both text strings and json-formatted log messages.
I tried to use router or filter in order to filter only the json messages but it didn't work. I followed the example in https://github.com/observIQ/stanza/blob/master/docs/operators/router.md

To Reproduce
I used the following pipeline:
pipeline:

  • id: message_type_router
    type: router
    routes:
    • output: message_router
      expr: '$.format == "json"'
  • id: message_router
    type: router
    routes:
    • output: stdout
      expr: '$record.log != nil and $record.log.message != nil and $record.log.message matches "XYZ"

Expected behavior
Json formatted messages should be passed to message_router and then checked against the expression (that fails for regular strings).

Actual behavior
I get errors in the log:
{"level":"warn","timestamp":"2022-01-02T16:28:05.671Z","message":"Running expression returned an error","operator_id":"$.message_type_router","operator_type":"router","error":"invalid operation: int(string) (1:3)\n | $.format == "json"\n | ..^"}

Environment:

  • Running on k8s
  • Stanza Version 1.4.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions