nixos/prometheus: set optional attributes to type types.nullOr

This makes sure that when a user hasn't set a Prometheus option it
won't show up in the prometheus.yml configuration file. This results
in smaller and easier to understand configuration files.
This commit is contained in:
Bas van Dijk 2019-04-17 14:49:09 +02:00
parent 57e5b75f9c
commit 55ef5d4246

View File

@ -105,7 +105,7 @@ let
] ++ ] ++
optional (cfg2.webExternalUrl != null) "--web.external-url=${cfg2.webExternalUrl}"; optional (cfg2.webExternalUrl != null) "--web.external-url=${cfg2.webExternalUrl}";
filterValidPrometheus = filterAttrsListRecursive (n: v: !(n == "_module" || v == null || v == [] || v == {})); filterValidPrometheus = filterAttrsListRecursive (n: v: !(n == "_module" || v == null));
filterAttrsListRecursive = pred: x: filterAttrsListRecursive = pred: x:
if isAttrs x then if isAttrs x then
listToAttrs ( listToAttrs (
@ -123,37 +123,37 @@ let
promTypes.globalConfig = types.submodule { promTypes.globalConfig = types.submodule {
options = { options = {
scrape_interval = mkOption { scrape_interval = mkOption {
type = types.str; type = types.nullOr types.str;
default = "1m"; default = null;
description = '' description = ''
How frequently to scrape targets by default. How frequently to scrape targets by default.
''; '';
}; };
scrape_timeout = mkOption { scrape_timeout = mkOption {
type = types.str; type = types.nullOr types.str;
default = "10s"; default = null;
description = '' description = ''
How long until a scrape request times out. How long until a scrape request times out.
''; '';
}; };
evaluation_interval = mkOption { evaluation_interval = mkOption {
type = types.str; type = types.nullOr types.str;
default = "1m"; default = null;
description = '' description = ''
How frequently to evaluate rules by default. How frequently to evaluate rules by default.
''; '';
}; };
external_labels = mkOption { external_labels = mkOption {
type = types.attrsOf types.str; type = types.nullOr (types.attrsOf types.str);
description = '' description = ''
The labels to add to any time series or alerts when The labels to add to any time series or alerts when
communicating with external systems (federation, remote communicating with external systems (federation, remote
storage, Alertmanager). storage, Alertmanager).
''; '';
default = {}; default = null;
}; };
}; };
}; };
@ -183,15 +183,15 @@ let
''; '';
}; };
metrics_path = mkOption { metrics_path = mkOption {
type = types.str; type = types.nullOr types.str;
default = "/metrics"; default = null;
description = '' description = ''
The HTTP resource path on which to fetch metrics from targets. The HTTP resource path on which to fetch metrics from targets.
''; '';
}; };
honor_labels = mkOption { honor_labels = mkOption {
type = types.bool; type = types.nullOr types.bool;
default = false; default = null;
description = '' description = ''
Controls how Prometheus handles conflicts between labels Controls how Prometheus handles conflicts between labels
that are already present in scraped data and labels that that are already present in scraped data and labels that
@ -213,15 +213,15 @@ let
''; '';
}; };
scheme = mkOption { scheme = mkOption {
type = types.enum ["http" "https"]; type = types.nullOr (types.enum ["http" "https"]);
default = "http"; default = null;
description = '' description = ''
The URL scheme with which to fetch metrics from targets. The URL scheme with which to fetch metrics from targets.
''; '';
}; };
params = mkOption { params = mkOption {
type = types.attrsOf (types.listOf types.str); type = types.nullOr (types.attrsOf (types.listOf types.str));
default = {}; default = null;
description = '' description = ''
Optional HTTP URL parameters. Optional HTTP URL parameters.
''; '';
@ -256,43 +256,43 @@ let
''; '';
}; };
dns_sd_configs = mkOption { dns_sd_configs = mkOption {
type = types.listOf promTypes.dns_sd_config; type = types.nullOr (types.listOf promTypes.dns_sd_config);
default = []; default = null;
description = '' description = ''
List of DNS service discovery configurations. List of DNS service discovery configurations.
''; '';
}; };
consul_sd_configs = mkOption { consul_sd_configs = mkOption {
type = types.listOf promTypes.consul_sd_config; type = types.nullOr (types.listOf promTypes.consul_sd_config);
default = []; default = null;
description = '' description = ''
List of Consul service discovery configurations. List of Consul service discovery configurations.
''; '';
}; };
file_sd_configs = mkOption { file_sd_configs = mkOption {
type = types.listOf promTypes.file_sd_config; type = types.nullOr (types.listOf promTypes.file_sd_config);
default = []; default = null;
description = '' description = ''
List of file service discovery configurations. List of file service discovery configurations.
''; '';
}; };
static_configs = mkOption { static_configs = mkOption {
type = types.listOf promTypes.static_config; type = types.nullOr (types.listOf promTypes.static_config);
default = []; default = null;
description = '' description = ''
List of labeled target groups for this job. List of labeled target groups for this job.
''; '';
}; };
ec2_sd_configs = mkOption { ec2_sd_configs = mkOption {
type = types.listOf promTypes.ec2_sd_config; type = types.nullOr (types.listOf promTypes.ec2_sd_config);
default = []; default = null;
description = '' description = ''
List of EC2 service discovery configurations. List of EC2 service discovery configurations.
''; '';
}; };
relabel_configs = mkOption { relabel_configs = mkOption {
type = types.listOf promTypes.relabel_config; type = types.nullOr (types.listOf promTypes.relabel_config);
default = []; default = null;
description = '' description = ''
List of relabel configurations. List of relabel configurations.
''; '';
@ -371,8 +371,8 @@ let
''; '';
}; };
port = mkOption { port = mkOption {
type = types.int; type = types.nullOr types.int;
default = 80; default = null;
description = '' description = ''
The port to scrape metrics from. If using the public IP The port to scrape metrics from. If using the public IP
address, this must instead be specified in the relabeling address, this must instead be specified in the relabeling
@ -417,8 +417,8 @@ let
''; '';
}; };
refresh_interval = mkOption { refresh_interval = mkOption {
type = types.str; type = types.nullOr types.str;
default = "30s"; default = null;
description = '' description = ''
The time after which the provided names are refreshed. The time after which the provided names are refreshed.
''; '';
@ -429,7 +429,8 @@ let
promTypes.consul_sd_config = types.submodule { promTypes.consul_sd_config = types.submodule {
options = { options = {
server = mkOption { server = mkOption {
type = types.str; type = types.nullOr types.str;
default = null;
description = "Consul server to query."; description = "Consul server to query.";
}; };
token = mkOption { token = mkOption {
@ -454,14 +455,15 @@ let
}; };
services = mkOption { services = mkOption {
type = types.listOf types.str; type = types.nullOr (types.listOf types.str);
default = null;
description = '' description = ''
A list of services for which targets are retrieved. A list of services for which targets are retrieved.
''; '';
}; };
tag_separator = mkOption { tag_separator = mkOption {
type = types.str; type = types.nullOr types.str;
default = ","; default = null;
description = '' description = ''
The string by which Consul tags are joined into the tag label. The string by which Consul tags are joined into the tag label.
''; '';
@ -477,12 +479,11 @@ let
Patterns for files from which target groups are extracted. Refer Patterns for files from which target groups are extracted. Refer
to the Prometheus documentation for permitted filename patterns to the Prometheus documentation for permitted filename patterns
and formats. and formats.
''; '';
}; };
refresh_interval = mkOption { refresh_interval = mkOption {
type = types.str; type = types.nullOr types.str;
default = "30s"; default = null;
description = '' description = ''
Refresh interval to re-read the files. Refresh interval to re-read the files.
''; '';
@ -493,7 +494,7 @@ let
promTypes.relabel_config = types.submodule { promTypes.relabel_config = types.submodule {
options = { options = {
source_labels = mkOption { source_labels = mkOption {
type = with types; nullOr (listOf str); type = types.nullOr (types.listOf str);
default = null; default = null;
description = '' description = ''
The source labels select values from existing labels. Their content The source labels select values from existing labels. Their content
@ -502,8 +503,8 @@ let
''; '';
}; };
separator = mkOption { separator = mkOption {
type = types.str; type = types.nullOr types.str;
default = ";"; default = null;
description = '' description = ''
Separator placed between concatenated source label values. Separator placed between concatenated source label values.
''; '';
@ -517,23 +518,23 @@ let
''; '';
}; };
regex = mkOption { regex = mkOption {
type = types.str; type = types.nullOr types.str;
default = "(.*)"; default = null;
description = '' description = ''
Regular expression against which the extracted value is matched. Regular expression against which the extracted value is matched.
''; '';
}; };
replacement = mkOption { replacement = mkOption {
type = types.str; type = types.nullOr types.str;
default = "$1"; default = null;
description = '' description = ''
Replacement value against which a regex replace is performed if the Replacement value against which a regex replace is performed if the
regular expression matches. regular expression matches.
''; '';
}; };
action = mkOption { action = mkOption {
type = types.enum ["replace" "keep" "drop"]; type = types.nullOr (types.enum ["replace" "keep" "drop"]);
default = "replace"; default = null;
description = '' description = ''
Action to perform based on regex matching. Action to perform based on regex matching.
''; '';