Skip to content

Commit

Permalink
Merge "Migrate MediaWiki.wikibase.query_contexts.* to statslib"
Browse files Browse the repository at this point in the history
  • Loading branch information
jenkins-bot authored and Gerrit Code Review committed Nov 30, 2024
2 parents 19edccc + 97cd13b commit c98f4f1
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use InvalidArgumentException;
use Wikibase\DataModel\Entity\NumericPropertyId;
use Wikibase\Lib\Store\AbstractTermPropertyLabelResolver;
use Wikibase\Lib\Store\Sql\Terms\Util\StatsdMonitoring;
use Wikibase\Lib\Store\Sql\Terms\Util\StatsMonitoring;
use Wikimedia\ObjectCache\BagOStuff;

/**
Expand All @@ -15,7 +15,7 @@
*/
class CachedDatabasePropertyLabelResolver extends AbstractTermPropertyLabelResolver {

use StatsdMonitoring;
use StatsMonitoring;

/**
* @var DatabaseTermInLangIdsResolver
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
use Wikibase\Lib\Store\Sql\Terms\Util\StatsdMonitoring;
use Wikibase\Lib\Store\Sql\Terms\Util\StatsMonitoring;
use Wikimedia\Rdbms\IDatabase;
use Wikimedia\Rdbms\IReadableDatabase;

Expand All @@ -20,7 +20,7 @@
*/
class DatabaseInnerTermStoreCleaner {

use StatsdMonitoring;
use StatsMonitoring;

/** @var IReadableDatabase a connection to DB_REPLICA. Note only set on cleanTermInLangIds */
private ?IReadableDatabase $dbr = null;
Expand Down
4 changes: 2 additions & 2 deletions lib/includes/Store/Sql/Terms/DatabaseMatchingTermsLookup.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use Wikibase\DataModel\Services\EntityId\EntityIdComposer;
use Wikibase\Lib\Rdbms\RepoDomainDb;
use Wikibase\Lib\Store\MatchingTermsLookup;
use Wikibase\Lib\Store\Sql\Terms\Util\StatsdMonitoring;
use Wikibase\Lib\Store\Sql\Terms\Util\StatsMonitoring;
use Wikibase\Lib\Store\TermIndexSearchCriteria;
use Wikibase\Lib\TermIndexEntry;
use Wikimedia\Rdbms\FakeResultWrapper;
Expand All @@ -28,7 +28,7 @@
*/
class DatabaseMatchingTermsLookup implements MatchingTermsLookup {

use StatsdMonitoring;
use StatsMonitoring;

private RepoDomainDb $repoDb;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Psr\Log\NullLogger;
use stdClass;
use Wikibase\Lib\Rdbms\RepoDomainDb;
use Wikibase\Lib\Store\Sql\Terms\Util\StatsdMonitoring;
use Wikibase\Lib\Store\Sql\Terms\Util\StatsMonitoring;
use Wikimedia\Rdbms\IResultWrapper;
use Wikimedia\Rdbms\SelectQueryBuilder;

Expand All @@ -19,7 +19,7 @@
*/
class DatabaseTermInLangIdsResolver implements TermInLangIdsResolver {

use StatsdMonitoring;
use StatsMonitoring;

/** @var TypeIdsResolver */
private $typeIdsResolver;
Expand Down
4 changes: 2 additions & 2 deletions lib/includes/Store/Sql/Terms/DatabaseTermStoreWriterBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Wikibase\DataModel\Entity\Int32EntityId;
use Wikibase\DataModel\Term\Fingerprint;
use Wikibase\Lib\Rdbms\RepoDomainDb;
use Wikibase\Lib\Store\Sql\Terms\Util\StatsdMonitoring;
use Wikibase\Lib\Store\Sql\Terms\Util\StatsMonitoring;
use Wikibase\Lib\StringNormalizer;
use Wikimedia\Rdbms\IDatabase;

Expand All @@ -21,7 +21,7 @@ abstract class DatabaseTermStoreWriterBase {

use NormalizedTermStorageMappingTrait;
use FingerprintableEntityTermStoreTrait;
use StatsdMonitoring;
use StatsMonitoring;

/** @var RepoDomainDb */
private $repoDb;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Wikibase\DataModel\Entity\Int32EntityId;
use Wikibase\DataModel\Term\TermTypes;
use Wikibase\Lib\Store\EntityTermLookupBase;
use Wikibase\Lib\Store\Sql\Terms\Util\StatsdMonitoring;
use Wikibase\Lib\Store\Sql\Terms\Util\StatsMonitoring;

/**
* Base class for a {@link PrefetchingTermLookup} that only supports a single entity type,
Expand All @@ -23,7 +23,7 @@
abstract class PrefetchingEntityTermLookupBase extends EntityTermLookupBase implements PrefetchingTermLookup {

use NormalizedTermStorageMappingTrait;
use StatsdMonitoring;
use StatsMonitoring;

/** @var string a subclass of {@link Int32EntityId} */
protected $entityIdClass;
Expand Down
31 changes: 31 additions & 0 deletions lib/includes/Store/Sql/Terms/Util/StatsMonitoring.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
namespace Wikibase\Lib\Store\Sql\Terms\Util;

use MediaWiki\MediaWikiServices;
use Wikibase\Lib\WikibaseSettings;

/**
* Trait for adding stats metrics on queries from repo/client
*
* @license GPL-2.0-or-later
*/
trait StatsMonitoring {
public function incrementForQuery( string $queryType ): void {
MediaWikiServices::getInstance()->getStatsFactory()
->getCounter( 'wikibase_repo_term_store_total' )
->setLabel( 'query_type', $queryType )
->copyToStatsdAt( "wikibase.repo.term_store.$queryType" )
->increment();
if ( WikibaseSettings::isRepoEnabled() ) {
$queryContext = 'repo';
} else {
$queryContext = 'client';
}
MediaWikiServices::getInstance()->getStatsFactory()
->getCounter( 'wikibase_query_contexts_term_store_total' )
->setLabel( 'query_context', $queryContext )
->setLabel( 'query_type', $queryType )
->copyToStatsdAt( "wikibase.query_contexts.$queryContext.term_store.$queryType" )
->increment();
}
}
26 changes: 0 additions & 26 deletions lib/includes/Store/Sql/Terms/Util/StatsdMonitoring.php

This file was deleted.

0 comments on commit c98f4f1

Please sign in to comment.