Skip to content

Commit 3c03f86

Browse files
use filters for shards stats
1 parent c73ecf2 commit 3c03f86

File tree

4 files changed

+33
-15
lines changed

4 files changed

+33
-15
lines changed

src/Controller/ElasticsearchShardController.php

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Component\HttpFoundation\Response;
1616
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
1717
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
18+
use Symfony\Component\Form\FormInterface;
1819

1920
/**
2021
* @Route("/admin")
@@ -34,6 +35,16 @@ public function __construct(ElasticsearchShardManager $elasticsearchShardManager
3435
$this->elasticsearchNodeManager = $elasticsearchNodeManager;
3536
}
3637

38+
private function filter(array $shards, FormInterface $form): array
39+
{
40+
return $this->elasticsearchShardManager->filter($shards, [
41+
'index' => $form->get('index')->getData(),
42+
'type' => $form->get('type')->getData(),
43+
'state' => $form->get('state')->getData(),
44+
'node' => $form->get('node')->getData(),
45+
]);
46+
}
47+
3748
/**
3849
* @Route("/shards", name="shards")
3950
*/
@@ -62,12 +73,7 @@ public function index(Request $request): Response
6273

6374
$nodesAvailable = $this->elasticsearchShardManager->getNodesAvailable($shards, $nodes);
6475

65-
$shards = $this->elasticsearchShardManager->filter($shards, [
66-
'index' => $form->get('index')->getData(),
67-
'type' => $form->get('type')->getData(),
68-
'state' => $form->get('state')->getData(),
69-
'node' => $form->get('node')->getData(),
70-
]);
76+
$shards = $this->filter($shards, $form);
7177

7278
return $this->renderAbstract($request, 'Modules/shard/shard_index.html.twig', [
7379
'shards' => $this->paginatorManager->paginate([
@@ -91,24 +97,29 @@ public function stats(Request $request): Response
9197
{
9298
$this->denyAccessUnlessGranted('SHARDS_STATS', 'global');
9399

100+
$nodes = $this->elasticsearchNodeManager->selectNodes(['data' => 'yes']);
101+
102+
$form = $this->createForm(ElasticsearchShardFilterType::class, null, ['node' => $nodes]);
103+
104+
$form->handleRequest($request);
105+
94106
$query = [
95107
'bytes' => 'b',
96108
'h' => 'index,shard,prirep,state,unassigned.reason,docs,store,node',
97109
];
98110

99-
$shards = $this->elasticsearchShardManager->getAll($query);
111+
$shards = $this->elasticsearchShardManager->getAll($query, [
112+
'index' => $form->get('index')->getData(),
113+
]);
100114

101-
$clusterStats = $this->elasticsearchClusterManager->getClusterStats();
115+
$shards = $this->filter($shards, $form);
102116

103117
$data = ['totals' => [], 'tables' => []];
104118
$data['totals']['shards_total'] = 0;
105119
$data['totals']['shards_total_primary'] = 0;
106-
$data['totals']['shards_total_unassigned'] = 0;
107-
if (true === isset($clusterStats['indices']['shards']['replication'])) {
108-
$data['totals']['shards_replication'] = round($clusterStats['indices']['shards']['replication']*100, 2).'%';
109-
}
110120
$data['totals']['shards_total_documents'] = 0;
111121
$data['totals']['shards_total_size'] = 0;
122+
$data['totals']['shards_total_unassigned'] = 0;
112123
$data['tables']['shards_by_state'] = [];
113124
$data['tables']['shards_by_unassigned_reason'] = [];
114125
$data['tables']['shards_by_type'] = [];
@@ -172,6 +183,7 @@ public function stats(Request $request): Response
172183

173184
return $this->renderAbstract($request, 'Modules/shard/shard_stats.html.twig', [
174185
'data' => $data,
186+
'form' => $form->createView(),
175187
]);
176188
}
177189

templates/Modules/shard/shard_stats.html.twig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@
1212
{% endblock %}
1313

1414
{% block main_content %}
15+
{% embed 'Embed/block_embed.html.twig' %}
16+
{% import 'Import/app_import.html.twig' as appImport %}
17+
{% block content %}
18+
{{ appImport.form({'form': form, 'type': 'search'}) }}
19+
{% endblock %}
20+
{% endembed %}
21+
1522
{% embed 'Embed/block_embed.html.twig' %}
1623
{% import 'Import/app_import.html.twig' as appImport %}
1724
{% block content %}

templates/Modules/shard/shard_tabs.html.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
<ul class="nav nav-tabs mb-4">
33
{% if is_granted('SHARDS', 'global') %}
44
<li class="nav-item">
5-
<a class="nav-link {% if 'list' == active %}active {{ theme_tab_active }}{% else %}{{ theme_tab }}{% endif %}" href="{{ path('shards') }}">{{ 'list'|trans }}</a>
5+
<a class="nav-link {% if 'list' == active %}active {{ theme_tab_active }}{% else %}{{ theme_tab }}{% endif %}" href="{{ path('shards', app.request.query.all) }}">{{ 'list'|trans }}</a>
66
</li>
77
{% endif %}
88

99
{% if is_granted('SHARDS_STATS', 'global') %}
1010
<li class="nav-item">
11-
<a class="nav-link {% if 'stats' == active %}active {{ theme_tab_active }}{% else %}{{ theme_tab }}{% endif %}" href="{{ path('shards_stats') }}">{{ 'stats'|trans }}</a>
11+
<a class="nav-link {% if 'stats' == active %}active {{ theme_tab_active }}{% else %}{{ theme_tab }}{% endif %}" href="{{ path('shards_stats', app.request.query.all) }}">{{ 'stats'|trans }}</a>
1212
</li>
1313
{% endif %}
1414

translations/messages.en.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,6 @@ stats_data:
681681
shards_total: "Total shards"
682682
shards_total_primary: "Primary shards"
683683
shards_total_unassigned: "Unassigned shards"
684-
shards_replication: "Replication"
685684
shards_total_documents: "Total documents"
686685
shards_total_size: "Total size"
687686
shards_by_state: "Shards by state"

0 commit comments

Comments
 (0)