summary refs log tree commit diff
path: root/pkgs/servers/monitoring/prometheus
diff options
context:
space:
mode:
authorCorbin <cds@corbinsimpson.com>2022-01-28 15:40:46 -0800
committerCorbin <cds@corbinsimpson.com>2022-01-28 15:58:32 -0800
commit175cc7efd2a4ae5d76df1e184ffe636633c0694d (patch)
tree85762c46e7154c0ed34909d4f808632815b3c699 /pkgs/servers/monitoring/prometheus
parente87db3c8c332cfed455f39a7784f473bab886c2d (diff)
downloadnixpkgs-175cc7efd2a4ae5d76df1e184ffe636633c0694d.tar
nixpkgs-175cc7efd2a4ae5d76df1e184ffe636633c0694d.tar.gz
nixpkgs-175cc7efd2a4ae5d76df1e184ffe636633c0694d.tar.bz2
nixpkgs-175cc7efd2a4ae5d76df1e184ffe636633c0694d.tar.lz
nixpkgs-175cc7efd2a4ae5d76df1e184ffe636633c0694d.tar.xz
nixpkgs-175cc7efd2a4ae5d76df1e184ffe636633c0694d.tar.zst
nixpkgs-175cc7efd2a4ae5d76df1e184ffe636633c0694d.zip
prometheus: Optionally remove service discovery.
I read this hilarious blog post:

https://wejick.wordpress.com/2022/01/29/can-i-have-a-smaller-prometheus/

We can have a smaller Prometheus too. This patch allows users to remove
service discovery for five public clouds (AWS, Azure, DigitalOcean, GCP,
and Linode) and also Kubernetes, simply by setting the corresponding
enable-flag to `false`. I have tested building with each flag as I added
it to the list. I also tested running with all six flags set to `false`,
and the resulting Prometheus can still handle my orthogonal
service-discovery configuration (files).

To meet Adam Savage's definition of science, I measured the size of the
`prometheus` and `promtool` binaries after adding each flag with
`ls -h`.

flag          | prometheus | promtool
--------------|------------|----------
starting size | 84M        | 74M
AWS           | 72M        | 61M
Azure         | 71M        | 61M
GCE           | 64M        | 53M
k8s           | 40M        | 53M
DO            | 39M        | 52M
Linode        | 38M        | 51M

I did not go as far as the blog post. If folks want, I'll make the rest
of the service discovery optional too.

I did not shrink the build closure, just the output closure; we still
pull all of the various vendored modules into the Nix store during
builds. I don't see how to do this in a neat or easy way.
Diffstat (limited to 'pkgs/servers/monitoring/prometheus')
-rw-r--r--pkgs/servers/monitoring/prometheus/default.nix20
1 files changed, 20 insertions, 0 deletions
diff --git a/pkgs/servers/monitoring/prometheus/default.nix b/pkgs/servers/monitoring/prometheus/default.nix
index 931e5f7ffea..806be646fa0 100644
--- a/pkgs/servers/monitoring/prometheus/default.nix
+++ b/pkgs/servers/monitoring/prometheus/default.nix
@@ -9,6 +9,12 @@
 , mkYarnPackage
 , nixosTests
 , fetchpatch
+, enableAWS ? true
+, enableAzure ? true
+, enableDigitalOcean ? true
+, enableGCE ? true
+, enableKubernetes ? true
+, enableLinode ? true
 }:
 
 let
@@ -92,6 +98,20 @@ buildGoModule rec {
     # webui-codemirror
     ln -s ${codemirror}/dist web/ui/module/codemirror-promql/dist
     ln -s ${codemirror}/lib web/ui/module/codemirror-promql/lib
+
+    # Disable some service discovery to shrink binaries.
+    ${lib.optionalString (!enableAWS)
+      "sed -i -e '/register aws/d' discovery/install/install.go"}
+    ${lib.optionalString (!enableAzure)
+      "sed -i -e '/register azure/d' discovery/install/install.go"}
+    ${lib.optionalString (!enableDigitalOcean)
+      "sed -i -e '/register digitalocean/d' discovery/install/install.go"}
+    ${lib.optionalString (!enableGCE)
+      "sed -i -e '/register gce/d' discovery/install/install.go"}
+    ${lib.optionalString (!enableKubernetes)
+      "sed -i -e '/register kubernetes/d' discovery/install/install.go"}
+    ${lib.optionalString (!enableLinode)
+      "sed -i -e '/register linode/d' discovery/install/install.go"}
   '';
 
   tags = [ "builtinassets" ];