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

support the new scrape_config_files option, prom ~v2.45 #782

Merged
merged 1 commit into from
Jul 11, 2024
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
19 changes: 19 additions & 0 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ The following parameters are available in the `prometheus` class:
* [`global_config`](#-prometheus--global_config)
* [`rule_files`](#-prometheus--rule_files)
* [`scrape_configs`](#-prometheus--scrape_configs)
* [`scrape_config_files`](#-prometheus--scrape_config_files)
* [`include_default_scrape_configs`](#-prometheus--include_default_scrape_configs)
* [`remote_read_configs`](#-prometheus--remote_read_configs)
* [`remote_write_configs`](#-prometheus--remote_write_configs)
Expand Down Expand Up @@ -447,6 +448,15 @@ Prometheus scrape configs

Default value: `[]`

##### <a name="-prometheus--scrape_config_files"></a>`scrape_config_files`

Data type: `Optional[Array]`

Specifies an Array of file globs. Scrape configs are read from all matching files and appended to
the list of scrape configs.

Default value: `undef`

##### <a name="-prometheus--include_default_scrape_configs"></a>`include_default_scrape_configs`

Data type: `Boolean`
Expand Down Expand Up @@ -11672,6 +11682,7 @@ The following parameters are available in the `prometheus::server` class:
* [`global_config`](#-prometheus--server--global_config)
* [`rule_files`](#-prometheus--server--rule_files)
* [`scrape_configs`](#-prometheus--server--scrape_configs)
* [`scrape_config_files`](#-prometheus--server--scrape_config_files)
* [`include_default_scrape_configs`](#-prometheus--server--include_default_scrape_configs)
* [`remote_read_configs`](#-prometheus--server--remote_read_configs)
* [`remote_write_configs`](#-prometheus--server--remote_write_configs)
Expand Down Expand Up @@ -11876,6 +11887,14 @@ Data type: `Array`

Default value: `$prometheus::scrape_configs`

##### <a name="-prometheus--server--scrape_config_files"></a>`scrape_config_files`

Data type: `Optional[Array]`



Default value: `$prometheus::scrape_config_files`

##### <a name="-prometheus--server--include_default_scrape_configs"></a>`include_default_scrape_configs`

Data type: `Boolean`
Expand Down
4 changes: 4 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@
# Prometheus rule files
# @param scrape_configs
# Prometheus scrape configs
# @param scrape_config_files
# Specifies an Array of file globs. Scrape configs are read from all matching files and appended to
# the list of scrape configs.
# @param include_default_scrape_configs
# Include the module default scrape configs
# @param remote_read_configs
Expand Down Expand Up @@ -228,6 +231,7 @@
String $package_name = 'prometheus',
Array $rule_files = [],
Array $scrape_configs = [],
Optional[Array] $scrape_config_files = undef,
Array $remote_read_configs = [],
Array $remote_write_configs = [],
Boolean $enable_tracing = false,
Expand Down
1 change: 1 addition & 0 deletions manifests/server.pp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
Hash $global_config = $prometheus::global_config,
Array $rule_files = $prometheus::rule_files,
Array $scrape_configs = $prometheus::scrape_configs,
Optional[Array] $scrape_config_files = $prometheus::scrape_config_files,
Boolean $include_default_scrape_configs = $prometheus::include_default_scrape_configs,
Array $remote_read_configs = $prometheus::remote_read_configs,
Array $remote_write_configs = $prometheus::remote_write_configs,
Expand Down
21 changes: 21 additions & 0 deletions spec/classes/server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,27 @@
}
end

describe 'scrape_config_files' do
context 'by default' do
it {
content = catalogue.resource('file', 'prometheus.yaml').send(:parameters)[:content]
expect(content).not_to include('scrape_config_files:')
}
end

context 'when set with a glob' do
let(:params) do
super().merge(scrape_config_files: ['/etc/prometheus/scrape_configs.d/*.yaml'])
end

it {
content = catalogue.resource('file', 'prometheus.yaml').send(:parameters)[:content]
expect(content).to include('scrape_config_files:')
expect(content).to include('- "/etc/prometheus/scrape_configs.d/*.yaml"')
}
end
end

describe 'max_open_files', if: facts[:os]['name'] != 'Archlinux' do
context 'by default' do
it {
Expand Down
4 changes: 4 additions & 0 deletions templates/prometheus.yaml.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<% global_config = scope.lookupvar('prometheus::server::global_config') -%>
<% rule_files = scope.lookupvar('prometheus::server::_rule_files') -%>
<% scrape_configs = scope.lookupvar('prometheus::config::scrape_configs') -%>
<% scrape_config_files = scope.lookupvar('prometheus::server::scrape_config_files') -%>
<% remote_read_configs = scope.lookupvar('prometheus::server::remote_read_configs') -%>
<% remote_write_configs = scope.lookupvar('prometheus::server::remote_write_configs') -%>
<% tracing_config = scope.lookupvar('prometheus::server::tracing_config') -%>
Expand All @@ -14,6 +15,9 @@
'alertmanagers'=>scope.lookupvar('prometheus::server::alertmanagers_config'),
},
}
if scrape_config_files
full_config['scrape_config_files'] = scrape_config_files
end
full_config['remote_read'] = remote_read_configs
full_config['remote_write'] = remote_write_configs
if @enable_tracing
Expand Down