From 0ffae5766bbb15e6d9104c87e5ad4a9218fe1569 Mon Sep 17 00:00:00 2001 From: Raito Bezarius Date: Tue, 22 Oct 2024 17:13:19 +0200 Subject: [PATCH] feat: add buildbot-profiler This enable the possibility to run buildbot-profiler on a production system. This exposes the UI but does not compile properly the JavaScript assets yet. Signed-off-by: Raito Bezarius --- buildbot_nix/__init__.py | 5 +++++ nix/coordinator.nix | 9 +++++++-- nix/profiler-plugin.nix | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 nix/profiler-plugin.nix diff --git a/buildbot_nix/__init__.py b/buildbot_nix/__init__.py index 22a77f6..8010b92 100644 --- a/buildbot_nix/__init__.py +++ b/buildbot_nix/__init__.py @@ -954,6 +954,7 @@ class GerritNixConfigurator(ConfiguratorBase): binary_cache_config: dict[str, str] | None = None, auth_method: AuthBase | None = None, manhole: Any = None, + enable_profiler: bool = False, ) -> None: super().__init__() self.manhole = manhole @@ -977,6 +978,7 @@ class GerritNixConfigurator(ConfiguratorBase): self.url = url self.prometheus_config = prometheus_config + self.enable_profiler = enable_profiler if binary_cache_config is not None: self.binary_cache_config = S3BinaryCacheConfig(**binary_cache_config) @@ -1081,6 +1083,9 @@ class GerritNixConfigurator(ConfiguratorBase): config_dict["www"].setdefault("plugins", {}) + if self.enable_profiler: + config_dict["www"]["plugins"]["profiler"] = True + if "authz" not in config_dict["www"]: config_dict["www"]["authz"] = util.Authz( allowRules=[ diff --git a/nix/coordinator.nix b/nix/coordinator.nix index d474d07..e3b24ec 100644 --- a/nix/coordinator.nix +++ b/nix/coordinator.nix @@ -140,6 +140,8 @@ in }; }; + profiler.enable = lib.mkEnableOption " the profiling of the buildbot instance"; + gerrit = { domain = lib.mkOption { type = lib.types.str; @@ -270,7 +272,8 @@ in read_secret_file('buildbot-oauth2-secret'), autologin=True ), - manhole=${debuggingManhole} + manhole=${debuggingManhole}, + enable_profiler=${builtins.toJSON cfg.profiler.enable} ) '' ]; @@ -288,7 +291,9 @@ in (ps.toPythonModule pkgs.buildbot-worker) pkgs.buildbot-plugins.www (pkgs.python3.pkgs.callPackage ../default.nix { }) - ] ++ lib.optional cfg.prometheus.enable (pkgs.python3.pkgs.callPackage ./prometheus-plugin.nix { }) + ] + ++ lib.optional cfg.prometheus.enable (pkgs.python3.pkgs.callPackage ./prometheus-plugin.nix { }) + ++ lib.optional cfg.profiler.enable (pkgs.python3.pkgs.callPackage ./profiler-plugin.nix { }) ); }; diff --git a/nix/profiler-plugin.nix b/nix/profiler-plugin.nix new file mode 100644 index 0000000..2144893 --- /dev/null +++ b/nix/profiler-plugin.nix @@ -0,0 +1,36 @@ +{ + lib, + buildPythonPackage, + fetchFromGitHub, + setuptools, + wheel, +}: + +buildPythonPackage rec { + pname = "buildbot-profiler"; + version = "1.2.2"; + pyproject = true; + + src = fetchFromGitHub { + owner = "tardyp"; + repo = "buildbot_profiler"; + rev = "v${version}"; + hash = "sha256-r56Cze0v3gKWKJwRy0BUYz5z8d0g3jerCIu3KreNxUc="; + }; + + build-system = [ + setuptools + wheel + ]; + + pythonImportsCheck = [ + "buildbot_profiler" + ]; + + meta = { + description = ""; + homepage = "https://github.com/tardyp/buildbot_profiler"; + license = lib.licenses.unfree; # FIXME: nix-init did not find a license + maintainers = with lib.maintainers; [ raitobezarius ]; + }; +}