Skip to content

Commit

Permalink
Move default timeouts from request to client configuration. (#9)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
claude-vessaz-hs committed Apr 11, 2022
1 parent 90a23da commit 0129c78
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions src/PrometheusPushGateway/PushGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class PushGateway
public function __construct(string $address, ?ClientInterface $client = null)
{
$this->address = strpos($address, 'http') === false ? 'http://' . $address : $address;
$this->client = $client ?? new Client();
$this->client = $client ?? new Client(['connect_timeout' => 10, 'timeout' => 20]);
}

/**
Expand Down Expand Up @@ -95,8 +95,6 @@ private function doRequest(?CollectorRegistry $collectorRegistry, string $job, a
'headers' => [
'Content-Type' => RenderTextFormat::MIME_TYPE,
],
'connect_timeout' => 10,
'timeout' => 20,
];

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

0 comments on commit 0129c78

Please sign in to comment.