Skip to content

Commit

Permalink
Merge pull request #184 from pantheon-systems/issue-3467907-error-whe…
Browse files Browse the repository at this point in the history
…n-trying

Issue #3467907 logger issue along with admin form.
  • Loading branch information
iamsumit authored Sep 4, 2024
2 parents 9d8adf1 + b3c0cdb commit aa24a5f
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 41 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
build_test:
strategy:
matrix:
drupal-version: [ 9, 10 ]
drupal-version: [ 10 ]
fail-fast: false
runs-on: ubuntu-latest
container:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,12 @@ public function buildForm(
ServerInterface $search_api_server = NULL
): array {
$file_list = $this->pantheonGuzzle
->getQueryResult('admin/file', ['query' => ['action' => 'VIEW']]);
->getQueryResult('admin/file', [
'query' => [
'action' => 'VIEW',
'wt' => 'json',
],
]);
$form['status'] = [
'#type' => 'vertical_tabs',
'#title' => $this->t('Pantheon Search Files'),
Expand Down
1 change: 0 additions & 1 deletion search_api_pantheon.module
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@
/**
* @file
*/

44 changes: 23 additions & 21 deletions src/Commands/Diagnose.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,86 +102,88 @@ public function diagnose() {
if ($pantheon_yml['search']['version'] != '8') {
throw new \Exception('Unsupported search.version in pantheon.yml or pantheon.upstream.yml');
}
$this->logger()->notice('Pantheon.yml file looks ok ✅');
$this->logger->notice('Pantheon.yml file looks ok ✅');

$this->logger()->notice('Index SCHEME Value: {var}', [
$this->logger->notice('Index SCHEME Value: {var}', [
'var' => $this->endpoint->getScheme(),
]);
$this->logger()->notice('Index HOST Value: {var}', [
$this->logger->notice('Index HOST Value: {var}', [
'var' => $this->endpoint->getHost(),
]);
$this->logger()->notice('Index PORT Value: {var}', [
$this->logger->notice('Index PORT Value: {var}', [
'var' => $this->endpoint->getPort(),
]);
$this->logger()->notice('Index CORE Value: {var}', [
$this->logger->notice('Index CORE Value: {var}', [
'var' => $this->endpoint->getCore(),
]);
$this->logger()->notice('Index PATH Value: {var}', [
$this->logger->notice('Index PATH Value: {var}', [
'var' => $this->endpoint->getPath(),
]);
$this->logger()->notice('Testing bare Connection...');
$this->logger->notice('Testing bare Connection...');
$response = $this->pingSolrHost();
$this->logger()->notice('Ping Received Response? {var}', [
$this->logger->notice('Ping Received Response? {var}', [
'var' => $response instanceof ResultInterface ? '' : '',
]);
$this->logger()->notice('Response http status == 200? {var}', [
$this->logger->notice('Response http status == 200? {var}', [
'var' => $response->getResponse()->getStatusCode() === 200 ? '' : '',
]);
if ($response->getResponse()->getStatusCode() !== 200) {
throw new \Exception('Cannot contact solr server.');
}
$this->logger()->notice('Drupal Integration...');
$this->logger->notice('Drupal Integration...');
// @codingStandardsIgnoreLine
$manager = \Drupal::getContainer()->get(
'plugin.manager.search_api_solr.connector'
);
$connectors = array_keys($manager->getDefinitions() ?? []);
$this->logger()->notice('Pantheon Connector Plugin Exists? {var}', [
$this->logger->notice('Pantheon Connector Plugin Exists? {var}', [
'var' => in_array('pantheon', $connectors) ? '' : '',
]);
$connectorPlugin = $manager->createInstance('pantheon');
$this->logger()->notice('Connector Plugin Instance created {var}', [
$this->logger->notice('Connector Plugin Instance created {var}', [
'var' => $connectorPlugin instanceof SolrConnectorInterface ? '' : '',
]);
if (!$connectorPlugin instanceof SolrConnectorInterface) {
throw new \Exception('Cannot instantiate solr connector.');
}
$this->logger()->notice('Adding Logger to connector...');
$this->logger->notice('Adding Logger to connector...');
$connectorPlugin->setLogger($this->logger);
$this->logger()->notice('Using connector plugin to get server Info...');
$this->logger->notice('Using connector plugin to get server Info...');
$info = $connectorPlugin->getServerInfo();
if ($this->output()->isVerbose()) {
$this->logger()->notice(print_r($info, TRUE));
$this->logger->notice(print_r($info, TRUE));
}
$this->logger()->notice('Solr Server Version {var}', [
$this->logger->notice('Solr Server Version {var}', [
'var' => $info['lucene']['solr-spec-version'] ?? '',
]);

$indexedStats = $this->pantheonGuzzle->getQueryResult('admin/luke', [
'query' => [
'stats' => 'true',
'wt' => 'json',
],
]);
if ($this->output()->isVerbose()) {
$this->logger()->notice('Solr Index Stats: {stats}', [
$this->logger->notice('Solr Index Stats: {stats}', [
'stats' => print_r($indexedStats['index'], TRUE),
]);
}
else {
$this->logger()->notice('We got Solr stats ✅');
$this->logger->notice('We got Solr stats ✅');
}
$beans = $this->pantheonGuzzle->getQueryResult('admin/mbeans', [
'query' => [
'stats' => 'true',
'wt' => 'json',
],
]);
if ($this->output()->isVerbose()) {
$this->logger()->notice('Mbeans Stats: {stats}', [
$this->logger->notice('Mbeans Stats: {stats}', [
'stats' => print_r($beans['solr-mbeans'], TRUE),
]);
}
else {
$this->logger()->notice('We got Mbeans stats ✅');
$this->logger->notice('We got Mbeans stats ✅');
}
}
catch (\Exception $e) {
Expand All @@ -194,7 +196,7 @@ public function diagnose() {
$this->logger->emergency("There's a problem somewhere...");
exit(1);
}
$this->logger()->notice(
$this->logger->notice(
"If there's an issue with the connection, it would have shown up here. You should be good to go!"
);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Commands/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public function postSchema(?string $server_id = NULL, ?string $path = NULL) {
$this->schemaPoster->postSchema($server_id, $files);
}
catch (\Exception $e) {
$this->logger()->error((string) $e);
$this->logger->error((string) $e);
}
}

Expand All @@ -112,7 +112,7 @@ public function postSchema(?string $server_id = NULL, ?string $path = NULL) {
*/
public function viewSchema(string $filename = 'schema.xml') {
$currentSchema = $this->schemaPoster->viewSchema($filename);
$this->logger()->notice($currentSchema);
$this->logger->notice($currentSchema);
}

}
21 changes: 11 additions & 10 deletions src/Commands/TestIndexAndQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,18 @@ public function testIndexAndQuery() {
$drupal_root = \DRUPAL_ROOT;

$response = $this->pingSolrHost();
$this->logger()->notice('Ping Received Response? {var}', [
$this->logger->notice('Ping Received Response? {var}', [
'var' => $response instanceof ResultInterface ? '' : '',
]);
$this->logger()->notice('Response http status == 200? {var}', [
$this->logger->notice('Response http status == 200? {var}', [
'var' => $response->getResponse()->getStatusCode() === 200 ? '' : '',
]);
if ($response->getResponse()->getStatusCode() !== 200) {
throw new \Exception('Cannot contact solr server.');
}

// Create a new random index.
$this->logger()->notice("Creating temporary index...");
$this->logger->notice("Creating temporary index...");
$module_root = \Drupal::service('extension.list.module')->getPath('search_api_pantheon');
$value = Yaml::parseFile($module_root . '/.ci/config/search_api.index.solr_index.yml');

Expand All @@ -113,10 +113,10 @@ public function testIndexAndQuery() {
\Drupal::service('config.installer')->installOptionalConfig($config_source);
$index = Index::load($index_id);
$index->save();
$this->logger()->notice("Temporary index created.");
$this->logger->notice("Temporary index created.");

$indexSingleItemQuery = $this->indexSingleItem($index->id());
$this->logger()->notice('Solr Update index with one document Response: {code} {reason}', [
$this->logger->notice('Solr Update index with one document Response: {code} {reason}', [
'code' => $indexSingleItemQuery->getResponse()->getStatusCode(),
'reason' => $indexSingleItemQuery->getResponse()->getStatusMessage(),
]);
Expand All @@ -125,18 +125,19 @@ public function testIndexAndQuery() {
throw new \Exception('Cannot unable to index simple item. Have you created an index for the server?');
}

$this->logger()->notice("Querying Solr for the indexed item...");
$this->logger->notice("Querying Solr for the indexed item...");
$result = $this->pantheonGuzzle->getQueryResult('select', [
'query' => [
'q' => 'index_id:' . $index->id(),
'fields' => ['id', 'index_id', 'name'],
'wt' => 'json',
],
]);
if ($result['response']['numFound'] === 1) {
$this->logger()->notice('We got exactly 1 result ✅');
$this->logger->notice('We got exactly 1 result ✅');
}
else {
$this->logger()->notice('We did not get exactly 1 result ❌ (numFound = {numFound})', [
$this->logger->notice('We did not get exactly 1 result ❌ (numFound = {numFound})', [
'numFound' => $result['response']['numFound'],
]);
}
Expand All @@ -153,15 +154,15 @@ public function testIndexAndQuery() {
}
finally {
if ($index) {
$this->logger()->notice('Removing content and index {index_id}', [
$this->logger->notice('Removing content and index {index_id}', [
'index_id' => $index->id(),
]);

$this->deleteSingleItem('1-' . $index->id());
$index->delete();
}
}
$this->logger()->notice(
$this->logger->notice(
"If there's an issue with Solr, it would have shown up here. You should be good to go!"
);
}
Expand Down
9 changes: 4 additions & 5 deletions src/EventSubscriber/SearchApiPantheonSolrConfigFilesAlter.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
<?php declare(strict_types = 1);
<?php

declare(strict_types = 1);

namespace Drupal\search_api_pantheon\EventSubscriber;

use Drupal\search_api_solr\Event\PostConfigFilesGenerationEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\Event\ResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;

/**
* @issue BUGS-4278
Expand All @@ -20,7 +19,7 @@ final class SearchApiPantheonSolrConfigFilesAlter implements EventSubscriberInte
/**
* PostConfigFilesGenerationEvent event handler.
*
* @param PostConfigFilesGenerationEvent $event
* @param \Drupal\search_api_solr\Event\PostConfigFilesGenerationEvent $event
*/
public function onPostConfigFilesGenerationEvent(PostConfigFilesGenerationEvent $event): void {
$files = $event->getConfigFiles();
Expand Down
1 change: 1 addition & 0 deletions src/Plugin/SolrConnector/PantheonSolrConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@ public function getFile($file = NULL) {
}
return $this->pantheonGuzzle->get('admin/file', [
'query' => $query,
'wt' => 'json',
]);
}

Expand Down

0 comments on commit aa24a5f

Please sign in to comment.