at 17.09-beta 3.7 kB view raw
1# Test the ELK stack: Elasticsearch, Logstash and Kibana. 2 3import ./make-test.nix ({ pkgs, ...} : 4let 5 esUrl = "http://localhost:9200"; 6in { 7 name = "ELK"; 8 meta = with pkgs.stdenv.lib.maintainers; { 9 maintainers = [ eelco chaoflow offline basvandijk ]; 10 }; 11 12 nodes = { 13 one = 14 { config, pkgs, ... }: { 15 # Not giving the machine at least 2060MB results in elasticsearch failing with the following error: 16 # 17 # OpenJDK 64-Bit Server VM warning: 18 # INFO: os::commit_memory(0x0000000085330000, 2060255232, 0) 19 # failed; error='Cannot allocate memory' (errno=12) 20 # 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. 23 # 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 26 # bit more room: 27 virtualisation.memorySize = 3000; 28 29 # For querying JSON objects returned from elasticsearch and kibana. 30 environment.systemPackages = [ pkgs.jq ]; 31 32 services = { 33 logstash = { 34 enable = true; 35 package = pkgs.logstash5; 36 inputConfig = '' 37 exec { command => "echo -n flowers" interval => 1 type => "test" } 38 exec { command => "echo -n dragons" interval => 1 type => "test" } 39 ''; 40 filterConfig = '' 41 if [message] =~ /dragons/ { 42 drop {} 43 } 44 ''; 45 outputConfig = '' 46 file { 47 path => "/tmp/logstash.out" 48 codec => line { format => "%{message}" } 49 } 50 elasticsearch { 51 hosts => [ "${esUrl}" ] 52 } 53 ''; 54 }; 55 56 elasticsearch = { 57 enable = true; 58 package = pkgs.elasticsearch5; 59 }; 60 61 kibana = { 62 enable = true; 63 package = pkgs.kibana5; 64 elasticsearch.url = esUrl; 65 }; 66 }; 67 }; 68 }; 69 70 testScript = '' 71 startAll; 72 73 $one->waitForUnit("elasticsearch.service"); 74 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 77 # node which elasticsearch considers risky. 78 # 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"); 81 82 # Perform some simple logstash tests. 83 $one->waitForUnit("logstash.service"); 84 $one->waitUntilSucceeds("cat /tmp/logstash.out | grep flowers"); 85 $one->waitUntilSucceeds("cat /tmp/logstash.out | grep -v dragons"); 86 87 # See if kibana is healthy. 88 $one->waitForUnit("kibana.service"); 89 $one->waitUntilSucceeds("curl --silent --show-error 'http://localhost:5601/api/status' | jq .status.overall.state | grep green"); 90 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"); 93 $one->waitUntilSucceeds("curl --silent --show-error '${esUrl}/_search' -H 'Content-Type: application/json' -d '{\"query\" : { \"match\" : { \"message\" : \"dragons\"}}}' | jq .hits.total | grep 0"); 94 ''; 95})