Skip to content

Commit

Permalink
Add max_open_files parameter for systemd systems
Browse files Browse the repository at this point in the history
  • Loading branch information
alexjfisher committed Jul 12, 2019
1 parent 0105ec3 commit d3e4fee
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
2 changes: 2 additions & 0 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
18 changes: 18 additions & 0 deletions spec/classes/prometheus_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
3 changes: 3 additions & 0 deletions templates/prometheus.systemd.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit d3e4fee

Please sign in to comment.