summaryrefslogtreecommitdiff
path: root/classes
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2023-04-09 20:50:33 +0300
committerAndrew Dolgov <[email protected]>2023-04-09 20:50:33 +0300
commit8f3646a9c93a06f76f6abb31020fdb74b4b1fc59 (patch)
tree4e6c9f39e0623ef70bedfee014f1bd20603f89ad /classes
parenta37eab2610a0a2bcb655258781c1c7e925dc94c0 (diff)
exp: jaeger tracing
Diffstat (limited to 'classes')
-rw-r--r--classes/counters.php11
-rwxr-xr-xclasses/feeds.php8
-rwxr-xr-xclasses/pref/feeds.php4
-rwxr-xr-xclasses/rpc.php3
-rw-r--r--classes/tracer.php49
5 files changed, 75 insertions, 0 deletions
diff --git a/classes/counters.php b/classes/counters.php
index 41bb1b9ae..378abac89 100644
--- a/classes/counters.php
+++ b/classes/counters.php
@@ -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;
}
}
diff --git a/classes/feeds.php b/classes/feeds.php
index 002a9eae7..1ce19b098 100755
--- a/classes/feeds.php
+++ b/classes/feeds.php
@@ -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"];
}
}
diff --git a/classes/pref/feeds.php b/classes/pref/feeds.php
index ed6560fd3..00d26d4f6 100755
--- a/classes/pref/feeds.php
+++ b/classes/pref/feeds.php
@@ -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,
diff --git a/classes/rpc.php b/classes/rpc.php
index 204b002d5..977b88d46 100755
--- a/classes/rpc.php
+++ b/classes/rpc.php
@@ -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);
}
diff --git a/classes/tracer.php b/classes/tracer.php
new file mode 100644
index 000000000..fde99927d
--- /dev/null
+++ b/classes/tracer.php
@@ -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;
+ }
+
+}