Chad has uploaded a new change for review.
https://gerrit.wikimedia.org/r/119503
Change subject: Expose search metrics to Javascript for performance tooling
......................................................................
Expose search metrics to Javascript for performance tooling
Provide both the time we spent on Elastic as well as in Cirrus.
NavigationTiming already provides the total page times
Bug: 62768
Change-Id: Ib25fd0e2e9ecb2e9bdb1eb564762c175659b9ff0
---
M includes/CirrusSearch.php
M includes/ElasticsearchIntermediary.php
M includes/Hooks.php
3 files changed, 46 insertions(+), 1 deletion(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CirrusSearch
refs/changes/03/119503/1
diff --git a/includes/CirrusSearch.php b/includes/CirrusSearch.php
index d05e247..ac50eb8 100644
--- a/includes/CirrusSearch.php
+++ b/includes/CirrusSearch.php
@@ -33,6 +33,11 @@
private $lastNamespacePrefix;
/**
+ * @var array metrics about the last thing we searched
+ */
+ private $lastSearchMetrics;
+
+ /**
* Override supports to shut off updates to Cirrus via the SearchEngine
infrastructure. Page
* updates and additions are chained on the end of the links update
job. Deletes are noticed
* via the ArticleDeleteComplete hook.
@@ -91,6 +96,8 @@
$status = $searcher->searchText( $term,
$this->showRedirects, $this->showSuggestion );
}
+ $this->lastSearchMetrics = $searcher->getSearchMetrics();
+
// For historical reasons all callers of searchText interpret
any Status return as an error
// so we must unwrap all OK statuses. Note that $status can be
"good" and still contain null
// since that is interpreted as no results.
@@ -132,7 +139,19 @@
return $parsed;
}
+ /**
+ * Get the sort of sorts we allow
+ * @return array
+ */
public function getValidSorts() {
return array( 'relevance', 'title_asc', 'title_desc' );
}
+
+ /**
+ * Get the metrics for the last search we performed. Null if we haven't
done any.
+ * @return array
+ */
+ public function getLastSearchMetrics() {
+ return $this->lastSearchMetrics;
+ }
}
diff --git a/includes/ElasticsearchIntermediary.php
b/includes/ElasticsearchIntermediary.php
index a753d97..178af54 100644
--- a/includes/ElasticsearchIntermediary.php
+++ b/includes/ElasticsearchIntermediary.php
@@ -43,6 +43,11 @@
private $slowMillis;
/**
+ * @var array Metrics about a completed search
+ */
+ private $searchMetrics = array();
+
+ /**
* Constructor.
*
* @param User|null $user user for which this search is being
performed. Attached to slow request logs. Note that
@@ -113,6 +118,14 @@
}
/**
+ * Get the search metrics we have
+ * @return array
+ */
+ public function getSearchMetrics() {
+ return $this->searchMetrics;
+ }
+
+ /**
* Does this status represent an Elasticsearch parse error?
* @param $status Status to check
* @return boolean is this a parse error?
@@ -141,6 +154,8 @@
$took = round( ( microtime( true ) - $this->requestStart ) *
1000 );
$logMessage = "$this->description took $took millis";
+ $this->searchMetrics['cirrustime'] = $took;
+
// Extract the amount of time Elasticsearch reported the last
request took if possible.
$result = ElasticaConnection::getClient()->getLastResponse();
if ( $result ) {
@@ -148,6 +163,7 @@
if ( isset( $data[ 'took' ] ) ) {
$elasticTook = $data[ 'took' ];
$logMessage .= " and $elasticTook Elasticsearch
millis";
+ $this->searchMetrics['elastictime'] =
$elasticTook;
}
}
diff --git a/includes/Hooks.php b/includes/Hooks.php
index d3d29d1..674c5fc 100644
--- a/includes/Hooks.php
+++ b/includes/Hooks.php
@@ -1,6 +1,7 @@
<?php
namespace CirrusSearch;
+use \CirrusSearch;
use \BetaFeatures;
use \JobQueueGroup;
use \Title;
@@ -147,7 +148,7 @@
}
/**
- * Called to prepend text before search results
+ * Called to prepend text before search results and inject metrics
* @param SpecialSearch $specialSearch The SpecialPage object for
Special:Search
* @param OutputPage $out The output page object
* @param string $term The term being searched for
@@ -155,11 +156,20 @@
*/
public static function specialSearchResultsPrependHook( $specialSearch,
$out, $term ) {
global $wgCirrusSearchShowNowUsing;
+
+ // Prepend our message if needed
if ( $wgCirrusSearchShowNowUsing ) {
$out->addHtml( Xml::openElement( 'div', array( 'class'
=> 'cirrussearch-now-using' ) ) .
$specialSearch->msg( 'cirrussearch-now-using'
)->parse() .
Xml::closeElement( 'div' ) );
}
+
+ // Embed metrics if this was a Cirrus page
+ $engine = $specialSearch->getSearchEngine();
+ if ( $engine instanceof CirrusSearch ) {
+ $out->addJsConfigVars( $engine->getLastSearchMetrics()
);
+ }
+
return true;
}
--
To view, visit https://gerrit.wikimedia.org/r/119503
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib25fd0e2e9ecb2e9bdb1eb564762c175659b9ff0
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/CirrusSearch
Gerrit-Branch: master
Gerrit-Owner: Chad <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits