EBernhardson has uploaded a new change for review.
https://gerrit.wikimedia.org/r/227870
Change subject: Allow disabling cirrus request logging from query string
......................................................................
Allow disabling cirrus request logging from query string
We want to be able to try throwing various combinations of search parameters at
the production elasticsearch instances for indexes that are too big to test
elsewhere (such as enwiki).
This allows a web request to recuse itself from the CirrusSearchRequests log if
it knows the secret key. The key will need to be set from the cluster's private
data repository.
Change-Id: Iac79ad90e3ae32aa10a8eba5df63e5906ea41aa3
---
M CirrusSearch.php
M includes/ElasticsearchIntermediary.php
M includes/Hooks.php
3 files changed, 43 insertions(+), 14 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CirrusSearch
refs/changes/70/227870/1
diff --git a/CirrusSearch.php b/CirrusSearch.php
index bd69af8..03b1dc2 100644
--- a/CirrusSearch.php
+++ b/CirrusSearch.php
@@ -611,6 +611,18 @@
*/
$wgCirrusSearchEnableSearchLogging = false;
+/**
+ * Whether elasticsearch queries should be logged on the server side.
+ */
+$wgCirrusSearchLogElasticRequests = true;
+
+/**
+ * When truthy and this value is passed as the cirrusLogElasticRequests query
+ * variable $wgCirrusSearchLogElasticRequests will be set to false for that
+ * request.
+ */
+$wgCirrusSearchLogElasticRequestsSecret = false;
+
// The maximum number of incategory:a|b|c items to OR together.
$wgCirrusSearchMaxIncategoryOptions = 100;
diff --git a/includes/ElasticsearchIntermediary.php
b/includes/ElasticsearchIntermediary.php
index dce6040..ec4ff09 100644
--- a/includes/ElasticsearchIntermediary.php
+++ b/includes/ElasticsearchIntermediary.php
@@ -166,19 +166,32 @@
* @return int number of milliseconds it took to complete the request
*/
private function finishRequest() {
+ global $wgCirrusSearchLogRequests;
+
if ( !$this->requestStart ) {
wfLogWarning( 'finishRequest called without staring a
request' );
return;
}
- // No need to check description because it must be set by
$this->start.
-
- // Build the log message
$endTime = microtime( true );
$took = round( ( $endTime - $this->requestStart ) * 1000 );
+ if ( $wgCirrusSearchLogRequests ) {
+ $logMessage = $this->buildLogMessage(
$this->requestStart, $endTime, $took );
+ LoggerFactory::getInstance( 'CirrusSearchRequests'
)->debug( $logMessage );
+ if ( $this->slowMillis && $took >= $this->slowMillis ) {
+ $logMessage .= $this->user ? ' for ' .
$this->user->getName() : '';
+ LoggerFactory::getInstance(
'CirrusSearchSlowRequests' )->info( $logMessage );
+ }
+ }
+ $this->requestStart = null;
+ return $took;
+ }
+
+ private function buildLogMessage( $startTime, $endTime, $took ) {
\RequestContext::getMain()->getStats()->timing(
'CirrusSearch.requestTime', $took );
+ // No need to check description because it must be set by
$this->start.
$logMessage = $this->description;
- $this->searchMetrics['wgCirrusStartTime'] = $this->requestStart;
+ $this->searchMetrics['wgCirrusStartTime'] = $startTime;
$this->searchMetrics['wgCirrusEndTime'] = $endTime;
$client = Connection::getClient();
@@ -213,7 +226,6 @@
$resultData[ 'suggest' ][ 'suggest' ][
0 ][ 'options' ][ 0 ][ 'text' ] . '\'';
}
}
- $request = $client->getLastRequest();
if ( php_sapi_name() === 'cli' ) {
$source = 'cli';
@@ -224,14 +236,7 @@
}
$logMessage .= ". Requested via $source by executor " .
self::getExecutionId();
- // Now log and clear our state.
- LoggerFactory::getInstance( 'CirrusSearchRequests' )->debug(
$logMessage );
- if ( $this->slowMillis && $took >= $this->slowMillis ) {
- $logMessage .= $this->user ? ' for ' .
$this->user->getName() : '';
- LoggerFactory::getInstance( 'CirrusSearchSlowRequests'
)->info( $logMessage );
- }
- $this->requestStart = null;
- return $took;
+ return $logMessage;
}
private function extractMessageAndStatus( $exception ) {
diff --git a/includes/Hooks.php b/includes/Hooks.php
index c425c56..2fc51e7 100644
--- a/includes/Hooks.php
+++ b/includes/Hooks.php
@@ -82,7 +82,9 @@
$wgCirrusSearchBoostLinks,
$wgCirrusSearchAllFields,
$wgCirrusSearchAllFieldsForRescore,
- $wgCirrusSearchPhraseSlop;
+ $wgCirrusSearchPhraseSlop,
+ $wgCirrusSearchLogElasticRequests,
+ $wgCirrusSearchLogElasticRequestsSecret;
// Install our prefix search hook only if we're enabled.
if ( $wgSearchType === 'CirrusSearch' ) {
@@ -108,6 +110,7 @@
self::overrideYesNo(
$wgCirrusSearchAllFieldsForRescore, $request, 'cirrusUseAllFieldsForRescore' );
self::overrideUseExtraPluginForRegex( $request );
self::overrideMoreLikeThisOptions( $request );
+ self::overrideSecret(
$wgCirrusSearchLogElasticRequests, $wgCirrusSearchLogElasticRequestsSecret,
$request, 'cirrusLogElasticRequests', false );
}
}
@@ -123,6 +126,15 @@
}
/**
+ * Set $dest to $value when $request->getVal( $name ) contains $secret
+ */
+ private static function overrideSecret( &$dest, $secret, $request,
$name, $value = true ) {
+ if ( $secret && $secret === $request->getVal( $name ) ) {
+ $dest = $value;
+ }
+ }
+
+ /**
* Set $dest to the true/false from $request->getVal( $name ) if yes/no.
*/
private static function overrideYesNo( &$dest, $request, $name ) {
--
To view, visit https://gerrit.wikimedia.org/r/227870
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Iac79ad90e3ae32aa10a8eba5df63e5906ea41aa3
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/CirrusSearch
Gerrit-Branch: master
Gerrit-Owner: EBernhardson <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits