Defined Type: prometheus::service_catalog_targets

Defined in:
modules/prometheus/manifests/service_catalog_targets.pp

Overview

Parameters:

  • services_config (Hash[String, Wmflib::Service])
  • targets_file (String)
  • networks (Array)
  • service_ips_override (Optional[Stdlib::IP::Address]) (defaults to: undef)


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
48
49
# File 'modules/prometheus/manifests/service_catalog_targets.pp', line 7

define prometheus::service_catalog_targets (
  Hash[String, Wmflib::Service] $services_config,
  String $targets_file,
  Array $networks,
  Optional[Stdlib::IP::Address] $service_ips_override = undef,
) {
  # Iterate over services
  $targets = $services_config.reduce([]) |$memo, $el| {
    $service_name = $el[0]
    $service_config = $el[1]

    $all_ips = wmflib::service::get_ips_for_services($service_name => $service_config, $::site)
    $network_ips = filter($all_ips) |$addr| { stdlib::ip_in_range($addr, $networks) }

    if length($network_ips) > 0 and $service_ips_override {
      $service_ips = [ $service_ips_override ]
    } else {
      $service_ips = $network_ips
    }

    # Iterate over this service's probes and collect targets.
    $probes = $service_config['probes'].reduce([]) |$memo, $probe| {

      # Iterate over addresses
      $probe_targets = $service_ips.reduce([]) |$memo, $addr| {
        $memo + wmflib::service::probe::targets(
          $service_name,
          $service_config,
          $probe,
          $addr,
        )
      }

      $memo + $probe_targets
    }

    $memo + $probes
  }

  file { $targets_file:
    content => to_yaml($targets),
  }
}