From e5efb382a93defddac995f51a46ae35999e76697 Mon Sep 17 00:00:00 2001 From: jakubenglicky Date: Mon, 8 Nov 2021 21:08:22 +0100 Subject: [PATCH] =?UTF-8?q?WIP=20P=C5=99id=C3=A1n=C3=AD=20lifetime=20polic?= =?UTF-8?q?y?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../LifetimePolicy/LifetimePolicyCommand.php | 41 +++++++++++++++++++ .../LifetimePolicy/create_index.json | 7 ++++ .../LifetimePolicy/index_template.json | 11 +++++ .../LifetimePolicy/lifetime_policy.json | 19 +++++++++ app/config/config.neon | 5 +++ 5 files changed, 83 insertions(+) create mode 100644 app/Elasticsearch/LifetimePolicy/LifetimePolicyCommand.php create mode 100644 app/Elasticsearch/LifetimePolicy/create_index.json create mode 100644 app/Elasticsearch/LifetimePolicy/index_template.json create mode 100644 app/Elasticsearch/LifetimePolicy/lifetime_policy.json diff --git a/app/Elasticsearch/LifetimePolicy/LifetimePolicyCommand.php b/app/Elasticsearch/LifetimePolicy/LifetimePolicyCommand.php new file mode 100644 index 0000000..b0423e6 --- /dev/null +++ b/app/Elasticsearch/LifetimePolicy/LifetimePolicyCommand.php @@ -0,0 +1,41 @@ +client = $client; + } + + + public function configure() + { + $this->setName('elasticsearch:lifetime-policy:enable'); + } + + + public function execute(\Symfony\Component\Console\Input\InputInterface $input, \Symfony\Component\Console\Output\OutputInterface $output): int + { + $lifetimePolicyFile = \Nette\Utils\FileSystem::read(__DIR__ . '/lifetime_policy.json'); + $this->client->ilm()->putLifecycle([ + 'policy' => self::LIFETIME_POLICY_NAME, + 'body' => $lifetimePolicyFile + ] + ); + $output->writeln('Lifetime policy \'' . self::LIFETIME_POLICY_NAME . '\' added.'); + + + return 0; + } + +} diff --git a/app/Elasticsearch/LifetimePolicy/create_index.json b/app/Elasticsearch/LifetimePolicy/create_index.json new file mode 100644 index 0000000..357059b --- /dev/null +++ b/app/Elasticsearch/LifetimePolicy/create_index.json @@ -0,0 +1,7 @@ +{ + "aliases": { + "test-alias":{ + "is_write_index": true + } + } +} diff --git a/app/Elasticsearch/LifetimePolicy/index_template.json b/app/Elasticsearch/LifetimePolicy/index_template.json new file mode 100644 index 0000000..749d1cf --- /dev/null +++ b/app/Elasticsearch/LifetimePolicy/index_template.json @@ -0,0 +1,11 @@ +{ + "index_patterns": ["monitoring-*"], + "template": { + "settings": { + "number_of_shards": 1, + "number_of_replicas": 1, + "index.lifecycle.name": "my_policy", + "index.lifecycle.rollover_alias": "test-alias" + } + } +} diff --git a/app/Elasticsearch/LifetimePolicy/lifetime_policy.json b/app/Elasticsearch/LifetimePolicy/lifetime_policy.json new file mode 100644 index 0000000..78a6810 --- /dev/null +++ b/app/Elasticsearch/LifetimePolicy/lifetime_policy.json @@ -0,0 +1,19 @@ +{ + "policy": { + "phases": { + "hot": { + "actions": { + "rollover": { + "max_age": "7d" + } + } + }, + "delete": { + "min_age": "8d", + "actions": { + "delete": {} + } + } + } + } +} diff --git a/app/config/config.neon b/app/config/config.neon index abbcde5..b72461b 100644 --- a/app/config/config.neon +++ b/app/config/config.neon @@ -455,6 +455,11 @@ services: arguments: isAllowed: %github.allow% + - + factory: \Pd\Monitoring\Elasticsearch\LifetimePolicy\LifetimePolicyCommand + tags: + - kdyby.console.command + decorator: Nette\Application\UI\Control: