1515use Symfony \Component \HttpFoundation \Response ;
1616use Symfony \Component \HttpKernel \Exception \NotFoundHttpException ;
1717use 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
0 commit comments