nixos/prometheus: abstract over optional option creation

This commit is contained in:
Bas van Dijk 2019-04-18 11:39:38 +02:00
parent 55ef5d4246
commit 285fd3c05a

View File

@ -120,41 +120,37 @@ let
map (filterAttrsListRecursive pred) x
else x;
mkDefOpt = type : defaultStr : description : mkOpt type (description + ''
Defaults to <literal>${defaultStr}</literal> in prometheus
when set to <literal>null</literal>.
'');
mkOpt = type : description : mkOption {
type = types.nullOr type;
default = null;
inherit description;
};
promTypes.globalConfig = types.submodule {
options = {
scrape_interval = mkOption {
type = types.nullOr types.str;
default = null;
description = ''
How frequently to scrape targets by default.
'';
};
scrape_interval = mkDefOpt types.str "1m" ''
How frequently to scrape targets by default.
'';
scrape_timeout = mkOption {
type = types.nullOr types.str;
default = null;
description = ''
How long until a scrape request times out.
'';
};
scrape_timeout = mkDefOpt types.str "10s" ''
How long until a scrape request times out.
'';
evaluation_interval = mkOption {
type = types.nullOr types.str;
default = null;
description = ''
How frequently to evaluate rules by default.
'';
};
evaluation_interval = mkDefOpt types.str "1m" ''
How frequently to evaluate rules by default.
'';
external_labels = mkOption {
type = types.nullOr (types.attrsOf types.str);
description = ''
The labels to add to any time series or alerts when
communicating with external systems (federation, remote
storage, Alertmanager).
'';
default = null;
};
external_labels = mkOpt (types.attrsOf types.str) ''
The labels to add to any time series or alerts when
communicating with external systems (federation, remote
storage, Alertmanager).
'';
};
};
@ -166,137 +162,94 @@ let
The job name assigned to scraped metrics by default.
'';
};
scrape_interval = mkOption {
type = types.nullOr types.str;
default = null;
description = ''
How frequently to scrape targets from this job. Defaults to the
globally configured default.
'';
};
scrape_timeout = mkOption {
type = types.nullOr types.str;
default = null;
description = ''
Per-target timeout when scraping this job. Defaults to the
globally configured default.
'';
};
metrics_path = mkOption {
type = types.nullOr types.str;
default = null;
description = ''
The HTTP resource path on which to fetch metrics from targets.
'';
};
honor_labels = mkOption {
type = types.nullOr types.bool;
default = null;
description = ''
Controls how Prometheus handles conflicts between labels
that are already present in scraped data and labels that
Prometheus would attach server-side ("job" and "instance"
labels, manually configured target labels, and labels
generated by service discovery implementations).
scrape_interval = mkOpt types.str ''
How frequently to scrape targets from this job. Defaults to the
globally configured default.
'';
If honor_labels is set to "true", label conflicts are
resolved by keeping label values from the scraped data and
ignoring the conflicting server-side labels.
scrape_timeout = mkOpt types.str ''
Per-target timeout when scraping this job. Defaults to the
globally configured default.
'';
If honor_labels is set to "false", label conflicts are
resolved by renaming conflicting labels in the scraped data
to "exported_&lt;original-label&gt;" (for example
"exported_instance", "exported_job") and then attaching
server-side labels. This is useful for use cases such as
federation, where all labels specified in the target should
be preserved.
'';
};
scheme = mkOption {
type = types.nullOr (types.enum ["http" "https"]);
default = null;
description = ''
The URL scheme with which to fetch metrics from targets.
'';
};
params = mkOption {
type = types.nullOr (types.attrsOf (types.listOf types.str));
default = null;
description = ''
Optional HTTP URL parameters.
'';
};
basic_auth = mkOption {
type = types.nullOr (types.submodule {
options = {
username = mkOption {
type = types.str;
description = ''
HTTP username
'';
};
password = mkOption {
type = types.str;
description = ''
HTTP password
'';
};
metrics_path = mkDefOpt types.str "/metrics" ''
The HTTP resource path on which to fetch metrics from targets.
'';
honor_labels = mkDefOpt types.bool "false" ''
Controls how Prometheus handles conflicts between labels
that are already present in scraped data and labels that
Prometheus would attach server-side ("job" and "instance"
labels, manually configured target labels, and labels
generated by service discovery implementations).
If honor_labels is set to "true", label conflicts are
resolved by keeping label values from the scraped data and
ignoring the conflicting server-side labels.
If honor_labels is set to "false", label conflicts are
resolved by renaming conflicting labels in the scraped data
to "exported_&lt;original-label&gt;" (for example
"exported_instance", "exported_job") and then attaching
server-side labels. This is useful for use cases such as
federation, where all labels specified in the target should
be preserved.
'';
scheme = mkDefOpt (types.enum ["http" "https"]) "http" ''
The URL scheme with which to fetch metrics from targets.
'';
params = mkOpt (types.attrsOf (types.listOf types.str)) ''
Optional HTTP URL parameters.
'';
basic_auth = mkOpt (types.submodule {
options = {
username = mkOption {
type = types.str;
description = ''
HTTP username
'';
};
});
default = null;
description = ''
Optional http login credentials for metrics scraping.
'';
};
tls_config = mkOption {
type = types.nullOr promTypes.tls_config;
default = null;
description = ''
Configures the scrape request's TLS settings.
'';
};
dns_sd_configs = mkOption {
type = types.nullOr (types.listOf promTypes.dns_sd_config);
default = null;
description = ''
List of DNS service discovery configurations.
'';
};
consul_sd_configs = mkOption {
type = types.nullOr (types.listOf promTypes.consul_sd_config);
default = null;
description = ''
List of Consul service discovery configurations.
'';
};
file_sd_configs = mkOption {
type = types.nullOr (types.listOf promTypes.file_sd_config);
default = null;
description = ''
List of file service discovery configurations.
'';
};
static_configs = mkOption {
type = types.nullOr (types.listOf promTypes.static_config);
default = null;
description = ''
List of labeled target groups for this job.
'';
};
ec2_sd_configs = mkOption {
type = types.nullOr (types.listOf promTypes.ec2_sd_config);
default = null;
description = ''
List of EC2 service discovery configurations.
'';
};
relabel_configs = mkOption {
type = types.nullOr (types.listOf promTypes.relabel_config);
default = null;
description = ''
List of relabel configurations.
'';
};
password = mkOption {
type = types.str;
description = ''
HTTP password
'';
};
};
}) ''
Optional http login credentials for metrics scraping.
'';
tls_config = mkOpt promTypes.tls_config ''
Configures the scrape request's TLS settings.
'';
dns_sd_configs = mkOpt (types.listOf promTypes.dns_sd_config) ''
List of DNS service discovery configurations.
'';
consul_sd_configs = mkOpt (types.listOf promTypes.consul_sd_config) ''
List of Consul service discovery configurations.
'';
file_sd_configs = mkOpt (types.listOf promTypes.file_sd_config) ''
List of file service discovery configurations.
'';
static_configs = mkOpt (types.listOf promTypes.static_config) ''
List of labeled target groups for this job.
'';
ec2_sd_configs = mkOpt (types.listOf promTypes.ec2_sd_config) ''
List of EC2 service discovery configurations.
'';
relabel_configs = mkOpt (types.listOf promTypes.relabel_config) ''
List of relabel configurations.
'';
};
};
@ -326,66 +279,41 @@ let
The AWS Region.
'';
};
endpoint = mkOption {
type = types.nullOr types.str;
default = null;
description = ''
Custom endpoint to be used.
'';
};
access_key = mkOption {
type = types.nullOr types.str;
default = null;
description = ''
The AWS API key id. If blank, the environment variable
<literal>AWS_ACCESS_KEY_ID</literal> is used.
'';
};
secret_key = mkOption {
type = types.nullOr types.str;
default = null;
description = ''
The AWS API key secret. If blank, the environment variable
<literal>AWS_SECRET_ACCESS_KEY</literal> is used.
'';
};
profile = mkOption {
type = types.nullOr types.str;
default = null;
description = ''
Named AWS profile used to connect to the API.
'';
};
role_arn = mkOption {
type = types.nullOr types.str;
default = null;
description = ''
AWS Role ARN, an alternative to using AWS API keys.
'';
};
refresh_interval = mkOption {
type = types.nullOr types.str;
default = null;
description = ''
Refresh interval to re-read the instance list.
'';
};
port = mkOption {
type = types.nullOr types.int;
default = null;
description = ''
The port to scrape metrics from. If using the public IP
address, this must instead be specified in the relabeling
rule.
'';
};
filters = mkOption {
type = types.nullOr (types.listOf promTypes.filter);
default = null;
description = ''
Filters can be used optionally to filter the instance list by other criteria.
'';
};
endpoint = mkOpt types.str ''
Custom endpoint to be used.
'';
access_key = mkOpt types.str ''
The AWS API key id. If blank, the environment variable
<literal>AWS_ACCESS_KEY_ID</literal> is used.
'';
secret_key = mkOpt types.str ''
The AWS API key secret. If blank, the environment variable
<literal>AWS_SECRET_ACCESS_KEY</literal> is used.
'';
profile = mkOpt types.str ''
Named AWS profile used to connect to the API.
'';
role_arn = mkOpt types.str ''
AWS Role ARN, an alternative to using AWS API keys.
'';
refresh_interval = mkDefOpt types.str "60s" ''
Refresh interval to re-read the instance list.
'';
port = mkDefOpt types.int "80" ''
The port to scrape metrics from. If using the public IP
address, this must instead be specified in the relabeling
rule.
'';
filters = mkOpt (types.listOf promTypes.filter) ''
Filters can be used optionally to filter the instance list by other criteria.
'';
};
};
@ -398,6 +326,7 @@ let
for the available filters.
'';
};
value = mkOption {
type = types.listOf types.str;
default = [];
@ -416,58 +345,36 @@ let
A list of DNS SRV record names to be queried.
'';
};
refresh_interval = mkOption {
type = types.nullOr types.str;
default = null;
description = ''
The time after which the provided names are refreshed.
'';
};
refresh_interval = mkDefOpt types.str "30s" ''
The time after which the provided names are refreshed.
'';
};
};
promTypes.consul_sd_config = types.submodule {
options = {
server = mkOption {
type = types.nullOr types.str;
default = null;
description = "Consul server to query.";
};
token = mkOption {
type = types.nullOr types.str;
description = "Consul token";
};
datacenter = mkOption {
type = types.nullOr types.str;
description = "Consul datacenter";
};
scheme = mkOption {
type = types.nullOr types.str;
description = "Consul scheme";
};
username = mkOption {
type = types.nullOr types.str;
description = "Consul username";
};
password = mkOption {
type = types.nullOr types.str;
description = "Consul password";
};
server = mkDefOpt types.str "localhost:8500" ''
Consul server to query.
'';
services = mkOption {
type = types.nullOr (types.listOf types.str);
default = null;
description = ''
A list of services for which targets are retrieved.
'';
};
tag_separator = mkOption {
type = types.nullOr types.str;
default = null;
description = ''
The string by which Consul tags are joined into the tag label.
'';
};
token = mkOpt types.str "Consul token";
datacenter = mkOpt types.str "Consul datacenter";
scheme = mkDefOpt types.str "http" "Consul scheme";
username = mkOpt types.str "Consul username";
password = mkOpt types.str "Consul password";
services = mkOpt (types.listOf types.str) ''
A list of services for which targets are retrieved.
'';
tag_separator = mkDefOpt types.str "," ''
The string by which Consul tags are joined into the tag label.
'';
};
};
@ -481,105 +388,68 @@ let
and formats.
'';
};
refresh_interval = mkOption {
type = types.nullOr types.str;
default = null;
description = ''
Refresh interval to re-read the files.
'';
};
refresh_interval = mkDefOpt types.str "5m" ''
Refresh interval to re-read the files.
'';
};
};
promTypes.relabel_config = types.submodule {
options = {
source_labels = mkOption {
type = types.nullOr (types.listOf str);
default = null;
description = ''
The source labels select values from existing labels. Their content
is concatenated using the configured separator and matched against
the configured regular expression.
'';
};
separator = mkOption {
type = types.nullOr types.str;
default = null;
description = ''
Separator placed between concatenated source label values.
'';
};
target_label = mkOption {
type = types.nullOr types.str;
default = null;
description = ''
Label to which the resulting value is written in a replace action.
It is mandatory for replace actions.
'';
};
regex = mkOption {
type = types.nullOr types.str;
default = null;
description = ''
Regular expression against which the extracted value is matched.
'';
};
replacement = mkOption {
type = types.nullOr types.str;
default = null;
description = ''
Replacement value against which a regex replace is performed if the
regular expression matches.
'';
};
action = mkOption {
type = types.nullOr (types.enum ["replace" "keep" "drop"]);
default = null;
description = ''
Action to perform based on regex matching.
'';
};
source_labels = mkOpt (types.listOf types.str) ''
The source labels select values from existing labels. Their content
is concatenated using the configured separator and matched against
the configured regular expression.
'';
separator = mkDefOpt types.str ";" ''
Separator placed between concatenated source label values.
'';
target_label = mkOpt types.str ''
Label to which the resulting value is written in a replace action.
It is mandatory for replace actions.
'';
regex = mkDefOpt types.str "(.*)" ''
Regular expression against which the extracted value is matched.
'';
replacement = mkDefOpt types.str "$1" ''
Replacement value against which a regex replace is performed if the
regular expression matches.
'';
action = mkDefOpt (types.enum ["replace" "keep" "drop"]) "replace" ''
Action to perform based on regex matching.
'';
};
};
promTypes.tls_config = types.submodule {
options = {
ca_file = mkOption {
type = types.nullOr types.str;
default = null;
description = ''
CA certificate to validate API server certificate with.
'';
};
cert_file = mkOption {
type = types.nullOr types.str;
default = null;
description = ''
Certificate file for client cert authentication to the server.
'';
};
key_file = mkOption {
type = types.nullOr types.str;
default = null;
description = ''
Key file for client cert authentication to the server.
'';
};
server_name = mkOption {
type = types.nullOr types.str;
default = null;
description = ''
ServerName extension to indicate the name of the server.
http://tools.ietf.org/html/rfc4366#section-3.1
'';
};
insecure_skip_verify = mkOption {
type = types.bool;
default = false;
description = ''
Disable validation of the server certificate.
'';
};
ca_file = mkOpt types.str ''
CA certificate to validate API server certificate with.
'';
cert_file = mkOpt types.str ''
Certificate file for client cert authentication to the server.
'';
key_file = mkOpt types.str ''
Key file for client cert authentication to the server.
'';
server_name = mkOpt types.str ''
ServerName extension to indicate the name of the server.
http://tools.ietf.org/html/rfc4366#section-3.1
'';
insecure_skip_verify = mkOpt types.bool ''
Disable validation of the server certificate.
'';
};
};