Sha256: 2453f37ae5968eb4eb038ded18d778c3e100a637a92605df192bfc386444545c

Contents?: true

Size: 1.09 KB

Versions: 190

Compression:

Stored size: 1.09 KB

Contents

# frozen_string_literal: true

require 'thread'
require 'socket'

module Aws
  module ClientSideMonitoring
    # @api private
    class Publisher
      attr_reader :agent_port
      attr_reader :agent_host

      def initialize(opts = {})
        @agent_host = opts[:agent_host] || "127.0.0.1"
        @agent_port = opts[:agent_port]
        @mutex = Mutex.new
      end

      def agent_port=(value)
        @mutex.synchronize do
          @agent_port = value
        end
      end

      def agent_host=(value)
        @mutex.synchronize do
          @agent_host = value
        end
      end

      def publish(request_metrics)
        send_datagram(request_metrics.api_call.to_json)
        request_metrics.api_call_attempts.each do |attempt|
          send_datagram(attempt.to_json)
        end
      end

      def send_datagram(msg)
        if @agent_port
          socket = UDPSocket.new
          begin
            socket.connect(@agent_host, @agent_port)
            socket.send(msg, 0)
          rescue Errno::ECONNREFUSED
            # Drop on the floor
          end
        end
      end
    end
  end
end

Version data entries

190 entries across 190 versions & 1 rubygems

Version Path
aws-sdk-core-3.214.0 lib/aws-sdk-core/client_side_monitoring/publisher.rb
aws-sdk-core-3.213.0 lib/aws-sdk-core/client_side_monitoring/publisher.rb
aws-sdk-core-3.212.0 lib/aws-sdk-core/client_side_monitoring/publisher.rb
aws-sdk-core-3.211.0 lib/aws-sdk-core/client_side_monitoring/publisher.rb
aws-sdk-core-3.210.0 lib/aws-sdk-core/client_side_monitoring/publisher.rb
aws-sdk-core-3.209.1 lib/aws-sdk-core/client_side_monitoring/publisher.rb
aws-sdk-core-3.209.0 lib/aws-sdk-core/client_side_monitoring/publisher.rb
aws-sdk-core-3.208.0 lib/aws-sdk-core/client_side_monitoring/publisher.rb
aws-sdk-core-3.207.0 lib/aws-sdk-core/client_side_monitoring/publisher.rb
aws-sdk-core-3.206.0 lib/aws-sdk-core/client_side_monitoring/publisher.rb
aws-sdk-core-3.205.0 lib/aws-sdk-core/client_side_monitoring/publisher.rb
aws-sdk-core-3.204.0 lib/aws-sdk-core/client_side_monitoring/publisher.rb
aws-sdk-core-3.203.0 lib/aws-sdk-core/client_side_monitoring/publisher.rb
aws-sdk-core-3.202.2 lib/aws-sdk-core/client_side_monitoring/publisher.rb
aws-sdk-core-3.202.1 lib/aws-sdk-core/client_side_monitoring/publisher.rb
aws-sdk-core-3.202.0 lib/aws-sdk-core/client_side_monitoring/publisher.rb
aws-sdk-core-3.201.5 lib/aws-sdk-core/client_side_monitoring/publisher.rb
aws-sdk-core-3.201.4 lib/aws-sdk-core/client_side_monitoring/publisher.rb
aws-sdk-core-3.201.3 lib/aws-sdk-core/client_side_monitoring/publisher.rb
aws-sdk-core-3.201.2 lib/aws-sdk-core/client_side_monitoring/publisher.rb