Puppet Function: wmflib::service::probe::targets

Defined in:
modules/wmflib/functions/service/probe/targets.pp
Function type:
Puppet Language

Overview

wmflib::service::probe::targets(String $service_name, Wmflib::Service $service_config, Wmflib::Service::Probe $probe, Stdlib::IP::Address $address)Array[Hash]

Parameters:

  • service_name (String)
  • service_config (Wmflib::Service)
  • probe (Wmflib::Service::Probe)
  • address (Stdlib::IP::Address)

Returns:

  • (Array[Hash])


5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
# File 'modules/wmflib/functions/service/probe/targets.pp', line 5

function wmflib::service::probe::targets(
  String $service_name,
  Wmflib::Service $service_config,
  Wmflib::Service::Probe $probe,
  Stdlib::IP::Address $address,
) >> Array[Hash] {
  $af = $address ? {
    Stdlib::IP::Address::V4 => 'ip4',
    Stdlib::IP::Address::V6 => 'ip6',
  }
  $port = $service_config['port']
  $common_labels = {
    'address' => $address,
    'family'  => $af,
  }

  if $probe['type'] == 'http' {
    $path = pick($probe['path'], '/')

    $scheme = $service_config['encryption'] ? {
      false   => 'http',
      default => 'https',
    }

    $probes = [
      {
        'labels'  => $common_labels + { 'module' => "http_${service_name}_${af}" },
        'targets' => [ "${service_name}:${port}@${scheme}://[${address}]:${port}${path}" ],
      },
    ]
  }

  if $probe['type'] =~ /^tcp/ {
    $probes = [
      {
        'labels'  => $common_labels + { 'module' => "tcp_${service_name}_${af}" },
        'targets' => [ "${service_name}:${port}@[${address}]:${port}" ],
      },
    ]
  }

  return flatten($probes)
}