diff --git a/nixos/doc/manual/release-notes/rl-2511.section.md b/nixos/doc/manual/release-notes/rl-2511.section.md index 15fd7c573239..db028db407e9 100644 --- a/nixos/doc/manual/release-notes/rl-2511.section.md +++ b/nixos/doc/manual/release-notes/rl-2511.section.md @@ -92,6 +92,8 @@ - [conman](https://github.com/dun/conman), a serial console management program. Available as [services.conman](#opt-services.conman.enable). +- [KMinion](https://github.com/redpanda-data/kminion), feature-rich Prometheus exporter for Apache Kafka. Available as [services.prometheus.exporters.kafka](options.html#opt-services.prometheus.exporters.kafka). + ## Backward Incompatibilities {#sec-release-25.11-incompatibilities} diff --git a/nixos/modules/services/monitoring/prometheus/exporters.nix b/nixos/modules/services/monitoring/prometheus/exporters.nix index 28144b6267c2..35a89ab1bf71 100644 --- a/nixos/modules/services/monitoring/prometheus/exporters.nix +++ b/nixos/modules/services/monitoring/prometheus/exporters.nix @@ -79,6 +79,7 @@ let "jitsi" "json" "junos-czerwonk" + "kafka" "kea" "keylight" "klipper" diff --git a/nixos/modules/services/monitoring/prometheus/exporters/kafka.nix b/nixos/modules/services/monitoring/prometheus/exporters/kafka.nix new file mode 100644 index 000000000000..ebe17e08aeac --- /dev/null +++ b/nixos/modules/services/monitoring/prometheus/exporters/kafka.nix @@ -0,0 +1,56 @@ +{ + config, + lib, + pkgs, + ... +}: + +let + cfg = config.services.prometheus.exporters.kafka; + inherit (lib) + mkIf + mkOption + mkMerge + types + concatStringsSep + ; +in +{ + port = 8080; + + extraOpts = { + package = lib.mkPackageOption pkgs "kminion" { }; + + environmentFile = mkOption { + type = with types; nullOr path; + default = null; + description = '' + File containing the credentials to access the repository, in the + format of an EnvironmentFile as described by systemd.exec(5) + ''; + }; + }; + serviceOpts = mkMerge ( + [ + { + serviceConfig = { + ExecStart = '' + ${lib.getExe cfg.package} + ''; + EnvironmentFile = mkIf (cfg.environmentFile != null) cfg.environmentFile; + RestartSec = "5s"; + RestrictAddressFamilies = [ + "AF_INET" + "AF_INET6" + ]; + }; + } + ] + ++ [ + (mkIf config.services.apache-kafka.enable { + after = [ "apache-kafka.service" ]; + requires = [ "apache-kafka.service" ]; + }) + ] + ); +} diff --git a/nixos/tests/prometheus-exporters.nix b/nixos/tests/prometheus-exporters.nix index 010e912b563a..cbfd5426af07 100644 --- a/nixos/tests/prometheus-exporters.nix +++ b/nixos/tests/prometheus-exporters.nix @@ -587,6 +587,63 @@ let ''; }; + kafka = { + exporterConfig = { + enable = true; + environmentFile = pkgs.writeTextFile { + name = "/tmp/prometheus-kafka-exporter.env"; + text = '' + KAFKA_BROKERS="localhost:9092" + ''; + }; + }; + metricProvider = { + services.apache-kafka = { + enable = true; + + clusterId = "pHG8aWuXSfWAibHFDCnsCQ"; + + formatLogDirs = true; + + settings = { + "node.id" = 1; + "process.roles" = [ + "broker" + "controller" + ]; + "listeners" = [ + "PLAINTEXT://:9092" + "CONTROLLER://:9093" + ]; + "listener.security.protocol.map" = [ + "PLAINTEXT:PLAINTEXT" + "CONTROLLER:PLAINTEXT" + ]; + "controller.quorum.voters" = [ + "1@localhost:9093" + ]; + "controller.listener.names" = [ "CONTROLLER" ]; + "log.dirs" = [ "/var/lib/apache-kafka" ]; + }; + }; + + systemd.services.apache-kafka.serviceConfig.StateDirectory = "apache-kafka"; + }; + exporterTest = '' + wait_for_unit("apache-kafka") + wait_for_open_port(9092) + wait_for_open_port(9093) + wait_for_unit("prometheus-kafka-exporter.service") + wait_for_open_port(8080) + wait_until_succeeds( + "journalctl -o cat -u prometheus-kafka-exporter.service | grep '\"version\":\"${pkgs.kminion.version}\"'" + ) + succeed( + "curl -sSf http://localhost:8080/metrics | grep 'kminion_exporter_up'" + ) + ''; + }; + knot = { exporterConfig = { enable = true; diff --git a/pkgs/by-name/km/kminion/package.nix b/pkgs/by-name/km/kminion/package.nix index 2575ff228e1b..9d9f8b150624 100644 --- a/pkgs/by-name/km/kminion/package.nix +++ b/pkgs/by-name/km/kminion/package.nix @@ -2,30 +2,42 @@ lib, fetchFromGitHub, buildGoModule, + nixosTests, }: -buildGoModule { +buildGoModule (finalAttrs: { pname = "kafka-minion"; - version = "2.2.7"; + version = "2.2.13"; src = fetchFromGitHub { owner = "redpanda-data"; repo = "kminion"; - rev = "0c90d4301ed4600d1aaf3345b6f16587d2f282fc"; - hash = "sha256-CWjX46Sfc9Xj+R7+CZeMuTY0iUStzyZXI4FotwqR44M="; + rev = "v${finalAttrs.version}"; + hash = "sha256-s7kHMMU/srqww/N5szTvX6hOFDV9k9hm+0EZUxIj9So="; }; - vendorHash = "sha256-6yfQVoY/bHMA4s0IN5ltnQdHWnE3kIKza36uEcGa11U="; + vendorHash = "sha256-vdbSKEWlFH4UkuBxu0LFs8+Rwa4aWTjE8gD4zKuvcs4="; doCheck = false; - passthru.updateScript = ./update.sh; + ldflags = [ + "-s" + "-w" + "-X main.version=${finalAttrs.version}" + "-X main.builtAt=unknown" + ]; + + passthru = { + tests = { + inherit (nixosTests.prometheus-exporters) kafka; + }; + updateScript = ./update.sh; + }; meta = with lib; { description = "Feature-rich Prometheus exporter for Apache Kafka written in Go"; license = licenses.mit; - platforms = platforms.linux; maintainers = with maintainers; [ cafkafk ]; mainProgram = "kminion"; }; -} +})