Module: GreenHat::GitLab

Defined in:
lib/greenhat/accessors/gitlab.rb

Overview

GitLab App Helpers

Class Method Summary collapse

Class Method Details

.identify_node(archive) ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'lib/greenhat/accessors/gitlab.rb', line 27

def self.identify_node(archive)
  gitlab_status = archive.things.find { |x| x.name == 'gitlab_status' }&.data&.keys
  hostname = archive.things.find { |x| x.type == 'hostname' }.data.first

  {
    host: hostname,
    services: gitlab_status || []
  }
end

.node_typesObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/greenhat/accessors/gitlab.rb', line 4

def self.node_types
  [
    {
      name: 'Web Service', pattern: %w[puma unicorn]
    },
    {
      name: 'Sidekiq', pattern: %w[sidekiq]
    },
    {
      name: 'Gitaly', pattern: %w[gitaly]
    },
    {
      name: 'Redis', pattern: %w[redis]
    },
    {
      name: 'PostgreSQL', pattern: %w[postgresql]
    },
    {
      name: 'PGBouncer', pattern: %w[pgbouncer]
    }
  ]
end

.services(archive, indent = 0) ⇒ Object

Show GitLab Services in a grid / include versions



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
# File 'lib/greenhat/accessors/gitlab.rb', line 38

def self.services(archive, indent = 0)
  manifest = archive.things.find { |x| x.type == 'gitlab/version-manifest.json' }
  gitlab_status = archive.things.find { |x| x.name == 'gitlab_status' }

  return nil unless gitlab_status

  list = gitlab_status.data.keys.sort.map do |service|
    color = gitlab_status.data.dig(service, 0, :status) == 'run' ? :green : :red

    # Collect Service version from manifest
    version = manifest.data.software[service.to_sym]&.display_version

    # If able to identify version use / fallback
    if version
      [
        service.pastel(color),
        "(#{version})".pastel(:bright_black)
      ].join(' ')
    else
      service.pastel(color)
    end
  end

  # Keep Alphabetical Sort
  groups = list.each_slice((list.size / 3.to_f).round).to_a

  table = TTY::Table.new do |t|
    loop do
      break if groups.all?(&:empty?)

      t << groups.map(&:shift)
    end
  end

  table.render(:unicode, padding: [0, 1, 0, 1], indent: indent)
end