Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
search_api_solr-3231063
Manage
Activity
Members
Labels
Plan
Custom issue tracker
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Issue forks
search_api_solr-3231063
Commits
f33f87a0
Commit
f33f87a0
authored
3 years ago
by
Alejandro Garza
Committed by
Markus Kalkbrenner
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3195477
by janusman, mkalkbrenner: Some improvements to search_api_solr_devel debugging
parent
ee0696d6
No related branches found
Branches containing commit
Tags
3.0.3
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
modules/search_api_solr_devel/src/Logging/SolariumRequestLogger.php
+91
-7
91 additions, 7 deletions
...arch_api_solr_devel/src/Logging/SolariumRequestLogger.php
with
91 additions
and
7 deletions
modules/search_api_solr_devel/src/Logging/SolariumRequestLogger.php
+
91
−
7
View file @
f33f87a0
...
...
@@ -2,7 +2,9 @@
namespace
Drupal\search_api_solr_devel\Logging
;
use
Drupal\Component\Utility\Timer
;
use
Drupal\Core\StringTranslation\StringTranslationTrait
;
use
Drupal\Component\Serialization\Json
;
use
Drupal\devel\DevelDumperManagerInterface
;
use
Drupal\search_api
\LoggerTrait
;
use
Drupal\search_api_solr
\Utility\Utility
;
...
...
@@ -64,6 +66,56 @@ class SolariumRequestLogger implements EventSubscriberInterface {
}
}
/**
* Show debug message and a data object dump.
*
* @param $counter int
* The current Solr query counter.
* @param $data mixed
* Data to dump.
* @param $message string
* Message to show.
*/
public
function
showMessage
(
$counter
,
$data
,
$message
)
{
$message
=
'Request #'
.
$counter
.
'. '
.
$message
;
$this
->
develDumperManager
->
message
(
$data
,
$message
,
'debug'
,
'kint'
);
}
/**
* Start timer for a query.
*
* @param $counter int
* The current Solr query counter.
*/
public
function
timerStart
(
$counter
)
{
Timer
::
start
(
'search_api_solr_devel_'
.
$counter
);
}
/**
* Returns timer for a query.
*
* @param $counter int
* The current Solr query counter.
* @return array
* The timer array.
*/
public
function
timerStop
(
$counter
)
{
return
Timer
::
stop
(
'search_api_solr_devel_'
.
$counter
);
}
/**
* Determine which Solr requests should be ignored.
*
* @param $handler string
* The Solr handler. Examples: "admin/ping", "select", etc.
* @return boolean
* TRUE when we should skip debugging this query.
*/
public
function
shouldIgnore
(
$handler
)
{
$regex
=
'/.*admin.*/'
;
return
preg_match
(
$regex
,
$handler
);
}
/**
* Dumps a Solr query as drupal messages.
*
...
...
@@ -78,12 +130,24 @@ class SolariumRequestLogger implements EventSubscriberInterface {
$request
=
$event
->
getRequest
();
$endpoint
=
$event
->
getEndpoint
();
$this
->
develDumperManager
->
message
(
$request
,
$counter
.
'. Solr request object'
,
'debug'
,
'kint'
);
$this
->
develDumperManager
->
message
(
$endpoint
,
$counter
.
'. Solr endpoint object'
,
'debug'
,
'kint'
);
$this
->
develDumperManager
->
message
(
AdapterHelper
::
buildUri
(
$request
,
$endpoint
),
$counter
.
'. Solr request'
,
'debug'
,
'kint'
);
if
(
$this
->
shouldIgnore
(
$request
->
getHandler
()))
{
return
;
}
$debug
=
[
'request count'
=>
$counter
,
'datetime'
=>
gmdate
(
"Y-m-d\TH:i:sP"
),
'Solr request'
=>
$request
,
'Solr endpoint'
=>
$endpoint
,
'Solr URI'
=>
AdapterHelper
::
buildUri
(
$request
,
$endpoint
),
];
// Show debugging on page.
$this
->
showMessage
(
$counter
,
$debug
,
'Search API Solr Debug: Request'
);
$this
->
develDumperManager
->
debug
(
$request
,
'Solr request'
);
$this
->
develDumperManager
->
debug
(
$endpoint
,
'Solr endpoint'
);
// Log raw data to file.
$this
->
develDumperManager
->
debug
(
$debug
,
'Search API Solr Debug: Request'
,
'default'
);
$this
->
timerStart
(
$counter
);
}
/**
...
...
@@ -93,10 +157,30 @@ class SolariumRequestLogger implements EventSubscriberInterface {
* The post execute event.
*/
public
function
postExecuteRequest
(
$event
)
{
static
$counter
=
0
;
$counter
++
;
if
(
$this
->
shouldIgnore
(
$event
->
getRequest
()
->
getHandler
()))
{
return
;
}
$timer
=
$this
->
timerStop
(
$counter
);
/** @var \Solarium\Core\Event\PostExecuteRequest $event */
$response
=
$event
->
getResponse
();
//$this->develDumperManager->message($response, 'Solr response', 'debug', 'kint');
$this
->
develDumperManager
->
debug
(
$response
,
'Solr response'
);
$debug
=
[
'request count'
=>
$counter
,
'datetime'
=>
gmdate
(
"Y-m-d\TH:i:sP"
),
'query_time'
=>
'Solr query took '
.
$timer
[
'time'
]
.
'ms.'
,
'Solr response headers'
=>
$response
->
getHeaders
(),
'Solr response body'
=>
$response
->
getBody
(),
];
// Show debugging on page.
$this
->
showMessage
(
$counter
,
$debug
,
'Search API Solr Debug: Response'
);
// Log raw data to file (using NULL plugin)
$this
->
develDumperManager
->
debug
(
$debug
,
'Search API Solr Debug: Response'
,
'default'
);
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment