1
0
mirror of https://github.com/danog/MadelineProto.git synced 2024-12-03 11:47:45 +01:00

Add inflight request gauge

This commit is contained in:
Daniil Gentili 2024-05-16 20:00:42 +02:00
parent f04d072af0
commit 6421d7f231
6 changed files with 52 additions and 7 deletions

2
docs

@ -1 +1 @@
Subproject commit f37b981f1b0dfb1ea4020e509180840a15a7289a Subproject commit 7fc41dd5738ab4c9dbc2e756e8140719ce2c2d1c

View File

@ -3643,6 +3643,12 @@
<code><![CDATA[$request->getSent()]]></code> <code><![CDATA[$request->getSent()]]></code>
<code><![CDATA[$request->getSent()]]></code> <code><![CDATA[$request->getSent()]]></code>
</PossiblyNullOperand> </PossiblyNullOperand>
<PossiblyNullReference>
<code><![CDATA[dec]]></code>
<code><![CDATA[dec]]></code>
<code><![CDATA[observe]]></code>
<code><![CDATA[observe]]></code>
</PossiblyNullReference>
<RedundantConditionGivenDocblockType> <RedundantConditionGivenDocblockType>
<code><![CDATA[$this->API->authorized_dc == $this->datacenter && $this->API->authorized === \danog\MadelineProto\API::LOGGED_IN]]></code> <code><![CDATA[$this->API->authorized_dc == $this->datacenter && $this->API->authorized === \danog\MadelineProto\API::LOGGED_IN]]></code>
</RedundantConditionGivenDocblockType> </RedundantConditionGivenDocblockType>

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

View File

@ -125,6 +125,11 @@ final class WriteLoop extends Loop
$this->connection->outgoing_messages[$message_id] = $message; $this->connection->outgoing_messages[$message_id] = $message;
$this->connection->new_outgoing[$message_id] = $message; $this->connection->new_outgoing[$message_id] = $message;
if ($message->getSent() === null) {
$this->connection->inFlightGauge?->inc([
'method' => $message->constructor,
]);
}
$message->sent(); $message->sent();
} }
if ($skipped_all) { if ($skipped_all) {
@ -371,6 +376,11 @@ final class WriteLoop extends Loop
if ($message->hasPromise()) { if ($message->hasPromise()) {
$this->connection->new_outgoing[$message_id] = $message; $this->connection->new_outgoing[$message_id] = $message;
} }
if ($message->getSent() === null) {
$this->connection->inFlightGauge?->inc([
'method' => $message->constructor,
]);
}
$message->sent(); $message->sent();
$message->cancellation?->subscribe(function () use ($message): void { $message->cancellation?->subscribe(function () use ($message): void {
if ($message->hasMsgId()) { if ($message->hasMsgId()) {

View File

@ -281,8 +281,11 @@ trait ResponseHandler
'error_message' => 'OK', 'error_message' => 'OK',
'error_code' => '200', 'error_code' => '200',
]); ]);
$this->requestLatencies?->observe( $this->inFlightGauge->dec([
(hrtime(true) - $request->getSent()) / 1_000_000_000.0, 'method' => $request->constructor,
]);
$this->requestLatencies->observe(
hrtime(true) - $request->getSent(),
['method' => $request->constructor] ['method' => $request->constructor]
); );
} }
@ -301,8 +304,11 @@ trait ResponseHandler
'error_message' => preg_replace('/\d+/', 'X', $response['error_message']), 'error_message' => preg_replace('/\d+/', 'X', $response['error_message']),
'error_code' => (string) $response['error_code'], 'error_code' => (string) $response['error_code'],
]); ]);
$this->requestLatencies?->observe( $this->inFlightGauge->dec([
(hrtime(true) - $request->getSent()) / 1_000_000_000.0, 'method' => $request->constructor,
]);
$this->requestLatencies->observe(
hrtime(true) - $request->getSent(),
['method' => $request->constructor] ['method' => $request->constructor]
); );
} }

View File

@ -44,6 +44,7 @@ trait Session
use CallHandler; use CallHandler;
use Reliable; use Reliable;
public ?BetterGauge $pendingOutgoingGauge = null; public ?BetterGauge $pendingOutgoingGauge = null;
public ?BetterGauge $inFlightGauge = null;
public ?BetterCounter $incomingCtr = null; public ?BetterCounter $incomingCtr = null;
public ?BetterCounter $outgoingCtr = null; public ?BetterCounter $outgoingCtr = null;
public ?BetterCounter $incomingBytesCtr = null; public ?BetterCounter $incomingBytesCtr = null;
@ -185,12 +186,34 @@ trait Session
{ {
$labels = ['datacenter' => (string) $this->datacenter, 'connection' => (string) $this->id]; $labels = ['datacenter' => (string) $this->datacenter, 'connection' => (string) $this->id];
$this->pendingOutgoingGauge = $this->API->getPromGauge("MadelineProto", "pending_outgoing_mtproto_messages", "Number of not-yet sent outgoing MTProto messages", $labels); $this->pendingOutgoingGauge = $this->API->getPromGauge("MadelineProto", "pending_outgoing_mtproto_messages", "Number of not-yet sent outgoing MTProto messages", $labels);
$this->inFlightGauge = $this->API->getPromGauge("MadelineProto", "inflight_requests", "Number of in-flight requests", $labels);
$this->incomingCtr = $this->API->getPromCounter("MadelineProto", "incoming_mtproto_messages", "Number of received MTProto messages", $labels); $this->incomingCtr = $this->API->getPromCounter("MadelineProto", "incoming_mtproto_messages", "Number of received MTProto messages", $labels);
$this->outgoingCtr = $this->API->getPromCounter("MadelineProto", "outgoing_mtproto_messages", "Number of sent MTProto messages", $labels); $this->outgoingCtr = $this->API->getPromCounter("MadelineProto", "outgoing_mtproto_messages", "Number of sent MTProto messages", $labels);
$this->incomingBytesCtr = $this->API->getPromCounter("MadelineProto", "incoming_bytes", "Number of received bytes", $labels); $this->incomingBytesCtr = $this->API->getPromCounter("MadelineProto", "incoming_bytes", "Number of received bytes", $labels);
$this->outgoingBytesCtr = $this->API->getPromCounter("MadelineProto", "outgoing_bytes", "Number of sent bytes", $labels); $this->outgoingBytesCtr = $this->API->getPromCounter("MadelineProto", "outgoing_bytes", "Number of sent bytes", $labels);
$this->requestResponse = $this->API->getPromCounter("MadelineProto", "request_responses", "Received RPC error or success status of requests by method.", $labels); $this->requestResponse = $this->API->getPromCounter("MadelineProto", "request_responses", "Received RPC error or success status of requests by method.", $labels);
$this->requestLatencies = $this->API->getPromHistogram("MadelineProto", "request_latencies", "Request latency by method", $labels); $this->requestLatencies = $this->API->getPromHistogram(
"MadelineProto",
"request_latencies",
"Request latency in nanoseconds by method",
$labels,
[
5_000_000,
10_000_000,
25_000_000,
50_000_000,
75_000_000,
100_000_000,
250_000_000,
500_000_000,
750_000_000,
1000_000_000,
2500_000_000,
5000_000_000,
7500_000_000,
10000_000_000,
]
);
if ($this->session_id === null) { if ($this->session_id === null) {
$this->resetSession("creating initial session"); $this->resetSession("creating initial session");
} }