From 06618b2afee5abbbda361bd9a47e9b51577a6916 Mon Sep 17 00:00:00 2001 From: Gocha Ossinkine Date: Tue, 18 Jan 2022 19:07:01 +0200 Subject: [PATCH] Add selectbox for server name --- README.md | 3 +++ mongo.init.d/xhgui.js | 1 + src/Controller/RunController.php | 3 +++ src/Searcher/MongoSearcher.php | 8 ++++++++ src/Searcher/PdoSearcher.php | 8 ++++++++ src/Searcher/SearcherInterface.php | 7 +++++++ templates/runs/list.twig | 11 ++++++++++- tests/Searcher/MongoTest.php | 8 ++++++++ tests/fixtures/normalized.json | 20 ++++++++++++++++++++ 9 files changed, 68 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 56590355c..09394ae81 100644 --- a/README.md +++ b/README.md @@ -102,6 +102,7 @@ NOTE: PDO may not support all the features of XHGui, see [#320]. > db.results.ensureIndex( { 'profile.main().cpu' : -1 } ) > db.results.ensureIndex( { 'meta.url' : 1 } ) > db.results.ensureIndex( { 'meta.simple_url' : 1 } ) + > db.results.ensureIndex( { 'meta.SERVER.SERVER_NAME' : 1 } ) ``` 7. Install dependencies with composer @@ -271,11 +272,13 @@ storage.) | Searcher::getAllWatches() | ✓ | ✓ [#435] | | Searcher::truncateWatches() | ✓ | ✓ [#435] | | Searcher::stats() | ✗ [#305] | ✓ | +| Searcher::getAllServerNames() | ✓ | ✗ [#460] | [#305]: https://github.com/perftools/xhgui/pull/305 [#384]: https://github.com/perftools/xhgui/pull/384 [#435]: https://github.com/perftools/xhgui/pull/435 [#436]: https://github.com/perftools/xhgui/pull/436 +[#460]: https://github.com/perftools/xhgui/pull/460 # Releases / Changelog diff --git a/mongo.init.d/xhgui.js b/mongo.init.d/xhgui.js index c386fca36..09472b510 100644 --- a/mongo.init.d/xhgui.js +++ b/mongo.init.d/xhgui.js @@ -3,3 +3,4 @@ db.results.ensureIndex( { 'profile.main().wt' : -1 } ); db.results.ensureIndex( { 'profile.main().mu' : -1 } ); db.results.ensureIndex( { 'profile.main().cpu' : -1 } ); db.results.ensureIndex( { 'meta.url' : 1 } ); +db.results.ensureIndex( { 'meta.SERVER.SERVER_NAME' : 1 } ); diff --git a/src/Controller/RunController.php b/src/Controller/RunController.php index c7db7a244..14def25de 100644 --- a/src/Controller/RunController.php +++ b/src/Controller/RunController.php @@ -47,6 +47,8 @@ public function index(Request $request): void 'projection' => true, ])); + $serverNames = $this->searcher->getAllServerNames(); + $title = 'Recent runs'; $titleMap = [ 'wt' => 'Longest wall time', @@ -71,6 +73,7 @@ public function index(Request $request): void 'search' => $search, 'has_search' => implode('', $search) !== '', 'title' => $title, + 'server_names' => $serverNames, ]); } diff --git a/src/Searcher/MongoSearcher.php b/src/Searcher/MongoSearcher.php index e5bcd9a30..675d2565f 100644 --- a/src/Searcher/MongoSearcher.php +++ b/src/Searcher/MongoSearcher.php @@ -364,4 +364,12 @@ public function stats(): array 'bytes' => 0, ]; } + + /** + * {@inheritdoc} + */ + public function getAllServerNames() + { + return $this->_collection->distinct('meta.SERVER.SERVER_NAME'); + } } diff --git a/src/Searcher/PdoSearcher.php b/src/Searcher/PdoSearcher.php index 836208a42..13e9de4c1 100644 --- a/src/Searcher/PdoSearcher.php +++ b/src/Searcher/PdoSearcher.php @@ -226,6 +226,14 @@ public function stats() return $row; } + /** + * {@inheritdoc} + */ + public function getAllServerNames() + { + return false; + } + /** * {@inheritdoc} */ diff --git a/src/Searcher/SearcherInterface.php b/src/Searcher/SearcherInterface.php index 8444204f6..19ea4db88 100644 --- a/src/Searcher/SearcherInterface.php +++ b/src/Searcher/SearcherInterface.php @@ -140,4 +140,11 @@ public function truncateWatches(); * @return array array of stats */ public function stats(); + + /** + * Get all the known server names. + * + * @return array|false array of server names or false if not supported + */ + public function getAllServerNames(); } diff --git a/templates/runs/list.twig b/templates/runs/list.twig index 90e763988..95ad82192 100644 --- a/templates/runs/list.twig +++ b/templates/runs/list.twig @@ -30,7 +30,16 @@
- + {% if server_names is iterable %} + + {% else %} + + {% endif %}
diff --git a/tests/Searcher/MongoTest.php b/tests/Searcher/MongoTest.php index 0ccb7f94f..af8f5fbf2 100644 --- a/tests/Searcher/MongoTest.php +++ b/tests/Searcher/MongoTest.php @@ -254,4 +254,12 @@ public function testTruncateWatchesPreserveIndexes(): void $this->assertEquals($options['name'], $name); } } + + public function testGetAllServerNames(): void + { + $result = $this->mongo->getAllServerNames(); + $this->assertCount(2, $result); + $this->assertContains('localhost', $result); + $this->assertContains('foo', $result); + } } diff --git a/tests/fixtures/normalized.json b/tests/fixtures/normalized.json index 9f70b74f9..56f27cbe4 100644 --- a/tests/fixtures/normalized.json +++ b/tests/fixtures/normalized.json @@ -279,5 +279,25 @@ "pmu": 0 } } + }, + { + "_id": "aaaaaaaaaaaaaaaaaaaaaab2", + "meta": { + "url": "/bar", + "simple_url": "/bar", + "get": [], + "env": [], + "SERVER": {"REQUEST_TIME": 1358614812, "SERVER_NAME": "foo", "REQUEST_METHOD": "GET"}, + "request_ts_micro": {"sec": 1358614812, "usec": 123456} + }, + "profile": { + "main()": { + "ct": 1, + "wt": 10, + "cpu": 12, + "mu": 3000, + "pmu": 3001 + } + } } ]