From db46b01ae9a3219dfbb57ee0b8e6e3573c94cc10 Mon Sep 17 00:00:00 2001 From: Raito Bezarius Date: Fri, 23 Aug 2024 19:42:17 +0200 Subject: [PATCH] feat(monitoring): add pyroscope to the infrastructure Vendored for the time being. See https://cl.forkos.org/c/nixpkgs/+/181 for upstreaming properly. Signed-off-by: Raito Bezarius --- hosts/meta01/default.nix | 1 + overlays/default.nix | 1 + overlays/pyroscope/default.nix | 42 +++++++++++++++++++++++ services/monitoring/default.nix | 3 +- services/monitoring/pyroscope/default.nix | 19 ++++++++++ services/monitoring/pyroscope/module.nix | 36 +++++++++++++++++++ 6 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 overlays/pyroscope/default.nix create mode 100644 services/monitoring/pyroscope/default.nix create mode 100644 services/monitoring/pyroscope/module.nix diff --git a/hosts/meta01/default.nix b/hosts/meta01/default.nix index 653a655..c50e0e6 100755 --- a/hosts/meta01/default.nix +++ b/hosts/meta01/default.nix @@ -23,6 +23,7 @@ bagel.services.loki.enable = true; bagel.services.grafana.enable = true; bagel.services.grapevine.enable = true; + bagel.services.pyroscope.enable = true; bagel.services.hookshot = { enable = true; admins = [ diff --git a/overlays/default.nix b/overlays/default.nix index 5162ed7..bf4af66 100644 --- a/overlays/default.nix +++ b/overlays/default.nix @@ -2,5 +2,6 @@ (final: prev: { iusb-spoof = final.callPackage ./iusb-spoof.nix {}; u-root = final.callPackage ./u-root {}; + pyroscope = final.callPackage ./pyroscope {}; }) ] diff --git a/overlays/pyroscope/default.nix b/overlays/pyroscope/default.nix new file mode 100644 index 0000000..5a6c975 --- /dev/null +++ b/overlays/pyroscope/default.nix @@ -0,0 +1,42 @@ +{ lib +, buildGoModule +, fetchFromGitHub +}: + +buildGoModule rec { + pname = "pyroscope"; + version = "1.7.1"; + + src = fetchFromGitHub { + owner = "grafana"; + repo = "pyroscope"; + rev = "v${version}"; + hash = "sha256-iMP67J0Q8Cgo52iImMzAM3PEkk6uLF7r6v9TyXZVaIE="; + }; + + env.GOWORK = "off"; + + vendorHash = "sha256-ggntpnU9s2rpkv6S0LnZNexrdkBsdsUrGPc93SVrK4M="; + + subPackages = [ "cmd/profilecli" "cmd/pyroscope" ]; + + ldflags = [ + "-extldflags" + "-static" + "-s" + "-w" + "-X=github.com/grafana/pyroscope/pkg/util/build.Branch=${src.rev}" + "-X=github.com/grafana/pyroscope/pkg/util/build.Version=${version}" + "-X=github.com/grafana/pyroscope/pkg/util/build.Revision=${src.rev}" + "-X=github.com/grafana/pyroscope/pkg/util/build.BuildDate=1970-01-01T00:00:00Z" + ]; + + meta = with lib; { + description = "Continuous profiling platform"; + homepage = "https://github.com/grafana/pyroscope"; + changelog = "https://github.com/grafana/pyroscope/blob/${src.rev}/CHANGELOG.md"; + license = licenses.agpl3Only; + maintainers = with maintainers; [ raitobezarius ]; + mainProgram = "pyroscope"; + }; +} diff --git a/services/monitoring/default.nix b/services/monitoring/default.nix index e972a3c..313b6fd 100644 --- a/services/monitoring/default.nix +++ b/services/monitoring/default.nix @@ -4,5 +4,6 @@ ./lgtm ./agent.nix ./hookshot-adapter + ./pyroscope ]; -} \ No newline at end of file +} diff --git a/services/monitoring/pyroscope/default.nix b/services/monitoring/pyroscope/default.nix new file mode 100644 index 0000000..5f9ecbf --- /dev/null +++ b/services/monitoring/pyroscope/default.nix @@ -0,0 +1,19 @@ +{ lib, config, ... }: +let + inherit (lib) mkEnableOption mkIf; + cfg = config.bagel.services.pyroscope; +in +{ + options.bagel.services.pyroscope = { + enable = mkEnableOption "pyroscope server"; + }; + + # TODO: send me to nixpkgs + imports = [ + ./module.nix + ]; + + config = mkIf cfg.enable { + services.pyroscope.enable = true; + }; +} diff --git a/services/monitoring/pyroscope/module.nix b/services/monitoring/pyroscope/module.nix new file mode 100644 index 0000000..1eeb722 --- /dev/null +++ b/services/monitoring/pyroscope/module.nix @@ -0,0 +1,36 @@ +{ pkgs, lib, config, ... }: +let + inherit (lib) mkEnableOption mkPackageOption mkOption types mkIf; + settingsFormatYaml = pkgs.formats.yaml { }; + cfg = config.services.pyroscope; + configFile = settingsFormatYaml.generate "settings.yaml" cfg.settings; +in +{ + options.services.pyroscope = { + enable = mkEnableOption "pyroscope, a continuous profiling platform"; + package = mkPackageOption pkgs "pyroscope" { }; + settings = mkOption { + description = "Pyroscope settings. See <>"; + + type = types.submodule { + freeformType = settingsFormatYaml.type; + }; + }; + }; + + config = mkIf cfg.enable { + systemd.services.pyroscope = { + description = "Pyroscope server - a continuous profiling platform"; + wantedBy = [ "multi-user.target" ]; + serviceConfig = { + ExecStart = "${cfg.package}/bin/pyroscope -config.file ${configFile}"; + WorkingDirectory = "/var/lib/pyroscope"; + User = "pyroscope"; + DynamicUser = true; + Restart = "on-failure"; + RuntimeDirectory = "pyroscope"; + StateDirectory = "pyroscope"; + }; + }; + }; +}