Better error handling in Proxy Resolver.

This commit is contained in:
Pavel Kovalenko 2020-05-20 19:01:05 +03:00 committed by Pavel Kovalenko
parent 138154ba6a
commit d98c1589ed
4 changed files with 14 additions and 6 deletions

View File

@ -7,6 +7,11 @@
#include <Poco/Net/HTTPResponse.h> #include <Poco/Net/HTTPResponse.h>
#include <common/logger_useful.h> #include <common/logger_useful.h>
namespace DB::ErrorCodes
{
extern const int BAD_ARGUMENTS;
}
namespace DB::S3 namespace DB::S3
{ {
ProxyResolverConfiguration::ProxyResolverConfiguration(const Poco::URI & endpoint_, String proxy_scheme_, unsigned proxy_port_) ProxyResolverConfiguration::ProxyResolverConfiguration(const Poco::URI & endpoint_, String proxy_scheme_, unsigned proxy_port_)
@ -30,13 +35,16 @@ Aws::Client::ClientConfigurationPerRequest ProxyResolverConfiguration::getConfig
Aws::Client::ClientConfigurationPerRequest cfg; Aws::Client::ClientConfigurationPerRequest cfg;
try try
{ {
/// It should be just empty GET / request. /// It should be just empty GET request.
Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_1_1); Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, endpoint.getPath(), Poco::Net::HTTPRequest::HTTP_1_1);
session->sendRequest(request); session->sendRequest(request);
Poco::Net::HTTPResponse response; Poco::Net::HTTPResponse response;
auto & response_body_stream = session->receiveResponse(response); auto & response_body_stream = session->receiveResponse(response);
if (response.getStatus() != Poco::Net::HTTPResponse::HTTP_OK)
throw Exception("Proxy resolver returned not OK status: " + response.getReason(), ErrorCodes::BAD_ARGUMENTS);
String proxy_host; String proxy_host;
/// Read proxy host as string from response body. /// Read proxy host as string from response body.
Poco::StreamCopier::copyToString(response_body_stream, proxy_host); Poco::StreamCopier::copyToString(response_body_stream, proxy_host);

View File

@ -6,7 +6,7 @@ namespace DB::S3
{ {
/** /**
* Proxy configuration where proxy host is obtained each time from specified endpoint. * Proxy configuration where proxy host is obtained each time from specified endpoint.
* For each request to S3 it makes GET request to specified endpoint and reads proxy host from a response body. * For each request to S3 it makes GET request to specified endpoint URL and reads proxy host from a response body.
* Specified scheme and port added to obtained proxy host to form completed proxy URL. * Specified scheme and port added to obtained proxy host to form completed proxy URL.
*/ */
class ProxyResolverConfiguration : public ProxyConfiguration class ProxyResolverConfiguration : public ProxyConfiguration

View File

@ -18,12 +18,12 @@
<secret_access_key>minio123</secret_access_key> <secret_access_key>minio123</secret_access_key>
<proxy> <proxy>
<!-- <!--
At each interaction with S3 resolver sends empty GET / request to specified endpoint to obtain proxy host. At each interaction with S3 resolver sends empty GET request to specified endpoint URL to obtain proxy host.
Proxy host is returned as string in response body. Proxy host is returned as string in response body.
Then S3 client uses proxy URL formed as proxy_scheme://proxy_host:proxy_port to make request. Then S3 client uses proxy URL formed as proxy_scheme://proxy_host:proxy_port to make request.
--> -->
<resolver> <resolver>
<endpoint>http://resolver:8080</endpoint> <endpoint>http://resolver:8080/hostname</endpoint>
<proxy_scheme>http</proxy_scheme> <proxy_scheme>http</proxy_scheme>
<proxy_port>8888</proxy_port> <proxy_port>8888</proxy_port>
</resolver> </resolver>

View File

@ -2,7 +2,7 @@ import bottle
import random import random
@bottle.route('/') @bottle.route('/hostname')
def index(): def index():
if random.randrange(2) == 0: if random.randrange(2) == 0:
return 'proxy1' return 'proxy1'