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 15, 2019
1 parent 5d0ad12 commit a62d187
Show file tree
Hide file tree
Showing 15 changed files with 589 additions and 60 deletions.
162 changes: 126 additions & 36 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -7,50 +7,140 @@
$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
}
}

$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')
}

# 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 }
$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.time' => $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${v1_log_format}\""
}
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 }
.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
186 changes: 180 additions & 6 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,148 @@
# [*usershell*]
# if requested, we create a user for prometheus or the exporters. The default
# shell is nologin. It can be overwritten to any valid path.
#
# CLI ==========================================================
# The following parameters represent system parameters invoked as command-line flags
# during prometheus startup. Defaults are handled by Prometheus.
#
# [*web_listen_address*]
# --web.listen-address="0.0.0.0:9090"
# Address to listen on for UI, API, and telemetry.
#
# [*web_read_timeout*]
# --web.read-timeout=5m
# Maximum duration before timing out read of the request, and closing idle connections.
#
# [*web_max_connections*]
# --web.max-connections=512
# Maximum number of simultaneous connections.
#
# [*web_route_prefix*]
# --web.route-prefix=<path>
# Prefix for the internal routes of web endpoints. Defaults to path of --web.external-url.
#
# [*web_user_assets*]
# --web.user-assets=<path>
# Path to static asset directory, available at /user.
#
# [*web_enable_lifecycle*]
# --web.enable-lifecycle
# Enable shutdown and reload via HTTP request
#
# [*web_enable_admin_api*]
# --web.enable-admin-api
# Enable API endpoints for admin control actions.
#
# [*web_page_title*]
# --web.page-title="Prometheus Time Series Collection and Processing Server"
# Document title of Prometheus instance.
#
# [*web_cors_origin*]
# --web.cors.origin=".*"
# Regex for CORS origin. It is fully anchored. Example: 'https?://(domain1|domain2)\.com'
#
# [*storage_retention_size*]
# --storage.tsdb.retention.size=STORAGE.TSDB.RETENTION.SIZE
# [EXPERIMENTAL] Maximum number of bytes that can be stored for blocks. Units supported: KB,
# MB, GB, TB, PB. This flag is experimental and can be changed in future releases.
#
# [*storage_no_lockfile*]
# --storage.tsdb.no-lockfile
# Do not create lockfile in data directory.
#
# [*storage_allow_overlapping_blocks*]
# --storage.tsdb.allow-overlapping-blocks
# [EXPERIMENTAL] Allow overlapping blocks, which in turn enables vertical compaction and
# vertical query merge.
#
# [*storage_wal_compression*]
# --storage.tsdb.wal-compression
# Compress the tsdb WAL.
#
# [*storage_flush_deadline*]
# --storage.remote.flush-deadline=<duration>
# How long to wait flushing sample on shutdown or config reload.
#
# [*storage_read_sample_limit*]
# --storage.remote.read-sample-limit=5e7
# Maximum overall number of samples to return via the remote read interface, in a single
# query. 0 means no limit. This limit is ignored for streamed response types.
#
# [*storage_read_concurrent_limit*]
# --storage.remote.read-concurrent-limit=10
# Maximum number of concurrent remote read calls. 0 means no limit.
#
# [*storage_read_max_bytes_in_frame*]
# --storage.remote.read-max-bytes-in-frame=1048576
# Maximum number of bytes in a single frame for streaming remote read response types before
# marshalling. Note that client might have limit on frame size as well. 1MB as recommended
# by protobuf by default.
#
# [*alert_for_outage_tolerance*]
# --rules.alert.for-outage-tolerance=1h
# Max time to tolerate prometheus outage for restoring "for" state of alert.
#
# [*alert_for_grace_period*]
# --rules.alert.for-grace-period=10m
# Minimum duration between alert and restored "for" state. This is maintained only for
# alerts with configured "for" time greater than grace period.
#
# [*alert_resend_delay*]
# --rules.alert.resend-delay=1m
# Minimum amount of time to wait before resending an alert to Alertmanager.
#
# [*alertmanager_notification_queue_capacity*]
# --alertmanager.notification-queue-capacity=10000
# The capacity of the queue for pending Alertmanager notifications.
#
# [*alertmanager_timeout*]
# --alertmanager.timeout=10s
# Timeout for sending alerts to Alertmanager.
#
# [*alertmanager_url*]
# [REMOVED, v1 ONLY] -alertmanager.url
# Comma-separated list of Alertmanager URLs to send notifications to.
# In Prometheus v2, Alertmanager must be discovered via service discovery
#
# [*query_lookback_delta*]
# --query.lookback-delta=5m
# The maximum lookback duration for retrieving metrics during expression evaluations.
#
# [*query_timeout*]
# --query.timeout=2m
# Maximum time a query may take before being aborted.
#
# [*query_max_concurrency*]
# --query.max-concurrency=20
# Maximum number of queries executed concurrently.
#
# [*query_max_samples*]
# --query.max-samples=50000000
# Maximum number of samples a single query can load into memory. Note that queries will fail
# if they try to load more samples than this into memory, so this also limits the number of
# samples a query can return.
#
# [*query_staleness_delta*]
# [REMOVED, v1 ONLY] -query.staleness-delta=5m0s
# Staleness delta allowance during expression evaluations.
#
# [*web_telemetry_path*]
# [REMOVED, v1 ONLY] -web.telemetry-path="/metrics"
# Path under which to expose metrics
#
# [*web_enable_remote_shutdown*]
# [REMOVED, v1 ONLY] -web.enable-remote-shutdown=false
# Enable remote service shutdown.
#
# [*log_level*]
# --log.level=info
# Only log messages with the given severity or above. One of: [debug, info, warn, error]
# Value of 'fatal' is also allowed in prometheus v1
#
# [*log_format*]
# --log.format=logfmt
# Output format of log messages. One of: [logfmt, json]
#
# Actions:
#
Expand Down Expand Up @@ -198,13 +340,45 @@
Optional[String[1]] $extract_command,
Boolean $manage_config,
Stdlib::Absolutepath $usershell,
Hash $extra_alerts = {},
Hash $config_hash = {},
Hash $config_defaults = {},
String $os = downcase($facts['kernel']),
Optional[String] $web_listen_address = undef,
Optional[String] $web_read_timeout = undef,
Optional[String] $web_max_connections = undef,
Optional[String] $web_route_prefix = undef,
Optional[String] $web_user_assets = undef,
Optional[Boolean] $web_enable_lifecycle = undef,
Optional[Boolean] $web_enable_admin_api = undef,
Optional[String] $web_page_title = undef,
Optional[String] $web_cors_origin = undef,
Optional[String] $storage_retention_size = undef,
Optional[Boolean] $storage_no_lockfile = undef,
Optional[Boolean] $storage_allow_overlapping_blocks = undef,
Optional[Boolean] $storage_wal_compression = undef,
Optional[String] $storage_flush_deadline = undef,
Optional[String] $storage_read_sample_limit = undef,
Optional[String] $storage_read_concurrent_limit = undef,
Optional[String] $storage_read_max_bytes_in_frame = undef,
Optional[String] $alert_for_outage_tolerance = undef,
Optional[String] $alert_for_grace_period = undef,
Optional[String] $alert_resend_delay = undef,
Optional[String] $alertmanager_notification_queue_capacity = undef,
Optional[String] $alertmanager_timeout = undef,
Optional[String] $alertmanager_url = undef, #v1 only
Optional[String] $query_lookback_delta = undef,
Optional[String] $query_timeout = undef,
Optional[String] $query_max_concurrency = undef,
Optional[String] $query_max_samples = undef,
Optional[String] $query_staleness_delta = undef, #v1 only
Optional[String] $web_telemetry_path = undef, #v1 only
Optional[Boolean] $web_enable_remote_shutdown = undef, #v1 only
Optional[Enum['debug', 'info', 'warn', 'error', 'fatal']] $log_level = undef,
Optional[Enum['logfmt', 'json']] $log_format = undef,
Hash $extra_alerts = {},
Hash $config_hash = {},
Hash $config_defaults = {},
String $os = downcase($facts['kernel']),
Optional[Variant[Stdlib::HTTPUrl, Stdlib::Unixpath, String[1]]] $external_url = undef,
Optional[Array[Hash[String[1], Any]]] $collect_scrape_jobs = [],
Optional[Integer] $max_open_files = undef,
Optional[Array[Hash[String[1], Any]]] $collect_scrape_jobs = [],
Optional[Integer] $max_open_files = undef,
) {

case $arch {
Expand Down
Loading

0 comments on commit a62d187

Please sign in to comment.