From a6cdcce08bb18d17819a2a76dfac8da7ce1a6328 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Sat, 28 May 2022 22:07:34 +0200 Subject: [PATCH] nixos/mimir: add test --- nixos/tests/all-tests.nix | 1 + nixos/tests/grafana-mimir.nix | 50 +++++++++++++++++++++++ pkgs/servers/monitoring/mimir/default.nix | 6 ++- 3 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 nixos/tests/grafana-mimir.nix diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index f4b6ee73562e..e61798676a0d 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -170,6 +170,7 @@ in frr = handleTest ./frr.nix {}; fsck = handleTest ./fsck.nix {}; ft2-clone = handleTest ./ft2-clone.nix {}; + grafana-mimir = handleTest ./grafana-mimir.nix {}; gerrit = handleTest ./gerrit.nix {}; geth = handleTest ./geth.nix {}; ghostunnel = handleTest ./ghostunnel.nix {}; diff --git a/nixos/tests/grafana-mimir.nix b/nixos/tests/grafana-mimir.nix new file mode 100644 index 000000000000..0aafa956f0be --- /dev/null +++ b/nixos/tests/grafana-mimir.nix @@ -0,0 +1,50 @@ +import ./make-test-python.nix ({ pkgs, ... }: { + name = "grafana-mimir"; + nodes = { + server = { ... }: { + environment.systemPackages = [ pkgs.jq ]; + services.mimir.enable = true; + services.mimir.configuration = { + ingester.ring.replication_factor = 1; + }; + + services.telegraf.enable = true; + services.telegraf.extraConfig = { + agent.interval = "1s"; + agent.flush_interval = "1s"; + inputs.exec = { + commands = [ + "${pkgs.coreutils}/bin/echo 'foo i=42i'" + ]; + data_format = "influx"; + }; + outputs = { + http = { + # test remote write + url = "http://localhost:8080/api/v1/push"; + + # Data format to output. + data_format = "prometheusremotewrite"; + + headers = { + Content-Type = "application/x-protobuf"; + Content-Encoding = "snappy"; + X-Scope-OrgID = "nixos"; + X-Prometheus-Remote-Write-Version = "0.1.0"; + }; + }; + }; + }; + }; + }; + + testScript = '' + start_all() + server.wait_for_unit("mimir.service") + server.wait_for_unit("telegraf.service") + server.wait_for_open_port(8080) + server.wait_until_succeeds( + "curl -H 'X-Scope-OrgID: nixos' http://127.0.0.1:8080/prometheus/api/v1/label/host/values | jq -r '.data[0]' | grep server" + ) + ''; +}) diff --git a/pkgs/servers/monitoring/mimir/default.nix b/pkgs/servers/monitoring/mimir/default.nix index 63e13da428c7..500ba3154753 100644 --- a/pkgs/servers/monitoring/mimir/default.nix +++ b/pkgs/servers/monitoring/mimir/default.nix @@ -1,4 +1,4 @@ -{ lib, buildGoModule, fetchFromGitHub }: +{ lib, buildGoModule, fetchFromGitHub, nixosTests }: buildGoModule rec { pname = "mimir"; version = "2.1.0"; @@ -17,6 +17,10 @@ buildGoModule rec { "cmd/mimirtool" ]; + passthru.tests = { + inherit (nixosTests) grafana-mimir; + }; + ldflags = let t = "github.com/grafana/mimir/pkg/util/version"; in [ ''-extldflags "-static"''