Skip to content

Commit

Permalink
Merge pull request #109 from wywy/master
Browse files Browse the repository at this point in the history
add support for remote_read
  • Loading branch information
bastelfreak authored Nov 15, 2017
2 parents bed7d29 + 0a4adf2 commit 0719789
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 8 deletions.
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,
$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
File renamed without changes.
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') -%>
<% 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('"', '') } -%>

0 comments on commit 0719789

Please sign in to comment.