diff --git a/REFERENCE.md b/REFERENCE.md
index 192e058e9..d0885d187 100644
--- a/REFERENCE.md
+++ b/REFERENCE.md
@@ -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)
@@ -447,6 +448,15 @@ Prometheus scrape configs
Default value: `[]`
+##### `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`
+
##### `include_default_scrape_configs`
Data type: `Boolean`
@@ -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)
@@ -11876,6 +11887,14 @@ Data type: `Array`
Default value: `$prometheus::scrape_configs`
+##### `scrape_config_files`
+
+Data type: `Optional[Array]`
+
+
+
+Default value: `$prometheus::scrape_config_files`
+
##### `include_default_scrape_configs`
Data type: `Boolean`
diff --git a/manifests/init.pp b/manifests/init.pp
index 190e70475..0222b1e27 100644
--- a/manifests/init.pp
+++ b/manifests/init.pp
@@ -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
@@ -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,
diff --git a/manifests/server.pp b/manifests/server.pp
index 8b8aca8f5..08f11542d 100644
--- a/manifests/server.pp
+++ b/manifests/server.pp
@@ -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,
diff --git a/spec/classes/server_spec.rb b/spec/classes/server_spec.rb
index 268bd87c1..e43024113 100644
--- a/spec/classes/server_spec.rb
+++ b/spec/classes/server_spec.rb
@@ -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 {
diff --git a/templates/prometheus.yaml.erb b/templates/prometheus.yaml.erb
index 45e47ca56..24d16e5f0 100644
--- a/templates/prometheus.yaml.erb
+++ b/templates/prometheus.yaml.erb
@@ -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') -%>
@@ -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