From ba3c3de8a6b21eb2a3e2fa29e90e051faf3d643a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20H=C3=B6ppner?= Date: Fri, 8 May 2020 23:58:31 +0100 Subject: [PATCH 1/3] prometheus: Split options listenAddress and port Accessing the configured port of a service is quite useful, for example when configuring virtual hosts for a service. The prometheus module did not expose the configured por separately, making it unnecessarily cumbersome to consume. This is a breaking change only if you were setting `listenAddress` to a non-standard value. If you were, you should now set `listenAddress` and `port` separately. --- .../services/monitoring/prometheus/default.nix | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/nixos/modules/services/monitoring/prometheus/default.nix b/nixos/modules/services/monitoring/prometheus/default.nix index 84a72afac2f..c64ab448e0e 100644 --- a/nixos/modules/services/monitoring/prometheus/default.nix +++ b/nixos/modules/services/monitoring/prometheus/default.nix @@ -46,7 +46,7 @@ let cmdlineArgs = cfg.extraFlags ++ [ "--storage.tsdb.path=${workingDir}/data/" "--config.file=${prometheusYml}" - "--web.listen-address=${cfg.listenAddress}" + "--web.listen-address=${cfg.listenAddress}:${builtins.toString cfg.port}" "--alertmanager.notification-queue-capacity=${toString cfg.alertmanagerNotificationQueueCapacity}" "--alertmanager.timeout=${toString cfg.alertmanagerTimeout}s" ] ++ @@ -489,9 +489,17 @@ in { ''; }; + port = mkOption { + type = types.int; + default = 9090; + description = '' + Port to listen on. + ''; + }; + listenAddress = mkOption { type = types.str; - default = "0.0.0.0:9090"; + default = "0.0.0.0"; description = '' Address to listen on for the web interface, API, and telemetry. ''; From 5d2a465addfe0ecc0cee9cb6a1514c4089e5a9ae Mon Sep 17 00:00:00 2001 From: Kirill Elagin Date: Thu, 23 Jul 2020 18:15:57 -0400 Subject: [PATCH 2/3] prometheus: Use types.port for port --- nixos/modules/services/monitoring/prometheus/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nixos/modules/services/monitoring/prometheus/default.nix b/nixos/modules/services/monitoring/prometheus/default.nix index c64ab448e0e..cbd4cc452a7 100644 --- a/nixos/modules/services/monitoring/prometheus/default.nix +++ b/nixos/modules/services/monitoring/prometheus/default.nix @@ -490,7 +490,7 @@ in { }; port = mkOption { - type = types.int; + type = types.port; default = 9090; description = '' Port to listen on. From e1d80de838d31bd1f05369120ecd7d4b191e9f9c Mon Sep 17 00:00:00 2001 From: Kirill Elagin Date: Thu, 23 Jul 2020 18:16:13 -0400 Subject: [PATCH 3/3] prometheus: Add assert for legacy listenAddress --- .../services/monitoring/prometheus/default.nix | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/nixos/modules/services/monitoring/prometheus/default.nix b/nixos/modules/services/monitoring/prometheus/default.nix index cbd4cc452a7..d7e06484b69 100644 --- a/nixos/modules/services/monitoring/prometheus/default.nix +++ b/nixos/modules/services/monitoring/prometheus/default.nix @@ -627,6 +627,21 @@ in { }; config = mkIf cfg.enable { + assertions = [ + ( let + legacy = builtins.match "(.*):(.*)" cfg.listenAddress; + in { + assertion = legacy == null; + message = '' + Do not specify the port for Prometheus to listen on in the + listenAddress option; use the port option instead: + services.prometheus.listenAddress = ${builtins.elemAt legacy 0}; + services.prometheus.port = ${builtins.elemAt legacy 1}; + ''; + } + ) + ]; + users.groups.prometheus.gid = config.ids.gids.prometheus; users.users.prometheus = { description = "Prometheus daemon user";