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
1 changed files with 223 additions and 353 deletions

View File

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