Skip to content

Commit c5b1eae

Browse files
committed
Finished Solr stats
1 parent 014fd7d commit c5b1eae

File tree

3 files changed

+48
-4
lines changed

3 files changed

+48
-4
lines changed

lib/Phpfastcache/Drivers/Solr/Driver.php

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
use Phpfastcache\Exceptions\PhpfastcacheLogicException;
2828
use Solarium\Client as SolariumClient;
2929
use Solarium\Core\Client\Adapter\Curl as SolariumCurlAdapter;
30+
use Solarium\Core\Client\Endpoint;
31+
use Solarium\Core\Client\Request;
3032
use Solarium\Exception\ExceptionInterface as SolariumExceptionInterface;
3133
use Solarium\QueryType\Select\Result\Document as SolariumDocument;
3234

@@ -235,11 +237,48 @@ protected function getSolrField(string $pfcField): string
235237

236238
public function getStats(): DriverStatistic
237239
{
240+
/**
241+
* Solr "phpfastcache" core info
242+
*/
243+
$coreAdminQuery = $this->instance->createCoreAdmin();
244+
$statusAction = $coreAdminQuery->createStatus();
245+
$coreAdminQuery->setAction($statusAction);
246+
$response = $this->instance->coreAdmin($coreAdminQuery);
247+
$coreServerInfo = $response->getData()['status'][$this->config->getCoreName()];
248+
249+
/**
250+
* Unfortunately Solarium does not offer
251+
* an API to query the admin info system :(
252+
*/
253+
$adminSystemInfoUrl = $this->config->getScheme()
254+
. '://'
255+
. $this->config->getHost()
256+
. ':'
257+
. $this->config->getPort()
258+
. rtrim($this->config->getPath(), '/')
259+
. '/solr/admin/info/system';
260+
261+
if (($content = \file_get_contents($adminSystemInfoUrl)) !== false) {
262+
try {
263+
$serverSystemInfo = \json_decode($content, true, 512, \JSON_THROW_ON_ERROR);
264+
} catch (\JsonException) {
265+
$serverSystemInfo = [];
266+
}
267+
}
268+
238269
return (new DriverStatistic())
239270
->setData(implode(', ', array_keys($this->itemInstances)))
240-
->setInfo('')
241-
->setRawData(null)
242-
->setSize(0);
271+
->setInfo(sprintf(
272+
'Solarium %s and Solr %s for %s %s. %d document(s) stored in the "%s" core',
273+
$this->instance::VERSION,
274+
$serverSystemInfo['lucene']['solr-spec-version'] ?? '[unknown SOLR version]',
275+
$serverSystemInfo['system']['name'] ?? '[unknown OS]',
276+
$serverSystemInfo['system']['version'] ?? '[unknown OS version]',
277+
$coreServerInfo['index']['numDocs'] ?? 0,
278+
$this->config->getCoreName()
279+
))
280+
->setRawData($coreServerInfo)
281+
->setSize($coreServerInfo['index']['sizeInBytes'] ?? 0);
243282
}
244283

245284
public function getConfig(): Config

tests/Solr.test.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,6 @@
4646
// $solrConfig->setEventDispatcher($yourEventDispatcher);
4747

4848
$cacheInstance = CacheManager::getInstance('Solr', $solrConfig);
49-
$testHelper->runCRUDTests($cacheInstance, false);
49+
$testHelper->runCRUDTests($cacheInstance);
5050

5151
$testHelper->terminateTest();

tests/lib/Helper/TestHelper.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,11 @@ public function runCRUDTests(ExtendedCacheItemPoolInterface|PhpfastcacheAbstract
535535
)
536536
);
537537
$this->printInfoText('<yellow>Driver info</yellow>: <magenta>' . $pool->getStats()->getInfo() . '</magenta>');
538+
$poolSize = $pool->getStats()->getSize();
539+
540+
if($poolSize){
541+
$this->printInfoText('<yellow>Driver size</yellow> (approximative): <magenta>' . round($pool->getStats()->getSize() / (1024 ** 2), 3) . ' Mo</magenta>');
542+
}
538543
}
539544

540545

0 commit comments

Comments
 (0)