1
0
mirror of https://github.com/danog/MadelineProto.git synced 2025-01-22 21:51:34 +01:00
This commit is contained in:
Daniil Gentili 2024-05-02 22:32:28 +02:00
parent 1c7bc488e2
commit ca81b3865a
8 changed files with 57 additions and 70 deletions

View File

@ -840,6 +840,10 @@ Want to add your own open-source project to this list? [Click here!](https://doc
* <a href="https://docs.madelineproto.xyz/API_docs/methods/messages.getAllDrafts.html" name="messages.getAllDrafts">Return all message drafts.: messages.getAllDrafts</a>
* <a href="https://docs.madelineproto.xyz/PHP/danog/MadelineProto/API.html#getSettings" name="getSettings">Return current settings: getSettings</a>
* <a href="https://docs.madelineproto.xyz/API_docs/methods/account.getAuthorizationForm.html" name="account.getAuthorizationForm">Returns a Telegram Passport authorization form for sharing data with a service: account.getAuthorizationForm</a>
* <a href="https://docs.madelineproto.xyz/PHP/danog/MadelineProto/API.html#getPromCounter" name="getPromCounter">Returns a closure linked to the specified prometheus counter: getPromCounter</a>
* <a href="https://docs.madelineproto.xyz/PHP/danog/MadelineProto/API.html#getPromGauge" name="getPromGauge">Returns a closure linked to the specified prometheus gauge: getPromGauge</a>
* <a href="https://docs.madelineproto.xyz/PHP/danog/MadelineProto/API.html#getPromHistogram" name="getPromHistogram">Returns a closure linked to the specified prometheus histogram: getPromHistogram</a>
* <a href="https://docs.madelineproto.xyz/PHP/danog/MadelineProto/API.html#getPromSummary" name="getPromSummary">Returns a closure linked to the specified prometheus summary: getPromSummary</a>
* <a href="https://docs.madelineproto.xyz/API_docs/methods/account.getWallPapers.html" name="account.getWallPapers">Returns a list of available wallpapers: account.getWallPapers</a>
* <a href="https://docs.madelineproto.xyz/API_docs/methods/messages.getEmojiURL.html" name="messages.getEmojiURL">Returns an HTTP URL which can be used to automatically log in into translation platform and suggest new emoji keywords ». The URL will be valid for 30 seconds after generation: messages.getEmojiURL</a>
* <a href="https://docs.madelineproto.xyz/API_docs/methods/messages.getAttachMenuBot.html" name="messages.getAttachMenuBot">Returns attachment menu entry for a bot mini app that can be launched from the attachment menu »: messages.getAttachMenuBot</a>

2
docs

@ -1 +1 @@
Subproject commit 3091dff6fac05cf7e7b4a8d782d4428d15b54ed4
Subproject commit ab4b4782f8582ca413bcd7c94eb4900c828fd970

View File

@ -2292,6 +2292,25 @@
<code><![CDATA[$id]]></code>
</TypeDoesNotContainType>
</file>
<file src="src/Ipc/AbstractServer.php">
<MixedAssignment>
<code><![CDATA[$payload]]></code>
<code><![CDATA[$payload[1]]]></code>
<code><![CDATA[$result]]></code>
</MixedAssignment>
<MixedMethodCall>
<code><![CDATA[disconnect]]></code>
</MixedMethodCall>
<PropertyNotSetInConstructor>
<code><![CDATA[$callback]]></code>
<code><![CDATA[$server]]></code>
<code><![CDATA[AbstractServer]]></code>
</PropertyNotSetInConstructor>
<TypeDoesNotContainType>
<code><![CDATA[$payload === self::SHUTDOWN]]></code>
<code><![CDATA[$payload === self::SHUTDOWN]]></code>
</TypeDoesNotContainType>
</file>
<file src="src/Ipc/Client.php">
<ArgumentTypeCoercion>
<code><![CDATA[$class]]></code>
@ -2443,22 +2462,9 @@
</UnresolvableInclude>
</file>
<file src="src/Ipc/Server.php">
<MixedAssignment>
<code><![CDATA[$payload]]></code>
<code><![CDATA[$payload[1]]]></code>
<code><![CDATA[$result]]></code>
</MixedAssignment>
<MixedMethodCall>
<code><![CDATA[disconnect]]></code>
</MixedMethodCall>
<PropertyNotSetInConstructor>
<code><![CDATA[$callback]]></code>
<code><![CDATA[$server]]></code>
<code><![CDATA[Server]]></code>
</PropertyNotSetInConstructor>
<TypeDoesNotContainType>
<code><![CDATA[$payload === self::SHUTDOWN]]></code>
<code><![CDATA[$payload === self::SHUTDOWN]]></code>
</TypeDoesNotContainType>
</file>
<file src="src/Ipc/ServerCallback.php">
<MissingReturnType>
@ -2466,7 +2472,6 @@
</MissingReturnType>
<PropertyNotSetInConstructor>
<code><![CDATA[ServerCallback]]></code>
<code><![CDATA[ServerCallback]]></code>
</PropertyNotSetInConstructor>
</file>
<file src="src/Ipc/Wrapper.php">

@ -1 +1 @@
Subproject commit 6fc533efe6e1ce440f6da4b0d7037460f73ce96b
Subproject commit ce6c264833ab1496f2cef6489aa646f8fc191f76

View File

@ -994,46 +994,6 @@ abstract class InternalDoc
{
return $this->wrapper->getAPI()->getPlugin($class);
}
/**
* Returns a closure linked to the specified prometheus counter.
*
* @return Closure(): void Call to increment the counter
*/
final public function getPromCounter(string $namespace, string $name, string $help, array $labels = [
]): \Closure
{
return $this->wrapper->getAPI()->getPromCounter($namespace, $name, $help, $labels);
}
/**
* Returns a closure linked to the specified prometheus gauge.
*
* @return Closure(float): void
*/
final public function getPromGauge(string $namespace, string $name, string $help, array $labels = [
]): \Closure
{
return $this->wrapper->getAPI()->getPromGauge($namespace, $name, $help, $labels);
}
/**
* Returns a closure linked to the specified prometheus histogram.
*
* @return Closure(float): void
*/
final public function getPromHistogram(string $namespace, string $name, string $help, $labels = [
], ?array $buckets = null): \Closure
{
return $this->wrapper->getAPI()->getPromHistogram($namespace, $name, $help, $labels, $buckets);
}
/**
* Returns a closure linked to the specified prometheus summary.
*
* @return Closure(float): void
*/
final public function getPromSummary(string $namespace, string $name, string $help, $labels = [
], int $maxAgeSeconds = 600, ?array $quantiles = null): \Closure
{
return $this->wrapper->getAPI()->getPromSummary($namespace, $name, $help, $labels, $maxAgeSeconds, $quantiles);
}
/**
* Gets info of the propic of a user.
*/

View File

@ -515,8 +515,10 @@ final class MTProto implements TLCallback, LoggerGetter, SettingsGetter
* Returns a closure linked to the specified prometheus gauge.
*
* @internal
*
* @return Closure(int): void
*
* @param array<string, string> $labels
*
* @return Closure(int|float): void
*/
public function getPromGauge(string $namespace, string $name, string $help, array $labels = []): Closure
{
@ -532,7 +534,9 @@ final class MTProto implements TLCallback, LoggerGetter, SettingsGetter
* Returns a closure linked to the specified prometheus counter.
*
* @internal
*
*
* @param array<string, string> $labels
*
* @return Closure(): void Call to increment the counter
*/
public function getPromCounter(string $namespace, string $name, string $help, array $labels = []): Closure
@ -549,10 +553,13 @@ final class MTProto implements TLCallback, LoggerGetter, SettingsGetter
* Returns a closure linked to the specified prometheus summary.
*
* @internal
*
*
* @param array<string, string> $labels
* @param ?list<float> $quantiles
*
* @return Closure(float): void
*/
public function getPromSummary(string $namespace, string $name, string $help, $labels = [], int $maxAgeSeconds = 600, ?array $quantiles = null): Closure
public function getPromSummary(string $namespace, string $name, string $help, array $labels = [], int $maxAgeSeconds = 600, ?array $quantiles = null): Closure
{
return Magic::getSummary(
$namespace,
@ -568,10 +575,13 @@ final class MTProto implements TLCallback, LoggerGetter, SettingsGetter
* Returns a closure linked to the specified prometheus histogram.
*
* @internal
*
*
* @param array<string, string> $labels
* @param ?list<float> $buckets
*
* @return Closure(float): void
*/
public function getPromHistogram(string $namespace, string $name, string $help, $labels = [], ?array $buckets = null): Closure
public function getPromHistogram(string $namespace, string $name, string $help, array $labels = [], ?array $buckets = null): Closure
{
return Magic::getHistogram(
$namespace,
@ -894,6 +904,7 @@ final class MTProto implements TLCallback, LoggerGetter, SettingsGetter
*/
private function cleanupProperties(): void
{
$this->updateCtr = $this->getPromCounter("", "update_count", "Number of received updates since the session was created");
// Start IPC server
if (!$this->ipcServer) {
$this->ipcServer = new Server($this);

View File

@ -28,6 +28,7 @@ use Amp\Http\Client\Request;
use Amp\Http\Client\Response;
use Amp\TimeoutException;
use AssertionError;
use Closure;
use danog\AsyncOrm\Annotations\OrmMappedArray;
use danog\AsyncOrm\DbArray;
use danog\AsyncOrm\KeyType;
@ -1260,8 +1261,11 @@ trait UpdateHandler
$this->handleUpdate($update);
}
/** @var Closure(): void */
private Closure $updateCtr;
private function handleUpdate(array $update): void
{
($this->updateCtr)(['type' => $update['_']]);
/** @var UpdateHandlerType::EVENT_HANDLER|UpdateHandlerType::WEBHOOK|UpdateHandlerType::GET_UPDATES $this->updateHandlerType */
match ($this->updateHandlerType) {
UpdateHandlerType::EVENT_HANDLER => $this->eventUpdateHandler($update),

View File

@ -208,6 +208,7 @@ final class Magic
*/
public static bool $hasBasedirLimitation = false;
private static CollectorRegistry $prometheus;
/** @var array<string, string> */
private static array $promLabels;
/**
* Encoded emojis.
@ -351,22 +352,22 @@ final class Magic
$alloc = self::getGauge("", "php_memstats_alloc_bytes", "RAM allocated by the PHP memory pool", []);
$inuse = self::getGauge("", "php_memstats_inuse_bytes", "RAM actually used by PHP", []);
EventLoop::unreference(EventLoop::repeat(1.0, static function () use ($alloc, $inuse): void {
$alloc((float) memory_get_usage(true));
$inuse((float) memory_get_usage(false));
$alloc(memory_get_usage(true));
$inuse(memory_get_usage(false));
}));
GarbageCollector::start();
self::$inited = true;
}
/**
* @param array<string, string> $labels
* @return Closure(int): void
* @return Closure(int|float): void
*/
public static function getGauge(string $namespace, string $name, string $help, array $labels): Closure
{
$labels += self::$promLabels;
$gauge = self::$prometheus->getOrRegisterGauge($namespace, $name, $help, array_keys($labels));
$labels = array_values($labels);
return static function (int $by) use ($labels, $gauge): void {
return static function (int|float $by) use ($labels, $gauge): void {
$gauge->incBy($by);
};
}
@ -385,6 +386,7 @@ final class Magic
}
/**
* @param array<string, string> $labels
* @param ?list<float> $buckets
* @return Closure(float): void
*/
public static function getHistogram(string $namespace, string $name, string $help, array $labels, ?array $buckets = null): Closure
@ -392,12 +394,13 @@ final class Magic
$labels += self::$promLabels;
$gauge = self::$prometheus->getOrRegisterHistogram($namespace, $name, $help, array_keys($labels), $buckets);
$labels = array_values($labels);
return static function ($value) use ($labels, $gauge): void {
return static function (float $value) use ($labels, $gauge): void {
$gauge->observe($value, $labels);
};
}
/**
* @param array<string, string> $labels
* @param ?list<float> $quantiles
* @return Closure(float): void
*/
public static function getSummary(string $namespace, string $name, string $help, array $labels, int $maxAgeSeconds = 600, ?array $quantiles = null): Closure
@ -405,7 +408,7 @@ final class Magic
$labels += self::$promLabels;
$gauge = self::$prometheus->getOrRegisterSummary($namespace, $name, $help, array_keys($labels), $maxAgeSeconds, $quantiles);
$labels = array_values($labels);
return static function ($value) use ($labels, $gauge): void {
return static function (float $value) use ($labels, $gauge): void {
$gauge->observe($value, $labels);
};
}