Awight has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/393922 )
Change subject: Rate limit thresholds failures to once per (minute x model x
wiki)
......................................................................
Rate limit thresholds failures to once per (minute x model x wiki)
Bug: T181567
Change-Id: I6dc4e6929cb48f4d1f060bf4ab6614db3a62d01f
---
M includes/Stats.php
1 file changed, 10 insertions(+), 12 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ORES
refs/changes/22/393922/1
diff --git a/includes/Stats.php b/includes/Stats.php
index 6f87383..e8e7582 100644
--- a/includes/Stats.php
+++ b/includes/Stats.php
@@ -52,7 +52,7 @@
$config = $this->getFiltersConfig( $model );
// Skip if the model is unconfigured or set to false.
if ( $config ) {
- $stats = $this->tryFetchStats( $model, $fromCache );
+ $stats = $this->fetchStats( $model, $fromCache );
// Skip if stats are empty.
if ( $stats !== false ) {
return $this->parseThresholds( $stats, $model );
@@ -84,15 +84,6 @@
return $config;
}
- private function tryFetchStats( $model, $fromCache ) {
- try {
- return $this->fetchStats( $model, $fromCache );
- } catch ( \RuntimeException $exception ) {
- $this->logger->error( 'Failed to fetch ORES stats: ' .
$exception->getMessage() );
- return false;
- }
- }
-
private function fetchStats( $model, $fromCache ) {
global $wgOresCacheVersion;
if ( $fromCache ) {
@@ -100,7 +91,7 @@
$result = $this->cache->getWithSetCallback(
$key,
\WANObjectCache::TTL_DAY,
- function () use ( $model ) {
+ function ( $oldValue, &$ttl ) use ( $model ) {
$statsdDataFactory =
MediaWikiServices::getInstance()->getStatsdDataFactory();
// @deprecated Only catching exceptions
to allow the
// failure to be cached, remove once
transition is
@@ -110,8 +101,15 @@
$statsdDataFactory->increment(
'ores.api.stats.ok' );
return $result;
} catch ( \RuntimeException $ex ) {
+ // TODO: We can also check the
service *before* the
+ // cached value expires, and
therefore reuse the old
+ // value until the service
recovers in case of failure.
$statsdDataFactory->increment(
'ores.api.stats.failed' );
- throw $ex;
+ $this->logger->error( 'Failed
to fetch ORES stats.' );
+
+ // Retry again soon.
+ $ttl =
\WANObjectCache::TTL_MINUTE;
+ return false;
}
}
);
--
To view, visit https://gerrit.wikimedia.org/r/393922
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I6dc4e6929cb48f4d1f060bf4ab6614db3a62d01f
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ORES
Gerrit-Branch: master
Gerrit-Owner: Awight <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits