From 1a0880086a06d0907bd842e5e109384d819a8438 Mon Sep 17 00:00:00 2001 From: Daniel Olsen Date: Fri, 20 Jan 2023 08:24:02 +0100 Subject: [PATCH] metrics: use matrix-lib to simplify generation of prometheus scrape config --- flake.lock | 36 ++++++++++++++++++------- hosts/jokum/services/matrix/synapse.nix | 15 ++++------- 2 files changed, 32 insertions(+), 19 deletions(-) diff --git a/flake.lock b/flake.lock index 35b3a71..829fd8c 100644 --- a/flake.lock +++ b/flake.lock @@ -1,12 +1,15 @@ { "nodes": { "matrix-next": { + "inputs": { + "nixpkgs-lib": "nixpkgs-lib" + }, "locked": { - "lastModified": 1671663871, - "narHash": "sha256-06G6xYTFPVuvmN/k2QDeBk9XIp4LDxEKWRL3aLAFFNo=", + "lastModified": 1674198693, + "narHash": "sha256-xjIJ4LinPNbV+0UYwhCldWUiL1e/B+hN4SR8cxOvxZA=", "owner": "dali99", "repo": "nixos-matrix-modules", - "rev": "b6f0a026a78200c0e526aa73279c228e08673437", + "rev": "07e95170e8887b918c288c9751e46d3e0b6ab34f", "type": "github" }, "original": { @@ -17,11 +20,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1673785634, - "narHash": "sha256-4SPGYVNutklnlpSMaqL+GA2x5DJ+QL85T+hOF6MHAZE=", + "lastModified": 1674091526, + "narHash": "sha256-eLhLKOpF1ix5xZeFF9g8uE1stdyxuBLJvWQ20gLbDto=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "54d5d59cb19728a0321efbcd22c539109489965b", + "rev": "fc5b90fd72177d9bcf435b10c12bb943549748c6", "type": "github" }, "original": { @@ -31,6 +34,21 @@ "type": "github" } }, + "nixpkgs-lib": { + "locked": { + "lastModified": 1673743903, + "narHash": "sha256-sloY6KYyVOozJ1CkbgJPpZ99TKIjIvM+04V48C04sMQ=", + "owner": "nix-community", + "repo": "nixpkgs.lib", + "rev": "7555e2dfcbac1533f047021f1744ac8871150f9f", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nixpkgs.lib", + "type": "github" + } + }, "nixpkgs-stable": { "locked": { "lastModified": 1673740915, @@ -78,11 +96,11 @@ }, "unstable": { "locked": { - "lastModified": 1673855649, - "narHash": "sha256-Pc1VumquuFMDR1Ers1QOVDDabL/trVwfqWXeKJPXLQg=", + "lastModified": 1674101896, + "narHash": "sha256-xWLaexT6IHhOJru54wrOMeBbkKeJzOZ4Pqrxctf82q0=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "c85d08692966cf022b0a741a794cb1650602d8af", + "rev": "a841e262264e48722dccc8469f066068146e406b", "type": "github" }, "original": { diff --git a/hosts/jokum/services/matrix/synapse.nix b/hosts/jokum/services/matrix/synapse.nix index 195cfb7..d3ad9ce 100644 --- a/hosts/jokum/services/matrix/synapse.nix +++ b/hosts/jokum/services/matrix/synapse.nix @@ -1,8 +1,10 @@ -{ config, lib, pkgs, values, ... }: +{ config, lib, pkgs, values, inputs, ... }: let cfg = config.services.matrix-synapse-next; + matrix-lib = inputs.matrix-next.lib; + imap0Attrs = with lib; f: set: listToAttrs (imap0 (i: attr: nameValuePair attr (f i attr set.${attr})) (attrNames set)); in { @@ -172,15 +174,8 @@ in { services.nginx.virtualHosts."matrix.pvv.ntnu.no" = lib.mkMerge [({ locations = let - isListenerType = type: listener: lib.lists.any (r: lib.lists.any (n: n == type) r.names) listener.resources; - isMetricsListener = l: isListenerType "metrics" l; - - firstMetricsListener = w: lib.lists.findFirst isMetricsListener (throw "No metrics endpoint on worker") w.settings.worker_listeners; - - wAddress = w: lib.lists.findFirst (_: true) (throw "No address in receiver") (firstMetricsListener w).bind_addresses; - wPort = w: (firstMetricsListener w).port; - - socketAddress = w: "${wAddress w}:${toString (wPort w)}"; + connectionInfo = w: matrix-lib.workerConnectionResource "metrics" w; + socketAddress = w: let c = connectionInfo w; in "${c.host}:${toString (c.port)}"; metricsPath = w: "/metrics/${w.type}/${toString w.index}"; proxyPath = w: "http://${socketAddress w}/_synapse/metrics";