Sha256: 60bda914ab690356cf8b9e88c17c4b5e601758417747bb47dc75154277ad9fb7

Contents?: true

Size: 1.52 KB

Versions: 5

Compression:

Stored size: 1.52 KB

Contents

module AgentTasks
  # When request(s) are received by the host agent, it is sent here
  # for handling & processing.
  #
  # @param json_string [String] the requests from the host agent
  #
  def handle_agent_tasks(json_string)
    tasks = Oj.load(json_string)

    if tasks.is_a?(Hash)
      process_agent_task(tasks)
    elsif tasks.is_a?(Array)
      tasks.each do |t|
        process_agent_task(t)
      end
    end
  end

  # Process a task sent from the host agent.
  #
  # @param task [String] the request json from the host agent
  #
  def process_agent_task(task)
    if task.key?("action")
      if task["action"] == "ruby.source"
        payload = ::Instana::Util.get_rb_source(task["args"]["file"])
      else
        payload = { :error => "Unrecognized action: #{task["action"]}. An newer Instana gem may be required for this. Current version: #{::Instana::VERSION}" }
      end
    else
      payload = { :error => "Instana Ruby: No action specified in request." }
    end

    path = "com.instana.plugin.ruby/response.#{@process[:report_pid]}?messageId=#{URI.encode(task['messageId'])}"
    uri = URI.parse("http://#{@discovered[:agent_host]}:#{@discovered[:agent_port]}/#{path}")
    req = Net::HTTP::Post.new(uri)
    req.body = Oj.dump(payload)
    ::Instana.logger.debug "Responding to agent request: #{req.inspect}"
    make_host_agent_request(req)

  rescue StandardError => e
    Instana.logger.debug "#{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
    Instana.logger.debug e.backtrace.join("\r\n")
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
instana-1.9.2 lib/instana/agent/tasks.rb
instana-1.9.1 lib/instana/agent/tasks.rb
instana-1.9.0 lib/instana/agent/tasks.rb
instana-1.9.0.daftrabbit lib/instana/agent/tasks.rb
instana-1.9.0.sillyrabbit lib/instana/agent/tasks.rb