Puppet Class: profile::wmcs::metricsinfra::prometheus_manager
- Defined in:
- modules/profile/manifests/wmcs/metricsinfra/prometheus_manager.pp
Overview
SPDX-License-Identifier: Apache-2.0
2 3 4 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 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'modules/profile/manifests/wmcs/metricsinfra/prometheus_manager.pp', line 2
class profile::wmcs::metricsinfra::prometheus_manager (
String $db_hostname = lookup('profile::wmcs::metricsinfra::prometheus_manager::db_hostname', {default_value => 'wu5emp5wblz.svc.trove.eqiad1.wikimedia.cloud'}),
String $db_database = lookup('profile::wmcs::metricsinfra::prometheus_manager::db_database', {default_value => 'prometheusconfig'}),
String $db_user_username = lookup('profile::wmcs::metricsinfra::prometheus_manager::db_user_username', {default_value => 'configuser'}),
String $db_user_password = lookup('profile::wmcs::metricsinfra::prometheus_manager::db_user_password'),
String $db_admin_username = lookup('profile::wmcs::metricsinfra::prometheus_manager::db_admin_username', {default_value => 'configadmin'}),
String $db_admin_password = lookup('profile::wmcs::metricsinfra::prometheus_manager::db_admin_password'),
Array[String[1]] $sync_exclude_projects = lookup('profile::wmcs::metricsinfra::prometheus_manager::sync_exclude_projects', {default_value => []}),
) {
$gitdir = '/var/lib/git'
$clone_dir = "${gitdir}/cloud/metricsinfra/prometheus-manager"
$venv_dir = "${clone_dir}/venv"
$config_dir = '/etc/prometheus-manager'
$config_file = "${config_dir}/config.yaml"
$metrics_dir = '/run/prometheus-manager-metrics'
wmflib::dir::mkdir_p("${gitdir}/cloud/metricsinfra")
file { $config_dir:
ensure => directory,
}
$config = {
'DATABASE' => {
'HOST' => $db_hostname,
'DATABASE' => $db_database,
'USER' => {
'USERNAME' => $db_user_username,
'PASSWORD' => $db_user_password,
},
'ADMIN' => {
'USERNAME' => $db_admin_username,
'PASSWORD' => $db_admin_password,
},
},
'SQLALCHEMY_ENGINE_OPTIONS' => {
# trove tends to kill db sessions at 120s of age,
# unlike default mariadb at 300s
'pool_recycle' => 90,
},
'OPENSTACK' => {
'CONFIG' => '/etc/novaobserver.yaml',
'CLOUD' => 'novaobserver',
'SYNC_EXCLUDE' => $sync_exclude_projects,
},
}
file { $config_file:
ensure => file,
content => to_yaml($config),
notify => Uwsgi::App['prometheus-manager'],
}
# Needed for prometheus exporter to share metrics between uwsgi processes
file { $metrics_dir:
ensure => directory,
owner => 'www-data',
group => 'www-data',
}
systemd::tmpfile { 'prometheus-manager-shared-metrics':
content => "d ${metrics_dir} 0755 www-data www-data",
}
# TODO: better deployment model (scap, debian, so on) - T288052
git::clone { 'cloud/metricsinfra/prometheus-manager':
ensure => latest,
directory => $clone_dir,
owner => 'www-data',
group => 'www-data',
notify => [
Uwsgi::App['prometheus-manager'],
Exec['prometheus-manager-venv-install'],
Exec['prometheus-manager-migrate'],
],
}
# the software uses some packages not in debian repos,
# so we need to do some ugly venv trickery (based on Quarry's manifests).
# the relevant pypi-only packages are as of writing:
# * flask-alembic
# * prometheus-flask-exporter
# * sqlalchemy-json
ensure_packages(['python3-venv'])
exec { 'prometheus-manager-venv':
user => 'www-data',
command => "/usr/bin/python3 -m venv ${venv_dir}",
creates => $venv_dir,
require => Git::Clone['cloud/metricsinfra/prometheus-manager'],
notify => Exec['prometheus-manager-venv-update-pip-wheel'],
}
exec { 'prometheus-manager-venv-update-pip-wheel':
user => 'www-data',
command => "${venv_dir}/bin/pip install -U pip wheel",
notify => Exec['prometheus-manager-venv-install'],
refreshonly => true,
}
exec { 'prometheus-manager-venv-install':
user => 'www-data',
command => "${venv_dir}/bin/pip install -e ${clone_dir}",
notify => Uwsgi::App['prometheus-manager'],
refreshonly => true,
}
$env = {
# fix prometheus exporter for multiple uwsgi processes/workers
'PROMETHEUS_MULTIPROC_DIR' => $metrics_dir,
# location of our config file
'PROMETHEUS_MANAGER_CONFIG_PATH' => $config_file,
}
$env_array = $env.map |String $key, String $value| {
"${key}=${value}"
}
uwsgi::app { 'prometheus-manager':
settings => {
uwsgi => {
'plugins' => 'python3',
'socket' => '/run/uwsgi/prometheus_manager.sock',
'wsgi-file' => "${clone_dir}/wsgi.py",
'chdir' => $clone_dir,
'callable' => 'app',
'master' => true,
'processes' => 4,
'venv' => $venv_dir,
'env' => $env_array,
},
},
}
# again, a better tool would be nice for deployment
# automatically run database migrations after git updates
exec { 'prometheus-manager-migrate':
command => "${venv_dir}/bin/pm-migrate",
cwd => $clone_dir,
environment => $env_array,
user => 'www-data',
require => [
File[$config_file],
Git::Clone['cloud/metricsinfra/prometheus-manager'],
],
refreshonly => true,
}
nginx::site { 'prometheus-manager-web-nginx':
require => Uwsgi::App['prometheus-manager'],
content => epp('profile/wmcs/metricsinfra/configserver/prometheus-manager.nginx.epp', {}),
}
systemd::timer::job { 'metricsinfra-maintain-projects':
ensure => present,
description => 'Syncronize list of OpenStack projects monitored by metricsinfra',
command => "${venv_dir}/bin/pm-maintain-projects",
user => 'www-data',
# every 20 minutes, so at minute :7, :27, :47
interval => {'start' => 'OnCalendar', 'interval' => '*-*-* *:7/20:00'},
environment => $env,
}
}
|