Skip to content

Commit

Permalink
Merge pull request #782 from lukebigum/scrape_config_files
Browse files Browse the repository at this point in the history
support the new scrape_config_files option, prom ~v2.45
  • Loading branch information
TheMeier authored Jul 11, 2024
2 parents 2c371dc + ba31b9b commit efcde35
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 0 deletions.
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 @@ -11674,6 +11684,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 @@ -11878,6 +11889,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

0 comments on commit efcde35

Please sign in to comment.