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
|
# File 'modules/thanos/manifests/rule.pp', line 30
class thanos::rule (
Hash[Stdlib::Fqdn, Hash] $rule_hosts,
Boolean $use_objstore,
Optional[Hash[String, String]] $objstore_account,
Optional[String] $objstore_password,
Array[Stdlib::Host] $alertmanagers,
Array[String] $rule_files,
Stdlib::HTTPSUrl $query_url,
Wmflib::Ensure $ensure = present,
Stdlib::Port::Unprivileged $query_port = 10902,
Stdlib::Port::Unprivileged $http_port = 17902,
Stdlib::Port::Unprivileged $grpc_port = 17901,
) {
ensure_packages(['thanos'])
if $use_objstore and ($objstore_account == undef or $objstore_password == undef) {
fail('thanos::rule: objstore_account and objstore_password are required when use_objstore is true')
}
$http_address = "0.0.0.0:${http_port}"
$grpc_address = "0.0.0.0:${grpc_port}"
$service_name = 'thanos-rule'
$data_dir = '/srv/thanos-rule'
$objstore_config_file = '/etc/thanos-rule/objstore.yaml'
$am_config_file = '/etc/thanos-rule/alertmanagers.yaml'
$am_config = { 'alertmanagers' => [
{ 'static_configs' => $alertmanagers.map |$a| { "${a}:9093" } }
]}
$replica = $::fqdn in $rule_hosts ? {
true => $rule_hosts[$::fqdn]['replica'],
false => 'unset'
}
$relabel_config_file = '/etc/thanos-rule/relabel.yaml'
$relabel_config = [
# Add 'source' label
{ 'target_label' => 'source', 'replacement' => 'thanos', 'action' => 'replace' },
]
file { $data_dir:
ensure => directory,
mode => '0750',
owner => 'thanos',
group => 'thanos',
}
file { '/etc/thanos-rule':
ensure => directory,
mode => '0555',
owner => 'root',
group => 'root',
}
file { '/etc/thanos-rule/rules':
ensure => directory,
mode => '0555',
owner => 'root',
group => 'root',
}
if $use_objstore and $ensure == 'present' {
file { $objstore_config_file:
ensure => file,
mode => '0440',
owner => 'thanos',
group => 'root',
show_diff => false,
content => template('thanos/objstore.yaml.erb'),
}
} else {
file { $objstore_config_file:
ensure => absent,
}
}
file { $am_config_file:
ensure => $ensure,
mode => '0444',
owner => 'thanos',
group => 'root',
content => to_yaml($am_config),
}
file { $relabel_config_file:
ensure => $ensure,
mode => '0444',
owner => 'thanos',
group => 'root',
content => to_yaml($relabel_config),
}
if $ensure != present {
$service_ensure = $ensure
} else { # handle fqdn-based service running/stopped status
if $::fqdn in $rule_hosts {
$service_ensure = 'present'
$service_enable = true
} else {
$service_ensure = 'absent'
$service_enable = false
}
}
systemd::service { $service_name:
ensure => $service_ensure,
restart => true,
override => true,
content => systemd_template('thanos-rule'),
service_params => {
enable => $service_enable,
hasrestart => true,
},
}
}
|