cyberdelia/logfmt-ruby

Parsing logic doesn't preserve data type

gtrevg opened this issue · 1 comments

In the documentation from http://godoc.org/github.com/kr/logfmt, the parsed JSON ends up being:

{ "foo": "bar", "a": 14, "baz": "hello kitty", "cool%story": "bro", "f": true, "%^asdf": true }

Both the Ruby & Python versions end up generating the following JSON:

{"foo":"bar", "a":"14", "baz":"hello kitty", "cool%story":"bro", "f":true, "%^asdf":true}

Even though "a" was originally an integer, it is now a string. This ends up becoming an issue when log data is sent into a data store like ElasticSearch which preserves the JSON types posted to it. If you try running aggregation queries such as min, max, and avg in ElasticSearch on a field that is of type string, you end up getting a ClassCastException[org.elasticsearch.index.fielddata.plain.PagedBytesIndexFieldData cannot be cast to org.elasticsearch.index.fielddata.IndexNumericFieldData error.
This issue sort of breaks the flow for logging in key value pairs, parsing that data, & sending that data to data store that properly supports JSON types.

Any ideas on how this can be fixed? I noticed in the original logfmt project, a formatter was implemented that would make sure to generate the correct JSON type. I'm guessing that somewhere in here there should be an isFloat/isInteger test and value type conversion.

Thanks

Fixed in #5