Sha256: 0b17225450e6448be18399ea1b1841e631f6135ce48516d6c71f9be5aff634ad

Contents?: true

Size: 777 Bytes

Versions: 9

Compression:

Stored size: 777 Bytes

Contents

require 'bigdecimal'

class BigDecimal
    # Floating-point numbers that go through the 'json' Logstash filter get automatically converted into BigDecimals.
    # Example of such a filter:
    #
    # filter {
    #   json {
    #     source => "message"
    #   }
    # }
    #
    # The problem is that { "value" => BigDecimal('0.12345') } gets serialized into { "value": "0.12345e0"}. We do
    # want to keep floating point numbers serialized as floating point numbers, even at the expense of loosing a little
    # bit of precision during the conversion. So, in the above example, the correct serialization would be:
    # { "value": 0.12345}
    def to_json(options = nil) #:nodoc:
      if finite?
        self.to_f.to_s
      else
        'null'
      end
    end
  end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
logstash-output-newrelic-1.5.2 lib/logstash/outputs/config/bigdecimal_patch.rb
logstash-output-newrelic-1.5.1 lib/logstash/outputs/config/bigdecimal_patch.rb
logstash-output-newrelic-1.5.0 lib/logstash/outputs/config/bigdecimal_patch.rb
logstash-output-newrelic-1.4.0 lib/logstash/outputs/config/bigdecimal_patch.rb
logstash-output-newrelic-1.3.0 lib/logstash/outputs/config/bigdecimal_patch.rb
logstash-output-newrelic-1.2.2 lib/logstash/outputs/config/bigdecimal_patch.rb
logstash-output-newrelic-1.2.1 lib/logstash/outputs/config/bigdecimal_patch.rb
logstash-output-newrelic-1.2.0 lib/logstash/outputs/config/bigdecimal_patch.rb
logstash-output-newrelic-1.1.4 lib/logstash/outputs/config/bigdecimal_patch.rb