Skip to content

Commit

Permalink
Add prom command line args and validation
Browse files Browse the repository at this point in the history
  • Loading branch information
Dustin Hooten committed Oct 23, 2019
1 parent 8f8da3c commit 303cb6a
Show file tree
Hide file tree
Showing 16 changed files with 659 additions and 61 deletions.
174 changes: 138 additions & 36 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -7,50 +7,152 @@
$max_open_files = $prometheus::max_open_files

if $prometheus::server::init_style {
if( versioncmp($prometheus::server::version, '2.0.0') < 0 ){
# helper variable indicating prometheus version, so we can use on this information in the template
$prometheus_v2 = false
$prometheus_v2 = versioncmp($prometheus::server::version, '2.0.0') >= 0

# Validation
$invalid_args = if $prometheus_v2 {
{
'alertmanager.url' => $prometheus::alertmanager_url,
'query.staleness-delta' => $prometheus::query_staleness_delta,
'web.telemetry-path' => $prometheus::web_telemetry_path,
'web.enable-remote-shutdown' => $prometheus::web_enable_remote_shutdown,
}
} else {
{
'web.enable-lifecycle' => $prometheus::web_enable_lifecycle,
'web.enable-admin-api' => $prometheus::web_enable_admin_api,
'web.page-title' => $prometheus::web_page_title,
'web.cors.origin' => $prometheus::web_cors_origin,
'storage.tsdb.retention.size' => $prometheus::storage_retention_size,
'storage.tsdb.no-lockfile' => $prometheus::storage_no_lockfile,
'storage.tsdb.allow-overlapping-blocks' => $prometheus::storage_allow_overlapping_blocks,
'storage.tsdb.wal-compression' => $prometheus::storage_wal_compression,
'storage.remote.flush-deadline' => $prometheus::storage_flush_deadline,
'storage.remote.read-concurrent-limit' => $prometheus::storage_read_concurrent_limit,
'storage.remote.read-max-bytes-in-frame' => $prometheus::storage_read_max_bytes_in_frame,
'rules.alert.for-outage-tolerance' => $prometheus::alert_for_outage_tolerance,
'rules.alert.for-grace-period' => $prometheus::alert_for_grace_period,
'rules.alert.resend-delay' => $prometheus::alert_resend_delay,
'query.lookback-delta' => $prometheus::query_lookback_delta,
'log.format' => $prometheus::log_format,
}
}

$invalid_options = $invalid_args
.filter |$key,$value| { $value or $key in $prometheus::server::extra_options}
.map |$key,$value| { $key }

unless empty($invalid_options) {
$error_message = if $prometheus_v2 {
'no longer available in prometheus v2'
} else {
'require prometheus v2; consider upgrading'
}
$error = "invalid command line arguments: [${join($invalid_options, ', ')}] ${error_message}"
fail($error)
}
unless $prometheus_v2 {
if $prometheus::server::remote_read_configs != [] {
fail('remote_read_configs requires prometheus 2.X')
fail('remote_read_configs requires prometheus v2')
}
if $prometheus::server::remote_write_configs != [] {
fail('remote_write_configs requires prometheus 2.X')
}
$_daemon_flags = [
'-log.format logger:stdout',
"-config.file=${prometheus::server::config_dir}/${prometheus::server::configname}",
"-storage.local.path=${prometheus::server::localstorage}",
"-storage.local.retention=${prometheus::server::storage_retention}",
"-web.console.templates=${prometheus::shared_dir}/consoles",
"-web.console.libraries=${prometheus::shared_dir}/console_libraries",
]
if $prometheus::server::extra_options {
$daemon_flags = $_daemon_flags + $prometheus::server::extra_options
} else {
$daemon_flags = $_daemon_flags
fail('remote_write_configs requires prometheus v2')
}
}
if ($prometheus_v2 and $prometheus::log_level == 'fatal') {
fail('fatal is no longer a valid value in prometheus v2')
}
if versioncmp($prometheus::server::version, '2.7.0') < 0 and $prometheus::storage_retention_size {
fail('storage.tsdb.retention.size is only available starting in prometheus 2.7')
}

# Formatting
$v1_log_format = if ($prometheus::log_format == 'json') { '?json=true' } else { undef }
$web_page_title = if ($prometheus::web_page_title) { "\"${prometheus::web_page_title}\"" } else { undef }
$web_cors_origin = if ($prometheus::web_cors_origin) { "\"${prometheus::web_cors_origin}\"" } else { undef }
$rtntn_suffix = if versioncmp($prometheus::server::version, '2.8.0') >= 0 { '.time' } else { undef }
$command_line_flags = if $prometheus_v2 {
{
'config.file' => "${prometheus::server::config_dir}/${prometheus::server::configname}",
'web.listen-address' => $prometheus::web_listen_address,
'web.read-timeout' => $prometheus::web_read_timeout,
'web.max-connections' => $prometheus::web_max_connections,
'web.external-url' => $prometheus::server::external_url,
'web.route-prefix' => $prometheus::web_route_prefix,
'web.user-assets' => $prometheus::web_user_assets,
'web.enable-lifecycle' => $prometheus::web_enable_lifecycle,
'web.enable-admin-api' => $prometheus::web_enable_admin_api,
'web.console.templates' => "${prometheus::shared_dir}/consoles",
'web.console.libraries' => "${prometheus::shared_dir}/console_libraries",
'web.page-title' => $web_page_title,
'web.cors.origin' => $web_cors_origin,
'storage.tsdb.path' => $prometheus::server::localstorage,
"storage.tsdb.retention${rtntn_suffix}" => $prometheus::server::storage_retention,
'storage.tsdb.retention.size' => $prometheus::storage_retention_size,
'storage.tsdb.no-lockfile' => $prometheus::storage_no_lockfile,
'storage.tsdb.allow-overlapping-blocks' => $prometheus::storage_allow_overlapping_blocks,
'storage.tsdb.wal-compression' => $prometheus::storage_wal_compression,
'storage.remote.flush-deadline' => $prometheus::storage_flush_deadline,
'storage.remote.read-sample-limit' => $prometheus::storage_read_sample_limit,
'storage.remote.read-concurrent-limit' => $prometheus::storage_read_concurrent_limit,
'storage.remote.read-max-bytes-in-frame' => $prometheus::storage_read_max_bytes_in_frame,
'rules.alert.for-outage-tolerance' => $prometheus::alert_for_outage_tolerance,
'rules.alert.for-grace-period' => $prometheus::alert_for_grace_period,
'rules.alert.resend-delay' => $prometheus::alert_resend_delay,
'alertmanager.notification-queue-capacity' => $prometheus::alertmanager_notification_queue_capacity,
'alertmanager.timeout' => $prometheus::alertmanager_timeout,
'query.lookback-delta' => $prometheus::query_lookback_delta,
'query.timeout' => $prometheus::query_timeout,
'query.max-concurrency' => $prometheus::query_max_concurrency,
'query.max-samples' => $prometheus::query_max_samples,
'log.level' => $prometheus::log_level,
'log.format' => $prometheus::log_format
}
} else {
# helper variable indicating prometheus version, so we can use on this information in the template
$prometheus_v2 = true
$daemon_flags_basic = [
"--config.file=${prometheus::server::config_dir}/${prometheus::server::configname}",
"--storage.tsdb.path=${prometheus::server::localstorage}",
"--storage.tsdb.retention=${prometheus::server::storage_retention}",
"--web.console.templates=${prometheus::server::shared_dir}/consoles",
"--web.console.libraries=${prometheus::server::shared_dir}/console_libraries",
]

if $prometheus::server::external_url {
$_daemon_flags = $daemon_flags_basic + "--web.external-url=${prometheus::server::external_url}"
} else {
$_daemon_flags = $daemon_flags_basic
{
'config.file' => "${prometheus::server::config_dir}/${prometheus::server::configname}",
'web.listen-address' => $prometheus::web_listen_address,
'web.read-timeout' => $prometheus::web_read_timeout,
'web.max-connections' => $prometheus::web_max_connections,
'web.external-url' => $prometheus::server::external_url,
'web.route-prefix' => $prometheus::web_route_prefix,
'web.user-assets' => $prometheus::web_user_assets,
'web.console.templates' => "${prometheus::shared_dir}/consoles",
'web.console.libraries' => "${prometheus::shared_dir}/console_libraries",
'web.telemetry-path' => $prometheus::web_telemetry_path,
'web.enable-remote-shutdown' => $prometheus::web_enable_remote_shutdown,
'storage.local.path' => $prometheus::server::localstorage,
'storage.local.retention' => $prometheus::server::storage_retention,
'alertmanager.notification-queue-capacity' => $prometheus::alertmanager_notification_queue_capacity,
'alertmanager.timeout' => $prometheus::alertmanager_timeout,
'alertmanager.url' => $prometheus::alertmanager_url,
'query.timeout' => $prometheus::query_timeout,
'query.max-concurrency' => $prometheus::query_max_concurrency,
'query.staleness-delta' => $prometheus::query_staleness_delta,
'log.level' => $prometheus::log_level,
'log.format' => 'logger:stdout',
}
if $prometheus::server::extra_options {
$daemon_flags = $_daemon_flags + $prometheus::server::extra_options
} else {
$daemon_flags = $_daemon_flags
}

$flag_prefix = if ($prometheus_v2) { '--' } else { '-' }
$extra_options = [$prometheus::server::extra_options].filter |$opts| { $opts and $opts != '' }
$flags = $command_line_flags
.filter |$flag, $value| {
$value ? {
Boolean => $value,
String => $value != '',
Undef => false,
default => fail("Illegal value for ${flag} parameter")
}
}
.map |$flag, $value| {
$value ? {
Boolean => "${flag_prefix}${flag}",
String => "${flag_prefix}${flag}=${value}",
default => fail("Illegal value for ${flag} parameter")
}
}
$daemon_flags = $flags + $extra_options

# the vast majority of files here are init-files
# so any change there should trigger a full service restart
Expand Down
Loading

0 comments on commit 303cb6a

Please sign in to comment.