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
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user