-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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 container multiline error Error decoding JSON: invalid character #20053
Comments
Hi @andresrc , did you ever find a solution to your problem? |
Pinging @elastic/integrations-platforms (Team:Platforms) |
Pinging @elastic/integrations-services (Team:Services) |
How is logging and rotation configured in general? The original report looks like Docker or kubernetes. Some environments use copytruncate, which at times can "trick" the reader to continue reading from the wrong location. In that case an "invalid" line is read, but the input should mostly recover. Also note, multiline JSON is not supported as well. Although we see parsing errors, the cases seem to be different, as the log source we read from differs. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
We are still running into this issue. |
Pinging @elastic/elastic-agent-data-plane (Team:Elastic-Agent-Data-Plane) |
@humberto-garza on which filebeat version are you testing it? |
@jlind23, we are using filebeat-7.10.0 Originally we were using 7.8 (as mentioned in the description), but even after upgrading, we have the same issue. |
@humberto-garza is there any chance to test it with the latest filebeat release available? |
Hi! We're labeling this issue as |
Still seeing the issue too. Feb 1 20:55:48 ip-x-x-x-x filebeat[471]: {"log.level":"error","@timestamp":"2023-02-01T20:55:47.995Z","log.logger":"reader_json","log.origin":{"file.name":"readjson/json.go","file.line":75},"message":"Error decoding JSON: invalid character '.' looking for beginning of value","service.name":"filebeat","ecs.version":"1.6.0"} |
Final edit and a complete rewrite: Well, this turns out to be a PEBKAC issue, and since I wasted many hours on debugging it, I might as well describe it in detail. The {"log":"This is a log\n","stream":"stdout","time":"2024-01-24T19:09:55.568450771Z"} That's the The following filebeat config will (somewhat, if we ignore the newline char) correctly parse that. - type: filestream
id: docker-logs
paths:
- /var/lib/docker/containers/*/*-json.log
parsers:
- container: ~ Resulting in an object like this: {
...
"message": "This is a log\n"
...
} Unfortunately, me, OP and the rest of the village folk have seen the helpful example config for nested JSON objects, and didn't realize its purpose, the fact that the documentation is very confusing does not help. "This can be helpful in situations where the application logs are wrapped in JSON objects, like when using Docker."... So if your config looks like this instead for the same message (or equivalent config with - type: filestream
id: docker-logs
paths:
- /var/lib/docker/containers/*/*-json.log
parsers:
- container: ~
- ndjson:
target: ""
add_error_key: true It's going to violently break itself with unhelpful error messages. So unless you have a log likes this {"log":"{\"message\":\"Started synchronization.\",\"request_id\":null}}\n","stream":"stdout","time":"2024-01-24T16:42:51.200033705Z"} The above config makes no sense and you should not parse it twice with
# This will drop non-nested messages, if you want to log both, this is not what you want
- type: filestream
id: docker-logs
paths:
- /var/lib/docker/containers/*/*-json.log
parsers:
- container: ~
- include_message.patterns: ['^\{']
- ndjson:
target: ""
add_error_key: true This issue can be closed, unless someone wants to improve the documentation with clear examples. |
filebeat.autodiscover:
providers:
- type: docker
hints.enabled: true
hints.default_config:
type: container
paths:
- /var/lib/docker/containers/${data.container.id}/*.log
parsers:
- ndjson:
message_key: "log"
multiline.type: pattern
multiline.pattern: ' \d+ --- \['
multiline.negate: true
multiline.match: after this is working with |
full error:
ERROR [reader_json] readjson/json.go:57 Error decoding JSON: invalid character 'a' looking for beginning of value.
filebeat config:
raw log in java from docker log:
I can't debug it, who can help me?
The text was updated successfully, but these errors were encountered: