Skip to content
Snippets Groups Projects
Commit 05b275ab authored by Dominik Hebeler's avatar Dominik Hebeler
Browse files

Merge branch '1286-add-key-related-anonymous-statistics' into 'development'

Resolve "Add Key related (anonymous) statistics"

Closes #1286

See merge request !2143
parents 7f9ce0d8 67d44f11
No related branches found
No related tags found
2 merge requests!2144Translated using Weblate (German),!2143Resolve "Add Key related (anonymous) statistics"
......@@ -2,6 +2,7 @@
namespace App\Models\Authorization;
use App\PrometheusExporter;
use Illuminate\Support\Facades\Redis;
class KeyAuthorization extends Authorization
......@@ -87,6 +88,10 @@ class KeyAuthorization extends Authorization
$mission = json_encode($mission);
Redis::rpush(\App\MetaGer::FETCHQUEUE_KEY, $mission);
if (config('metager.metager.keys.uni_mainz') === $this->key) {
PrometheusExporter::UpdateMainzKeyStatus($this->availableTokens);
}
return true;
}
/**
......
......@@ -6,6 +6,7 @@ use App\Localization;
use App\MetaGer;
use App\Models\Authorization\Authorization;
use app\Models\parserSkripte\Overture;
use App\PrometheusExporter;
use App\SearchSettings;
use Illuminate\Support\Facades\Redis;
use LaravelLocalization;
......@@ -199,8 +200,12 @@ abstract class Searchengine
}
$this->getNext($metager, $body);
// Pay for the searchengine if cost > 0 and returned results
if (!$this->cached && $this->configuration->cost > 0 && sizeof($this->results) > 0) {
app(Authorization::class)->makePayment($this->configuration->cost);
if ($this->configuration->cost > 0 && sizeof($this->results) > 0) {
// Remove namespace before passing engine to exporter
PrometheusExporter::KeyUsed(preg_replace("/^.*\\\/", "", get_class($this)), $this->cached);
if (!$this->cached) {
app(Authorization::class)->makePayment($this->configuration->cost);
}
}
$this->markNew();
$this->loaded = true;
......
......@@ -66,4 +66,17 @@ class PrometheusExporter
$counter = $registry->getOrRegisterCounter("metager", "overture_failed", "counts how often overture failed a response");
$counter->inc();
}
public static function KeyUsed(string $engine, bool $cached)
{
$registry = CollectorRegistry::getDefault();
$counter = $registry->getOrRegisterCounter("metager", "key_used", "Counts MetaGer Key Usage", ["searchengine", "cached"]);
$counter->inc([$engine, json_encode($cached)]);
}
public static function UpdateMainzKeyStatus($tokens)
{
$registry = CollectorRegistry::getDefault();
$gauge = $registry->getOrRegisterGauge("metager", "key", "Tracks status of the Mainz Key", ["owner"]);
$gauge->set($tokens, ["mainz"]);
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment