From 642e7d5dfa1814c09072f93d79a0d1097534c364 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Thu, 9 May 2024 21:06:07 +0200 Subject: [PATCH] Fixes --- psalm-baseline.xml | 14 +++----- src/Loop/Connection/Common.php | 2 +- src/MTProtoSession/ResponseHandler.php | 8 ++--- src/Settings/Prometheus.php | 45 ++++++++++++++++++++++++++ 4 files changed, 55 insertions(+), 14 deletions(-) create mode 100644 src/Settings/Prometheus.php diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 9d70e93fd..d1fe4fbe4 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -2301,9 +2301,6 @@ - - getPromGauge("", "ipc_server_connections", "Number of IPC server connections")]]> - @@ -3320,9 +3317,6 @@ authorization['user']['bot']]]> authorization['user']['id']]]> - - getPromCounter("", "update_count", "Number of received updates since the session was created")]]> - @@ -3656,7 +3650,7 @@ - + @@ -3665,6 +3659,10 @@ getMsgId()]]> + + getSent()]]> + getSent()]]> + API->authorized_dc == $this->datacenter && $this->API->authorized === \danog\MadelineProto\API::LOGGED_IN]]> @@ -4509,8 +4507,6 @@ - - diff --git a/src/Loop/Connection/Common.php b/src/Loop/Connection/Common.php index 6266285dc..686405c9a 100644 --- a/src/Loop/Connection/Common.php +++ b/src/Loop/Connection/Common.php @@ -61,6 +61,6 @@ trait Common $this->connection = $connection; $this->datacenter = $connection->getDatacenterID(); $this->shared = $connection->getShared(); - $this->timeout = (int)($this->shared->getSettings()->getTimeout() * 1_000_000_000.0); + $this->timeout = (int) ($this->shared->getSettings()->getTimeout() * 1_000_000_000.0); } } diff --git a/src/MTProtoSession/ResponseHandler.php b/src/MTProtoSession/ResponseHandler.php index c0bb0eb38..15f1a1175 100644 --- a/src/MTProtoSession/ResponseHandler.php +++ b/src/MTProtoSession/ResponseHandler.php @@ -279,10 +279,10 @@ trait ResponseHandler $this->requestResponse->inc([ 'method' => $request->constructor, 'error_message' => 'OK', - 'error_code' => '200' + 'error_code' => '200', ]); $this->requestLatencies?->observe( - hrtime(true) - $request->getSent(), + (hrtime(true) - $request->getSent()) / 1_000_000_000.0, ['method' => $request->constructor] ); } @@ -299,10 +299,10 @@ trait ResponseHandler $this->requestResponse->inc([ 'method' => $request->constructor, 'error_message' => preg_replace('/\d+/', 'X', $response['error_message']), - 'error_code' => (string) $response['error_code'] + 'error_code' => (string) $response['error_code'], ]); $this->requestLatencies?->observe( - hrtime(true) - $request->getSent(), + (hrtime(true) - $request->getSent()) / 1_000_000_000.0, ['method' => $request->constructor] ); } diff --git a/src/Settings/Prometheus.php b/src/Settings/Prometheus.php new file mode 100644 index 000000000..6dde1a9c2 --- /dev/null +++ b/src/Settings/Prometheus.php @@ -0,0 +1,45 @@ +. + * + * @author Daniil Gentili + * @copyright 2016-2023 Daniil Gentili + * @license https://opensource.org/licenses/AGPL-3.0 AGPLv3 + * @link https://docs.madelineproto.xyz MadelineProto documentation + */ + +namespace danog\MadelineProto\Settings; + +use danog\MadelineProto\SettingsAbstract; + +/** + * Prometheus settings. + */ +final class Prometheus extends SettingsAbstract +{ + /** + * Whether to enable prometheus stat reporting for this session. + */ + protected bool $enablePrometheus = false; + /** + * Whether to enable additional prometheus stat reporting for this session. + */ + public function setEnablePrometheus(bool $enable): self + { + $this->enablePrometheus = $enable; + return $this; + } + /** + * Whether additional prometheus stat reporting is enabled for this session. + */ + public function getEnablePrometheus(): bool + { + return $this->enablePrometheus; + } +}