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

add support for remote_read #109

Merged
merged 1 commit into from Nov 15, 2017
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
8 changes: 8 additions & 0 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,27 @@
$global_config,
$rule_files,
$scrape_configs,
$remote_read_configs,
$purge = true,
$config_template = $::prometheus::params::config_template,
) {

if $prometheus::init_style {
if( versioncmp($::prometheus::version, '2.0.0') < 0 ){
# helper variable indicating prometheus version, so we can use on this information in the template
$prometheus_v2 = false
if $remote_read_configs != [] {
fail('remote_read_configs requires prometheus 2.X')
}
$daemon_flags = [
"-config.file=${::prometheus::config_dir}/prometheus.yaml",
"-storage.local.path=${::prometheus::localstorage}",
"-web.console.templates=${::prometheus::shared_dir}/consoles",
"-web.console.libraries=${::prometheus::shared_dir}/console_libraries",
]
} else {
# helper variable indicating prometheus version, so we can use on this information in the template
$prometheus_v2 = true
$daemon_flags = [
"--config.file=${::prometheus::config_dir}/prometheus.yaml",
"--storage.tsdb.path=${::prometheus::localstorage}",
Expand Down
15 changes: 10 additions & 5 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@
# [*scrape_configs*]
# Prometheus scrape configs
#
# [*remote_read_configs*]
# Prometheus remote_read config to scrape prometheus 1.8+ instances
#
# [*alert_relabel_config*]
# Prometheus alert relabel config under alerting
#
Expand Down Expand Up @@ -144,6 +147,7 @@
Hash $global_config = $::prometheus::params::global_config,
Array $rule_files = $::prometheus::params::rule_files,
Array $scrape_configs = $::prometheus::params::scrape_configs,
Array $remote_read_configs = $::prometheus::params::remote_read_configs,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Datatypes \o/

$alerts = $::prometheus::params::alerts,
Array $alert_relabel_config = $::prometheus::params::alert_relabel_config,
Array $alertmanagers_config = $::prometheus::params::alertmanagers_config,
Expand All @@ -167,11 +171,12 @@
anchor {'prometheus_first': }
-> class { '::prometheus::install': }
-> class { '::prometheus::config':
global_config => $global_config,
rule_files => $rule_files,
scrape_configs => $scrape_configs,
purge => $purge_config_dir,
config_template => $config_template,
global_config => $global_config,
rule_files => $rule_files,
scrape_configs => $scrape_configs,
remote_read_configs => $remote_read_configs,
purge => $purge_config_dir,
config_template => $config_template,
}
-> class { '::prometheus::alerts':
location => $config_dir,
Expand Down
1 change: 1 addition & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@
$package_name = 'prometheus'
$rule_files = [ "${config_dir}/alert.rules" ]
$scrape_configs = [ { 'job_name'=> 'prometheus', 'scrape_interval'=> '10s', 'scrape_timeout'=> '10s', 'static_configs'=> [ { 'targets'=> [ 'localhost:9090' ], 'labels'=> { 'alias'=> 'Prometheus'} } ] } ]
$remote_read_configs = []
$shared_dir = '/usr/local/share/prometheus'
$statsd_exporter_download_extension = 'tar.gz'
$statsd_exporter_download_url_base = 'https://github.com/prometheus/statsd_exporter/releases'
Expand Down
2 changes: 1 addition & 1 deletion spec/classes/prometheus_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@
'owner' => 'prometheus',
'group' => 'prometheus',
'mode' => '0660',
'content' => File.read(fixtures('files', 'prometheus.yaml'))
'content' => File.read(fixtures('files', "prometheus#{prom_major}.yaml"))
).that_notifies('Class[prometheus::service_reload]')
}

Expand Down
21 changes: 21 additions & 0 deletions spec/fixtures/files/prometheus2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
global:
scrape_interval: 15s
evaluation_interval: 15s
external_labels:
monitor: master
rule_files:
- "/etc/prometheus/alert.rules"
scrape_configs:
- job_name: prometheus
scrape_interval: 10s
scrape_timeout: 10s
static_configs:
- targets:
- localhost:9090
labels:
alias: Prometheus
alerting:
alert_relabel_configs: []
alertmanagers: []
remote_read: []
10 changes: 8 additions & 2 deletions templates/prometheus.yaml.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@
<% global_config = scope.lookupvar('::prometheus::global_config') -%>
<% rule_files = scope.lookupvar('::prometheus::rule_files') -%>
<% scrape_configs = scope.lookupvar('::prometheus::scrape_configs') -%>
<% remote_read_configs = scope.lookupvar('::prometheus::remote_read_configs') -%>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what happens when we get an empty array here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it ends up in the config as "remote_read": [] and prometheus just ignores it

<% full_config = {
'global'=>global_config,
'rule_files'=>rule_files,
'scrape_configs'=>scrape_configs,
'alerting'=>{
'alert_relabel_configs'=>scope.lookupvar('::prometheus::alert_relabel_config'),
'alertmanagers'=>scope.lookupvar('::prometheus::alertmanagers_config'),
}
} -%>
},
}
if @prometheus_v2
# this variable has to be absent on 1.X, so we filter using the helper variable
full_config['remote_read'] = remote_read_configs
end
-%>
<%= full_config.to_yaml(options = {:line_width => -1}).gsub(/source_labels: ".+?"/) { |x| x.gsub('"', '') } -%>