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

Fix handling of @timestamp and type from the JSON decoder #1421

Merged
merged 1 commit into from
Apr 20, 2016

Conversation

tsg
Copy link
Contributor

@tsg tsg commented Apr 19, 2016

If json.keys_under_root and json.overwrite_keys are set, and the keys
@timestamp or type show up in the decoded JSON, they can cause issues because
the Elasticsearch output makes some assumptions about them: @timestamp has to
be of type common.Time and type has to be of type string.

The fix attempts to make use of the @timestamp and type from the JSON, but if
parsing fails or the resulting values are invalid, the fields are not overwritten
and an error key is added to help with troubleshooting.

Fixes #1378.

Also hardens the getIndex call in libbeat, to protect against wrong types there
as well.

}
event[k] = vstr
} else {
event[k] = v
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if k == jsonErrorKey?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then it gets overwritten. IMHO that's fine, because keys_under_root is not the default and we usually recommend people not to use it. When people use it, it's implied that "I'm aware that everything can get overwritten".

@tsg
Copy link
Contributor Author

tsg commented Apr 20, 2016

Comments addressed.

If `json.keys_under_root` and `json.overwrite_keys` are set, and the keys
`@timestamp` or `type` show up in the decoded JSON, they can cause issues because
the Elasticsearch output makes some assumptions about them: @timestamp has to
be of type `common.Time` and `type` has to be of type `string`.

The fix attempts to make use of the `@timestamp` and `type` from the JSON, but if
parsing fails or the resulting values are invalid, the fields are not overwritten
and an error key is added to help with troubleshooting.

Fixes elastic#1378.

Also hardens the `getIndex` call in libbeat, to protect against wrong types there
as well.
@tsg tsg force-pushed the fix_json_timestamp_overwrite branch from 39acc25 to 439383b Compare April 20, 2016 14:33
ts, err := common.ParseTime(vstr)
if err != nil {
logp.Err("JSON: Won't overwrite @timestamp because of parsing error: %v", err)
event[jsonErrorKey] = fmt.Sprintf("@timestamp not overwritten (parse error on %s)", vstr)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better to include the error and the value. Probably the error already includes the failed value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

filebeat panic with json overwrite_keys and elasticsearch output
3 participants