class Instana::Snapshot::FargateContainer

Describes a Fargate container visible to the current process @since 1.197.0

Constants

ID

Public Class Methods

new(container, metadata_uri: ENV['ECS_CONTAINER_METADATA_URI']) click to toggle source
# File lib/instana/snapshot/fargate_container.rb, line 11
def initialize(container, metadata_uri: ENV['ECS_CONTAINER_METADATA_URI'])
  @container = container
  @metadata_uri = URI(metadata_uri)
  @client = Backend::RequestClient.new(@metadata_uri.host, @metadata_uri.port, use_ssl: @metadata_uri.scheme == "https")
end

Public Instance Methods

data() click to toggle source
# File lib/instana/snapshot/fargate_container.rb, line 21
def data
  payload = {
    dockerId: @container['DockerId'],
    dockerName: @container['DockerName'],
    containerName: @container['Name'],
    image: @container['Image'],
    imageId: @container['ImageID'],
    taskArn: @container['Labels']['com.amazonaws.ecs.task-arn'],
    taskDefinition: @container['Labels']['com.amazonaws.ecs.task-definition-data.family'],
    taskDefinitionVersion: @container['Labels']['com.amazonaws.ecs.task-definition-data.version'],
    clusterArn: @container['Labels']['com.amazonaws.ecs.cluster'],
    desiredStatus: @container['DesiredStatus'],
    knownStatus: @container['KnownStatus'],
    ports: @container['Ports'],
    limits: {
      cpu: @container['Limits']['CPU'],
      memory: @container['Limits']['Memory']
    },
    createdAt: @container['CreatedAt'],
    startedAt: @container['StartedAt']
  }

  if current_container?
    payload[:instrumented] = true
    payload[:runtime] = 'ruby'
  end

  payload
end
entity_id() click to toggle source
# File lib/instana/snapshot/fargate_container.rb, line 17
def entity_id
  "#{@container['Labels']['com.amazonaws.ecs.task-arn']}::#{@container['Name']}"
end
snapshot() click to toggle source
# File lib/instana/snapshot/fargate_container.rb, line 51
def snapshot
  {
    name: ID,
    entityId: entity_id,
    data: data
  }
end
source() click to toggle source
# File lib/instana/snapshot/fargate_container.rb, line 59
def source
  return unless current_container?

  {
    hl: true,
    cp: 'aws',
    e: entity_id
  }
end

Private Instance Methods

current_conatiner() click to toggle source
# File lib/instana/snapshot/fargate_container.rb, line 78
def current_conatiner
  path = @metadata_uri.path
  response = @client.send_request('GET', path)

  raise "Unable to get `#{path}`. Got `#{response.code}`." unless response.ok?

  response.json
end
current_container?() click to toggle source
# File lib/instana/snapshot/fargate_container.rb, line 71
def current_container?
  return @current_container if @current_container

  current_conatiner_response = current_conatiner
  @current_container = @container['DockerName'] == current_conatiner_response['DockerName']
end