Class: Instana::Snapshot::FargateContainer

Inherits:
Object
  • Object
show all
Defined in:
lib/instana/snapshot/fargate_container.rb

Overview

Describes a Fargate container visible to the current process

Since:

  • 1.197.0

Constant Summary collapse

ID =

Since:

  • 1.197.0

'com.instana.plugin.aws.ecs.container'.freeze

Instance Method Summary collapse

Constructor Details

#initialize(container, metadata_uri: ENV['ECS_CONTAINER_METADATA_URI']) ⇒ FargateContainer

Returns a new instance of FargateContainer.

Since:

  • 1.197.0



11
12
13
14
15
# File 'lib/instana/snapshot/fargate_container.rb', line 11

def initialize(container, metadata_uri: ENV['ECS_CONTAINER_METADATA_URI'])
  @container = container
   = URI()
  @client = Backend::RequestClient.new(.host, .port, use_ssl: .scheme == "https")
end

Instance Method Details

#dataObject

Since:

  • 1.197.0



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# 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_idObject

Since:

  • 1.197.0



17
18
19
# File 'lib/instana/snapshot/fargate_container.rb', line 17

def entity_id
  "#{@container['Labels']['com.amazonaws.ecs.task-arn']}::#{@container['Name']}"
end

#snapshotObject

Since:

  • 1.197.0



51
52
53
54
55
56
57
# File 'lib/instana/snapshot/fargate_container.rb', line 51

def snapshot
  {
    name: ID,
    entityId: entity_id,
    data: data
  }
end

#sourceObject

Since:

  • 1.197.0



59
60
61
62
63
64
65
66
67
# File 'lib/instana/snapshot/fargate_container.rb', line 59

def source
  return unless current_container?

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