Class: Gitlab::QA::Component::Chaos

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

Constant Summary collapse

DOCKER_IMAGE =
'ghcr.io/shopify/toxiproxy'
DOCKER_IMAGE_TAG =
'2.5.0'

Instance Attribute Summary

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, #ip_address, #prepare, #prepare_docker_container, #prepare_docker_image, #prepare_network, #process_exec_commands, #pull, #restart, #tag, #teardown, #teardown!

Methods included from Scenario::Actable

#act, included

Constructor Details

#initializeChaos

Returns a new instance of Chaos.



11
12
13
14
# File 'lib/gitlab/qa/component/chaos.rb', line 11

def initialize
  super
  @network = "test"
end

Instance Method Details

#nameObject



16
17
18
# File 'lib/gitlab/qa/component/chaos.rb', line 16

def name
  @name ||= "chaos"
end

#startObject



20
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/gitlab/qa/component/chaos.rb', line 20

def start
  prepare
  docker.run(image: image, tag: tag) do |command|
    command << '-d '
    command << "--name #{name}"
    command << "--network #{@network}"
    command << "--publish 8474:8474"
  end

  Toxiproxy.host = "http://localhost:8474"

  begin
    attempts ||= 1
    Toxiproxy.populate([
                         {
                           name: "postgres",
                           listen: "[::]:5432",
                           upstream: "postgres.test:5432",
                           "enabled": true
                         },
                         {
                           name: "praefect",
                           listen: "[::]:2305",
                           upstream: "praefect.test:2305",
                           "enabled": true
                         },
                         {
                           name: "gitaly1",
                           listen: "[::]:8076",
                           upstream: "gitaly1.test:8076",
                           "enabled": true
                         },
                         {
                           name: "gitaly2",
                           listen: "[::]:8077",
                           upstream: "gitaly2.test:8077",
                           "enabled": true
                         },
                         {
                           name: "gitaly3",
                           listen: "[::]:8078",
                           upstream: "gitaly3.test:8078",
                           "enabled": true
                         }
                       ])
  rescue StandardError => e
    Runtime::Logger.warn e.message

    # This should resolve within seconds, but give some leeway for the toxiproxy container to start
    if (attempts += 1) < 10
      Runtime::Logger.info "Waiting #{attempts} seconds before retrying setting toxiproxy config"
      sleep attempts
      retry
    end
  end
end