From 374446758928f6101df8a609de6cc614afbd24f3 Mon Sep 17 00:00:00 2001 From: David Smith Date: Wed, 1 Aug 2018 17:21:10 +0100 Subject: [PATCH 01/11] nixos/curator: init elasticsearch curator https://www.elastic.co/guide/en/elasticsearch/client/curator/5.5/index.html --- .../services/search/elasticsearch-curator.nix | 94 +++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 nixos/modules/services/search/elasticsearch-curator.nix diff --git a/nixos/modules/services/search/elasticsearch-curator.nix b/nixos/modules/services/search/elasticsearch-curator.nix new file mode 100644 index 000000000000..c694f812caf6 --- /dev/null +++ b/nixos/modules/services/search/elasticsearch-curator.nix @@ -0,0 +1,94 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + cfg = config.services.elasticsearch-curator; + curatorConfig = pkgs.writeTextFile { + name = "config.yaml"; + text = '' + --- + # Remember, leave a key empty if there is no value. None will be a string, + # not a Python "NoneType" + client: + hosts: ${builtins.toJSON cfg.hosts} + port: ${cfg.port} + url_prefix: + use_ssl: False + certificate: + client_cert: + client_key: + ssl_no_validate: False + http_auth: + timeout: 30 + master_only: False + logging: + loglevel: INFO + logfile: + logformat: default + blacklist: ['elasticsearch', 'urllib3'] + ''; + }; + curatorAction = pkgs.writeTextFile { + name = "action.yaml"; + text = cfg.actionYAML; + }; +in { + + options.services.elasticsearch-curator = { + + enable = mkEnableOption "elasticsearch curator"; + interval = mkOption { + description = "The frequency to run curator, a systemd.time such as 'hourly'"; + default = "hourly"; + type = types.str; + }; + hosts = mkOption { + description = "a list of elasticsearch hosts to connect to"; + type = types.listOf types.str; + default = ["localhost"]; + }; + port = mkOption { + description = "the port that elasticsearch is listening on"; + type = types.int; + default = 9200; + }; + actionYAML = mkOption { + description = "curator action.yaml file contents, alternatively use curator-cli which takes a simple action command"; + example = '' + --- + actions: + 1: + action: delete_indices + description: >- + Delete indices older than 45 days (based on index name), for logstash- + prefixed indices. Ignore the error if the filter does not result in an + actionable list of indices (ignore_empty_list) and exit cleanly. + options: + ignore_empty_list: True + disable_action: False + filters: + - filtertype: pattern + kind: prefix + value: logstash- + - filtertype: age + source: name + direction: older + timestring: '%Y.%m.%d' + unit: days + unit_count: 45 + ''; + }; + }; + + config = mkIf cfg.enable { + + systemd.services.elasticsearch-curator = { + enable = cfg.enable; + startAt = cfg.interval; + serviceConfig = { + ExecStart = ''${pkgs.python36Packages.elasticsearch-curator}/bin/curator --config ${curatorConfig} ${curatorAction}''; + }; + }; + }; +} From 2ec33f527b604ae438e34fc598d85c50d88e4a61 Mon Sep 17 00:00:00 2001 From: David Smith Date: Tue, 21 Aug 2018 09:39:12 +0100 Subject: [PATCH 02/11] elasticsearch-curator: don't need to add enable to elasticsearch-curator service --- nixos/modules/services/search/elasticsearch-curator.nix | 1 - 1 file changed, 1 deletion(-) diff --git a/nixos/modules/services/search/elasticsearch-curator.nix b/nixos/modules/services/search/elasticsearch-curator.nix index c694f812caf6..63ffe10d21f0 100644 --- a/nixos/modules/services/search/elasticsearch-curator.nix +++ b/nixos/modules/services/search/elasticsearch-curator.nix @@ -84,7 +84,6 @@ in { config = mkIf cfg.enable { systemd.services.elasticsearch-curator = { - enable = cfg.enable; startAt = cfg.interval; serviceConfig = { ExecStart = ''${pkgs.python36Packages.elasticsearch-curator}/bin/curator --config ${curatorConfig} ${curatorAction}''; From 842000566b5d7cab0a7ed5b1cd1ee00962175a2b Mon Sep 17 00:00:00 2001 From: David Smith Date: Tue, 21 Aug 2018 09:39:25 +0100 Subject: [PATCH 03/11] elasticsearch-curator: add test --- nixos/tests/elk.nix | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/nixos/tests/elk.nix b/nixos/tests/elk.nix index 4c5c441ca265..665e27a05534 100644 --- a/nixos/tests/elk.nix +++ b/nixos/tests/elk.nix @@ -63,6 +63,33 @@ let package = elk.kibana; elasticsearch.url = esUrl; }; + + elasticsearch-curator = { + enable = true; + actionYAML = '' + --- + actions: + 1: + action: delete_indices + description: >- + Delete indices older than 1 minute (based on index name), for logstash- + prefixed indices. Ignore the error if the filter does not result in an + actionable list of indices (ignore_empty_list) and exit cleanly. + options: + ignore_empty_list: True + disable_action: False + filters: + - filtertype: pattern + kind: prefix + value: logstash- + - filtertype: age + source: name + direction: older + timestring: '%Y.%m.%d' + unit: minutes + unit_count: 1 + ''; + }; }; }; }; @@ -91,6 +118,9 @@ let # See if logstash messages arive in elasticsearch. $one->waitUntilSucceeds("curl --silent --show-error '${esUrl}/_search' -H 'Content-Type: application/json' -d '{\"query\" : { \"match\" : { \"message\" : \"flowers\"}}}' | jq .hits.total | grep -v 0"); $one->waitUntilSucceeds("curl --silent --show-error '${esUrl}/_search' -H 'Content-Type: application/json' -d '{\"query\" : { \"match\" : { \"message\" : \"dragons\"}}}' | jq .hits.total | grep 0"); + $one->systemctl("stop logstash"); + $one->systemctl("start elasticsearch-curator"); + $one->waitUntilSucceeds("! curl --silent --show-error '${esUrl}/_cat/indices' | grep logstash | grep -q ^$1"); ''; }; in mapAttrs mkElkTest { From 32200033a632c3eed1edab14b832297a1b2e0df6 Mon Sep 17 00:00:00 2001 From: Bas van Dijk Date: Tue, 21 Aug 2018 17:24:52 +0200 Subject: [PATCH 04/11] elasticsearch-curator: include the module in the module-list & fix bug --- nixos/modules/module-list.nix | 1 + nixos/modules/services/search/elasticsearch-curator.nix | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix index 2846afea8fbc..85440a8025c9 100644 --- a/nixos/modules/module-list.nix +++ b/nixos/modules/module-list.nix @@ -623,6 +623,7 @@ ./services/scheduling/fcron.nix ./services/scheduling/marathon.nix ./services/search/elasticsearch.nix + ./services/search/elasticsearch-curator.nix ./services/search/hound.nix ./services/search/kibana.nix ./services/search/solr.nix diff --git a/nixos/modules/services/search/elasticsearch-curator.nix b/nixos/modules/services/search/elasticsearch-curator.nix index 63ffe10d21f0..43785c392fee 100644 --- a/nixos/modules/services/search/elasticsearch-curator.nix +++ b/nixos/modules/services/search/elasticsearch-curator.nix @@ -12,7 +12,7 @@ let # not a Python "NoneType" client: hosts: ${builtins.toJSON cfg.hosts} - port: ${cfg.port} + port: ${toString cfg.port} url_prefix: use_ssl: False certificate: From 16ce3c8f74c753633d320a59a6cc95f361eee101 Mon Sep 17 00:00:00 2001 From: Bas van Dijk Date: Tue, 21 Aug 2018 17:41:26 +0200 Subject: [PATCH 05/11] elasticsearch-curator: include missing boto3 dependency TODO: we're still missing the requests-aws4auth>=0.9 dependency --- .../python-modules/elasticsearch-curator/default.nix | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkgs/development/python-modules/elasticsearch-curator/default.nix b/pkgs/development/python-modules/elasticsearch-curator/default.nix index 4b0aba45cd7a..c3e6df2da475 100644 --- a/pkgs/development/python-modules/elasticsearch-curator/default.nix +++ b/pkgs/development/python-modules/elasticsearch-curator/default.nix @@ -1,6 +1,7 @@ { stdenv , buildPythonPackage , fetchPypi +, boto3 , click , certifi , voluptuous @@ -33,6 +34,7 @@ buildPythonPackage rec { voluptuous pyyaml elasticsearch + boto3 ]; checkInputs = [ From 61b646741c5d4b43009e1abf17770b0d3047cfad Mon Sep 17 00:00:00 2001 From: Bas van Dijk Date: Sat, 25 Aug 2018 16:34:56 +0200 Subject: [PATCH 06/11] pythonPackages.requests-aws4auth: init at 0.9 Needed by elasticsearch-curator. --- .../elasticsearch-curator/default.nix | 2 ++ .../requests-aws4auth/default.nix | 21 +++++++++++++++++++ pkgs/top-level/python-packages.nix | 2 ++ 3 files changed, 25 insertions(+) create mode 100644 pkgs/development/python-modules/requests-aws4auth/default.nix diff --git a/pkgs/development/python-modules/elasticsearch-curator/default.nix b/pkgs/development/python-modules/elasticsearch-curator/default.nix index c3e6df2da475..7df3049a493a 100644 --- a/pkgs/development/python-modules/elasticsearch-curator/default.nix +++ b/pkgs/development/python-modules/elasticsearch-curator/default.nix @@ -4,6 +4,7 @@ , boto3 , click , certifi +, requests-aws4auth , voluptuous , pyyaml , elasticsearch @@ -31,6 +32,7 @@ buildPythonPackage rec { propagatedBuildInputs = [ click certifi + requests-aws4auth voluptuous pyyaml elasticsearch diff --git a/pkgs/development/python-modules/requests-aws4auth/default.nix b/pkgs/development/python-modules/requests-aws4auth/default.nix new file mode 100644 index 000000000000..05a15841c42b --- /dev/null +++ b/pkgs/development/python-modules/requests-aws4auth/default.nix @@ -0,0 +1,21 @@ +{ lib, buildPythonPackage, fetchPypi, requests }: +buildPythonPackage rec { + pname = "requests-aws4auth"; + version = "0.9"; + + src = fetchPypi { + inherit pname version; + sha256 = "0g52a1pm53aqkc9qb5q1m918c1qy6q47c1qz63p5ilynfbs3m5y9"; + }; + + propagatedBuildInputs = [ requests ]; + + doCheck = false; + + meta = with lib; { + description = "Amazon Web Services version 4 authentication for the Python Requests library."; + homepage = https://github.com/sam-washington/requests-aws4auth; + license = licenses.mit; + maintainers = [ maintainers.basvandijk ]; + }; +} diff --git a/pkgs/top-level/python-packages.nix b/pkgs/top-level/python-packages.nix index 322f831b4b50..3ba335146ce3 100644 --- a/pkgs/top-level/python-packages.nix +++ b/pkgs/top-level/python-packages.nix @@ -2009,6 +2009,8 @@ in { requests-unixsocket = callPackage ../development/python-modules/requests-unixsocket {}; + requests-aws4auth = callPackage ../development/python-modules/requests-aws4auth { }; + howdoi = callPackage ../development/python-modules/howdoi {}; neurotools = callPackage ../development/python-modules/neurotools {}; From 8aa331874175dc3d35c9211ea2e627c8194f40d4 Mon Sep 17 00:00:00 2001 From: Bas van Dijk Date: Sat, 25 Aug 2018 16:44:27 +0200 Subject: [PATCH 07/11] elasticsearch-curator: disable test-suite because it hangs --- .../python-modules/elasticsearch-curator/default.nix | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/pkgs/development/python-modules/elasticsearch-curator/default.nix b/pkgs/development/python-modules/elasticsearch-curator/default.nix index 7df3049a493a..3b882c5f8731 100644 --- a/pkgs/development/python-modules/elasticsearch-curator/default.nix +++ b/pkgs/development/python-modules/elasticsearch-curator/default.nix @@ -24,10 +24,7 @@ buildPythonPackage rec { sha256 = "e75abeb7f7be939b1c64c071898760dc10ab5f08307c253fc074abf8a41a76f0"; }; - # The integration tests require a running elasticsearch cluster. - postUnpackPhase = '' - rm -r test/integration - ''; + doCheck = false; propagatedBuildInputs = [ click From 241377ee76b0f3c8f9a852756689ec01fe05764a Mon Sep 17 00:00:00 2001 From: Bas van Dijk Date: Sat, 25 Aug 2018 16:46:39 +0200 Subject: [PATCH 08/11] nixos/tests/elk.nix: make sure the test doesn't wait for too long on elasticsearch-curator --- nixos/tests/elk.nix | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/nixos/tests/elk.nix b/nixos/tests/elk.nix index 665e27a05534..15be72b80bba 100644 --- a/nixos/tests/elk.nix +++ b/nixos/tests/elk.nix @@ -72,7 +72,7 @@ let 1: action: delete_indices description: >- - Delete indices older than 1 minute (based on index name), for logstash- + Delete indices older than 1 second (based on index name), for logstash- prefixed indices. Ignore the error if the filter does not result in an actionable list of indices (ignore_empty_list) and exit cleanly. options: @@ -86,7 +86,7 @@ let source: name direction: older timestring: '%Y.%m.%d' - unit: minutes + unit: seconds unit_count: 1 ''; }; @@ -118,6 +118,8 @@ let # See if logstash messages arive in elasticsearch. $one->waitUntilSucceeds("curl --silent --show-error '${esUrl}/_search' -H 'Content-Type: application/json' -d '{\"query\" : { \"match\" : { \"message\" : \"flowers\"}}}' | jq .hits.total | grep -v 0"); $one->waitUntilSucceeds("curl --silent --show-error '${esUrl}/_search' -H 'Content-Type: application/json' -d '{\"query\" : { \"match\" : { \"message\" : \"dragons\"}}}' | jq .hits.total | grep 0"); + + # Test elasticsearch-curator. $one->systemctl("stop logstash"); $one->systemctl("start elasticsearch-curator"); $one->waitUntilSucceeds("! curl --silent --show-error '${esUrl}/_cat/indices' | grep logstash | grep -q ^$1"); From 228705fc3358ab9e6eeee44e623fae406a45f8d6 Mon Sep 17 00:00:00 2001 From: Bas van Dijk Date: Sat, 25 Aug 2018 18:59:32 +0200 Subject: [PATCH 09/11] elasticsearch-curator: add note to the NixOS release notes --- nixos/doc/manual/release-notes/rl-1809.xml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/nixos/doc/manual/release-notes/rl-1809.xml b/nixos/doc/manual/release-notes/rl-1809.xml index 8ee2a5f16238..d190394b9887 100644 --- a/nixos/doc/manual/release-notes/rl-1809.xml +++ b/nixos/doc/manual/release-notes/rl-1809.xml @@ -111,6 +111,12 @@ $ nix-instantiate -E '(import <nixpkgsunstable> {}).gitFull' stroke configuration interface. + + + The new services.elasticsearch-curator service + periodically curates or manages, your Elasticsearch indices and snapshots. + + From d5e7d48f5e10d58bdb2ed08214b4e33333e69763 Mon Sep 17 00:00:00 2001 From: Bas van Dijk Date: Sun, 26 Aug 2018 01:12:16 +0200 Subject: [PATCH 10/11] requests-aws4auth: only disable tests on python >= 3 --- .../python-modules/requests-aws4auth/default.nix | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/pkgs/development/python-modules/requests-aws4auth/default.nix b/pkgs/development/python-modules/requests-aws4auth/default.nix index 05a15841c42b..b7010eccf0b3 100644 --- a/pkgs/development/python-modules/requests-aws4auth/default.nix +++ b/pkgs/development/python-modules/requests-aws4auth/default.nix @@ -1,4 +1,5 @@ -{ lib, buildPythonPackage, fetchPypi, requests }: +{ lib, buildPythonPackage, fetchPypi, fetchzip, isPy3k, requests }: +with lib; buildPythonPackage rec { pname = "requests-aws4auth"; version = "0.9"; @@ -8,11 +9,17 @@ buildPythonPackage rec { sha256 = "0g52a1pm53aqkc9qb5q1m918c1qy6q47c1qz63p5ilynfbs3m5y9"; }; + postPatch = optionalString isPy3k '' + sed "s/path_encoding_style/'path_encoding_style'/" \ + -i requests_aws4auth/service_parameters.py + ''; + propagatedBuildInputs = [ requests ]; - doCheck = false; + # The test fail on Python >= 3 because of module import errors. + doCheck = !isPy3k; - meta = with lib; { + meta = { description = "Amazon Web Services version 4 authentication for the Python Requests library."; homepage = https://github.com/sam-washington/requests-aws4auth; license = licenses.mit; From 954eb34a5363877e5efed27ddc2bc748f6265019 Mon Sep 17 00:00:00 2001 From: Bas van Dijk Date: Sun, 26 Aug 2018 01:20:15 +0200 Subject: [PATCH 11/11] elasticsearch-curator: explain why we disable the test-suite --- .../development/python-modules/elasticsearch-curator/default.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/pkgs/development/python-modules/elasticsearch-curator/default.nix b/pkgs/development/python-modules/elasticsearch-curator/default.nix index 3b882c5f8731..1ea6e4cabad8 100644 --- a/pkgs/development/python-modules/elasticsearch-curator/default.nix +++ b/pkgs/development/python-modules/elasticsearch-curator/default.nix @@ -24,6 +24,7 @@ buildPythonPackage rec { sha256 = "e75abeb7f7be939b1c64c071898760dc10ab5f08307c253fc074abf8a41a76f0"; }; + # The test hangs so we disable it. doCheck = false; propagatedBuildInputs = [