Class: Utility

Inherits:
Object
  • Object
show all
Defined in:
lib/fluent/plugin/utility.rb

Class Method Summary collapse

Class Method Details

.compress_payload(payload, logger) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/fluent/plugin/utility.rb', line 4

def self.compress_payload(payload, logger)
    logger.info("Compressing metrics payload")
    json_payload = payload.to_json

    # Compress the JSON string using zlib's GzipWriter
    compressed_payload = StringIO.new    
    Zlib::GzipWriter.wrap(compressed_payload) do |gz|
      begin
        gz.write(json_payload)
      ensure
        gz.close
      end
    end

    # convert the compressed data to a string
    compressed_data = compressed_payload.string

    logger.info("Original metrics payload size: #{json_payload.bytesize} bytes")
    logger.info("Compressed metrics payload size: #{compressed_data.bytesize} bytes")

    return compressed_data
end