diff options
author | Bas van Dijk <v.dijk.bas@gmail.com> | 2019-04-16 16:06:11 +0200 |
---|---|---|
committer | Bas van Dijk <v.dijk.bas@gmail.com> | 2019-04-16 16:06:11 +0200 |
commit | a913d0891cae7557bf6b56d6fc7b251aff373b2e (patch) | |
tree | 0bd818b942009536e60f20c89af6a8c3bb812f12 /nixos | |
parent | a23db5db08206e77c2861107bfaf600b8ff7f5ce (diff) | |
download | nixlib-a913d0891cae7557bf6b56d6fc7b251aff373b2e.tar nixlib-a913d0891cae7557bf6b56d6fc7b251aff373b2e.tar.gz nixlib-a913d0891cae7557bf6b56d6fc7b251aff373b2e.tar.bz2 nixlib-a913d0891cae7557bf6b56d6fc7b251aff373b2e.tar.lz nixlib-a913d0891cae7557bf6b56d6fc7b251aff373b2e.tar.xz nixlib-a913d0891cae7557bf6b56d6fc7b251aff373b2e.tar.zst nixlib-a913d0891cae7557bf6b56d6fc7b251aff373b2e.zip |
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.
Diffstat (limited to 'nixos')
-rw-r--r-- | nixos/modules/services/monitoring/prometheus/default.nix | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/nixos/modules/services/monitoring/prometheus/default.nix b/nixos/modules/services/monitoring/prometheus/default.nix index 525b0b18cecf..e7ac12c07d33 100644 --- a/nixos/modules/services/monitoring/prometheus/default.nix +++ b/nixos/modules/services/monitoring/prometheus/default.nix @@ -54,7 +54,7 @@ let rule_files = map (promtoolCheck "check-rules" "rules") (cfg.ruleFiles ++ [ (pkgs.writeText "prometheus.rules" (concatStringsSep "\n" cfg.rules)) ]); - scrape_configs = cfg.scrapeConfigs; + scrape_configs = filterEmpty cfg.scrapeConfigs; }; generatedPrometheusYml = writePrettyJSON "prometheus.yml" promConfig; @@ -81,7 +81,7 @@ let rule_files = map (prom2toolCheck "check rules" "rules") (cfg2.ruleFiles ++ [ (pkgs.writeText "prometheus.rules" (concatStringsSep "\n" cfg2.rules)) ]); - scrape_configs = cfg2.scrapeConfigs; + scrape_configs = filterEmpty cfg2.scrapeConfigs; alerting = optionalAttrs (cfg2.alertmanagerURL != []) { alertmanagers = [{ static_configs = [{ @@ -108,6 +108,21 @@ let ] ++ 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 { options = { scrape_interval = mkOption { |