@@ -1,95 +1,107 @@
1−# Test the ELK stack: Elasticsearch, Logstash and Kibana.
1+{ system ? builtins.currentSystem }:
2−
2+with import ../lib/testing.nix { inherit system; };
3−import ./make-test.nix ({ pkgs, ...} :
3+with pkgs.lib;
5 esUrl = "http://localhost:9200";
5 esUrl = "http://localhost:9200";
8− meta = with pkgs.stdenv.lib.maintainers; {
9− maintainers = [ eelco chaoflow offline basvandijk ];
7+ mkElkTest = name : elk : makeTest {
9+ meta = with pkgs.stdenv.lib.maintainers; {
10+ maintainers = [ eelco chaoflow offline basvandijk ];
12− nodes = {
12+ nodes = {
14− { config, pkgs, ... }: {
14+ { config, pkgs, ... }: {
15− # Not giving the machine at least 2060MB results in elasticsearch failing with the following error:
15+ # Not giving the machine at least 2060MB results in elasticsearch failing with the following error:
17− # OpenJDK 64-Bit Server VM warning:
17+ # OpenJDK 64-Bit Server VM warning:
18− # INFO: os::commit_memory(0x0000000085330000, 2060255232, 0)
18+ # INFO: os::commit_memory(0x0000000085330000, 2060255232, 0)
19− # failed; error='Cannot allocate memory' (errno=12)
19+ # failed; error='Cannot allocate memory' (errno=12)
21− # There is insufficient memory for the Java Runtime Environment to continue.
21+ # There is insufficient memory for the Java Runtime Environment to continue.
22− # Native memory allocation (mmap) failed to map 2060255232 bytes for committing reserved memory.
22+ # Native memory allocation (mmap) failed to map 2060255232 bytes for committing reserved memory.
24− # When setting this to 2500 I got "Kernel panic - not syncing: Out of
24+ # When setting this to 2500 I got "Kernel panic - not syncing: Out of
25− # memory: compulsory panic_on_oom is enabled" so lets give it even a
25+ # memory: compulsory panic_on_oom is enabled" so lets give it even a
26− # bit more room:
26+ # bit more room:
27− virtualisation.memorySize = 3000;
27+ virtualisation.memorySize = 3000;
29− # For querying JSON objects returned from elasticsearch and kibana.
29+ # For querying JSON objects returned from elasticsearch and kibana.
30− environment.systemPackages = [ pkgs.jq ];
30+ environment.systemPackages = [ pkgs.jq ];
32− services = {
32+ services = {
33− logstash = {
33+ logstash = {
34− enable = true;
34+ enable = true;
35− package = pkgs.logstash5;
35+ package = elk.logstash;
36− inputConfig = ''
36+ inputConfig = ''
37− exec { command => "echo -n flowers" interval => 1 type => "test" }
37+ exec { command => "echo -n flowers" interval => 1 type => "test" }
38− exec { command => "echo -n dragons" interval => 1 type => "test" }
38+ exec { command => "echo -n dragons" interval => 1 type => "test" }
40− filterConfig = ''
40+ filterConfig = ''
41− if [message] =~ /dragons/ {
41+ if [message] =~ /dragons/ {
45− outputConfig = ''
45+ outputConfig = ''
47− path => "/tmp/logstash.out"
47+ path => "/tmp/logstash.out"
48− codec => line { format => "%{message}" }
48+ codec => line { format => "%{message}" }
50− elasticsearch {
50+ elasticsearch {
51− hosts => [ "${esUrl}" ]
51+ hosts => [ "${esUrl}" ]
56− elasticsearch = {
56+ elasticsearch = {
57− enable = true;
57+ enable = true;
58− package = pkgs.elasticsearch5;
58+ package = elk.elasticsearch;
61− kibana = {
61+ kibana = {
62− enable = true;
62+ enable = true;
63− package = pkgs.kibana5;
63+ package = elk.kibana;
64− elasticsearch.url = esUrl;
64+ elasticsearch.url = esUrl;
70− testScript = ''
70+ testScript = ''
71− startAll;
71+ startAll;
73− $one->waitForUnit("elasticsearch.service");
73+ $one->waitForUnit("elasticsearch.service");
75− # Continue as long as the status is not "red". The status is probably
75+ # Continue as long as the status is not "red". The status is probably
76− # "yellow" instead of "green" because we are using a single elasticsearch
76+ # "yellow" instead of "green" because we are using a single elasticsearch
77− # node which elasticsearch considers risky.
77+ # node which elasticsearch considers risky.
79− # TODO: extend this test with multiple elasticsearch nodes and see if the status turns "green".
79+ # TODO: extend this test with multiple elasticsearch nodes and see if the status turns "green".
80− $one->waitUntilSucceeds("curl --silent --show-error '${esUrl}/_cluster/health' | jq .status | grep -v red");
80+ $one->waitUntilSucceeds("curl --silent --show-error '${esUrl}/_cluster/health' | jq .status | grep -v red");
82− # Perform some simple logstash tests.
82+ # Perform some simple logstash tests.
83− $one->waitForUnit("logstash.service");
83+ $one->waitForUnit("logstash.service");
84− $one->waitUntilSucceeds("cat /tmp/logstash.out | grep flowers");
84+ $one->waitUntilSucceeds("cat /tmp/logstash.out | grep flowers");
85− $one->waitUntilSucceeds("cat /tmp/logstash.out | grep -v dragons");
85+ $one->waitUntilSucceeds("cat /tmp/logstash.out | grep -v dragons");
87− # See if kibana is healthy.
87+ # See if kibana is healthy.
88− $one->waitForUnit("kibana.service");
88+ $one->waitForUnit("kibana.service");
89− $one->waitUntilSucceeds("curl --silent --show-error 'http://localhost:5601/api/status' | jq .status.overall.state | grep green");
89+ $one->waitUntilSucceeds("curl --silent --show-error 'http://localhost:5601/api/status' | jq .status.overall.state | grep green");
91− # See if logstash messages arive in elasticsearch.
91+ # See if logstash messages arive in elasticsearch.
92− $one->waitUntilSucceeds("curl --silent --show-error '${esUrl}/_search' -H 'Content-Type: application/json' -d '{\"query\" : { \"match\" : { \"message\" : \"flowers\"}}}' | jq .hits.total | grep -v 0");
92+ $one->waitUntilSucceeds("curl --silent --show-error '${esUrl}/_search' -H 'Content-Type: application/json' -d '{\"query\" : { \"match\" : { \"message\" : \"flowers\"}}}' | jq .hits.total | grep -v 0");
93− $one->waitUntilSucceeds("curl --silent --show-error '${esUrl}/_search' -H 'Content-Type: application/json' -d '{\"query\" : { \"match\" : { \"message\" : \"dragons\"}}}' | jq .hits.total | grep 0");
93+ $one->waitUntilSucceeds("curl --silent --show-error '${esUrl}/_search' -H 'Content-Type: application/json' -d '{\"query\" : { \"match\" : { \"message\" : \"dragons\"}}}' | jq .hits.total | grep 0");
96+in mapAttrs mkElkTest {
98+ elasticsearch = pkgs.elasticsearch5;
99+ logstash = pkgs.logstash5;
100+ kibana = pkgs.kibana5;
103+ elasticsearch = pkgs.elasticsearch6;
104+ logstash = pkgs.logstash6;
105+ kibana = pkgs.kibana6;