mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Linter
synced 2024-11-23 15:36:52 +00:00
Merge "Collect selective update statistics from LintUpdate job"
This commit is contained in:
commit
27b5eaeaf8
|
@ -31,6 +31,7 @@
|
|||
"LinkRenderer",
|
||||
"JobQueueGroup",
|
||||
"WikiPageFactory",
|
||||
"StatsFactory",
|
||||
"Linter.CategoryManager",
|
||||
"Linter.TotalsLookup",
|
||||
"Linter.Database",
|
||||
|
|
|
@ -45,6 +45,7 @@ use MediaWiki\Storage\Hook\RevisionDataUpdatesHook;
|
|||
use MediaWiki\Title\Title;
|
||||
use MediaWiki\User\UserIdentity;
|
||||
use Skin;
|
||||
use Wikimedia\Stats\StatsFactory;
|
||||
use WikiPage;
|
||||
|
||||
class Hooks implements
|
||||
|
@ -59,6 +60,7 @@ class Hooks implements
|
|||
private LinkRenderer $linkRenderer;
|
||||
private JobQueueGroup $jobQueueGroup;
|
||||
private WikiPageFactory $wikiPageFactory;
|
||||
private StatsFactory $statsFactory;
|
||||
private CategoryManager $categoryManager;
|
||||
private TotalsLookup $totalsLookup;
|
||||
private Database $database;
|
||||
|
@ -68,6 +70,7 @@ class Hooks implements
|
|||
* @param LinkRenderer $linkRenderer
|
||||
* @param JobQueueGroup $jobQueueGroup
|
||||
* @param WikiPageFactory $wikiPageFactory
|
||||
* @param StatsFactory $statsFactory
|
||||
* @param CategoryManager $categoryManager
|
||||
* @param TotalsLookup $totalsLookup
|
||||
* @param Database $database
|
||||
|
@ -76,6 +79,7 @@ class Hooks implements
|
|||
LinkRenderer $linkRenderer,
|
||||
JobQueueGroup $jobQueueGroup,
|
||||
WikiPageFactory $wikiPageFactory,
|
||||
StatsFactory $statsFactory,
|
||||
CategoryManager $categoryManager,
|
||||
TotalsLookup $totalsLookup,
|
||||
Database $database,
|
||||
|
@ -84,6 +88,7 @@ class Hooks implements
|
|||
$this->linkRenderer = $linkRenderer;
|
||||
$this->jobQueueGroup = $jobQueueGroup;
|
||||
$this->wikiPageFactory = $wikiPageFactory;
|
||||
$this->statsFactory = $statsFactory;
|
||||
$this->categoryManager = $categoryManager;
|
||||
$this->totalsLookup = $totalsLookup;
|
||||
$this->database = $database;
|
||||
|
@ -359,7 +364,8 @@ class Hooks implements
|
|||
|
||||
$updates[] = new LintUpdate(
|
||||
$this->wikiPageFactory,
|
||||
$renderedRevision
|
||||
$this->statsFactory,
|
||||
$renderedRevision,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,22 +24,28 @@ use MediaWiki\Content\Renderer\ContentParseParams;
|
|||
use MediaWiki\Content\TextContent;
|
||||
use MediaWiki\Deferred\DataUpdate;
|
||||
use MediaWiki\Logger\LoggerFactory;
|
||||
use MediaWiki\MainConfigNames;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use MediaWiki\Page\WikiPageFactory;
|
||||
use MediaWiki\Revision\RenderedRevision;
|
||||
use MediaWiki\Revision\RevisionRecord;
|
||||
use MediaWiki\Revision\SlotRecord;
|
||||
use Wikimedia\Stats\StatsFactory;
|
||||
|
||||
class LintUpdate extends DataUpdate {
|
||||
|
||||
private WikiPageFactory $wikiPageFactory;
|
||||
private StatsFactory $statsFactory;
|
||||
private RenderedRevision $renderedRevision;
|
||||
|
||||
public function __construct(
|
||||
WikiPageFactory $wikiPageFactory,
|
||||
StatsFactory $statsFactory,
|
||||
RenderedRevision $renderedRevision
|
||||
) {
|
||||
parent::__construct();
|
||||
$this->wikiPageFactory = $wikiPageFactory;
|
||||
$this->statsFactory = $statsFactory;
|
||||
$this->renderedRevision = $renderedRevision;
|
||||
}
|
||||
|
||||
|
@ -62,6 +68,10 @@ class LintUpdate extends DataUpdate {
|
|||
|
||||
$pOptions = $page->makeParserOptions( 'canonical' );
|
||||
$pOptions->setUseParsoid();
|
||||
$pOptions->setRenderReason( 'LintUpdate' );
|
||||
|
||||
// XXX no previous output available on this code path
|
||||
$previousOutput = null;
|
||||
|
||||
LoggerFactory::getInstance( 'Linter' )->debug(
|
||||
'{method}: Parsing {page}',
|
||||
|
@ -83,9 +93,34 @@ class LintUpdate extends DataUpdate {
|
|||
$pOptions,
|
||||
// no need to generate HTML
|
||||
false,
|
||||
// XXX no previous output available
|
||||
null
|
||||
$previousOutput
|
||||
);
|
||||
$content->getContentHandler()->getParserOutput( $content, $cpoParams );
|
||||
$output = $content->getContentHandler()->getParserOutput( $content, $cpoParams );
|
||||
|
||||
// T371713: Temporary statistics collection code to determine
|
||||
// feasibility of Parsoid selective update
|
||||
$sampleRate = MediaWikiServices::getInstance()->getMainConfig()->get(
|
||||
MainConfigNames::ParsoidSelectiveUpdateSampleRate
|
||||
);
|
||||
$doSample = ( $sampleRate && mt_rand( 1, $sampleRate ) === 1 );
|
||||
if ( $doSample ) {
|
||||
$labels = [
|
||||
'source' => 'LintUpdate',
|
||||
'type' => 'full',
|
||||
'reason' => $pOptions->getRenderReason(),
|
||||
'parser' => 'parsoid',
|
||||
'opportunistic' => 'false',
|
||||
];
|
||||
$totalStat = $this->statsFactory
|
||||
->getCounter( 'parsercache_selective_total' );
|
||||
$timeStat = $this->statsFactory
|
||||
->getCounter( 'parsercache_selective_cpu_seconds' );
|
||||
foreach ( $labels as $key => $value ) {
|
||||
$totalStat->setLabel( $key, $value );
|
||||
$timeStat->setLabel( $key, $value );
|
||||
}
|
||||
$totalStat->increment();
|
||||
$timeStat->incrementBy( $output->getTimeProfile( 'cpu' ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@ use MediaWiki\Revision\RevisionRecord;
|
|||
use MediaWiki\Revision\SlotRecord;
|
||||
use MediaWikiIntegrationTestCase;
|
||||
use RefreshLinksJob;
|
||||
use Wikimedia\Stats\StatsFactory;
|
||||
use WikiPage;
|
||||
use WikitextContent;
|
||||
|
||||
|
@ -200,6 +201,7 @@ class LintUpdateTest extends MediaWikiIntegrationTestCase {
|
|||
|
||||
return new LintUpdate(
|
||||
$wikiPageFactory,
|
||||
StatsFactory::newNull(),
|
||||
$renderedRevision
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue