Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arch Linux: Fix node_exporter installation #576

Merged
merged 1 commit into from
Aug 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -6350,6 +6350,8 @@ The following parameters are available in the `prometheus::node_exporter` class:
* [`service_name`](#service_name)
* [`user`](#user)
* [`version`](#version)
* [`env_vars`](#env_vars)
* [`env_file_path`](#env_file_path)
* [`scrape_host`](#scrape_host)
* [`export_scrape_job`](#export_scrape_job)
* [`scrape_port`](#scrape_port)
Expand Down Expand Up @@ -6446,7 +6448,7 @@ Data type: `Prometheus::Initstyle`

Service startup scripts style (e.g. rc, upstart or systemd)

Default value: `$facts['service_provider']`
Default value: `$prometheus::init_style`

##### <a name="install_method"></a>`install_method`

Expand Down Expand Up @@ -6552,6 +6554,22 @@ Data type: `String[1]`

The binary release version

##### <a name="env_vars"></a>`env_vars`

Data type: `Hash[String[1], Scalar]`

hash with custom environment variables thats passed to the exporter via init script / unit file

Default value: `{}`

##### <a name="env_file_path"></a>`env_file_path`

Data type: `Stdlib::Absolutepath`

The path to the file with the environmetn variable that is read from the init script/systemd unit

Default value: `$prometheus::env_file_path`

##### <a name="scrape_host"></a>`scrape_host`

Data type: `Optional[Stdlib::Host]`
Expand Down
5 changes: 3 additions & 2 deletions data/Archlinux.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@ prometheus::server::init_style: 'none'
prometheus::version: '2.10.0'
prometheus::install_method: 'package'
prometheus::bin_dir: '/usr/bin'
prometheus::env_file_path: '/etc/default'
prometheus::env_file_path: '/etc/conf.d'
prometheus::node_exporter::package_name: 'prometheus-node-exporter'
prometheus::node_exporter::install_method: 'package'
prometheus::node_exporter::bin_name: 'prometheus-node-exporter'
prometheus::node_exporter::user: 'node_exporter'
prometheus::node_exporter::group: 'node_exporter'
prometheus::node_exporter::manage_user: false
prometheus::node_exporter::manage_group: false
prometheus::node_exporter::service_name: 'prometheus-node-exporter'
prometheus::node_exporter::init_style: 'none'
prometheus::bird_exporter::install_method: 'package'
prometheus::bird_exporter::bin_name: 'prometheus-bird-exporter'
prometheus::bird_exporter::package_name: 'prometheus-bird-exporter'
prometheus::bird_exporter::manage_user: false
prometheus::bird_exporter::manage_group: false
prometheus::bird_exporter::init_style: 'none'
prometheus::bird_exporter::service_name: 'prometheus-bird-exporter'
prometheus::bird_exporter::env_file_path: '/etc/conf.d'
10 changes: 9 additions & 1 deletion manifests/node_exporter.pp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@
# User which runs the service
# @param version
# The binary release version
# @param env_vars
# hash with custom environment variables thats passed to the exporter via init script / unit file
# @param env_file_path
# The path to the file with the environmetn variable that is read from the init script/systemd unit
class prometheus::node_exporter (
String $download_extension,
Prometheus::Uri $download_url_base,
Expand All @@ -68,7 +72,7 @@
Boolean $service_enable = true,
Stdlib::Ensure::Service $service_ensure = 'running',
String[1] $service_name = 'node_exporter',
Prometheus::Initstyle $init_style = $facts['service_provider'],
Prometheus::Initstyle $init_style = $prometheus::init_style,
Prometheus::Install $install_method = $prometheus::install_method,
Boolean $manage_group = true,
Boolean $manage_service = true,
Expand All @@ -87,6 +91,8 @@
String[1] $scrape_job_name = 'node',
Optional[Hash] $scrape_job_labels = undef,
Optional[String[1]] $bin_name = undef,
Hash[String[1], Scalar] $env_vars = {},
Stdlib::Absolutepath $env_file_path = $prometheus::env_file_path,
) inherits prometheus {
# Prometheus added a 'v' on the realease name at 0.13.0
if versioncmp ($version, '0.13.0') >= 0 {
Expand Down Expand Up @@ -145,5 +151,7 @@
scrape_job_name => $scrape_job_name,
scrape_job_labels => $scrape_job_labels,
bin_name => $bin_name,
env_vars => $env_vars,
env_file_path => $env_file_path,
}
}
23 changes: 16 additions & 7 deletions spec/classes/node_exporter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,32 @@
context 'without parameters' do
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_class('prometheus') }
it { is_expected.to contain_prometheus__daemon('node_exporter').with(options: ' ') }
it { is_expected.to contain_service('node_exporter') }

if facts[:os]['name'] == 'Archlinux'
it { is_expected.not_to contain_user('node-exporter') }
it { is_expected.not_to contain_group('node-exporter') }
it { is_expected.not_to contain_file('/opt/node_exporter-1.0.1.linux-amd64/node_exporter') }
it { is_expected.not_to contain_file('/usr/local/bin/node_exporter') }
it { is_expected.to contain_package('prometheus-node-exporter') }
it { is_expected.to contain_systemd__unit_file('node_exporter.service') }
it { is_expected.not_to contain_systemd__unit_file('node_exporter.service') }
it { is_expected.to contain_service('prometheus-node-exporter') }
it { is_expected.to contain_prometheus__daemon('prometheus-node-exporter').with(options: ' ') }
else
it { is_expected.to contain_user('node-exporter') }
it { is_expected.to contain_group('node-exporter') }
it { is_expected.to contain_file('/opt/node_exporter-1.0.1.linux-amd64/node_exporter') }
it { is_expected.to contain_file('/usr/local/bin/node_exporter') }
it { is_expected.to contain_service('node_exporter') }
it { is_expected.to contain_prometheus__daemon('node_exporter').with(options: ' ') }
it { is_expected.to contain_systemd__unit_file('node_exporter.service') }
end

# rubocop:disable Style/IdenticalConditionalBranches
# rubocop:disable RSpec/RepeatedExample
if facts[:os]['family'] == 'RedHat'
it { is_expected.not_to contain_file('/etc/sysconfig/node_exporter') }
elsif facts[:os]['name'] == 'Archlinux'
it { is_expected.to contain_file('/etc/default/node_exporter') }
it { is_expected.to contain_file('/etc/conf.d/prometheus-node-exporter') }
it { is_expected.not_to contain_file('/etc/sysconfig/node_exporter') }
it { is_expected.not_to contain_file('/etc/default/node_exporter') }
else
it { is_expected.not_to contain_file('/etc/default/node_exporter') }
it { is_expected.not_to contain_file('/etc/sysconfig/node_exporter') }
Expand All @@ -47,6 +49,8 @@
{
collectors_enable: %w[foo bar],
collectors_disable: %w[baz qux],
init_style: 'systemd',
service_name: 'node_exporter',
install_method: 'url'
}
end
Expand All @@ -68,7 +72,9 @@
{
collectors_enable: %w[foo bar],
collectors_disable: %w[baz qux],
extra_options: '--path.procfs /host/proc --path.sysfs /host/sys'
extra_options: '--path.procfs /host/proc --path.sysfs /host/sys',
service_name: 'node_exporter',
install_method: 'url'
}
end

Expand All @@ -83,6 +89,7 @@
arch: 'amd64',
os: 'linux',
bin_dir: '/usr/local/bin',
service_name: 'node_exporter',
install_method: 'url'
}
end
Expand All @@ -98,7 +105,9 @@
context 'with no download_extension' do
let(:params) do
{
install_method: 'url',
download_extension: '',
service_name: 'node_exporter'
}
end

Expand Down
8 changes: 8 additions & 0 deletions spec/classes/unbound_exporter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,21 @@
it { is_expected.to contain_user('unbound-exporter') }
it { is_expected.to contain_systemd__unit_file('unbound_exporter.service') }

# rubocop:disable RSpec/RepeatedExample
if facts[:os]['family'] == 'RedHat'
it { is_expected.to contain_file('/etc/sysconfig/unbound_exporter') }
it { is_expected.not_to contain_file('/etc/default/unbound_exporter') }
it { is_expected.not_to contain_file('/etc/conf.d/unbound_exporter') }
elsif facts[:os]['name'] == 'Archlinux'
it { is_expected.to contain_file('/etc/conf.d/unbound_exporter') }
it { is_expected.not_to contain_file('/etc/sysconfig/unbound_exporter') }
it { is_expected.not_to contain_file('/etc/default/unbound_exporter') }
else
it { is_expected.to contain_file('/etc/default/unbound_exporter') }
it { is_expected.not_to contain_file('/etc/sysconfig/unbound_exporter') }
it { is_expected.not_to contain_file('/etc/conf.d/unbound_exporter') }
end
# rubocop:enable RSpec/RepeatedExample
end
end
end
Expand Down