From c605f3912d435e327feb643d6d390bb4acb144ce Mon Sep 17 00:00:00 2001 From: Tom Prince <tom.prince@private.storage> Date: Thu, 10 Feb 2022 14:36:30 -0700 Subject: [PATCH] Stop using `/etc/hosts` to name the monitoring host. --- morph/lib/base.nix | 22 +++++++++++++------ morph/lib/monitoring.nix | 5 +++++ .../modules/monitoring/exporters/promtail.nix | 8 ++++++- 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/morph/lib/base.nix b/morph/lib/base.nix index 6fb5fccd..b29cac0b 100644 --- a/morph/lib/base.nix +++ b/morph/lib/base.nix @@ -18,6 +18,12 @@ corresponding private keys for the system. ''; }; + monitoringEndpoint = lib.mkOption { + type = lib.types.str; + description = '' + The IPv4 address of the monitoring node this node should conenct to. + ''; + }; monitoringvpnIPv4 = lib.mkOption { type = lib.types.str; description = '' @@ -57,14 +63,16 @@ # qualified domain name. deployment.targetHost = config.networking.fqdn; - networking.hosts = { - # To stream logs to the monitoring host, all nodes need to know its address - ${nodes.monitoring.config.services.private-storage.monitoring.vpn.server.ip} = [ - "monitoring" "monitoring.monitoringvpn" - ]; - }; + # This is the host that nodes should connect to for push-based monitoring. + # Note that this needs to be overridden on the monitoring host, otherwise + # we'd end up with infinite recursion. + grid.monitoringEndpoint = nodes.monitoring.config.grid.monitoringEndpoint; - services.private-storage.monitoring.exporters.promtail.enable = true; + # To stream logs to the monitoring host, all nodes need to know its address + services.private-storage.monitoring.exporters.promtail = { + enable = true; + serverHost = config.grid.monitoringEndpoint; + }; assertions = [ # This is a check to save somebody in the future trying to debug why diff --git a/morph/lib/monitoring.nix b/morph/lib/monitoring.nix index c955f09b..3ef62451 100644 --- a/morph/lib/monitoring.nix +++ b/morph/lib/monitoring.nix @@ -92,6 +92,11 @@ in { } ]; + # We use `mkForce` here, to override the value specified in `morph/lib/base.nix`, + # Since the default value depends on the value defined on this node, there + # would otherwise be infinite recursiion. + grid.monitoringEndpoint = lib.mkForce monitoringvpnIPv4; + deployment.secrets = lib.mkMerge [ { "monitoringvpn-private-key" = { diff --git a/nixos/modules/monitoring/exporters/promtail.nix b/nixos/modules/monitoring/exporters/promtail.nix index c056ebeb..2a73d22a 100644 --- a/nixos/modules/monitoring/exporters/promtail.nix +++ b/nixos/modules/monitoring/exporters/promtail.nix @@ -15,6 +15,12 @@ let in { options.services.private-storage.monitoring.exporters.promtail = { enable = lib.mkEnableOption "Promtail log exporter service"; + serverHost = lib.mkOption { + type = lib.types.str; + description = '' + The server host that logs should be pushed to. + ''; + }; }; config = lib.mkIf cfg.enable { @@ -28,7 +34,7 @@ in { }; clients = [{ - url = "http://monitoring:3100/loki/api/v1/push"; + url = "http://${cfg.serverHost}:3100/loki/api/v1/push"; }]; scrape_configs = [{ -- GitLab