Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions app/Elasticsearch/LifetimePolicy/LifetimePolicyCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php declare(strict_types = 1);

namespace Pd\Monitoring\Elasticsearch\LifetimePolicy;

class LifetimePolicyCommand extends \Symfony\Component\Console\Command\Command
{

private const LIFETIME_POLICY_NAME = 'monitoring-lifetime-policy';

private \Elasticsearch\Client $client;


public function __construct(\Elasticsearch\Client $client)
{
parent::__construct();

$this->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;
}

}
7 changes: 7 additions & 0 deletions app/Elasticsearch/LifetimePolicy/create_index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"aliases": {
"test-alias":{
"is_write_index": true
}
}
}
11 changes: 11 additions & 0 deletions app/Elasticsearch/LifetimePolicy/index_template.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
19 changes: 19 additions & 0 deletions app/Elasticsearch/LifetimePolicy/lifetime_policy.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"policy": {
"phases": {
"hot": {
"actions": {
"rollover": {
"max_age": "7d"
}
}
},
"delete": {
"min_age": "8d",
"actions": {
"delete": {}
}
}
}
}
}
5 changes: 5 additions & 0 deletions app/config/config.neon
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,11 @@ services:
arguments:
isAllowed: %github.allow%

-
factory: \Pd\Monitoring\Elasticsearch\LifetimePolicy\LifetimePolicyCommand
tags:
- kdyby.console.command


decorator:
Nette\Application\UI\Control:
Expand Down