mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-07-14 06:00:33 +03:00
nixos/prometheus: filter out empty srcape_configs attributes
This results in a smaller prometheus.yml config file. It also allows us to use the same options for both prometheus-1 and prometheus-2 since the new options for prometheus-2 default to null and will be filtered out if they are not set.
This commit is contained in:
parent
a23db5db08
commit
a913d0891c
1 changed files with 17 additions and 2 deletions
|
@ -54,7 +54,7 @@ let
|
||||||
rule_files = map (promtoolCheck "check-rules" "rules") (cfg.ruleFiles ++ [
|
rule_files = map (promtoolCheck "check-rules" "rules") (cfg.ruleFiles ++ [
|
||||||
(pkgs.writeText "prometheus.rules" (concatStringsSep "\n" cfg.rules))
|
(pkgs.writeText "prometheus.rules" (concatStringsSep "\n" cfg.rules))
|
||||||
]);
|
]);
|
||||||
scrape_configs = cfg.scrapeConfigs;
|
scrape_configs = filterEmpty cfg.scrapeConfigs;
|
||||||
};
|
};
|
||||||
|
|
||||||
generatedPrometheusYml = writePrettyJSON "prometheus.yml" promConfig;
|
generatedPrometheusYml = writePrettyJSON "prometheus.yml" promConfig;
|
||||||
|
@ -81,7 +81,7 @@ let
|
||||||
rule_files = map (prom2toolCheck "check rules" "rules") (cfg2.ruleFiles ++ [
|
rule_files = map (prom2toolCheck "check rules" "rules") (cfg2.ruleFiles ++ [
|
||||||
(pkgs.writeText "prometheus.rules" (concatStringsSep "\n" cfg2.rules))
|
(pkgs.writeText "prometheus.rules" (concatStringsSep "\n" cfg2.rules))
|
||||||
]);
|
]);
|
||||||
scrape_configs = cfg2.scrapeConfigs;
|
scrape_configs = filterEmpty cfg2.scrapeConfigs;
|
||||||
alerting = optionalAttrs (cfg2.alertmanagerURL != []) {
|
alerting = optionalAttrs (cfg2.alertmanagerURL != []) {
|
||||||
alertmanagers = [{
|
alertmanagers = [{
|
||||||
static_configs = [{
|
static_configs = [{
|
||||||
|
@ -108,6 +108,21 @@ let
|
||||||
] ++
|
] ++
|
||||||
optional (cfg2.webExternalUrl != null) "--web.external-url=${cfg2.webExternalUrl}";
|
optional (cfg2.webExternalUrl != null) "--web.external-url=${cfg2.webExternalUrl}";
|
||||||
|
|
||||||
|
filterEmpty = filterAttrsListRecursive (_n: v: !(v == null || v == [] || v == {}));
|
||||||
|
filterAttrsListRecursive = pred: x:
|
||||||
|
if isAttrs x then
|
||||||
|
listToAttrs (
|
||||||
|
concatMap (name:
|
||||||
|
let v = x.${name}; in
|
||||||
|
if pred name v then [
|
||||||
|
(nameValuePair name (filterAttrsListRecursive pred v))
|
||||||
|
] else []
|
||||||
|
) (attrNames x)
|
||||||
|
)
|
||||||
|
else if isList x then
|
||||||
|
map (filterAttrsListRecursive pred) x
|
||||||
|
else x;
|
||||||
|
|
||||||
promTypes.globalConfig = types.submodule {
|
promTypes.globalConfig = types.submodule {
|
||||||
options = {
|
options = {
|
||||||
scrape_interval = mkOption {
|
scrape_interval = mkOption {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue