nixos/prometheus: abstract over optional option creation
This commit is contained in:
parent
55ef5d4246
commit
285fd3c05a
|
@ -120,41 +120,37 @@ let
|
||||||
map (filterAttrsListRecursive pred) x
|
map (filterAttrsListRecursive pred) x
|
||||||
else 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 {
|
promTypes.globalConfig = types.submodule {
|
||||||
options = {
|
options = {
|
||||||
scrape_interval = mkOption {
|
scrape_interval = mkDefOpt types.str "1m" ''
|
||||||
type = types.nullOr types.str;
|
|
||||||
default = null;
|
|
||||||
description = ''
|
|
||||||
How frequently to scrape targets by default.
|
How frequently to scrape targets by default.
|
||||||
'';
|
'';
|
||||||
};
|
|
||||||
|
|
||||||
scrape_timeout = mkOption {
|
scrape_timeout = mkDefOpt types.str "10s" ''
|
||||||
type = types.nullOr types.str;
|
|
||||||
default = null;
|
|
||||||
description = ''
|
|
||||||
How long until a scrape request times out.
|
How long until a scrape request times out.
|
||||||
'';
|
'';
|
||||||
};
|
|
||||||
|
|
||||||
evaluation_interval = mkOption {
|
evaluation_interval = mkDefOpt types.str "1m" ''
|
||||||
type = types.nullOr types.str;
|
|
||||||
default = null;
|
|
||||||
description = ''
|
|
||||||
How frequently to evaluate rules by default.
|
How frequently to evaluate rules by default.
|
||||||
'';
|
'';
|
||||||
};
|
|
||||||
|
|
||||||
external_labels = mkOption {
|
external_labels = mkOpt (types.attrsOf types.str) ''
|
||||||
type = types.nullOr (types.attrsOf types.str);
|
|
||||||
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 = null;
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -166,33 +162,21 @@ let
|
||||||
The job name assigned to scraped metrics by default.
|
The job name assigned to scraped metrics by default.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
scrape_interval = mkOption {
|
scrape_interval = mkOpt types.str ''
|
||||||
type = types.nullOr types.str;
|
|
||||||
default = null;
|
|
||||||
description = ''
|
|
||||||
How frequently to scrape targets from this job. Defaults to the
|
How frequently to scrape targets from this job. Defaults to the
|
||||||
globally configured default.
|
globally configured default.
|
||||||
'';
|
'';
|
||||||
};
|
|
||||||
scrape_timeout = mkOption {
|
scrape_timeout = mkOpt types.str ''
|
||||||
type = types.nullOr types.str;
|
|
||||||
default = null;
|
|
||||||
description = ''
|
|
||||||
Per-target timeout when scraping this job. Defaults to the
|
Per-target timeout when scraping this job. Defaults to the
|
||||||
globally configured default.
|
globally configured default.
|
||||||
'';
|
'';
|
||||||
};
|
|
||||||
metrics_path = mkOption {
|
metrics_path = mkDefOpt types.str "/metrics" ''
|
||||||
type = types.nullOr types.str;
|
|
||||||
default = null;
|
|
||||||
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 = mkDefOpt types.bool "false" ''
|
||||||
type = types.nullOr types.bool;
|
|
||||||
default = null;
|
|
||||||
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
|
||||||
Prometheus would attach server-side ("job" and "instance"
|
Prometheus would attach server-side ("job" and "instance"
|
||||||
|
@ -211,23 +195,16 @@ let
|
||||||
federation, where all labels specified in the target should
|
federation, where all labels specified in the target should
|
||||||
be preserved.
|
be preserved.
|
||||||
'';
|
'';
|
||||||
};
|
|
||||||
scheme = mkOption {
|
scheme = mkDefOpt (types.enum ["http" "https"]) "http" ''
|
||||||
type = types.nullOr (types.enum ["http" "https"]);
|
|
||||||
default = null;
|
|
||||||
description = ''
|
|
||||||
The URL scheme with which to fetch metrics from targets.
|
The URL scheme with which to fetch metrics from targets.
|
||||||
'';
|
'';
|
||||||
};
|
|
||||||
params = mkOption {
|
params = mkOpt (types.attrsOf (types.listOf types.str)) ''
|
||||||
type = types.nullOr (types.attrsOf (types.listOf types.str));
|
|
||||||
default = null;
|
|
||||||
description = ''
|
|
||||||
Optional HTTP URL parameters.
|
Optional HTTP URL parameters.
|
||||||
'';
|
'';
|
||||||
};
|
|
||||||
basic_auth = mkOption {
|
basic_auth = mkOpt (types.submodule {
|
||||||
type = types.nullOr (types.submodule {
|
|
||||||
options = {
|
options = {
|
||||||
username = mkOption {
|
username = mkOption {
|
||||||
type = types.str;
|
type = types.str;
|
||||||
|
@ -242,63 +219,39 @@ let
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
});
|
}) ''
|
||||||
default = null;
|
|
||||||
description = ''
|
|
||||||
Optional http login credentials for metrics scraping.
|
Optional http login credentials for metrics scraping.
|
||||||
'';
|
'';
|
||||||
};
|
|
||||||
tls_config = mkOption {
|
tls_config = mkOpt promTypes.tls_config ''
|
||||||
type = types.nullOr promTypes.tls_config;
|
|
||||||
default = null;
|
|
||||||
description = ''
|
|
||||||
Configures the scrape request's TLS settings.
|
Configures the scrape request's TLS settings.
|
||||||
'';
|
'';
|
||||||
};
|
|
||||||
dns_sd_configs = mkOption {
|
dns_sd_configs = mkOpt (types.listOf promTypes.dns_sd_config) ''
|
||||||
type = types.nullOr (types.listOf promTypes.dns_sd_config);
|
|
||||||
default = null;
|
|
||||||
description = ''
|
|
||||||
List of DNS service discovery configurations.
|
List of DNS service discovery configurations.
|
||||||
'';
|
'';
|
||||||
};
|
|
||||||
consul_sd_configs = mkOption {
|
consul_sd_configs = mkOpt (types.listOf promTypes.consul_sd_config) ''
|
||||||
type = types.nullOr (types.listOf promTypes.consul_sd_config);
|
|
||||||
default = null;
|
|
||||||
description = ''
|
|
||||||
List of Consul service discovery configurations.
|
List of Consul service discovery configurations.
|
||||||
'';
|
'';
|
||||||
};
|
|
||||||
file_sd_configs = mkOption {
|
file_sd_configs = mkOpt (types.listOf promTypes.file_sd_config) ''
|
||||||
type = types.nullOr (types.listOf promTypes.file_sd_config);
|
|
||||||
default = null;
|
|
||||||
description = ''
|
|
||||||
List of file service discovery configurations.
|
List of file service discovery configurations.
|
||||||
'';
|
'';
|
||||||
};
|
|
||||||
static_configs = mkOption {
|
static_configs = mkOpt (types.listOf promTypes.static_config) ''
|
||||||
type = types.nullOr (types.listOf promTypes.static_config);
|
|
||||||
default = null;
|
|
||||||
description = ''
|
|
||||||
List of labeled target groups for this job.
|
List of labeled target groups for this job.
|
||||||
'';
|
'';
|
||||||
};
|
|
||||||
ec2_sd_configs = mkOption {
|
ec2_sd_configs = mkOpt (types.listOf promTypes.ec2_sd_config) ''
|
||||||
type = types.nullOr (types.listOf promTypes.ec2_sd_config);
|
|
||||||
default = null;
|
|
||||||
description = ''
|
|
||||||
List of EC2 service discovery configurations.
|
List of EC2 service discovery configurations.
|
||||||
'';
|
'';
|
||||||
};
|
|
||||||
relabel_configs = mkOption {
|
relabel_configs = mkOpt (types.listOf promTypes.relabel_config) ''
|
||||||
type = types.nullOr (types.listOf promTypes.relabel_config);
|
|
||||||
default = null;
|
|
||||||
description = ''
|
|
||||||
List of relabel configurations.
|
List of relabel configurations.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
|
||||||
|
|
||||||
promTypes.static_config = types.submodule {
|
promTypes.static_config = types.submodule {
|
||||||
options = {
|
options = {
|
||||||
|
@ -326,68 +279,43 @@ let
|
||||||
The AWS Region.
|
The AWS Region.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
endpoint = mkOption {
|
endpoint = mkOpt types.str ''
|
||||||
type = types.nullOr types.str;
|
|
||||||
default = null;
|
|
||||||
description = ''
|
|
||||||
Custom endpoint to be used.
|
Custom endpoint to be used.
|
||||||
'';
|
'';
|
||||||
};
|
|
||||||
access_key = mkOption {
|
access_key = mkOpt types.str ''
|
||||||
type = types.nullOr types.str;
|
|
||||||
default = null;
|
|
||||||
description = ''
|
|
||||||
The AWS API key id. If blank, the environment variable
|
The AWS API key id. If blank, the environment variable
|
||||||
<literal>AWS_ACCESS_KEY_ID</literal> is used.
|
<literal>AWS_ACCESS_KEY_ID</literal> is used.
|
||||||
'';
|
'';
|
||||||
};
|
|
||||||
secret_key = mkOption {
|
secret_key = mkOpt types.str ''
|
||||||
type = types.nullOr types.str;
|
|
||||||
default = null;
|
|
||||||
description = ''
|
|
||||||
The AWS API key secret. If blank, the environment variable
|
The AWS API key secret. If blank, the environment variable
|
||||||
<literal>AWS_SECRET_ACCESS_KEY</literal> is used.
|
<literal>AWS_SECRET_ACCESS_KEY</literal> is used.
|
||||||
'';
|
'';
|
||||||
};
|
|
||||||
profile = mkOption {
|
profile = mkOpt types.str ''
|
||||||
type = types.nullOr types.str;
|
|
||||||
default = null;
|
|
||||||
description = ''
|
|
||||||
Named AWS profile used to connect to the API.
|
Named AWS profile used to connect to the API.
|
||||||
'';
|
'';
|
||||||
};
|
|
||||||
role_arn = mkOption {
|
role_arn = mkOpt types.str ''
|
||||||
type = types.nullOr types.str;
|
|
||||||
default = null;
|
|
||||||
description = ''
|
|
||||||
AWS Role ARN, an alternative to using AWS API keys.
|
AWS Role ARN, an alternative to using AWS API keys.
|
||||||
'';
|
'';
|
||||||
};
|
|
||||||
refresh_interval = mkOption {
|
refresh_interval = mkDefOpt types.str "60s" ''
|
||||||
type = types.nullOr types.str;
|
|
||||||
default = null;
|
|
||||||
description = ''
|
|
||||||
Refresh interval to re-read the instance list.
|
Refresh interval to re-read the instance list.
|
||||||
'';
|
'';
|
||||||
};
|
|
||||||
port = mkOption {
|
port = mkDefOpt types.int "80" ''
|
||||||
type = types.nullOr types.int;
|
|
||||||
default = null;
|
|
||||||
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
|
||||||
rule.
|
rule.
|
||||||
'';
|
'';
|
||||||
};
|
|
||||||
filters = mkOption {
|
filters = mkOpt (types.listOf promTypes.filter) ''
|
||||||
type = types.nullOr (types.listOf promTypes.filter);
|
|
||||||
default = null;
|
|
||||||
description = ''
|
|
||||||
Filters can be used optionally to filter the instance list by other criteria.
|
Filters can be used optionally to filter the instance list by other criteria.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
|
||||||
|
|
||||||
promTypes.filter = types.submodule {
|
promTypes.filter = types.submodule {
|
||||||
options = {
|
options = {
|
||||||
|
@ -398,6 +326,7 @@ let
|
||||||
for the available filters.
|
for the available filters.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
value = mkOption {
|
value = mkOption {
|
||||||
type = types.listOf types.str;
|
type = types.listOf types.str;
|
||||||
default = [];
|
default = [];
|
||||||
|
@ -416,60 +345,38 @@ let
|
||||||
A list of DNS SRV record names to be queried.
|
A list of DNS SRV record names to be queried.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
refresh_interval = mkOption {
|
|
||||||
type = types.nullOr types.str;
|
refresh_interval = mkDefOpt types.str "30s" ''
|
||||||
default = null;
|
|
||||||
description = ''
|
|
||||||
The time after which the provided names are refreshed.
|
The time after which the provided names are refreshed.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
|
||||||
|
|
||||||
promTypes.consul_sd_config = types.submodule {
|
promTypes.consul_sd_config = types.submodule {
|
||||||
options = {
|
options = {
|
||||||
server = mkOption {
|
server = mkDefOpt types.str "localhost:8500" ''
|
||||||
type = types.nullOr types.str;
|
Consul server to query.
|
||||||
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";
|
|
||||||
};
|
|
||||||
|
|
||||||
services = mkOption {
|
token = mkOpt types.str "Consul token";
|
||||||
type = types.nullOr (types.listOf types.str);
|
|
||||||
default = null;
|
datacenter = mkOpt types.str "Consul datacenter";
|
||||||
description = ''
|
|
||||||
|
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.
|
A list of services for which targets are retrieved.
|
||||||
'';
|
'';
|
||||||
};
|
|
||||||
tag_separator = mkOption {
|
tag_separator = mkDefOpt types.str "," ''
|
||||||
type = types.nullOr types.str;
|
|
||||||
default = null;
|
|
||||||
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.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
|
||||||
|
|
||||||
promTypes.file_sd_config = types.submodule {
|
promTypes.file_sd_config = types.submodule {
|
||||||
options = {
|
options = {
|
||||||
|
@ -481,107 +388,70 @@ let
|
||||||
and formats.
|
and formats.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
refresh_interval = mkOption {
|
|
||||||
type = types.nullOr types.str;
|
refresh_interval = mkDefOpt types.str "5m" ''
|
||||||
default = null;
|
|
||||||
description = ''
|
|
||||||
Refresh interval to re-read the files.
|
Refresh interval to re-read the files.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
|
||||||
|
|
||||||
promTypes.relabel_config = types.submodule {
|
promTypes.relabel_config = types.submodule {
|
||||||
options = {
|
options = {
|
||||||
source_labels = mkOption {
|
source_labels = mkOpt (types.listOf types.str) ''
|
||||||
type = types.nullOr (types.listOf str);
|
|
||||||
default = null;
|
|
||||||
description = ''
|
|
||||||
The source labels select values from existing labels. Their content
|
The source labels select values from existing labels. Their content
|
||||||
is concatenated using the configured separator and matched against
|
is concatenated using the configured separator and matched against
|
||||||
the configured regular expression.
|
the configured regular expression.
|
||||||
'';
|
'';
|
||||||
};
|
|
||||||
separator = mkOption {
|
separator = mkDefOpt types.str ";" ''
|
||||||
type = types.nullOr types.str;
|
|
||||||
default = null;
|
|
||||||
description = ''
|
|
||||||
Separator placed between concatenated source label values.
|
Separator placed between concatenated source label values.
|
||||||
'';
|
'';
|
||||||
};
|
|
||||||
target_label = mkOption {
|
target_label = mkOpt types.str ''
|
||||||
type = types.nullOr types.str;
|
|
||||||
default = null;
|
|
||||||
description = ''
|
|
||||||
Label to which the resulting value is written in a replace action.
|
Label to which the resulting value is written in a replace action.
|
||||||
It is mandatory for replace actions.
|
It is mandatory for replace actions.
|
||||||
'';
|
'';
|
||||||
};
|
|
||||||
regex = mkOption {
|
regex = mkDefOpt types.str "(.*)" ''
|
||||||
type = types.nullOr types.str;
|
|
||||||
default = null;
|
|
||||||
description = ''
|
|
||||||
Regular expression against which the extracted value is matched.
|
Regular expression against which the extracted value is matched.
|
||||||
'';
|
'';
|
||||||
};
|
|
||||||
replacement = mkOption {
|
replacement = mkDefOpt types.str "$1" ''
|
||||||
type = types.nullOr types.str;
|
|
||||||
default = null;
|
|
||||||
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 = mkDefOpt (types.enum ["replace" "keep" "drop"]) "replace" ''
|
||||||
type = types.nullOr (types.enum ["replace" "keep" "drop"]);
|
|
||||||
default = null;
|
|
||||||
description = ''
|
|
||||||
Action to perform based on regex matching.
|
Action to perform based on regex matching.
|
||||||
'';
|
'';
|
||||||
};
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
promTypes.tls_config = types.submodule {
|
promTypes.tls_config = types.submodule {
|
||||||
options = {
|
options = {
|
||||||
ca_file = mkOption {
|
ca_file = mkOpt types.str ''
|
||||||
type = types.nullOr types.str;
|
|
||||||
default = null;
|
|
||||||
description = ''
|
|
||||||
CA certificate to validate API server certificate with.
|
CA certificate to validate API server certificate with.
|
||||||
'';
|
'';
|
||||||
};
|
|
||||||
cert_file = mkOption {
|
cert_file = mkOpt types.str ''
|
||||||
type = types.nullOr types.str;
|
|
||||||
default = null;
|
|
||||||
description = ''
|
|
||||||
Certificate file for client cert authentication to the server.
|
Certificate file for client cert authentication to the server.
|
||||||
'';
|
'';
|
||||||
};
|
|
||||||
key_file = mkOption {
|
key_file = mkOpt types.str ''
|
||||||
type = types.nullOr types.str;
|
|
||||||
default = null;
|
|
||||||
description = ''
|
|
||||||
Key file for client cert authentication to the server.
|
Key file for client cert authentication to the server.
|
||||||
'';
|
'';
|
||||||
};
|
|
||||||
server_name = mkOption {
|
server_name = mkOpt types.str ''
|
||||||
type = types.nullOr types.str;
|
|
||||||
default = null;
|
|
||||||
description = ''
|
|
||||||
ServerName extension to indicate the name of the server.
|
ServerName extension to indicate the name of the server.
|
||||||
http://tools.ietf.org/html/rfc4366#section-3.1
|
http://tools.ietf.org/html/rfc4366#section-3.1
|
||||||
'';
|
'';
|
||||||
};
|
|
||||||
insecure_skip_verify = mkOption {
|
insecure_skip_verify = mkOpt types.bool ''
|
||||||
type = types.bool;
|
|
||||||
default = false;
|
|
||||||
description = ''
|
|
||||||
Disable validation of the server certificate.
|
Disable validation of the server certificate.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
|
||||||
|
|
||||||
in {
|
in {
|
||||||
options = {
|
options = {
|
||||||
|
|
Loading…
Reference in New Issue