Puppet Class: profile::prometheus::services

Defined in:
modules/profile/manifests/prometheus/services.pp

Overview

SPDX-License-Identifier: Apache-2.0 Uses the prometheus module and generates the specific configuration needed for WMF production

Parameters:

  • replica_label (String) (defaults to: lookup('prometheus::replica_label'))
  • enable_thanos_upload (Boolean) (defaults to: lookup('profile::prometheus::enable_thanos_upload', { 'default_value' => false }))
  • thanos_min_time (Optional[String]) (defaults to: lookup('profile::prometheus::thanos::min_time', { 'default_value' => undef }))
  • alertmanagers (Array[Stdlib::Host]) (defaults to: lookup('alertmanagers', {'default_value' => []}))
  • storage_retention (String) (defaults to: lookup('profile::prometheus::services::storage_retention', {'default_value' => '4032h'}))
  • max_chunks_to_persist (Integer) (defaults to: lookup('prometheus::server::max_chunks_to_persist', {'default_value' => 524288}))
  • memory_chunks (Integer) (defaults to: lookup('prometheus::server::memory_chunks', {'default_value' => 1048576}))
  • disable_compaction (Boolean) (defaults to: lookup('profile::prometheus::thanos::disable_compaction', { 'default_value' => false }))
  • alerting_relabel_configs_extra (Array) (defaults to: lookup('profile::prometheus::services::alerting_relabel_configs_extra'))


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
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'modules/profile/manifests/prometheus/services.pp', line 5

class profile::prometheus::services (
    String $replica_label                 = lookup('prometheus::replica_label'),
    Boolean $enable_thanos_upload         = lookup('profile::prometheus::enable_thanos_upload', { 'default_value' => false }),
    Optional[String] $thanos_min_time     = lookup('profile::prometheus::thanos::min_time', { 'default_value' => undef }),
    Array[Stdlib::Host] $alertmanagers    = lookup('alertmanagers', {'default_value' => []}),
    String $storage_retention             = lookup('profile::prometheus::services::storage_retention', {'default_value' => '4032h'}),
    Integer $max_chunks_to_persist        = lookup('prometheus::server::max_chunks_to_persist', {'default_value' => 524288}),
    Integer $memory_chunks                = lookup('prometheus::server::memory_chunks', {'default_value' => 1048576}),
    Boolean $disable_compaction           = lookup('profile::prometheus::thanos::disable_compaction', { 'default_value' => false }),
    Array $alerting_relabel_configs_extra = lookup('profile::prometheus::services::alerting_relabel_configs_extra'),
){

    $targets_path = '/srv/prometheus/services/targets'
    $port = 9903

    $config_extra = {
        # All metrics will get an additional 'site' label when queried by
        # external systems (e.g. via federation)
        'external_labels' => {
            'site'       => $::site,
            'replica'    => $replica_label,
            'prometheus' => 'services',
        },
    }

    $jmx_exporter_jobs = [
      {
        'job_name'        => 'cassandra',
        'scrape_timeout'  => '25s',
        'scheme'          => 'http',
        'file_sd_configs' => [
          { 'files' => [ "${targets_path}/cassandra_*.yaml" ]}
        ],
        # Drop restbase table/cf 'meta' metrics, not needed
        'metric_relabel_configs' => [
          { 'source_labels' => ['columnfamily'],
            'regex'  => 'meta',
            'action' => 'drop',
          },
          { 'source_labels' => ['table'],
            'regex'  => 'meta',
            'action' => 'drop',
          },
        ],
      },
    ]

    prometheus::jmx_exporter_config{ "cassandra_dev_${::site}":
        dest       => "${targets_path}/cassandra_dev_${::site}.yaml",
        class_name => 'role::cassandra_dev',
    }

    prometheus::jmx_exporter_config{ "cassandra_restbase_production_${::site}":
        dest       => "${targets_path}/cassandra_restbase_production_${::site}.yaml",
        class_name => 'role::restbase::production',
    }

    prometheus::jmx_exporter_config{ "cassandra_sessionstore_production_${::site}":
        dest       => "${targets_path}/cassandra_sessionstore_production_${::site}.yaml",
        class_name => 'role::sessionstore',
    }

    $max_block_duration = ($enable_thanos_upload and $disable_compaction) ? {
        true    => '2h',
        default => '24h',
    }

    prometheus::server { 'services':
        listen_address                 => "127.0.0.1:${port}",
        storage_retention              => $storage_retention,
        max_chunks_to_persist          => $max_chunks_to_persist,
        memory_chunks                  => $memory_chunks,
        scrape_configs_extra           => $jmx_exporter_jobs,
        global_config_extra            => $config_extra,
        min_block_duration             => '2h',
        max_block_duration             => $max_block_duration,
        alertmanagers                  => $alertmanagers.map |$a| { "${a}:9093" },
        alerting_relabel_configs_extra => $alerting_relabel_configs_extra,
    }

    prometheus::web { 'services':
        proxy_pass => "http://localhost:${port}/services",
    }

    profile::thanos::sidecar { 'services':
        prometheus_port     => $port,
        prometheus_instance => 'services',
        enable_upload       => $enable_thanos_upload,
        min_time            => $thanos_min_time,
    }

    prometheus::rule { 'rules_services.yml':
        instance => 'services',
        source   => 'puppet:///modules/profile/prometheus/rules_services.yml',
    }

    prometheus::pint::source { 'services':
        port => $port,
    }
}