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 unmarshals JSON integers as float64 #2038

Closed
andrewkroh opened this issue Jul 15, 2016 · 5 comments
Closed

Filebeat unmarshals JSON integers as float64 #2038

andrewkroh opened this issue Jul 15, 2016 · 5 comments
Labels

Comments

@andrewkroh
Copy link
Member

andrewkroh commented Jul 15, 2016

Filebeat can unmarshal arbitrary JSON data, and when it unmarshals numbers they are of type float64. If you try to use a conditional filter with equals to match against a number read from JSON you get the following error.

condition.go:240: WARN unexpected type float64 in equals condition as it accepts only integers and strings.

Filebeat version: 5.0.0 git c54b7c4

Config:

$ cat filebeat.dev.yml 
filebeat.prospectors:
  - paths:
    - "./input.json"
    json.keys_under_root: false

processors:
  - drop_event:
      when:
        and:
          - contains:
              json.http_user_agent: "ELB-HealthChecker"
          - equals:
              json.status: 200

output.console:
  pretty: true

logging.level: debug

Input file:

$ cat input.json 
{"http_user_agent": "ELB-HealthChecker/1.0", "status": 200}
@andrewkroh andrewkroh added the Filebeat Filebeat label Jul 15, 2016
@andrewkroh andrewkroh changed the title equals condition does not work on floats "equals" condition does not work on floats Jul 15, 2016
@tsg
Copy link
Contributor

tsg commented Jul 15, 2016

The fact that JSON unmarshals all numbers to float is quite unfortunate. Maybe we can fix that..

@tsg tsg closed this as completed Jul 15, 2016
@tsg tsg reopened this Jul 15, 2016
@monicasarbu
Copy link
Contributor

monicasarbu commented Jul 15, 2016

This is the expected behavior. "equals" excepts only integers and strings as it doesn't really make sense for floats. If you want to compare a float, then the "range" operation is needed.

@monicasarbu
Copy link
Contributor

@andrewkroh How the numbers look like in the json file? Do they look like integers?

@andrewkroh andrewkroh changed the title "equals" condition does not work on floats Filebeat unmarshals JSON integers as float64 Jul 15, 2016
@andrewkroh
Copy link
Member Author

@monicasarbu Yes, the value is an integer in the JSON. I included an example in the description.

I updated the title to reflect the fact that the focus should probably be on the unmarshaling behavior instead of the processor condition since equals is designed for ints and strings.

@tsg
Copy link
Contributor

tsg commented Jul 19, 2016

Unfortunately that's just how Unmarshal works in Go: if it's a number, put it in float64. One option that I'm thinking is that after unmarshalling, we do a pass through the result and for all float64s we check if they are within ε of an integer, and if they are we convert to int64. We make ε configurable with a default value of 1e-6 or something like that.

@andrewkroh @monicasarbu Thoughts? Alternatives?

tsg pushed a commit to tsg/beats that referenced this issue Jul 25, 2016
The change modifies the unmarshaling logic to try parsing the numbers
in an int64 first, and only on error parse to a float64. In practice,
this means that e.g. 1 will become an int64 and 1.0 will become a
float64.

Fixes elastic#2038. Includes a system test to verify that ticket.
andrewkroh pushed a commit that referenced this issue Jul 26, 2016
The change modifies the unmarshaling logic to try parsing the numbers
in an int64 first, and only on error parse to a float64. In practice,
this means that e.g. 1 will become an int64 and 1.0 will become a
float64.

Fixes #2038. Includes a system test to verify that ticket.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants