Skip to content
This repository was archived by the owner on Sep 19, 2022. It is now read-only.

Commit b8141c8

Browse files
committed
Merge pull request #95 from pajavyskocil/responseTime
Fix logging request params
1 parent ff0af12 commit b8141c8

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
All notable changes to this project will be documented in this file.
33

44
## [Unreleased]
5+
#### Added
6+
- Added logging response time for each request into RPC/LDAP
7+
8+
#### Fixed
9+
- Fix logging request params
510

611
## [v3.7.3]
712
#### Fixed

lib/LdapConnector.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,11 @@ protected function search($base, $filter, $attributes = null)
116116
Logger::debug('sspmod_perun_LdapConnector.search - Connection to Perun LDAP established. ' .
117117
'Ready to perform search query. host: ' . $this->hostname . ', user: ' . $this->user);
118118

119+
$startTime = microtime(true);
119120
$result = ldap_search($conn, $base, $filter, $attributes);
121+
$endTime = microtime(true);
122+
123+
$responseTime = round(($endTime - $startTime) * 1000, 3);
120124

121125
// no such entity
122126
if (ldap_errno($conn) === 2) {
@@ -127,8 +131,8 @@ protected function search($base, $filter, $attributes = null)
127131

128132
ldap_close($conn);
129133

130-
Logger::debug('sspmod_perun_LdapConnector.search - search query proceeded. ' .
131-
'query base: ' . $base . ', filter: ' . $filter . ', response: ' . var_export($entries, true));
134+
Logger::debug('sspmod_perun_LdapConnector.search - search query proceeded in ' . $responseTime . 'ms. ' .
135+
'Query base: ' . $base . ', filter: ' . $filter . ', response: ' . var_export($entries, true));
132136

133137
return $entries;
134138
}

lib/RpcConnector.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,21 @@ public function get($manager, $method, $params = [])
6666
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, self::CONNECT_TIMEOUT);
6767
curl_setopt($ch, CURLOPT_TIMEOUT, self::TIMEOUT);
6868

69+
$startTime = microtime(true);
6970
$json = curl_exec($ch);
71+
$endTime = microtime(true);
7072
curl_close($ch);
7173

72-
Logger::debug('perun.RPC: GET call $uri with params: ' . $paramsQuery . ', response: ' . $json);
74+
$responseTime = round($endTime - $startTime, 3);
75+
Logger::debug('perun.RPC: GET call ' . $uri . ' with params: ' . $paramsQuery . ', response : ' .
76+
$json . ' in: ' . $responseTime . 's.');
7377

7478
$result = json_decode($json, true);
7579

7680
if (json_last_error() !== JSON_ERROR_NONE) {
7781
throw new Exception(
78-
'Cant\'t decode response from Perun. Call: $uri, Params: $paramsQuery, Response: $json'
82+
'Cant\'t decode response from Perun. Call: ' . $uri . ', Params: ' . $paramsQuery .
83+
', Response: ' . $json
7984
);
8085
}
8186
if (isset($result['errorId'])) {
@@ -107,17 +112,22 @@ public function post($manager, $method, $params = [])
107112
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, self::CONNECT_TIMEOUT);
108113
curl_setopt($ch, CURLOPT_TIMEOUT, self::TIMEOUT);
109114

115+
$startTime = microtime(true);
110116
$json = curl_exec($ch);
117+
$endTime = microtime(true);
111118
curl_close($ch);
112119

113-
Logger::debug('perun.RPC: POST call $uri with params: ' . $paramsJson . ', response: ' . $json);
120+
$responseTime = round($endTime - $startTime, 3);
121+
Logger::debug('perun.RPC: POST call ' . $uri . ' with params: ' . $paramsJson . ', response : ' .
122+
$json . ' in: ' . $responseTime . 's.');
114123

115124
$result = json_decode($json, true);
116125

117126

118127
if (json_last_error() !== JSON_ERROR_NONE) {
119128
throw new Exception(
120-
'Cant\'t decode response from Perun. Call: $uri, Params: $paramsJson, Response: $json'
129+
'Cant\'t decode response from Perun. Call: ' . $uri . ', Params: ' . $paramsJson .
130+
', Response: ' . $json
121131
);
122132
}
123133
if (isset($result['errorId'])) {

0 commit comments

Comments
 (0)