Skip to content

Commit 0129c78

Browse files
Move default timeouts from request to client configuration. (#9)
The current implementation does not allow the configuration of custom timeouts since they are set to 20s/10s for each request. Passing in a custom client with specified timeouts does not change the timeout since they are overridden. In some scenarios, it is desirable to have shorter timeouts to avoid stalling the processing of requests/jobs. This change should not modify the library's default behaviour but move the timeouts into the client configuration to allow the customization of the values by providing a different instance of the Guzzle client. Signed-off-by: Claude Vessaz <claude.vessaz@hootsuite.com>
1 parent 90a23da commit 0129c78

File tree

1 file changed

+1
-3
lines changed

1 file changed

+1
-3
lines changed

src/PrometheusPushGateway/PushGateway.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class PushGateway
3434
public function __construct(string $address, ?ClientInterface $client = null)
3535
{
3636
$this->address = strpos($address, 'http') === false ? 'http://' . $address : $address;
37-
$this->client = $client ?? new Client();
37+
$this->client = $client ?? new Client(['connect_timeout' => 10, 'timeout' => 20]);
3838
}
3939

4040
/**
@@ -95,8 +95,6 @@ private function doRequest(?CollectorRegistry $collectorRegistry, string $job, a
9595
'headers' => [
9696
'Content-Type' => RenderTextFormat::MIME_TYPE,
9797
],
98-
'connect_timeout' => 10,
99-
'timeout' => 20,
10098
];
10199

102100
if ($method !== self::HTTP_DELETE && $collectorRegistry !== null) {

0 commit comments

Comments
 (0)