Class: Gitlab::QA::Component::Telegraf

Inherits:
Base
  • Object
show all
Defined in:
lib/gitlab/qa/component/telegraf.rb

Overview

Component to collect docker metrics

Constant Summary collapse

DOCKER_IMAGE =
'telegraf'
DOCKER_IMAGE_TAG =
'1.21-alpine'
LOG_DIR =
'/etc/telegraf/log'

Instance Attribute Summary collapse

Attributes inherited from Base

#docker, #environment, #network, #ports, #runner_network, #volumes

Instance Method Summary collapse

Methods inherited from Base

#add_network_alias, #hostname, #image, #instance, #prepare_docker_container, #prepare_docker_image, #prepare_network, #process_exec_commands, #pull, #restart, #tag, #teardown!

Methods included from Scenario::Actable

#act, included

Constructor Details

#initializeTelegraf

Returns a new instance of Telegraf.



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/gitlab/qa/component/telegraf.rb', line 15

def initialize
  super

  @name = DOCKER_IMAGE
  @host_log_dir = "#{Runtime::Env.host_artifacts_dir}/#{@name}"
  @environment = Runtime::Env.variables.slice(
    'QA_INFLUXDB_TOKEN',
    'QA_INFLUXDB_URL',
    'QA_RUN_TYPE',
    'CI_JOB_NAME',
    'CI_PIPELINE_ID'
  )
end

Instance Attribute Details

#host_log_dirObject (readonly)

Returns the value of attribute host_log_dir.



29
30
31
# File 'lib/gitlab/qa/component/telegraf.rb', line 29

def host_log_dir
  @host_log_dir
end

#nameObject (readonly)

Returns the value of attribute name.



29
30
31
# File 'lib/gitlab/qa/component/telegraf.rb', line 29

def name
  @name
end

#telegraf_configObject (readonly)

Returns the value of attribute telegraf_config.



29
30
31
# File 'lib/gitlab/qa/component/telegraf.rb', line 29

def telegraf_config
  @telegraf_config
end

Instance Method Details

#preparevoid

This method returns an undefined value.

Run prepare commands



45
46
47
48
49
50
51
52
53
54
# File 'lib/gitlab/qa/component/telegraf.rb', line 45

def prepare
  @telegraf_config = File.open("#{Dir.mktmpdir(nil, ENV['CI_BUILDS_DIR'])}/telegraf.conf", 'w') do |file|
    file.write(config)
    file.path
  end
  FileUtils.mkdir_p(host_log_dir)

  prepare_docker_image
  prepare_docker_container
end

#startvoid

This method returns an undefined value.

Start container



34
35
36
37
38
39
40
# File 'lib/gitlab/qa/component/telegraf.rb', line 34

def start
  docker.run(image: image, tag: tag) do |command|
    set_command_args(command)
    set_volumes(command)
    set_environment(command)
  end
end

#teardownvoid

This method returns an undefined value.

Run teardown



59
60
61
62
63
# File 'lib/gitlab/qa/component/telegraf.rb', line 59

def teardown
  return unless run_telegraf?

  super
end