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

Filebeat json parser is trying to parse excluded lines #31794

Closed
dosmanak opened this issue Jun 1, 2022 · 3 comments · Fixed by #32094
Closed

Filebeat json parser is trying to parse excluded lines #31794

dosmanak opened this issue Jun 1, 2022 · 3 comments · Fixed by #32094
Labels
8.5-candidate bug Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team

Comments

@dosmanak
Copy link
Contributor

dosmanak commented Jun 1, 2022

filebeat log is filled with errors "Error decoding JSON: invalid character"

Steps to Reproduce:

filebeat.yml

---
filebeat.inputs:
  - type: filestream
    id: 0
    paths:
      - '/data/mixed_json_plain.log'
    exclude_lines: [ "^PLAIN" ]
    parsers:
      - ndjson:
          add_error_key: true
          keys_under_root: true
          overwrite_keys: true
          message_key: message
          expand_keys: true

output.file:
  path: /data/filebeat_output
  rotate_every_kb: 100000
  rotate_on_startup: false
  codec.json:
    pretty: true

log sample file mixed_json_plain.log

{"id":1,"message":"lorem ipsum"}
PLAIN first line
PLAIN second line
{"id":2,"message":"dolor sit amet"}
{"id":3,"message":"consectetur adipiscing elit"}

To reproduce errors

docker run --rm -v $PWD:/data -v $PWD/filebeat.yml:/usr/share/filebeat/filebeat.yml docker.elastic.co/beats/filebeat:8.2.0

When run with -e -d '*' it is visible on debug level, the line is exluded correctly.

Drop line as it does match one of the exclude patterns%sPLAIN first line

Full debug log is in linked Discuss Forum URL
Interresting lines are

{"log.level":"error","@timestamp":"2022-05-31T15:20:47.977Z","log.logger":"parser_json","log.origin":{"file.name":"readjson/json.go","file.line":74},"message":"Error decoding JSON: invalid character 'P' looking for beginning of value","service.name":"filebeat","ecs.version":"1.6.0"}
{"log.level":"debug","@timestamp":"2022-05-31T15:20:47.977Z","log.logger":"input.filestream","log.origin":{"file.name":"filestream/input.go","file.line":351},"message":"Drop line as it does match one of the exclude patterns%sPLAIN first line","service.name":"filebeat","id":"0","source_file":"filestream::0::native::7639481-54","path":"/data/mixed_json_plain.log","state-id":"native::7639481-54","ecs.version":"1.6.0"}
@botelastic botelastic bot added the needs_team Indicates that the issue/PR needs a Team:* label label Jun 1, 2022
@dosmanak
Copy link
Contributor Author

dosmanak commented Jun 1, 2022

I have changed to processors.decode_json_fields which works fine even on multiline json events without specifying so.

@kvch kvch added the Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team label Jun 1, 2022
@elasticmachine
Copy link
Collaborator

Pinging @elastic/elastic-agent-data-plane (Team:Elastic-Agent-Data-Plane)

@botelastic botelastic bot removed the needs_team Indicates that the issue/PR needs a Team:* label label Jun 1, 2022
@kvch kvch added bug needs_team Indicates that the issue/PR needs a Team:* label labels Jun 1, 2022
@botelastic botelastic bot removed the needs_team Indicates that the issue/PR needs a Team:* label label Jun 1, 2022
@kvch
Copy link
Contributor

kvch commented Jun 20, 2022

The log input behaves the same way, and produces the same error. Maybe in filestream we could make exclude_lines and include_lines parser, so we have more flexibility in filtering out lines.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
8.5-candidate bug Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants