mirror of
https://github.com/nextcloud/server.git
synced 2026-04-15 22:11:17 -04:00
perf: log slow DNS operations
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
This commit is contained in:
parent
cc89a2a2b8
commit
adf7ea5f0b
3 changed files with 14 additions and 5 deletions
|
|
@ -8,15 +8,20 @@ declare(strict_types=1);
|
|||
*/
|
||||
namespace OC\Http\Client;
|
||||
|
||||
use OC\Diagnostics\TLogSlowOperation;
|
||||
use OC\Net\IpAddressClassifier;
|
||||
use OCP\Http\Client\LocalServerException;
|
||||
use Psr\Http\Message\RequestInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class DnsPinMiddleware {
|
||||
|
||||
use TLogSlowOperation;
|
||||
|
||||
public function __construct(
|
||||
private NegativeDnsCache $negativeDnsCache,
|
||||
private IpAddressClassifier $ipAddressClassifier,
|
||||
private LoggerInterface $logger,
|
||||
) {
|
||||
}
|
||||
|
||||
|
|
@ -88,7 +93,11 @@ class DnsPinMiddleware {
|
|||
* Wrapper for dns_get_record
|
||||
*/
|
||||
protected function dnsGetRecord(string $hostname, int $type): array|false {
|
||||
return \dns_get_record($hostname, $type);
|
||||
return $this->monitorAndLog(
|
||||
$this->logger,
|
||||
'dns_get_record',
|
||||
fn () => \dns_get_record($hostname, $type),
|
||||
);
|
||||
}
|
||||
|
||||
public function addDnsPinning(): callable {
|
||||
|
|
|
|||
|
|
@ -12,11 +12,9 @@ namespace OC\Session;
|
|||
use OC\Authentication\Token\IProvider;
|
||||
use OC\Diagnostics\TLogSlowOperation;
|
||||
use OCP\Authentication\Exceptions\InvalidTokenException;
|
||||
use OCP\ILogger;
|
||||
use OCP\Session\Exceptions\SessionNotAvailableException;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use function call_user_func_array;
|
||||
use function microtime;
|
||||
|
||||
/**
|
||||
* Class Internal
|
||||
|
|
@ -198,7 +196,7 @@ class Internal extends Session {
|
|||
return $this->monitorAndLog(
|
||||
$this->logger,
|
||||
$functionName,
|
||||
function () use ($silence, $functionName, $parameters){
|
||||
function () use ($silence, $functionName, $parameters) {
|
||||
if ($silence) {
|
||||
return @call_user_func_array($functionName, $parameters);
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ use OC\Net\IpAddressClassifier;
|
|||
use OCP\Http\Client\LocalServerException;
|
||||
use OCP\ICacheFactory;
|
||||
use Psr\Http\Message\RequestInterface;
|
||||
use Psr\Log\NullLogger;
|
||||
use Test\TestCase;
|
||||
|
||||
class DnsPinMiddlewareTest extends TestCase {
|
||||
|
|
@ -35,9 +36,10 @@ class DnsPinMiddlewareTest extends TestCase {
|
|||
|
||||
$ipAddressClassifier = new IpAddressClassifier();
|
||||
$negativeDnsCache = new NegativeDnsCache($cacheFactory);
|
||||
$logger = new NullLogger();
|
||||
|
||||
$this->dnsPinMiddleware = $this->getMockBuilder(DnsPinMiddleware::class)
|
||||
->setConstructorArgs([$negativeDnsCache, $ipAddressClassifier])
|
||||
->setConstructorArgs([$negativeDnsCache, $ipAddressClassifier, $logger])
|
||||
->onlyMethods(['dnsGetRecord'])
|
||||
->getMock();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue