exp: jaeger tracing
This commit is contained in:
@@ -145,6 +145,7 @@ class Counters {
|
||||
* @return array<int, array<string, int|string>>
|
||||
*/
|
||||
private static function get_feeds(array $feed_ids = null): array {
|
||||
$scope = Tracer::start(__FUNCTION__);
|
||||
|
||||
$ret = [];
|
||||
|
||||
@@ -211,6 +212,8 @@ class Counters {
|
||||
|
||||
}
|
||||
|
||||
$scope->close();
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
@@ -218,6 +221,8 @@ class Counters {
|
||||
* @return array<int, array<string, int|string>>
|
||||
*/
|
||||
private static function get_global(): array {
|
||||
$scope = Tracer::start(__FUNCTION__);
|
||||
|
||||
$ret = [
|
||||
[
|
||||
"id" => "global-unread",
|
||||
@@ -234,6 +239,8 @@ class Counters {
|
||||
"counter" => $subcribed_feeds
|
||||
]);
|
||||
|
||||
$scope->close();
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
@@ -241,6 +248,7 @@ class Counters {
|
||||
* @return array<int, array<string, int|string>>
|
||||
*/
|
||||
private static function get_virt(): array {
|
||||
$scope = Tracer::start(__FUNCTION__);
|
||||
|
||||
$ret = [];
|
||||
|
||||
@@ -287,6 +295,7 @@ class Counters {
|
||||
}
|
||||
}
|
||||
|
||||
$scope->close();
|
||||
return $ret;
|
||||
}
|
||||
|
||||
@@ -295,6 +304,7 @@ class Counters {
|
||||
* @return array<int, array<string, int|string>>
|
||||
*/
|
||||
static function get_labels(array $label_ids = null): array {
|
||||
$scope = Tracer::start(__FUNCTION__);
|
||||
|
||||
$ret = [];
|
||||
|
||||
@@ -346,6 +356,7 @@ class Counters {
|
||||
array_push($ret, $cv);
|
||||
}
|
||||
|
||||
$scope->close();
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -987,6 +987,7 @@ class Feeds extends Handler_Protected {
|
||||
* @throws PDOException
|
||||
*/
|
||||
static function _get_counters($feed, bool $is_cat = false, bool $unread_only = false, ?int $owner_uid = null): int {
|
||||
$scope = Tracer::start(__FUNCTION__, ['tags' => ['args' => json_encode(func_get_args())]]);
|
||||
|
||||
$n_feed = (int) $feed;
|
||||
$need_entries = false;
|
||||
@@ -1010,11 +1011,14 @@ class Feeds extends Handler_Protected {
|
||||
$handler = PluginHost::getInstance()->get_feed_handler($feed_id);
|
||||
if (implements_interface($handler, 'IVirtualFeed')) {
|
||||
/** @var IVirtualFeed $handler */
|
||||
$scope->close();
|
||||
return $handler->get_unread($feed_id);
|
||||
} else {
|
||||
$scope->close();
|
||||
return 0;
|
||||
}
|
||||
} else if ($n_feed == Feeds::FEED_RECENTLY_READ) {
|
||||
$scope->close();
|
||||
return 0;
|
||||
// tags
|
||||
} else if ($feed != "0" && $n_feed == 0) {
|
||||
@@ -1028,6 +1032,7 @@ class Feeds extends Handler_Protected {
|
||||
$row = $sth->fetch();
|
||||
|
||||
// Handle 'SUM()' returning null if there are no results
|
||||
$scope->close();
|
||||
return $row["count"] ?? 0;
|
||||
|
||||
} else if ($n_feed == Feeds::FEED_STARRED) {
|
||||
@@ -1061,6 +1066,7 @@ class Feeds extends Handler_Protected {
|
||||
|
||||
$label_id = Labels::feed_to_label_id($feed);
|
||||
|
||||
$scope->close();
|
||||
return self::_get_label_unread($label_id, $owner_uid);
|
||||
}
|
||||
|
||||
@@ -1080,6 +1086,7 @@ class Feeds extends Handler_Protected {
|
||||
$sth->execute([$owner_uid]);
|
||||
$row = $sth->fetch();
|
||||
|
||||
$scope->close();
|
||||
return $row["unread"];
|
||||
|
||||
} else {
|
||||
@@ -1092,6 +1099,7 @@ class Feeds extends Handler_Protected {
|
||||
$sth->execute([$feed, $owner_uid]);
|
||||
$row = $sth->fetch();
|
||||
|
||||
$scope->close();
|
||||
return $row["unread"];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1104,12 +1104,16 @@ class Pref_Feeds extends Handler_Protected {
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
private function feedlist_init_feed(int $feed_id, ?string $title = null, bool $unread = false, string $error = '', string $updated = ''): array {
|
||||
$scope = Tracer::start(__FUNCTION__, ['tags' => ['args' => json_encode(func_get_args())]]);
|
||||
|
||||
if (!$title)
|
||||
$title = Feeds::_get_title($feed_id, false);
|
||||
|
||||
if ($unread === false)
|
||||
$unread = Feeds::_get_counters($feed_id, false, true);
|
||||
|
||||
$scope->close();
|
||||
|
||||
return [
|
||||
'id' => 'FEED:' . $feed_id,
|
||||
'name' => $title,
|
||||
|
||||
@@ -106,6 +106,8 @@ class RPC extends Handler_Protected {
|
||||
}
|
||||
|
||||
function getAllCounters(): void {
|
||||
$scope = Tracer::start(__FUNCTION__);
|
||||
|
||||
@$seq = (int) $_REQUEST['seq'];
|
||||
|
||||
$feed_id_count = (int) ($_REQUEST["feed_id_count"] ?? -1);
|
||||
@@ -132,6 +134,7 @@ class RPC extends Handler_Protected {
|
||||
'seq' => $seq
|
||||
];
|
||||
|
||||
$scope->close();
|
||||
print json_encode($reply);
|
||||
}
|
||||
|
||||
|
||||
49
classes/tracer.php
Normal file
49
classes/tracer.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
use OpenTracing\GlobalTracer;
|
||||
use OpenTracing\Scope;
|
||||
|
||||
class Tracer {
|
||||
private static $instance;
|
||||
|
||||
public function __construct() {
|
||||
$config = new \Jaeger\Config(
|
||||
[
|
||||
'sampler' => [
|
||||
'type' => \Jaeger\SAMPLER_TYPE_CONST,
|
||||
'param' => true,
|
||||
],
|
||||
'logging' => true,
|
||||
"local_agent" => [
|
||||
"reporting_host" => "172.17.172.39",
|
||||
"reporting_port" => 6832
|
||||
],
|
||||
'dispatch_mode' => \Jaeger\Config::JAEGER_OVER_BINARY_UDP,
|
||||
],
|
||||
'tt-rss'
|
||||
);
|
||||
|
||||
$config->initializeTracer();
|
||||
|
||||
register_shutdown_function(function() {
|
||||
$tracer = GlobalTracer::get();
|
||||
$tracer->flush();
|
||||
});
|
||||
}
|
||||
|
||||
private function _start(string $name, array $options = []) {
|
||||
$tracer = GlobalTracer::get();
|
||||
return $tracer->startActiveSpan($name, $options);
|
||||
}
|
||||
|
||||
public static function start(string $name, array $options = []) : Scope {
|
||||
return self::get_instance()->_start($name, $options);
|
||||
}
|
||||
|
||||
public static function get_instance() : Tracer {
|
||||
if (self::$instance == null)
|
||||
self::$instance = new self();
|
||||
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user