From d3e4feeb573702afcbf3cf4d7fef500a6efffeed Mon Sep 17 00:00:00 2001 From: Alexander Fisher Date: Sun, 17 Feb 2019 20:08:00 +0000 Subject: [PATCH] Add `max_open_files` parameter for systemd systems --- manifests/config.pp | 2 ++ manifests/init.pp | 6 ++++++ spec/classes/prometheus_spec.rb | 18 ++++++++++++++++++ templates/prometheus.systemd.erb | 3 +++ 4 files changed, 29 insertions(+) diff --git a/manifests/config.pp b/manifests/config.pp index 944fb4596..e8e233280 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -4,6 +4,8 @@ assert_private() + $max_open_files = $prometheus::max_open_files + if $prometheus::server::init_style { if( versioncmp($prometheus::server::version, '2.0.0') < 0 ){ # helper variable indicating prometheus version, so we can use on this information in the template diff --git a/manifests/init.pp b/manifests/init.pp index ba168e501..2471065e5 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -141,6 +141,11 @@ # creating the appropriate prometheus scrape configs for each endpoint. All scrape_config # options can be passed as hash elements. Only the job_name is mandatory. # +# [*max_open_files*] +# The maximum number of file descriptors for the prometheus server. +# Defaults to `undef`, but set to a large integer to override your default OS limit. +# Currently only implemented for systemd based service. +# # Actions: # # Requires: see Modulefile @@ -194,6 +199,7 @@ String $os = downcase($facts['kernel']), Optional[Variant[Stdlib::HTTPUrl, Stdlib::Unixpath, String[1]]] $external_url = undef, Optional[Array[Hash[String[1], Any]]] $collect_scrape_jobs = [], + Optional[Integer] $max_open_files = undef, ) { case $arch { diff --git a/spec/classes/prometheus_spec.rb b/spec/classes/prometheus_spec.rb index 8ce629614..415f66419 100644 --- a/spec/classes/prometheus_spec.rb +++ b/spec/classes/prometheus_spec.rb @@ -126,6 +126,24 @@ 'content' => File.read(fixtures('files', "prometheus#{prom_major}.systemd")) ) } + describe 'max_open_files' do + context 'by default' do + it { + content = catalogue.resource('systemd::unit_file', 'prometheus.service').send(:parameters)[:content] + expect(content).not_to include('LimitNOFILE') + } + end + context 'when set to 1000000' do + let(:params) do + parameters.merge('max_open_files' => 1_000_000) + end + + it { + content = catalogue.resource('systemd::unit_file', 'prometheus.service').send(:parameters)[:content] + expect(content).to include('LimitNOFILE=1000000') + } + end + end elsif ['ubuntu-14.04-x86_64'].include?(os) # init_style = 'upstart' diff --git a/templates/prometheus.systemd.erb b/templates/prometheus.systemd.erb index e960be7f1..c56b3cf07 100644 --- a/templates/prometheus.systemd.erb +++ b/templates/prometheus.systemd.erb @@ -12,6 +12,9 @@ ExecStart=<%= scope.lookupvar('prometheus::server::bin_dir') %>/prometheus \ ExecReload=/bin/kill -HUP $MAINPID KillMode=process Restart=always +<% if @max_open_files -%> +LimitNOFILE=<%= @max_open_files %> +<% end -%> [Install] WantedBy=multi-user.target