Skip to content

Commit 100de54

Browse files
committed
New enable_promethus_exporter parameter
Set `enable_promethus_exporter` to `true` to install and start a Prometheus CvmFS Exporter published metrics from CvmFS mounts. By default it will be listening on port 9868
1 parent 6105fef commit 100de54

File tree

6 files changed

+96
-0
lines changed

6 files changed

+96
-0
lines changed

REFERENCE.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,17 @@ class{'cvmfs':
9696
}
9797
```
9898

99+
##### Enable Prometheus Metrics Exporter
100+
101+
```puppet
102+
class{ 'cvmfs':
103+
enable_prometheus_exporter => true,
104+
}
105+
class{ 'nftables::rules::node_exporter':
106+
port => 9868,
107+
}
108+
```
109+
99110
#### Parameters
100111

101112
The following parameters are available in the `cvmfs` class:
@@ -159,6 +170,7 @@ The following parameters are available in the `cvmfs` class:
159170
* [`cvmfs_xattr_privileged_gids`](#-cvmfs--cvmfs_xattr_privileged_gids)
160171
* [`cvmfs_xattr_protected_xattrs`](#-cvmfs--cvmfs_xattr_protected_xattrs)
161172
* [`cvmfs_cache_refcount`](#-cvmfs--cvmfs_cache_refcount)
173+
* [`enable_prometheus_exporter`](#-cvmfs--enable_prometheus_exporter)
162174
* [`cvmfs_yum`](#-cvmfs--cvmfs_yum)
163175
* [`cvmfs_yum_priority`](#-cvmfs--cvmfs_yum_priority)
164176
* [`cvmfs_yum_proxy`](#-cvmfs--cvmfs_yum_proxy)
@@ -646,6 +658,14 @@ If set to yes, deduplicate open file descriptors by refcounting.
646658

647659
Default value: `undef`
648660

661+
##### <a name="-cvmfs--enable_prometheus_exporter"></a>`enable_prometheus_exporter`
662+
663+
Data type: `Boolean`
664+
665+
Install and start a Prometheus exporter on port 9868
666+
667+
Default value: `false`
668+
649669
##### <a name="-cvmfs--cvmfs_yum"></a>`cvmfs_yum`
650670

651671
Data type: `Optional[Stdlib::Httpurl]`

manifests/init.pp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@
4545
# cvmfs_cache_refcount => 'yes',
4646
# }
4747
#
48+
# @example Enable Prometheus Metrics Exporter
49+
# class{ 'cvmfs':
50+
# enable_prometheus_exporter => true,
51+
# }
52+
# class{ 'nftables::rules::node_exporter':
53+
# port => 9868,
54+
# }
55+
#
4856
# @param mount_method
4957
# The `autofs` option will configure cvmfs to be mounted with autofs. The `mount` option will
5058
# use puppet's mount type, currently adding a line to /etc/fstab. The *none* option
@@ -121,6 +129,7 @@
121129
# @param cvmfs_xattr_privileged_gids group IDs that are allowed to access the extended attributes by `$cvmfs_xattr_protected_xattrs`.
122130
# @param cvmfs_xattr_protected_xattrs List of extended attributes (full name, e.g. user.fqrn) that are only accessible by root and the group IDs listed by `$cvmfs_xattr_privileged_gids`.
123131
# @param cvmfs_cache_refcount If set to yes, deduplicate open file descriptors by refcounting.
132+
# @param enable_prometheus_exporter Install and start a Prometheus exporter on port 9868
124133
#
125134
# Deprecated paramters below
126135
# @param cvmfs_yum Deprecated, use repo_base
@@ -195,6 +204,7 @@
195204
Optional[Array[Integer[0],1]] $cvmfs_cpu_affinity = undef,
196205
Optional[Array[Integer[1],1]] $cvmfs_xattr_privileged_gids = undef,
197206
Optional[Array[String[1],1]] $cvmfs_xattr_protected_xattrs = undef,
207+
Boolean $enable_prometheus_exporter = false,
198208
# Deprecated Parameters
199209
Optional[Boolean] $cvmfs_yum_manage_repo = undef,
200210
Optional[Stdlib::Httpurl] $cvmfs_yum = undef,

manifests/install.pp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
String[1] $cvmfs_version = $cvmfs::cvmfs_version,
66
Stdlib::Absolutepath $cvmfs_cache_base = $cvmfs::cvmfs_cache_base,
77
Optional[Enum['yes','no']] $cvmfs_claim_ownership = $cvmfs::cvmfs_claim_ownership,
8+
Boolean $enable_prometheus_exporter = $cvmfs::enable_prometheus_exporter,
89
) inherits cvmfs {
910
# Create the cache dir if one is defined, otherwise assume default is in the package.
1011
# Require the package so we know the user is in place.
@@ -36,4 +37,8 @@
3637
content => "---\n#This file generated by puppet and is used by custom facts only.\ncvmfs_cache_base: ${cvmfs_cache_base}\n",
3738
require => Package['cvmfs'],
3839
}
40+
41+
package { 'prometheus-cvmfs-exporter':
42+
ensure => bool2str($enable_prometheus_exporter, 'installed','absent'),
43+
}
3944
}

manifests/service.pp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
class cvmfs::service (
55
Enum['autofs','mount','none'] $mount_method = $cvmfs::mount_method,
66
Boolean $manage_autofs_service = $cvmfs::manage_autofs_service,
7+
Boolean $enable_prometheus_exporter = $cvmfs::enable_prometheus_exporter,
78
) inherits cvmfs {
89
# CVMFS 2.1 at least uses cvmfs_config.
910

@@ -19,4 +20,9 @@
1920
}
2021
)
2122
}
23+
24+
service { 'cvmfs-client-prometheus.socket':
25+
ensure => $enable_prometheus_exporter,
26+
enable => $enable_prometheus_exporter,
27+
}
2228
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# frozen_string_literal: true
2+
3+
require 'spec_helper_acceptance'
4+
5+
describe 'cvmfs enable_prometheus_exporter' do
6+
it 'configures and work with no errors' do
7+
# Clean up all existing mounts
8+
shell('cvmfs_config killall', acceptable_exit_codes: [0, 127])
9+
pp = <<-PUPPET
10+
class{ 'cvmfs':
11+
cvmfs_http_proxy => 'http://ca-proxy.cern.ch:3128;DIRECT',
12+
enable_prometheus_exporter => true,
13+
}
14+
cvmfs::domain{ 'cern.ch':
15+
cvmfs_server_url => 'http://cvmfs-stratum-one.cern.ch/cvmfs/@fqrn@'
16+
}
17+
PUPPET
18+
# Run it three times, it should be stable by then
19+
apply_manifest(pp, catch_failures: true)
20+
apply_manifest(pp, catch_failures: true)
21+
apply_manifest(pp, catch_changes: true)
22+
# The automounter can retrun before it is actually working.
23+
shell('sleep 10')
24+
shell('ls /cvmfs/cms.cern.ch', acceptable_exit_codes: 0)
25+
end
26+
27+
describe service('cvmfs-client-prometheus.socket') do
28+
it { is_expected.to be_enabled }
29+
it { is_expected.to be_running }
30+
end
31+
32+
describe port('9868') do
33+
it { is_expected.to be_listening }
34+
end
35+
36+
describe command('curl -s http://localhost:9868/metrics') do
37+
its(:stdout) { is_expected.to match(%r{^# HELP}) }
38+
end
39+
end

spec/classes/init_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@
3030
it { is_expected.to contain_concat__fragment('cvmfs_default_local_header').without_content(%r{^CVMFS_UID_MAP.*$}) }
3131
it { is_expected.to contain_concat__fragment('cvmfs_default_local_header').without_content(%r{^CVMFS_GID_MAP.*$}) }
3232

33+
it {
34+
is_expected.to contain_package('prometheus-cvmfs-exporter').with_ensure('absent')
35+
is_expected.to contain_service('cvmfs-client-prometheus.socket').with_ensure(false).with_enable(false)
36+
}
37+
3338
case facts[:os]['family']
3439
when 'Debian'
3540
it { is_expected.to contain_class('cvmfs::apt') }
@@ -49,6 +54,17 @@
4954
it { is_expected.to contain_concat__fragment('cvmfs_default_local_header').with_content(%r{^CVMFS_HTTP_PROXY='http://foobar.example.org:3128'$}) }
5055
end
5156

57+
context 'with enable_prometheus_exporter set true' do
58+
let(:params) do
59+
super().merge(enable_prometheus_exporter: true)
60+
end
61+
62+
it {
63+
is_expected.to contain_package('prometheus-cvmfs-exporter').with_ensure('installed')
64+
is_expected.to contain_service('cvmfs-client-prometheus.socket').with_ensure(true).with_enable(true)
65+
}
66+
end
67+
5268
context 'with defaults and cvmfspartsize fact unset' do
5369
it { is_expected.to contain_class('cvmfs::config') }
5470
it { is_expected.to contain_concat__fragment('cvmfs_default_local_header').with_content(%r{^CVMFS_QUOTA_LIMIT='1000'$}) }

0 commit comments

Comments
 (0)