lib/logstash/outputs/scalyr.rb
# A request comprises multiple Scalyr Events.  This function creates a request hash for
# final upload to Scalyr (from an array of events, and an optional hash of current threads)
# Note: The request body field will be json-encoded.
A request comprises multiple Scalyr Events.  This function creates a request hash for
final upload to Scalyr (from an array of events, and an optional hash of current threads)
Note: The request body field will be json-encoded.
A request comprises multiple Scalyr Events . This function creates a request hash for final upload to Scalyr ( from an array of events and an optional hash of current threads ) Note : The request body field will be json - encoded .
def create_multi_event_request(scalyr_events, logstash_events, current_threads, current_logs, batch_has_event_level_server_host = false)
    body = {
      :session => @session_id + Thread.current.object_id.to_s,
      :token => @api_write_token,
      :events => scalyr_events,
    }
    add_client_timestamp_to_body body
    if current_threads
      threads = Array.new
      current_threads.each do |thread_name, id|
        threads << { :id => id.to_s, :name => "LogStash: #{thread_name}" }
      end
      body[:threads] = threads
    end
    if current_logs
      logs = Array.new
      current_logs.each do |identifier, log|
        logs << log
      end
      body[:logs] = logs
    end
    if batch_has_event_level_server_host
      body[:sessionInfo] = @server_attributes_without_serverhost if @server_attributes_without_serverhost
    else
      body[:sessionInfo] = @server_attributes if @server_attributes
    end
    start_time = Time.now.to_f
    begin
      serialized_body = self.json_encode(body)
    rescue Java::JavaLang::ClassCastException => e
      @logger.warn("Error serializing events to JSON, likely due to the presence of Bignum values. Converting Bignum values to strings.")
      @stats_lock.synchronize do
        @multi_receive_statistics[:total_java_class_cast_errors] += 1
      end
      Scalyr::Common::Util.convert_bignums(body)
      serialized_body = self.json_encode(body)
    end
    end_time = Time.now.to_f
    serialization_duration = end_time - start_time
    serialized_request_size = serialized_body.bytesize
    if not @estimate_each_event_size and serialized_request_size >= @max_request_buffer + 5000
      @logger.warn("Serialized request size (#{serialized_request_size}) is larger than max_request_buffer (#{max_request_buffer})!")
    end
    {
      :body => serialized_body, :record_count => scalyr_events.size, :serialization_duration => serialization_duration,
      :logstash_events => logstash_events
    }
  end
def create_multi_event_request ( scalyr_events , logstash_events , current_threads , current_logs , batch_has_event_level_server_host = false ) body = { :session => @session_id + Thread . current . object_id . to_s , :token => @api_write_token , :events => scalyr_events , } add_client_timestamp_to_body body if current_threads threads = Array . new current_threads . each do | thread_name , id | threads << { :id => id . to_s , :name => "LogStash: #{thread_name}" } end body [ :threads ] = threads end if current_logs logs = Array . new current_logs . each do | identifier , log | logs << log end body [ :logs ] = logs end if batch_has_event_level_server_host body [ :sessionInfo ] = @server_attributes_without_serverhost if @server_attributes_without_serverhost else body [ :sessionInfo ] = @server_attributes if @server_attributes end start_time = Time . now . to_f begin serialized_body = self . json_encode ( body ) rescue Java :: JavaLang :: ClassCastException => e @logger . warn ( "Error serializing events to JSON, likely due to the presence of Bignum values. Converting Bignum values to strings." ) @stats_lock . synchronize do @multi_receive_statistics [ :total_java_class_cast_errors ] += 1 end Scalyr :: Common :: Util . convert_bignums ( body ) serialized_body = self . json_encode ( body ) end end_time = Time . now . to_f serialization_duration = end_time - start_time serialized_request_size = serialized_body . bytesize if not @estimate_each_event_size and serialized_request_size >= @max_request_buffer + 5000 @logger . warn ( "Serialized request size (#{serialized_request_size}) is larger than max_request_buffer (#{max_request_buffer})!" ) end { :body => serialized_body , :record_count => scalyr_events . size , :serialization_duration => serialization_duration , :logstash_events => logstash_events } end
A request comprises multiple Scalyr Events.
A request comprises multiple Scalyr Events .
# build the scalyr thread JSON object # build the scalyr thread logs object # add serverAttributes # If serverHost is defined on any of the events, we don't send it via sessionInfo since # sesionInfo has the higest priority and would always overwritte the event level one # We time serialization to get some insight on how long it takes to serialize the request body # We give it "buffer" since the splitting code allows for some slack and doesn't take into account top-level non-event attributes # TODO: If we end up here is estimate config opsion is false, split the request here into multiple ones
scalyr_events
logstash_events
current_threads
current_logs
batch_has_event_level_server_host