Skip to content

Commit 097759e

Browse files
author
Илья
committed
Update logs
1 parent 362fd7b commit 097759e

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

src/Auth/IamAuth.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ abstract class IamAuth extends Auth
1313
*/
1414
public function requestToken($request_data)
1515
{
16-
$this->logger()->info('YDB: Obtaining new IAM token...');
16+
$this->logger()->debug('YDB: Request new IAM token...');
17+
$startTime = microtime(true);
1718

1819
$curl = curl_init(Iam::IAM_TOKEN_API_URL);
1920

@@ -33,6 +34,8 @@ public function requestToken($request_data)
3334

3435
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
3536

37+
$this->logger->debug("YDB: Received IAM response in ".((microtime(true)-$startTime)*1000)." miliseconds");
38+
3639
if ($status === 200) {
3740
$token = json_decode($result);
3841

src/Iam.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public function token($force = false)
9696
*/
9797
public function newToken()
9898
{
99-
$this->logger()->info('YDB: Obtaining new IAM token...');
99+
$this->logger()->debug('YDB: Obtaining new token...');
100100

101101
$tokenInfo = $this->config('credentials')->getTokenInfo();
102102
$this->iam_token = $tokenInfo->getToken();
@@ -383,7 +383,7 @@ protected function loadTokenFromFile()
383383
$this->iam_token = $token->iamToken;
384384
$this->expires_at = $token->expiresAt;
385385
$this->refresh_at = $token->refreshAt ?? time();
386-
$this->logger()->info('YDB: Reused IAM token [...' . substr($this->iam_token, -6) . '].');
386+
$this->logger()->debug('YDB: Reused token [...' . substr($this->iam_token, -6) . '].');
387387
return $token->iamToken;
388388
}
389389
}

src/Retry/Retry.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,22 +77,26 @@ public function retry(Closure $closure, bool $idempotent)
7777
$startTime = microtime(true);
7878
$retryCount = 0;
7979
$lastException = null;
80-
while (microtime(true) < $startTime + $this->timeoutMs / 1000) {
80+
$deadline = is_null($this->timeoutMs) ? PHP_INT_MAX : $startTime + $this->timeoutMs / 1000;
81+
$this->logger->debug("YDB: begin retry function. Deadline: $deadline");
82+
do {
8183
$this->logger->debug("YDB: Run user function. Retry count: $retryCount. s: ".(microtime(true) - $startTime));
8284
try {
8385
return $closure();
84-
} catch (Exception $e) {
85-
$this->logger->warning("YDB: Received exception: ".$e->getMessage());
86+
} catch (\Exception $e) {
87+
$this->logger->debug("YDB: Received exception: ".$e->getMessage());
88+
$lastException = $e;
8689
if (!$this->canRetry($e, $idempotent)){
87-
$lastException = $e;
8890
break;
8991
}
9092
$retryCount++;
91-
$lastException = $e;
9293
$delay = $this->retryDelay($retryCount, $this->backoffType(get_class($e)))*1000;
94+
$this->logger->debug("YDB: Sleep $delay microseconds before retry");
9395
usleep($delay);
9496
}
95-
}
97+
} while (microtime(true) < $deadline);
98+
$this->logger->error("YDB: Timeout retry function. ms: "
99+
.((microtime(true)-$startTime)*1000). "Retry count: $retryCount");
96100
throw $lastException;
97101
}
98102

@@ -111,7 +115,7 @@ protected function alwaysRetry(string $exception)
111115
return in_array($exception, self::$alwaysRetry);
112116
}
113117

114-
protected function canRetry(Exception $e, bool $idempotent)
118+
protected function canRetry(\Exception $e, bool $idempotent)
115119
{
116120
return is_a($e, RetryableException::class) && ($this->alwaysRetry(get_class($e)) || $idempotent);
117121
}

0 commit comments

Comments
 (0)